XFEstudio/HaloPixelToolBox
重命名应用标识并加入迁移与发布调整
将应用标识从 HaloPixelToolBox.Client 统一迁移为 HaloPixelToolBox(AssemblyName、RootNamespace、XAML Title、manifest 显示名等);在 App 构造中调用 ApplicationIdentityMigration.Run(),新增 ApplicationIdentityMigration 用于迁移旧 LocalAppData 目录与注册表自启项并删除旧自启键,确保旧用户数据与自启设置平滑过渡。 引入 SystemProfile 常量(ApplicationName、ApplicationExecutableName、LegacyApplicationName),并调整 InstallPath 默认值;在 Installer 端统一使用 SystemProfile.ApplicationName 并增加对旧客户端残留的清理(CleanupLegacyClientArtifacts),InstallProgressPage 新增 CreateApplicationShortcut(),改用 using(File.OpenRead) 并改进异常与文件存在检查、路径规范化与安全判断。 调整升级启动逻辑:UpgradeHelper.StartUpdate 以安装器位于 AppContext.BaseDirectory 为启动路径并传递安装目录参数;安装流程中将创建快捷方式逻辑抽成方法并改进健壮性。 修改 SettingPageViewModel 中自动启动注册默认名称为 HaloPixelToolBox;修正若干 XAML 布局与窗口标题小改动;多个项目的 PublishProfile 从 win-$(Platform).pubxml 切换/新增为 FolderProfile.pubxml,新增相应 pubxml 文件并在 HaloPixelToolBox.Installer.csproj 引用,同时移除不必要包;更新 .gitignore 发布配置规则。 总体目标:把发布产物与运行时标识统一为 HaloPixelToolBox,保证升级/安装时的数据、自启与快捷方式不丢失或重复,并简化发布流程。
5bd2eb8
代码差异
@@ -364,3 +364,7 @@ FodyWeavers.xsd
/HaloPixelToolBox.Installer.Package/Source.zip
/HaloPixelToolBox.Installer/Resources/Resource/Source.zip
/Client/HaloPixelToolBox.Installer/Resources/Resource/Source.zip
# Shared, credential-free publish profiles used by the client packaging workflow.
!Client/HaloPixelToolBox.Client/Properties/PublishProfiles/FolderProfile.pubxml
!Client/HaloPixelToolBox.Installer/Properties/PublishProfiles/FolderProfile.pubxml
@@ -29,6 +29,7 @@ public partial class App : Application
/// </summary>
public App()
{
ApplicationIdentityMigration.Run();
var keyInstance = AppInstance.FindOrRegisterForKey("MainInstance");
if (!keyInstance.IsCurrent)
{
@@ -1,12 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<AssemblyName>HaloPixelToolBox</AssemblyName>
<RootNamespace>HaloPixelToolBox.Client</RootNamespace>
<TargetFramework>net10.0-windows10.0.22621.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;ARM64</Platforms>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
<PublishProfile>FolderProfile.pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<Version>1.3.0</Version>
<EnableMsixTooling>true</EnableMsixTooling>
@@ -7,7 +7,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="HaloPixelToolBox.Client">
Title="HaloPixelToolBox">
<Window.SystemBackdrop>
<MicaBackdrop />
</Window.SystemBackdrop>
@@ -15,7 +15,7 @@
<mp:PhoneIdentity PhoneProductId="449a555a-b6b8-44b1-9b17-592898649b32" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>XFEApplication</DisplayName>
<DisplayName>HaloPixelToolBox</DisplayName>
<PublisherDisplayName>XFEstudio</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
@@ -34,8 +34,8 @@
Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="$ext_specifiedsolutionname$"
Description="$ext_specifiedsolutionname$"
DisplayName="HaloPixelToolBox"
Description="HaloPixelToolBox"
BackgroundColor="transparent"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png">
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>x64</Platform>
<PublishDir>bin\win-x64\Release\net10.0-windows10.0.22621.0\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net10.0-windows10.0.22621.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>
</Project>
@@ -0,0 +1,76 @@
using System.Diagnostics;
using Microsoft.Win32;
namespace HaloPixelToolBox.Client.Utilities;
/// <summary>
/// 在发布产物由 HaloPixelToolBox.Client 更名后保留用户数据和自启动配置。
/// </summary>
public static class ApplicationIdentityMigration
{
private const string ApplicationName = "HaloPixelToolBox";
private const string LegacyApplicationName = "HaloPixelToolBox.Client";
public static void Run()
{
CopyLegacyAppData();
MigrateAutoStartRegistration();
}
private static void CopyLegacyAppData()
{
try
{
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var legacyRoot = Path.GetFullPath(Path.Combine(localAppData, LegacyApplicationName));
var currentRoot = Path.GetFullPath(Path.Combine(localAppData, ApplicationName));
if (!Directory.Exists(legacyRoot) || string.Equals(legacyRoot, currentRoot, StringComparison.OrdinalIgnoreCase))
return;
Directory.CreateDirectory(currentRoot);
foreach (var sourcePath in Directory.EnumerateFiles(legacyRoot, "*", SearchOption.AllDirectories))
{
try
{
var relativePath = Path.GetRelativePath(legacyRoot, sourcePath);
var destinationPath = Path.GetFullPath(Path.Combine(currentRoot, relativePath));
if (!destinationPath.StartsWith(currentRoot + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase) ||
File.Exists(destinationPath))
continue;
var destinationDirectory = Path.GetDirectoryName(destinationPath);
if (!string.IsNullOrEmpty(destinationDirectory))
Directory.CreateDirectory(destinationDirectory);
File.Copy(sourcePath, destinationPath);
}
catch (Exception ex)
{
Debug.WriteLine($"无法迁移旧应用数据文件 {sourcePath}:{ex.Message}");
}
}
}
catch (Exception ex)
{
Debug.WriteLine($"无法迁移旧应用数据:{ex.Message}");
}
}
private static void MigrateAutoStartRegistration()
{
try
{
const string runKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
using var key = Registry.CurrentUser.OpenSubKey(runKey, true);
if (key?.GetValue(LegacyApplicationName) is null)
return;
if (key.GetValue(ApplicationName) is null && !string.IsNullOrWhiteSpace(Environment.ProcessPath))
key.SetValue(ApplicationName, $"\"{Environment.ProcessPath}\"");
key.DeleteValue(LegacyApplicationName, false);
}
catch (Exception ex)
{
Debug.WriteLine($"无法迁移旧自启动配置:{ex.Message}");
}
}
}
@@ -52,16 +52,17 @@ public static class UpgradeHelper
/// </summary>
public static void StartUpdate(string downloadUrl)
{
var startInfo = new ProcessStartInfo("Installer.exe")
var installDirectory = AppContext.BaseDirectory;
var startInfo = new ProcessStartInfo(Path.Combine(installDirectory, "Installer.exe"))
{
UseShellExecute = true,
Verb = "runas"
};
startInfo.ArgumentList.Add("Upgrade");
startInfo.ArgumentList.Add(downloadUrl);
startInfo.ArgumentList.Add("");
startInfo.ArgumentList.Add(installDirectory);
Process.Start(startInfo);
Process.GetCurrentProcess().Kill();
Application.Current.Exit();
}
}
}
@@ -53,7 +53,7 @@ public partial class SettingPageViewModel : ViewModelBase
partial void OnMinimizeWhenOpenChanged(bool value) => SystemProfile.MinimizeWhenOpen = value;
private static void SetAutoStart(bool enable) => SetAutoStart(enable, Assembly.GetExecutingAssembly().GetName().Name ?? "HaloPixelToolBox.Client");
private static void SetAutoStart(bool enable) => SetAutoStart(enable, Assembly.GetExecutingAssembly().GetName().Name ?? "HaloPixelToolBox");
private static void SetAutoStart(bool enable, string appName, string exePath = "")
{
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="XFEApplication.app"/>
<assemblyIdentity version="1.0.0.0" name="HaloPixelToolBox.app"/>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
@@ -16,4 +16,4 @@
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
</windowsSettings>
</application>
</assembly>
</assembly>
@@ -6,6 +6,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<PublishProfile>FolderProfile.pubxml</PublishProfile>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>Resources\Icon\Icon.ico</ApplicationIcon>
<AssemblyName>Installer</AssemblyName>
@@ -51,7 +52,6 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageReference Include="XFEExtension.NetCore" Version="4.2.4" />
<PackageReference Include="XFEExtension.NetCore.InputSimulator" Version="2.3.0" />
</ItemGroup>
@@ -2,6 +2,10 @@
public class SystemProfile
{
public const string ApplicationName = "HaloPixelToolBox";
public const string ApplicationExecutableName = ApplicationName + ".exe";
public const string LegacyApplicationName = "HaloPixelToolBox.Client";
/// <summary>
/// 当前窗口DPI缩放
/// </summary>
@@ -29,9 +33,11 @@ public class SystemProfile
/// <summary>
/// 安装目录
/// </summary>
public static string InstallPath { get; set; } = @$"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)}\HaloPixelToolBox.Client";
public static string InstallPath { get; set; } = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
ApplicationName);
/// <summary>
/// 第一次安装
/// </summary>
public static bool FirstInstall { get; set; } = false;
}
}