发布包改为 GCL 单目录布局,.GC 增加 safedog 与中英双语日志
包结构
- 压缩包内只有一个顶层目录 GCL-<版本>-<平台>/,解压后不再散落一屏 dll
- 启动器改名为 GCL-<版本>-<平台>(.exe),Flutter 前端与后端仍在同一目录
- 守护进程移入包内 safedog/,运行时复制到 .GC/safedog
运行目录
- .GC 新增 safedog/:实际运行守护进程,整目录替换永远不会覆盖正在运行的它
- .GC 新增 logs/:按天写 gc-YYYYMMDD.log(中文)与 gc-YYYYMMDD.en.log(英文)
- 启动器、后端、SAVEDOG 共用同一组日志文件,整条启动/更新链路可一起排查
更新链路
- 包名/目录统一 GCL- 前缀,同时兼容旧 GC- 包(可从旧版本升级)
- 更新包解压后展平单顶层目录,仍按整目录替换安装
- Linux 无扩展名启动器仍可识别,兼容脚本清理旧版时覆盖 GCL-*
验证
- ./build.sh build 通过,产物 GCL-1.0.9-{win-amd64,win-arm64,linux-amd64}.zip
- 实跑 Linux 包:.GC/safedog/GC-SAVEDOG 与 .GC/logs/gc-20261118[.en].log 均生成
- GC.Tests --update-test 全部通过
This commit is contained in:
1 parent
a361c889f8
commit
31b0c93b25
17 files changed
+415
-126
No files matched your search
@@ -8,12 +8,14 @@ namespace GC.Services;
|
||||
/// 运行目录约定(可执行文件旁边,不内置任何模型):
|
||||
/// <code>
|
||||
/// <安装目录>/
|
||||
/// GC(.exe | .app/...)
|
||||
/// GCL(.exe | .app/...)
|
||||
/// .GC/
|
||||
/// settings.json 设置与已安装版本记录
|
||||
/// model/ 模型(启动时下载)
|
||||
/// cache/ 下载缓存 / 原子替换暂存
|
||||
/// update/ 待下次启动应用的启动器更新包
|
||||
/// safedog/ 更新守护进程(首次启动从安装包复制过来)
|
||||
/// logs/ 日志,按天分中英两份:gc-YYYYMMDD.log / .en.log
|
||||
/// </code>
|
||||
/// 开发态同样使用仓库根 .GC/model,并自动同步仓库 model/ 的可分发部分。
|
||||
/// EMS_MODELS / EMS_DATA / EMS_HOME 可显式覆盖。
|
||||
@@ -40,6 +42,12 @@ public sealed class AppPaths
|
||||
public string CacheRoot => Path.Combine(HomeRoot, "cache");
|
||||
public string UpdateRoot => Path.Combine(HomeRoot, "update");
|
||||
|
||||
/// <summary>日志目录:<c>.GC/logs</c>,里面按天放中英两份日志。</summary>
|
||||
public string LogsRoot => Path.Combine(HomeRoot, "logs");
|
||||
|
||||
/// <summary>守护进程目录:<c>.GC/safedog</c>(程序本体与用户数据分开)。</summary>
|
||||
public string SafedogRoot => Path.Combine(HomeRoot, "safedog");
|
||||
|
||||
/// <summary>用户配置目录(与可重建的缓存分开,删 cache 不会丢设置)。</summary>
|
||||
public string ConfigRoot => Path.Combine(HomeRoot, "config");
|
||||
|
||||
@@ -255,6 +263,8 @@ public sealed class AppPaths
|
||||
Directory.CreateDirectory(CacheRoot);
|
||||
Directory.CreateDirectory(ModelRoot);
|
||||
Directory.CreateDirectory(UpdateRoot);
|
||||
Directory.CreateDirectory(LogsRoot);
|
||||
Directory.CreateDirectory(SafedogRoot);
|
||||
|
||||
MigrateLegacySettings();
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace GC.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 双语文件日志。
|
||||
///
|
||||
/// 每条记录同时写两个文件(都在 <c>.GC/logs</c> 下,按天滚动):
|
||||
/// <code>
|
||||
/// gc-20261118.log 中文
|
||||
/// gc-20261118.en.log 英文
|
||||
/// </code>
|
||||
/// 中英分开而不是写在一个文件里:用户排查时不用在一行里找自己看得懂的那半句;
|
||||
/// 也给反馈问题时直接发对应语言的文件即可。
|
||||
///
|
||||
/// 日志失败绝不影响主流程(磁盘满、只读目录都只是少一份日志)。
|
||||
/// </summary>
|
||||
public static class GcLog
|
||||
{
|
||||
private static readonly object Gate = new();
|
||||
private static string? _dir;
|
||||
private static string _day = "";
|
||||
private static string _zhPath = "";
|
||||
private static string _enPath = "";
|
||||
|
||||
public static bool Enabled
|
||||
{
|
||||
get { lock (Gate) return _dir != null; }
|
||||
}
|
||||
|
||||
/// <summary>绑定日志目录(通常是 <c>.GC/logs</c>)。重复调用会切到新目录。</summary>
|
||||
public static void Init(string dir)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 目录都建不了就退化成只写控制台
|
||||
return;
|
||||
}
|
||||
|
||||
lock (Gate)
|
||||
{
|
||||
_dir = dir;
|
||||
_day = "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void Info(string zh, string en) => Write("INFO ", zh, en);
|
||||
public static void Warn(string zh, string en) => Write("WARN ", zh, en);
|
||||
public static void Error(string zh, string en) => Write("ERROR", zh, en);
|
||||
|
||||
private static void Write(string level, string zh, string en)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
var prefix = $"{now:yyyy-MM-dd HH:mm:ss} [{level}] ";
|
||||
var lineZh = prefix + zh;
|
||||
var lineEn = prefix + en;
|
||||
|
||||
try { Console.WriteLine(lineZh); } catch { /* 无控制台 */ }
|
||||
|
||||
lock (Gate)
|
||||
{
|
||||
if (_dir == null) return;
|
||||
|
||||
var day = now.ToString("yyyyMMdd");
|
||||
if (day != _day)
|
||||
{
|
||||
_day = day;
|
||||
_zhPath = Path.Combine(_dir, $"gc-{day}.log");
|
||||
_enPath = Path.Combine(_dir, $"gc-{day}.en.log");
|
||||
}
|
||||
|
||||
Append(_zhPath, lineZh);
|
||||
Append(_enPath, lineEn);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Append(string path, string line)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.AppendAllText(path, line + Environment.NewLine, new UTF8Encoding(false));
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 日志失败不能影响程序
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public sealed class ReleaseInfo
|
||||
public string Version => NormalizeVersion(TagName, Name);
|
||||
|
||||
private static readonly string[] VersionPrefixes =
|
||||
{ "v", "V", "GC-", "gc-", "release-", "Release-" };
|
||||
{ "v", "V", "GCL-", "gcl-", "GC-", "gc-", "release-", "Release-" };
|
||||
|
||||
private static readonly string[] PrereleaseTags =
|
||||
{ "alpha", "beta", "rc", "pre", "dev", "snapshot" };
|
||||
@@ -31,7 +31,7 @@ public sealed class ReleaseInfo
|
||||
var raw = !string.IsNullOrWhiteSpace(tag) ? tag : name;
|
||||
if (string.IsNullOrWhiteSpace(raw)) return "";
|
||||
raw = raw!.Trim();
|
||||
// "v1.0.1" / "GC-1.0.1" / "release-1.0.1" -> 取第一段像版本号的部分
|
||||
// "v1.0.1" / "GCL-1.0.1" / "GC-1.0.1" / "release-1.0.1" -> 取第一段像版本号的部分
|
||||
foreach (var prefix in VersionPrefixes)
|
||||
if (raw.StartsWith(prefix, StringComparison.Ordinal)) { raw = raw[prefix.Length..]; break; }
|
||||
// 形如 GC-1.0.1-Win-amd64 时只取版本段;但 2.3.0-beta 这类预发布串要保留完整。
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace GC.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 运行期目录准备:
|
||||
/// <list type="number">
|
||||
/// <item>创建 <c>.GC/logs</c> 与 <c>.GC/safedog</c>;</item>
|
||||
/// <item>把安装包里的守护进程复制到 <c>.GC/safedog</c>(程序本体与用户数据分开);</item>
|
||||
/// <item>初始化双语日志并写一条启动记录。</item>
|
||||
/// </list>
|
||||
///
|
||||
/// 为什么要复制而不是直接用包里的:更新时会整目录替换程序文件,
|
||||
/// 正在运行的守护进程无法被覆盖。放到 .GC 后,整目录替换永远不碰它,
|
||||
/// 新版守护进程在下一次启动时复制进来即可。
|
||||
/// </summary>
|
||||
public static class RuntimeLayout
|
||||
{
|
||||
/// <summary>准备目录与日志,返回实际使用的守护进程路径(可能为 null)。</summary>
|
||||
public static string? Ensure(AppPaths paths)
|
||||
{
|
||||
try { Directory.CreateDirectory(paths.LogsRoot); } catch { }
|
||||
try { Directory.CreateDirectory(paths.SafedogRoot); } catch { }
|
||||
|
||||
GcLog.Init(paths.LogsRoot);
|
||||
|
||||
var safedog = InstallSafedog(paths);
|
||||
|
||||
GcLog.Info(
|
||||
$"启动 GC {LauncherRuntimeInfo.CurrentLauncherVersion}({LauncherRuntimeInfo.CurrentRid})," +
|
||||
$"数据目录 {paths.HomeRoot},守护进程 {(safedog == null ? "未找到" : Path.GetFileName(safedog))}",
|
||||
$"Starting GC {LauncherRuntimeInfo.CurrentLauncherVersion} ({LauncherRuntimeInfo.CurrentRid}), " +
|
||||
$"data directory {paths.HomeRoot}, safedog {(safedog == null ? "not found" : Path.GetFileName(safedog))}");
|
||||
|
||||
return safedog;
|
||||
}
|
||||
|
||||
/// <summary>把包内守护进程同步到 <c>.GC/safedog</c>。已是最新则不动。</summary>
|
||||
private static string? InstallSafedog(AppPaths paths)
|
||||
{
|
||||
var name = SavedogFiles.ExecutableName;
|
||||
var target = Path.Combine(paths.SafedogRoot, name);
|
||||
|
||||
var source = FindPackaged(paths, name);
|
||||
if (source != null && NeedsCopy(source, target))
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(paths.SafedogRoot);
|
||||
File.Copy(source, target, overwrite: true);
|
||||
MarkExecutable(target);
|
||||
GcLog.Info($"已更新守护进程到 {target}", $"Safedog updated at {target}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
GcLog.Warn($"复制守护进程失败(继续使用已有版本):{ex.Message}",
|
||||
$"Failed to copy safedog (falling back to the existing one): {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return File.Exists(target) ? target : source;
|
||||
}
|
||||
|
||||
private static string? FindPackaged(AppPaths paths, string name)
|
||||
{
|
||||
var candidates = new[]
|
||||
{
|
||||
Path.Combine(paths.InstallDirectory, "safedog", name),
|
||||
Path.Combine(paths.InstallDirectory, name),
|
||||
Path.Combine(paths.AppRoot, "safedog", name),
|
||||
Path.Combine(paths.AppRoot, name),
|
||||
};
|
||||
|
||||
foreach (var candidate in candidates)
|
||||
{
|
||||
if (File.Exists(candidate)) return candidate;
|
||||
}
|
||||
|
||||
// macOS:可能在 .app/Contents/MacOS 里
|
||||
try
|
||||
{
|
||||
foreach (var app in Directory.GetDirectories(paths.InstallDirectory, "*.app"))
|
||||
{
|
||||
var inside = Path.Combine(app, "Contents", "MacOS", name);
|
||||
if (File.Exists(inside)) return inside;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool NeedsCopy(string source, string target)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(target)) return true;
|
||||
var a = new FileInfo(source);
|
||||
var b = new FileInfo(target);
|
||||
return a.Length != b.Length || a.LastWriteTimeUtc > b.LastWriteTimeUtc;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static void MarkExecutable(string path)
|
||||
{
|
||||
if (OperatingSystem.IsWindows()) return;
|
||||
try
|
||||
{
|
||||
var mode = File.GetUnixFileMode(path);
|
||||
File.SetUnixFileMode(path, mode | UnixFileMode.UserExecute |
|
||||
UnixFileMode.GroupExecute | UnixFileMode.OtherExecute);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
@@ -195,7 +195,7 @@ internal static class Program
|
||||
Directory.CreateDirectory(stage);
|
||||
// Linux 的启动器没有扩展名,测试包名要跟着平台走
|
||||
var launcherExt = OperatingSystem.IsWindows() ? ".exe" : "";
|
||||
File.WriteAllText(Path.Combine(stage, "GC-9.9.9-" + LauncherUpdater.PlatformLabel + launcherExt),
|
||||
File.WriteAllText(Path.Combine(stage, "GCL-9.9.9-" + LauncherUpdater.PlatformLabel + launcherExt),
|
||||
"new launcher");
|
||||
var zip = Path.Combine(tmp, "GC-" + rid + ".zip");
|
||||
ZipFile.CreateFromDirectory(stage, zip);
|
||||
@@ -238,14 +238,14 @@ internal static class Program
|
||||
{
|
||||
var script = File.ReadAllText(scriptPath);
|
||||
Check(!script.Contains(tmp), "脚本不含绝对路径");
|
||||
Check(script.Contains("GC-*.app") || script.Contains("GC-*"), "脚本按 GC-* 匹配删除");
|
||||
Check(script.Contains("GCL-*") || script.Contains("GC-*"), "脚本按 GCL-*/GC-* 匹配删除");
|
||||
}
|
||||
|
||||
// 5b) 只发产物、不发 Release:更新包只存在于仓库 dist/<系统>-<架构>/ 目录里。
|
||||
// 清单不写 url、不写 path,只给 dir + name + sha256,客户端要能自己找过去。
|
||||
var distDir = Path.Combine(remote, "dist", LauncherUpdater.PlatformLabel);
|
||||
Directory.CreateDirectory(distDir);
|
||||
var distName = "GC-9.9.10-" + LauncherUpdater.PlatformLabel + ".zip";
|
||||
var distName = "GCL-9.9.10-" + LauncherUpdater.PlatformLabel + ".zip";
|
||||
var distZip = Path.Combine(distDir, distName);
|
||||
File.Copy(zip, distZip, true);
|
||||
|
||||
|
||||
Reference in new issue
Block a user