diff --git a/build.sh b/build.sh index a91d883..548f9b0 100755 --- a/build.sh +++ b/build.sh @@ -113,14 +113,25 @@ JSON echo " 运行目录 -> $REL/.GC (settings.json + model/ + cache/ + update/)" } +# 系统/架构名(用于 Release 附件命名:GC-版本-系统-架构-是否内置dotnet) +rid_label() { + case "$1" in + win-x64) echo "Win-Amd64" ;; + win-arm64) echo "Win-Arm64" ;; + osx-arm64) echo "Mac-Arm64" ;; + *) echo "$1" ;; + esac +} + +# $1=RID $2=输出目录 $3=self-contained(true/false) publish_rid() { - RID="$1"; OUT="$2" + RID="$1"; OUT="$2"; SELF="$3" echo "" - echo "==> 编译 ${RID} -> ${OUT}" + echo "==> 编译 ${RID} (self-contained=${SELF}) -> ${OUT}" dotnet publish "$APP_PROJ" \ -c Release \ -r "$RID" \ - --self-contained true \ + --self-contained "$SELF" \ -p:Version="$VERSION" \ -p:DebugType=none \ -p:PublishSingleFile=true \ @@ -142,20 +153,35 @@ pack_models() { } # 启动器更新包:只包含程序文件,排除 .GC(否则会覆盖用户已下载的模型与设置) +# 命名:GC-<版本>-<系统>-<架构>-<是否内置dotnet>.zip +# selfcontained = 内置 .NET 运行时(免安装,体积大) +# framework = 不内置(需机器已装 .NET 8,体积小) +# 3 平台 × 2 种 = 6 个发布包 pack_launcher() { - echo "==> 生成启动器更新包(不含 .GC)" + echo "==> 生成 6 个启动器发布包(不含 .GC)" WIN64="$ROOT_DIR/dist/win-x64" WINARM="$ROOT_DIR/dist/win-arm64" MACBIN="$ROOT_DIR/dist/mac-arm64/EarthModelStudio.app/Contents/MacOS" [ -d "$MACBIN" ] || MACBIN="$ROOT_DIR/dist/mac-arm64" - [ -d "$WIN64" ] && ( cd "$WIN64" && zip -qr "$ROOT_DIR/dist/GC-win-x64.zip" . \ - -x "./.GC" "./.GC/*" "*.DS_Store" ) - [ -d "$WINARM" ] && ( cd "$WINARM" && zip -qr "$ROOT_DIR/dist/GC-win-arm64.zip" . \ - -x "./.GC" "./.GC/*" "*.DS_Store" ) - [ -d "$MACBIN" ] && ( cd "$MACBIN" && zip -qr "$ROOT_DIR/dist/GC-osx-arm64.zip" . \ - -x "./.GC" "./.GC/*" "*.DS_Store" ) + pack_one "Win-Amd64" "$WIN64" + pack_one "Win-Arm64" "$WINARM" + pack_one "Mac-Arm64" "$MACBIN" stamp_versions - ls -lh "$ROOT_DIR"/dist/GC-*.zip 2>/dev/null || true + ls -lh "$ROOT_DIR"/dist/GC-"$VERSION"-*.zip 2>/dev/null || true +} + +# 同一份产物打两个包(内置 / 不内置 dotnet 的区分由 publish 阶段分别输出到 +# dist/-selfcontained 与 dist/-framework,文件名后缀标识即可) +pack_one() { + LABEL="$1"; SRC="$2" + [ -d "$SRC" ] || return 0 + for KIND in selfcontained framework; do + DIR="${SRC}-${KIND}" + [ -d "$DIR" ] || DIR="$SRC" + ZIP="$ROOT_DIR/dist/GC-${VERSION}-${LABEL}-${KIND}.zip" + ( cd "$DIR" && zip -qr "$ZIP" . -x "./.GC" "./.GC/*" "*.DS_Store" ) + echo " -> $(basename "$ZIP")" + done } package_mac_app() { @@ -203,18 +229,24 @@ case "$TASK" in publish) mkdir -p "$ROOT_DIR/dist" stamp_versions - publish_rid "osx-arm64" "dist/mac-arm64" - publish_rid "win-x64" "dist/win-x64" - publish_rid "win-arm64" "dist/win-arm64" + # 3 平台 × {内置dotnet, 不内置dotnet} = 6 个发布包 + for RID in osx-arm64 win-x64 win-arm64; do + publish_rid "$RID" "dist/$RID-selfcontained" true + publish_rid "$RID" "dist/$RID-framework" false + done + # 兼容原有 .app 结构与 .GC 骨架(取内置版作为代表) + [ -d "$ROOT_DIR/dist/mac-arm64" ] || cp -R "$ROOT_DIR/dist/osx-arm64-selfcontained" "$ROOT_DIR/dist/mac-arm64" + [ -d "$ROOT_DIR/dist/win-x64" ] || cp -R "$ROOT_DIR/dist/win-x64-selfcontained" "$ROOT_DIR/dist/win-x64" + [ -d "$ROOT_DIR/dist/win-arm64" ] || cp -R "$ROOT_DIR/dist/win-arm64-selfcontained" "$ROOT_DIR/dist/win-arm64" package_mac_app prepare_runtime_layout "dist/win-x64" prepare_runtime_layout "dist/win-arm64" prepare_runtime_layout "dist/mac-arm64/EarthModelStudio.app/Contents/MacOS" pack_launcher echo "" - echo "==> 三个平台编译完成(发布包不含模型,首次启动自动下载):" - du -sh "$ROOT_DIR/dist"/* 2>/dev/null || true - echo " 把 version.json / model/ 推送到 gitcode,启动器就会自动检查更新" + echo "==> 三平台 × 2 模式 = 6 个发布包完成(不含模型,首次启动自动下载):" + ls -lh "$ROOT_DIR"/dist/GC-"$VERSION"-*.zip 2>/dev/null || true + echo " 把 6 个 zip 传 Release,把 version.json / model/ 推送到 gitcode" ;; models) build_models diff --git a/model/_engine/src/CelestialView.cs b/model/_engine/src/CelestialView.cs index 4ec8104..b8438c7 100644 --- a/model/_engine/src/CelestialView.cs +++ b/model/_engine/src/CelestialView.cs @@ -53,7 +53,7 @@ public class CelestialView : Control, IDisposable AvaloniaProperty.Register(nameof(ExaggerateTilt)); public static readonly StyledProperty FrameRateProperty = - AvaloniaProperty.Register(nameof(FrameRate), 30); + AvaloniaProperty.Register(nameof(FrameRate), 120); public static readonly StyledProperty ShowHudProperty = AvaloniaProperty.Register(nameof(ShowHud), true); @@ -379,7 +379,8 @@ public class CelestialView : Control, IDisposable { base.OnAttachedToVisualTree(e); _camElevTarget = DefaultElevation; - _timer = new DispatcherTimer(TimeSpan.FromMilliseconds(16), DispatcherPriority.Render, OnTick); + // 8ms 轮询以支撑最高 120 FPS(模型内部仍按 FrameRate 限流);不依赖系统 VSync 节拍 + _timer = new DispatcherTimer(TimeSpan.FromMilliseconds(8), DispatcherPriority.Render, OnTick); _lastTick = Stopwatch.GetTimestamp(); _timer.Start(); } diff --git a/model/_engine/src/EarthModelView.cs b/model/_engine/src/EarthModelView.cs index 7111372..9f39809 100644 --- a/model/_engine/src/EarthModelView.cs +++ b/model/_engine/src/EarthModelView.cs @@ -85,7 +85,7 @@ public sealed class EarthModelView : UserControl, IDisposable ShowOrbit = true, ShowGraticule = true, ShowKeyLatitudes = true, - FrameRate = 60, + FrameRate = 120, View = IsRevolution ? SceneView.Revolution : SceneView.Rotation }; _canvas.JumpToOrbit(StartAngle); diff --git a/src/main/dotnet/EarthModelStudio/Assets/i18n/en.json b/src/main/dotnet/EarthModelStudio/Assets/i18n/en.json index 0a68aed..1761361 100644 --- a/src/main/dotnet/EarthModelStudio/Assets/i18n/en.json +++ b/src/main/dotnet/EarthModelStudio/Assets/i18n/en.json @@ -1,5 +1,5 @@ { - "app.name": "Earth Model Studio", + "app.name": "Morris GC", "app.tagline": "Astronomy teaching models · visual launcher", "app.version": "Version", "app.platform": "Platform", @@ -74,6 +74,7 @@ "set.memory.current": "In use", "set.memory.unit": "MB", "set.memory.hint": "2048 MB or more is recommended; 1024 MB for low-end devices.", + "set.memory.auto": "Auto (allocate based on device memory)", "set.preallocate": "Preload land data at startup", "set.preallocate.desc": "Faster first frame, slightly slower startup.", "set.sources": "Model sources", diff --git a/src/main/dotnet/EarthModelStudio/Assets/i18n/zh-CN.json b/src/main/dotnet/EarthModelStudio/Assets/i18n/zh-CN.json index bc634da..fae4865 100644 --- a/src/main/dotnet/EarthModelStudio/Assets/i18n/zh-CN.json +++ b/src/main/dotnet/EarthModelStudio/Assets/i18n/zh-CN.json @@ -1,5 +1,5 @@ { - "app.name": "地球模型工作室", + "app.name": "Morris GC", "app.tagline": "天文教学模型 · 可视化启动器", "app.version": "版本", "app.platform": "平台", @@ -74,6 +74,7 @@ "set.memory.current": "当前占用", "set.memory.unit": "MB", "set.memory.hint": "建议 2048 MB 以上,低配设备可选 1024 MB。", + "set.memory.auto": "自动(根据设备内存分配)", "set.preallocate": "启动时预加载模型地表数据", "set.preallocate.desc": "打开后首帧更快,启动耗时略增。", "set.sources": "模型源", diff --git a/src/main/dotnet/EarthModelStudio/Models/AppSettings.cs b/src/main/dotnet/EarthModelStudio/Models/AppSettings.cs index 099100c..5f62a11 100644 --- a/src/main/dotnet/EarthModelStudio/Models/AppSettings.cs +++ b/src/main/dotnet/EarthModelStudio/Models/AppSettings.cs @@ -13,12 +13,15 @@ public sealed class AppSettings /// light | dark public string Theme { get; set; } = "light"; - /// 渲染帧率:24 / 30 / 60 - public int RenderFps { get; set; } = 30; + /// 渲染帧率:24 / 30 / 60 / 90 / 120(上限 120,关闭 VSync 同步) + public int RenderFps { get; set; } = 120; /// 启动时运行内存分配(MB)——决定场景缓存/纹理预算。 public int MemoryMb { get; set; } = 2048; + /// 自动模式:根据设备可用内存自动计算预算(忽略 MemoryMb)。 + public bool MemoryAuto { get; set; } = true; + /// 启动时检查模型源更新。 public bool CheckSourceOnStartup { get; set; } diff --git a/src/main/dotnet/EarthModelStudio/Services/AppServices.cs b/src/main/dotnet/EarthModelStudio/Services/AppServices.cs index e594a3c..61b0ed5 100644 --- a/src/main/dotnet/EarthModelStudio/Services/AppServices.cs +++ b/src/main/dotnet/EarthModelStudio/Services/AppServices.cs @@ -38,7 +38,8 @@ public sealed class AppServices var services = new AppServices(paths); L.I.Initialize(services.Settings.Current.Language); - services.Memory.Apply(services.Settings.Current.MemoryMb); + services.Memory.ApplyAuto(services.Settings.Current.MemoryAuto, + services.Settings.Current.MemoryMb); Current = services; return services; diff --git a/src/main/dotnet/EarthModelStudio/Services/GitCodeReleaseRemote.cs b/src/main/dotnet/EarthModelStudio/Services/GitCodeReleaseRemote.cs index b72466e..3795e40 100644 --- a/src/main/dotnet/EarthModelStudio/Services/GitCodeReleaseRemote.cs +++ b/src/main/dotnet/EarthModelStudio/Services/GitCodeReleaseRemote.cs @@ -25,7 +25,7 @@ public sealed class GitCodeReleaseRemote : IModelRemote private readonly GitCodeRemote _content; private readonly HttpClient _http; private readonly string _releasesUrl; - private readonly Dictionary _assets = new(); + private readonly Dictionary _assets = new(); public GitCodeReleaseRemote(string? manifestUrl, string? repository, HttpClient? http = null) { @@ -101,7 +101,7 @@ public sealed class GitCodeReleaseRemote : IModelRemote if (rid == null || string.IsNullOrWhiteSpace(asset.Url)) continue; // 同名平台取第一个有效附件 if (!_assets.ContainsKey(rid)) - _assets[rid] = (asset.Url, asset.Sha256, asset.Size); + _assets[rid] = (asset.Url, asset.Sha256, asset.Size, asset.Name); } // 把附件地址写回 packages:有附件就用附件的直链与校验值, @@ -114,6 +114,7 @@ public sealed class GitCodeReleaseRemote : IModelRemote version.Launcher.Packages[rid] = pkg; } pkg.Url = info.Url; + pkg.AssetName = info.Name; if (!string.IsNullOrWhiteSpace(info.Sha256)) pkg.Sha256 = info.Sha256; if (info.Size > 0) pkg.Size = info.Size; } @@ -141,13 +142,17 @@ public sealed class GitCodeReleaseRemote : IModelRemote { foreach (var a in assets.EnumerateArray()) { + // 跳过 GitCode 自动生成的源码包(type=source),只取真正的发布附件 + var type = Str(a, "type"); + if (string.Equals(type, "source", StringComparison.OrdinalIgnoreCase)) continue; info.Assets.Add(new ReleaseAsset { Name = Str(a, "name") ?? Str(a, "file_name") ?? "", BrowserDownloadUrl = Str(a, "browser_download_url"), DownloadUrl = Str(a, "download_url") ?? Str(a, "url"), Size = Num(a, "size"), - Sha256 = Str(a, "sha256") ?? Str(a, "digest") + Sha256 = Str(a, "sha256") ?? Str(a, "digest"), + Type = type }); } } diff --git a/src/main/dotnet/EarthModelStudio/Services/MemoryBudget.cs b/src/main/dotnet/EarthModelStudio/Services/MemoryBudget.cs index b9512fd..b779411 100644 --- a/src/main/dotnet/EarthModelStudio/Services/MemoryBudget.cs +++ b/src/main/dotnet/EarthModelStudio/Services/MemoryBudget.cs @@ -21,6 +21,27 @@ public sealed class MemoryBudget Changed?.Invoke(); } + /// + /// 自动预算:取设备可用物理内存的一部分(约 1/4), + /// 夹在 512–8192 MB 之间,低配设备也不会因为预算过大而卡顿。 + /// + public static int AutoComputeMb() + { + try + { + var info = GC.GetGCMemoryInfo(); + var totalMb = info.TotalAvailableMemoryBytes / (1024.0 * 1024.0); + if (totalMb > 0) + return (int)Math.Clamp(Math.Round(totalMb / 4.0 / 256.0) * 256, 512, 8192); + } + catch { /* 平台不支持时回退默认值 */ } + return 2048; + } + + /// 按设置应用:auto 时自动计算,否则用手动值。 + public void ApplyAuto(bool auto, int manualMb) + => Apply(auto ? AutoComputeMb() : manualMb); + /// 内存情况变化(例如模型窗口开关)时刷新展示。 public void Refresh() => Changed?.Invoke(); diff --git a/src/main/dotnet/EarthModelStudio/Services/ReleaseModels.cs b/src/main/dotnet/EarthModelStudio/Services/ReleaseModels.cs index 89a6739..67afc23 100644 --- a/src/main/dotnet/EarthModelStudio/Services/ReleaseModels.cs +++ b/src/main/dotnet/EarthModelStudio/Services/ReleaseModels.cs @@ -28,9 +28,17 @@ public sealed class ReleaseInfo // "v1.0.1" / "GC-1.0.1" / "release-1.0.1" -> 取第一段像版本号的部分 foreach (var prefix in new[] { "v", "V", "GC-", "gc-", "release-", "Release-" }) if (raw.StartsWith(prefix, StringComparison.Ordinal)) { raw = raw[prefix.Length..]; break; } - // 形如 GC-1.0.1-Win-amd64 时只取版本段 + // 形如 GC-1.0.1-Win-amd64 时只取版本段;但 2.3.0-beta 这类预发布串要保留完整。 + // 用「后缀是否常见预发布标签」区分,避免把 "-Win" 误当成预发布。 var dash = raw.IndexOf('-'); - if (dash > 0 && System.Version.TryParse(raw[..dash], out _)) raw = raw[..dash]; + if (dash > 0 && System.Version.TryParse(raw[..dash], out _)) + { + var tail = raw[(dash + 1)..].ToLowerInvariant(); + bool isPrerelease = tail.StartsWith("alpha") || tail.StartsWith("beta") || + tail.StartsWith("rc") || tail.StartsWith("pre") || + tail.StartsWith("dev") || tail.StartsWith("snapshot"); + if (!isPrerelease) raw = raw[..dash]; + } return raw; } } @@ -41,11 +49,43 @@ public sealed class ReleaseAsset public string? BrowserDownloadUrl { get; set; } public string? DownloadUrl { get; set; } public long Size { get; set; } - public string? Sha256 { get; set; } + /// 附件类型:GitCode 用 "source" 表示自动生成的源码压缩包,需跳过。 + public string? Type { get; set; } + + private string? _sha256; + /// + /// 校验值。真实 Release 的 digest 形如 "sha256:899fc1...", + /// 这里统一剥掉算法前缀,只留 hex,便于与 SHA256.HashData 结果比较。 + /// + public string? Sha256 + { + get => _sha256; + set + { + if (string.IsNullOrWhiteSpace(value)) { _sha256 = null; return; } + var v = value!.Trim(); + var colon = v.IndexOf(':'); + if (colon > 0 && v[..colon].Equals("sha256", StringComparison.OrdinalIgnoreCase)) + v = v[(colon + 1)..]; + _sha256 = v.Trim(); + } + } [JsonIgnore] public string Url => BrowserDownloadUrl ?? DownloadUrl ?? ""; + /// 单文件发布包(.exe 等)不能走解压,需要直接作为 payload 内容。 + public bool IsSingleFile + { + get + { + var n = Name.ToLowerInvariant(); + return !n.EndsWith(".zip", StringComparison.Ordinal) && + !n.EndsWith(".tar.gz", StringComparison.Ordinal) && + !n.EndsWith(".tgz", StringComparison.Ordinal); + } + } + /// 解析附件名里的系统/架构,映射到 .NET RID。 /// 如 win-x64 / win-arm64 / osx-arm64;无法识别返回 null。 public string? RidFromName(string fullName) @@ -60,8 +100,12 @@ public sealed class ReleaseAsset if (!win && !mac && !linux) return null; bool arm64 = lower.Contains("arm64") || lower.Contains("aarch64") || lower.Contains("win-arm"); - bool x86 = lower.Contains("x86") && !lower.Contains("x64") && !lower.Contains("amd64") && !arm64; - // amd64 / x64 / x86_64 都视为 x64 + // x86_64 / x86-64 / amd64 / x64 都是 64 位;只有裸 "x86"/"win-x86" 才是 32 位 + bool is64 = lower.Contains("x64") || lower.Contains("amd64") || + lower.Contains("x86-64") || lower.Contains("x86_64"); + bool x86 = !is64 && !arm64 && + (lower.Contains("x86") || lower.Contains("win32") || lower.Contains("i386")); + // 其余(未显式标注 32 位)一律按 64 位处理,覆盖 "GC-1.0.1-Windows.zip" 这类简写 var arch = arm64 ? "arm64" : x86 ? "x86" : "x64"; if (win) return "win-" + arch; diff --git a/src/main/dotnet/EarthModelStudio/Services/SettingsService.cs b/src/main/dotnet/EarthModelStudio/Services/SettingsService.cs index 82dfe2d..9c39ad6 100644 --- a/src/main/dotnet/EarthModelStudio/Services/SettingsService.cs +++ b/src/main/dotnet/EarthModelStudio/Services/SettingsService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using EarthModelStudio.Models; namespace EarthModelStudio.Services; @@ -17,24 +18,40 @@ public sealed class SettingsService public void Load() { Current = Json.Read(_paths.SettingsFile) ?? new AppSettings(); - if (Current.Sources.Count == 0) SeedSources(); + SeedDefaultSource(); if (Current.MemoryMb < 256) Current.MemoryMb = 2048; } /// - /// 自动更新由 UpdateService 负责(版本清单 version.json),这里不预置任何在线源; - /// 只给「下载」页留一条空的自定义源占位。 + /// 默认下载源(gitcode 官方仓库)始终内置在列表里,且不允许删除: + /// 它是启动器自动更新的同源仓库,用户清掉会导致模型无法回退。 + /// 老配置里没有这条时自动补上;已有的用户自定义源保持不变。 /// - private void SeedSources() + public const string DefaultSourceId = "gitcode-official"; + public const string DefaultSourceUrl = "https://gitcode.com/2509_92447106/GC"; + + private void SeedDefaultSource() { - Current.Sources.Add(new ModelSource + var existing = Current.Sources.FirstOrDefault(s => + string.Equals(s.Id, DefaultSourceId, StringComparison.OrdinalIgnoreCase)); + if (existing == null) { - Id = "custom", - Name = "自定义源", - Url = "", - Enabled = false - }); - Save(); + Current.Sources.Insert(0, new ModelSource + { + Id = DefaultSourceId, + Name = "Morris GC (GitCode)", + Url = DefaultSourceUrl, + Enabled = true, + BuiltIn = true + }); + Save(); + } + else + { + // 强制保证内置标记与地址,避免旧配置被用户改坏后失去保护 + existing.BuiltIn = true; + if (string.IsNullOrWhiteSpace(existing.Url)) existing.Url = DefaultSourceUrl; + } } public void Save() diff --git a/src/main/dotnet/EarthModelStudio/Services/UpdateModels.cs b/src/main/dotnet/EarthModelStudio/Services/UpdateModels.cs index 62d974b..56d3b1e 100644 --- a/src/main/dotnet/EarthModelStudio/Services/UpdateModels.cs +++ b/src/main/dotnet/EarthModelStudio/Services/UpdateModels.cs @@ -32,6 +32,8 @@ public sealed class RepoPackage 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 diff --git a/src/main/dotnet/EarthModelStudio/Services/UpdateService.cs b/src/main/dotnet/EarthModelStudio/Services/UpdateService.cs index 96dd3a1..d531bc3 100644 --- a/src/main/dotnet/EarthModelStudio/Services/UpdateService.cs +++ b/src/main/dotnet/EarthModelStudio/Services/UpdateService.cs @@ -314,24 +314,36 @@ public sealed class UpdateService Directory.CreateDirectory(_paths.UpdateRoot); var payload = Path.Combine(_paths.UpdateRoot, "payload"); if (Directory.Exists(payload)) Directory.Delete(payload, true); - var zip = Path.Combine(_paths.CacheRoot, "launcher-" + Safe(launcher.Version) + ".zip"); - await File.WriteAllBytesAsync(zip, bytes, ct); - try + Directory.CreateDirectory(payload); + + // 单文件发布包(.exe / .app.zip 里的可执行文件不在此列)就是程序本体,不能解压。 + // 直接按附件原名放进 payload,脚本会把 payload/ 整体覆盖到安装目录。 + var assetName = package!.AssetName; + bool singleFile = !string.IsNullOrWhiteSpace(assetName) && + !assetName!.EndsWith(".zip", StringComparison.OrdinalIgnoreCase) && + !assetName.EndsWith(".tar.gz", StringComparison.OrdinalIgnoreCase); + string executableName; + if (singleFile) { - ZipSafety.ExtractToDirectory(zip, payload); + executableName = Path.GetFileName(assetName!); + await File.WriteAllBytesAsync(Path.Combine(payload, executableName), bytes, ct); } - finally + else { - try { File.Delete(zip); } catch { } + var zip = Path.Combine(_paths.CacheRoot, "launcher-" + Safe(launcher.Version) + ".zip"); + await File.WriteAllBytesAsync(zip, bytes, ct); + try { ZipSafety.ExtractToDirectory(zip, payload); } + finally { try { File.Delete(zip); } catch { } } + FlattenPayload(payload); + executableName = Path.GetFileName(Environment.ProcessPath ?? ""); } - FlattenPayload(payload); Json.Write(Path.Combine(_paths.UpdateRoot, "pending.json"), new PendingUpdate { Version = launcher.Version, Rid = rid, InstallDirectory = _paths.InstallDirectory, - Executable = Path.GetFileName(Environment.ProcessPath ?? ""), + Executable = executableName, Payload = "payload", DownloadedAt = DateTime.UtcNow.ToString("O") }); diff --git a/src/main/dotnet/EarthModelStudio/Styles/AppTheme.axaml b/src/main/dotnet/EarthModelStudio/Styles/AppTheme.axaml index 51fa5c1..f8ffd43 100644 --- a/src/main/dotnet/EarthModelStudio/Styles/AppTheme.axaml +++ b/src/main/dotnet/EarthModelStudio/Styles/AppTheme.axaml @@ -246,4 +246,42 @@ + + + + + + + + + diff --git a/src/main/dotnet/EarthModelStudio/ViewModels/DownloadViewModel.cs b/src/main/dotnet/EarthModelStudio/ViewModels/DownloadViewModel.cs index 0e0089f..d68264e 100644 --- a/src/main/dotnet/EarthModelStudio/ViewModels/DownloadViewModel.cs +++ b/src/main/dotnet/EarthModelStudio/ViewModels/DownloadViewModel.cs @@ -93,6 +93,7 @@ public partial class DownloadViewModel : ObservableObject internal void RemoveSource(SourceItemViewModel source) { + if (source.Model.BuiltIn) return; // 内置默认源不允许删除 _services.Settings.Current.Sources.Remove(source.Model); _services.Settings.Save(); var wasSelected = SelectedSource == source; @@ -325,6 +326,8 @@ public partial class SourceItemViewModel : ObservableObject public string Name => string.IsNullOrWhiteSpace(Model.Name) ? Model.Id : Model.Name; public string HostText => string.IsNullOrWhiteSpace(Model.Url) ? L.I["dl.noSource"] : Model.DisplayHost; public bool HasUrl => !string.IsNullOrWhiteSpace(Model.Url); + /// 内置默认源不可删除(下载页隐藏删除按钮)。 + public bool CanRemove => !Model.BuiltIn; public bool Enabled { diff --git a/src/main/dotnet/EarthModelStudio/ViewModels/SettingsViewModel.cs b/src/main/dotnet/EarthModelStudio/ViewModels/SettingsViewModel.cs index eee8e6d..27e5dee 100644 --- a/src/main/dotnet/EarthModelStudio/ViewModels/SettingsViewModel.cs +++ b/src/main/dotnet/EarthModelStudio/ViewModels/SettingsViewModel.cs @@ -24,11 +24,12 @@ public partial class SettingsViewModel : ObservableObject public ObservableCollection Sources { get; } = new(); public ObservableCollection Languages { get; } = new(); - public int[] FrameRates { get; } = { 24, 30, 60 }; + public int[] FrameRates { get; } = { 24, 30, 60, 90, 120 }; [ObservableProperty] private LanguageOption? _selectedLanguage; - [ObservableProperty] private int _selectedFps = 30; + [ObservableProperty] private int _selectedFps = 120; [ObservableProperty] private double _memoryValue = 2048; + [ObservableProperty] private bool _memoryAuto = true; [ObservableProperty] private string _statusMessage = ""; [ObservableProperty] private bool _autoUpdate = true; @@ -46,7 +47,9 @@ public partial class SettingsViewModel : ObservableObject public string PendingText => string.IsNullOrWhiteSpace(_services.Settings.Current.PendingLauncherVersion) ? L.I["update.none"] : _services.Settings.Current.PendingLauncherVersion!; - public string MemoryValueText => $"{(int)Math.Round(MemoryValue)} MB"; + public string MemoryValueText => MemoryAuto + ? $"{L.I["set.memory.auto"]} ({_services.Memory.BudgetMb} MB)" + : $"{(int)Math.Round(MemoryValue)} MB"; public string UsageText => _services.Memory.UsageText; public string ModelRoot => _services.Paths.ModelRoot; public string DataRoot => _services.Paths.DataRoot; @@ -69,6 +72,7 @@ public partial class SettingsViewModel : ObservableObject var settings = _services.Settings.Current; SelectedFps = settings.RenderFps; MemoryValue = settings.MemoryMb; + MemoryAuto = settings.MemoryAuto; AutoUpdate = settings.AutoUpdateOnStartup; Sources.Clear(); @@ -133,6 +137,15 @@ public partial class SettingsViewModel : ObservableObject OnPropertyChanged(nameof(UsageText)); } + partial void OnMemoryAutoChanged(bool value) + { + if (_loading) return; + _services.Settings.Apply(s => s.MemoryAuto = value); + _services.Memory.ApplyAuto(value, (int)Math.Round(MemoryValue)); + OnPropertyChanged(nameof(MemoryValueText)); + OnPropertyChanged(nameof(UsageText)); + } + [RelayCommand] private void OpenModelFolder() => Shell.OpenFolder(_services.Paths.ModelRoot); @@ -160,6 +173,7 @@ public partial class SettingsViewModel : ObservableObject internal void RemoveSource(SettingsSourceViewModel source) { + if (source.Model.BuiltIn) return; // 内置默认源不允许删除 _services.Settings.Current.Sources.Remove(source.Model); _services.Settings.Save(); Sources.Remove(source); @@ -184,6 +198,8 @@ public partial class SettingsSourceViewModel : ObservableObject public string Name => string.IsNullOrWhiteSpace(Model.Name) ? Model.Id : Model.Name; public string UrlText => string.IsNullOrWhiteSpace(Model.Url) ? L.I["dl.noSource"] : Model.Url; + /// 内置默认源不可删除。 + public bool CanRemove => !Model.BuiltIn; public bool Enabled { diff --git a/src/main/dotnet/EarthModelStudio/Views/DownloadView.axaml b/src/main/dotnet/EarthModelStudio/Views/DownloadView.axaml index d92e7ff..4c08d47 100644 --- a/src/main/dotnet/EarthModelStudio/Views/DownloadView.axaml +++ b/src/main/dotnet/EarthModelStudio/Views/DownloadView.axaml @@ -32,7 +32,7 @@