using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace GC.Services; /// 仓库根 version.json:由构建脚本 VersionStamp 自动生成,模型一改版本就变。 public sealed class RepoVersion { public int Schema { get; set; } = 1; public string Generated { get; set; } = ""; public string Repository { get; set; } = ""; public string Branch { get; set; } = "main"; public string ModelDir { get; set; } = "model"; public RepoLauncher Launcher { get; set; } = new(); public List Models { get; set; } = new(); } public sealed class RepoLauncher { public string Version { get; set; } = "1.0.0"; /// 启动器源码指纹(自动算,仅展示,不触发升级)。 public string Revision { get; set; } = ""; public Dictionary Packages { get; set; } = new(); } /// 某个平台的启动器发布包;url 优先,否则用 path 去仓库里解析下载地址。 public sealed class RepoPackage { public string? Url { get; set; } public string? Path { get; set; } public string? Sha256 { get; set; } public long Size { get; set; } /// Release 附件名(用于判断是 zip 还是单文件 exe / .app.zip)。 public string? AssetName { get; set; } } public sealed class RepoModel { public string Id { get; set; } = ""; public string Version { get; set; } = ""; /// 模型在仓库里的目录,如 model/earth-rotation。 public string Dir { get; set; } = ""; } /// 远端目录树里的一个条目。 public sealed class RepoEntry { public string Name { get; init; } = ""; /// 仓库内完整路径。 public string Path { get; init; } = ""; /// 相对所请求根目录的路径,统一用 / 分隔。 public string RelativePath { get; init; } = ""; public bool IsDirectory { get; init; } public string? DownloadUrl { get; init; } public long Size { get; init; } public string? Sha { get; init; } } /// /// 远端源抽象:gitcode 是默认实现,本地目录实现用于离线教学与自动化测试。 /// public interface IModelRemote { string DisplayName { get; } /// 源标识(xhmcl / gitcode / local),用于判断当前是哪个源。 string SourceId => SourcePreset.Detect(DisplayName).Id; Task GetVersionAsync(CancellationToken ct); Task> ListTreeAsync(string rootPath, CancellationToken ct); Task DownloadAsync(RepoEntry entry, CancellationToken ct); Task DownloadPackageAsync(RepoPackage package, CancellationToken ct); } public sealed class UpdateProgress { public double Value { get; init; } public string Message { get; init; } = ""; public string? Detail { get; init; } } public enum UpdateOutcome { NoChange, Applied, Partial, Unavailable, Disabled } public sealed class UpdateResult { public UpdateOutcome Outcome { get; init; } public string Message { get; init; } = ""; public int UpdatedModels { get; init; } public List ModelNames { get; init; } = new(); public string? LauncherMessage { get; init; } public string? Error { get; init; } }