feat: 添加便携模式和打包脚本,精简打包大小

This commit is contained in:
2026-01-17 17:58:37 +08:00
parent c276e9e2b9
commit b0e785bd06
8 changed files with 332 additions and 20 deletions

View File

@@ -11,7 +11,7 @@ namespace TimerApp
public int IdleThresholdSeconds { get; set; } = 30;
public bool IsDarkMode { get; set; } = true;
private static string LegacyConfigPath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.json");
private static string LegacyConfigPath => Path.Combine(AppContext.BaseDirectory, "settings.json");
private static string ConfigPath
{
@@ -22,11 +22,22 @@ namespace TimerApp
}
}
private static string EffectiveConfigPath => PortableMode.IsPortable ? LegacyConfigPath : ConfigPath;
public static AppSettings Load()
{
try
{
string path = File.Exists(ConfigPath) ? ConfigPath : LegacyConfigPath;
string path;
if (PortableMode.IsPortable)
{
path = LegacyConfigPath;
}
else
{
path = File.Exists(ConfigPath) ? ConfigPath : LegacyConfigPath;
}
if (File.Exists(path))
{
string json = File.ReadAllText(path);
@@ -44,9 +55,12 @@ namespace TimerApp
{
try
{
Directory.CreateDirectory(Path.GetDirectoryName(ConfigPath)!);
string path = EffectiveConfigPath;
string? dir = Path.GetDirectoryName(path);
if (!string.IsNullOrWhiteSpace(dir))
Directory.CreateDirectory(dir);
string json = JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(ConfigPath, json);
File.WriteAllText(path, json);
}
catch
{