mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
[Registry Preview] Adds application to Open with list for REG files (#26033)
* 25834 * Asociate Registry Preview with .reg files * Add setting for making RP default app for .reg files * Run spellcheck * Run spellcheck again * Fix build --------- Co-authored-by: Stefan Markovic <stefan@janeasystems.com>
This commit is contained in:
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.Windows.AppLifecycle;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using LaunchActivatedEventArgs = Windows.ApplicationModel.Activation.LaunchActivatedEventArgs;
|
||||
|
||||
@@ -31,23 +32,47 @@ namespace RegistryPreview
|
||||
/// <param name="args">Details about the launch request and process.</param>
|
||||
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)
|
||||
// Keeping commented out but this is invaluable for protocol activation testing.
|
||||
// #if DEBUG
|
||||
// System.Diagnostics.Debugger.Launch();
|
||||
// #endif
|
||||
|
||||
// Open With... handler - gets activation arguments if they are available.
|
||||
AppActivationArguments activatedArgs = AppInstance.GetCurrent().GetActivatedEventArgs();
|
||||
if (activatedArgs.Kind == ExtendedActivationKind.File)
|
||||
{
|
||||
// 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];
|
||||
if (activatedArgs.Data != null)
|
||||
{
|
||||
IFileActivatedEventArgs eventArgs = (IFileActivatedEventArgs)activatedArgs.Data;
|
||||
if (eventArgs.Files.Count > 0)
|
||||
{
|
||||
AppFilename = eventArgs.Files[0].Path;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Anything else should be treated as no file loaded
|
||||
AppFilename = string.Empty;
|
||||
// Right click on a REG file and selected Preview
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user