mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 02:06:36 +02:00
* Flatten everything and succeed build * Figure out Settings assets * Remove UseCommonOutputDirectory tag * Proper settings app path * [VCM] Fix assets location * Fix some runtime paths * [RegistryPreview]Use MRTCore specific pri file * [Hosts]Use MRTCore specific pri file * [Settings]Use MRTCore specific pri file * [Peek]Use MRTCore specific pri file * [FileLocksmith]Use MRTCore specific pri file * [ScreenRuler]Use MRTCore specific pri file * [PowerRename]Use MRTCore specific pri file * [Peek]Move assets to own folder * [FileLocksmith] Use own Assets path * [Hosts]Use own assets folder * [PowerRename]Use own assets dir * [MeasureTool] Use its own assets folder * [ImageResizer]Use its own assets path * Fix spellcheck * Fix tab instead of space in project files * Normalize target frameworks and platforms * Remove WINRT_NO_MAKE_DETECTION flag. No longer needed? * Fix AOT and Hosts locations * Fix Dll version differences on dependency * Add Common.UI.csproj as refernce to fix dll versions * Update ControlzEx to normalize dll versions * Update System.Management version to 7.0.2 * Add GPOWrapper to Registry Preview to fix dll versions * [PTRun]Reference Microsoft.Extensions.Hosting to fix dll versions * Fix remaining output paths / dll version conflicts * [KeyboardManager]Executables still on their own directories * Fix Monaco paths * WinAppSDK apps get to play outside again * Enable VCM settings again * Fix KBM Editor path again * [Monaco]Set to own Assets dir * Fix installer preamble; Fix publish. remove unneeded publishes * Remove Hardlink functions * Installer builds again (still needs work to work) * Readd Monaco to spellcheck excludes * Fix spellcheck and call publish.cmd again * [Installer] Remove components that don't need own dirs * [Installer] Refactor Power Launcher * [Installer] Refactor Color Picker * [Installer] Refactor Monaco assets * [Installer]Generate File script no longer needs to remove files * [Installer]Refactor FileLocksmith * [Installer] Refactor Hosts * [Installer]Refactor Image Resizer * [Installer]Refactor MouseUtils * [Installer]Refactor MWB * [Installer]Refactor MeasureTool * [Installer]Refactor Peek * [Installer]Refactor PowerRename and registry fixes * [Installer]Refactor RegistryPreview * [Installer]Refactor ShortcutGuide * [Installer]Refactor Settings * [Installer]Clean up some unused stuff * [Installer]Clean up stuff for user install * [Installer]Fix WinUi3Apps wxs * [Installer]Fix misplaced folders * [Installer]Move x86 VCM dll to right path * Fix monaco language list location * [Installer]Fix VCM directory reference * [CI]Fix signing * [Installer] Fix resources folder for release CI * [ci]Looks like we still ship NLog on PowerToys Run * [Settings]Add dependency to avoid dll collision with Experimentation * [RegistryPreview]Move XAML files to own path * [RegistryPreview]Fix app icon * [Hosts]Move XAML files to their own path * [FileLocksmith]Move XAML files to their own path * [Peek]Move XAML files to own path * [ScreenRuler]Move XAML files to its own path * [Settings]Move XAML to its own path * [ColorPicker]Move Resources to Assets * [ShortcutGuide]Move svgs to own Assets path * [Awake]Move images to assets path * [Runner]Remove debug checks for PowerToys Run assets * [PTRun]Move images to its own assets path * [ImageResizer]Icon for context menu on own assets path * [PowerRename]Move ico to its own path * Remove unneeded intermediary directories * Remove further int dirs * Move tests to its own output path * Fix spellcheck * spellcheck: remove warnings * [CppAnalyzers]Ignore rule in a tool * [CI]Check if all deps.json files reference same versions * fix spellcheck * [ci]Fix task identation * [ci]Add script to guard against asset conflicts * [ci]Add more deps.json audit steps in the release build * Add xbf to spellcheck expects * Fix typo in asset conflict check scripts * Fix some more dependency conflicts * Downgrade CsWinRT to have the same dll version as sdk * [ci]Do a recursive check for every deps.json * Fix spellcheck error inside comment * [ci]Fix asset script error * [ci]Name deps.json verify tasks a bit better * [ci]Improve deps json verify script output * [ci]Update WinRT version to the same running in CI * Also upgrade CsWinRT in NOTICE.MD * [PowerRename]Move XAML files to own path * [Common]Fix Settings executable path * [ci]Verify there's no xbf files in app directories * [installer]Fix firewall path * [Monaco]Move new files to their proper assets path * [Monaco]Fix paths for new files after merge * [Feedback]Removed unneeded build conditions * [Feedback]Clear vcxproj direct reference to frameworks * [Feedback]RunPlugins name to hold PTRun plugins * [Feedback]Remove unneeded foreach * [Feedback]Shortcut Guide svgs with ** in project file * [Feedback]Fix spellcheck
160 lines
5.1 KiB
C#
160 lines
5.1 KiB
C#
// 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.IO;
|
|
using System.IO.Abstractions;
|
|
using System.Linq;
|
|
using System.Net.NetworkInformation;
|
|
using System.Security.Principal;
|
|
using Microsoft.PowerToys.Settings.UI.Library.CustomAction;
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
|
|
{
|
|
public static class Helper
|
|
{
|
|
public static readonly IFileSystem FileSystem = new FileSystem();
|
|
|
|
public static string UserLocalAppDataPath { get; set; } = string.Empty;
|
|
|
|
public static bool AllowRunnerToForeground()
|
|
{
|
|
var result = false;
|
|
var processes = Process.GetProcessesByName("PowerToys");
|
|
if (processes.Length > 0)
|
|
{
|
|
var pid = processes[0].Id;
|
|
result = NativeMethods.AllowSetForegroundWindow(pid);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public static string GetSerializedCustomAction(string moduleName, string actionName, string actionValue)
|
|
{
|
|
var customAction = new CustomActionDataModel
|
|
{
|
|
Name = actionName,
|
|
Value = actionValue,
|
|
};
|
|
|
|
var moduleCustomAction = new ModuleCustomAction
|
|
{
|
|
ModuleAction = customAction,
|
|
};
|
|
|
|
var sendCustomAction = new SendCustomAction(moduleName)
|
|
{
|
|
Action = moduleCustomAction,
|
|
};
|
|
|
|
return sendCustomAction.ToJsonString();
|
|
}
|
|
|
|
public static IFileSystemWatcher GetFileWatcher(string moduleName, string fileName, Action onChangedCallback)
|
|
{
|
|
var path = FileSystem.Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{moduleName}");
|
|
|
|
if (!FileSystem.Directory.Exists(path))
|
|
{
|
|
FileSystem.Directory.CreateDirectory(path);
|
|
}
|
|
|
|
var watcher = FileSystem.FileSystemWatcher.CreateNew();
|
|
watcher.Path = path;
|
|
watcher.Filter = fileName;
|
|
watcher.NotifyFilter = NotifyFilters.LastWrite;
|
|
watcher.EnableRaisingEvents = true;
|
|
|
|
watcher.Changed += (o, e) => onChangedCallback();
|
|
|
|
return watcher;
|
|
}
|
|
|
|
public static string LocalApplicationDataFolder()
|
|
{
|
|
WindowsIdentity currentUser = WindowsIdentity.GetCurrent();
|
|
SecurityIdentifier currentUserSID = currentUser.User;
|
|
|
|
SecurityIdentifier localSystemSID = new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null);
|
|
if (currentUserSID.Equals(localSystemSID) && UserLocalAppDataPath != string.Empty)
|
|
{
|
|
return UserLocalAppDataPath;
|
|
}
|
|
else
|
|
{
|
|
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
}
|
|
}
|
|
|
|
public static string GetPowerToysInstallationFolder()
|
|
{
|
|
// PowerToys.exe is in the parent folder relative to Settings.
|
|
var settingsPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
|
return Directory.GetParent(settingsPath).FullName;
|
|
}
|
|
|
|
private static readonly interop.LayoutMapManaged LayoutMap = new interop.LayoutMapManaged();
|
|
|
|
public static string GetKeyName(uint key)
|
|
{
|
|
return LayoutMap.GetKeyName(key);
|
|
}
|
|
|
|
public static string GetProductVersion()
|
|
{
|
|
return interop.CommonManaged.GetProductVersion();
|
|
}
|
|
|
|
public static int CompareVersions(string version1, string version2)
|
|
{
|
|
try
|
|
{
|
|
// Split up the version strings into int[]
|
|
// Example: v10.0.2 -> {10, 0, 2};
|
|
if (version1 == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(version1));
|
|
}
|
|
else if (version2 == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(version2));
|
|
}
|
|
|
|
var v1 = version1.Substring(1).Split('.').Select(int.Parse).ToArray();
|
|
var v2 = version2.Substring(1).Split('.').Select(int.Parse).ToArray();
|
|
|
|
if (v1.Length != 3 || v2.Length != 3)
|
|
{
|
|
throw new FormatException();
|
|
}
|
|
|
|
if (v1[0] - v2[0] != 0)
|
|
{
|
|
return v1[0] - v2[0];
|
|
}
|
|
|
|
if (v1[1] - v2[1] != 0)
|
|
{
|
|
return v1[1] - v2[1];
|
|
}
|
|
|
|
return v1[2] - v2[2];
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw new FormatException("Bad product version format");
|
|
}
|
|
}
|
|
|
|
public const uint VirtualKeyWindows = interop.Constants.VK_WIN_BOTH;
|
|
|
|
public static bool Windows11()
|
|
{
|
|
return Environment.OSVersion.Version.Major >= 10 && Environment.OSVersion.Version.Build >= 22000;
|
|
}
|
|
}
|
|
}
|