// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Microsoft.UI.Xaml;
using Windows.ApplicationModel.Activation;
using LaunchActivatedEventArgs = Windows.ApplicationModel.Activation.LaunchActivatedEventArgs;
namespace RegistryPreview
{
///
/// Provides application-specific behavior to supplement the default Application class.
///
public partial class App : Application
{
///
/// Initializes a new instance of the class.
///
public App()
{
this.InitializeComponent();
}
///
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
///
/// Details about the launch request and process.
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
// Grab the command line parameters directly from the Environment since this is expected to be run
// via Context Menu of a REG file.
string[] cmdArgs = Environment.GetCommandLineArgs();
if (cmdArgs == null)
{
// Covers the double click exe scenario and treated as no file loaded
AppFilename = string.Empty;
}
else if (cmdArgs.Length == 2)
{
// GetCommandLineArgs() send in the called EXE as 0 and the selected filename as 1
AppFilename = cmdArgs[1];
}
else
{
// Anything else should be treated as no file loaded
AppFilename = string.Empty;
}
// Start the application
appWindow = new MainWindow();
appWindow.Activate();
}
private Window appWindow;
#pragma warning disable SA1401 // Fields should be private
#pragma warning disable CA2211 // Non-constant fields should not be visible. TODO: consider making it a property
public static string AppFilename;
#pragma warning restore CA2211 // Non-constant fields should not be visible
#pragma warning restore SA1401 // Fields should be private
}
}