This commit is contained in:
2509_92447106 committed 2026-11-07 19:31:02 +08:00
1 parent ab39c5103d
commit d81ab2acaa
20 files changed
+312 -66

No files matched your search

+49 -17
View File
@@ -113,14 +113,25 @@ JSON
echo " 运行目录 -> $REL/.GC (settings.json + model/ + cache/ + update/)" 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() { publish_rid() {
RID="$1"; OUT="$2" RID="$1"; OUT="$2"; SELF="$3"
echo "" echo ""
echo "==> 编译 ${RID} -> ${OUT}" echo "==> 编译 ${RID} (self-contained=${SELF}) -> ${OUT}"
dotnet publish "$APP_PROJ" \ dotnet publish "$APP_PROJ" \
-c Release \ -c Release \
-r "$RID" \ -r "$RID" \
--self-contained true \ --self-contained "$SELF" \
-p:Version="$VERSION" \ -p:Version="$VERSION" \
-p:DebugType=none \ -p:DebugType=none \
-p:PublishSingleFile=true \ -p:PublishSingleFile=true \
@@ -142,20 +153,35 @@ pack_models() {
} }
# 启动器更新包:只包含程序文件,排除 .GC(否则会覆盖用户已下载的模型与设置) # 启动器更新包:只包含程序文件,排除 .GC(否则会覆盖用户已下载的模型与设置)
# 命名:GC-<版本>-<系统>-<架构>-<是否内置dotnet>.zip
# selfcontained = 内置 .NET 运行时(免安装,体积大)
# framework = 不内置(需机器已装 .NET 8,体积小)
# 3 平台 × 2 种 = 6 个发布包
pack_launcher() { pack_launcher() {
echo "==> 生成启动器更新包(不含 .GC)" echo "==> 生成 6 个启动器发布包(不含 .GC)"
WIN64="$ROOT_DIR/dist/win-x64" WIN64="$ROOT_DIR/dist/win-x64"
WINARM="$ROOT_DIR/dist/win-arm64" WINARM="$ROOT_DIR/dist/win-arm64"
MACBIN="$ROOT_DIR/dist/mac-arm64/EarthModelStudio.app/Contents/MacOS" MACBIN="$ROOT_DIR/dist/mac-arm64/EarthModelStudio.app/Contents/MacOS"
[ -d "$MACBIN" ] || MACBIN="$ROOT_DIR/dist/mac-arm64" [ -d "$MACBIN" ] || MACBIN="$ROOT_DIR/dist/mac-arm64"
[ -d "$WIN64" ] && ( cd "$WIN64" && zip -qr "$ROOT_DIR/dist/GC-win-x64.zip" . \ pack_one "Win-Amd64" "$WIN64"
-x "./.GC" "./.GC/*" "*.DS_Store" ) pack_one "Win-Arm64" "$WINARM"
[ -d "$WINARM" ] && ( cd "$WINARM" && zip -qr "$ROOT_DIR/dist/GC-win-arm64.zip" . \ pack_one "Mac-Arm64" "$MACBIN"
-x "./.GC" "./.GC/*" "*.DS_Store" )
[ -d "$MACBIN" ] && ( cd "$MACBIN" && zip -qr "$ROOT_DIR/dist/GC-osx-arm64.zip" . \
-x "./.GC" "./.GC/*" "*.DS_Store" )
stamp_versions 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/<rid>-selfcontained 与 dist/<rid>-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() { package_mac_app() {
@@ -203,18 +229,24 @@ case "$TASK" in
publish) publish)
mkdir -p "$ROOT_DIR/dist" mkdir -p "$ROOT_DIR/dist"
stamp_versions stamp_versions
publish_rid "osx-arm64" "dist/mac-arm64" # 3 平台 × {内置dotnet, 不内置dotnet} = 6 个发布包
publish_rid "win-x64" "dist/win-x64" for RID in osx-arm64 win-x64 win-arm64; do
publish_rid "win-arm64" "dist/win-arm64" 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 package_mac_app
prepare_runtime_layout "dist/win-x64" prepare_runtime_layout "dist/win-x64"
prepare_runtime_layout "dist/win-arm64" prepare_runtime_layout "dist/win-arm64"
prepare_runtime_layout "dist/mac-arm64/EarthModelStudio.app/Contents/MacOS" prepare_runtime_layout "dist/mac-arm64/EarthModelStudio.app/Contents/MacOS"
pack_launcher pack_launcher
echo "" echo ""
echo "==> 三个平台编译完成(发布包不含模型,首次启动自动下载):" echo "==> 三平台 × 2 模式 = 6 个发布包完成(不含模型,首次启动自动下载):"
du -sh "$ROOT_DIR/dist"/* 2>/dev/null || true ls -lh "$ROOT_DIR"/dist/GC-"$VERSION"-*.zip 2>/dev/null || true
echo " 把 version.json / model/ 推送到 gitcode,启动器就会自动检查更新" echo " 把 6 个 zip 传 Release,把 version.json / model/ 推送到 gitcode"
;; ;;
models) models)
build_models build_models
+3 -2
View File
@@ -53,7 +53,7 @@ public class CelestialView : Control, IDisposable
AvaloniaProperty.Register<CelestialView, bool>(nameof(ExaggerateTilt)); AvaloniaProperty.Register<CelestialView, bool>(nameof(ExaggerateTilt));
public static readonly StyledProperty<int> FrameRateProperty = public static readonly StyledProperty<int> FrameRateProperty =
AvaloniaProperty.Register<CelestialView, int>(nameof(FrameRate), 30); AvaloniaProperty.Register<CelestialView, int>(nameof(FrameRate), 120);
public static readonly StyledProperty<bool> ShowHudProperty = public static readonly StyledProperty<bool> ShowHudProperty =
AvaloniaProperty.Register<CelestialView, bool>(nameof(ShowHud), true); AvaloniaProperty.Register<CelestialView, bool>(nameof(ShowHud), true);
@@ -379,7 +379,8 @@ public class CelestialView : Control, IDisposable
{ {
base.OnAttachedToVisualTree(e); base.OnAttachedToVisualTree(e);
_camElevTarget = DefaultElevation; _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(); _lastTick = Stopwatch.GetTimestamp();
_timer.Start(); _timer.Start();
} }
+1 -1
View File
@@ -85,7 +85,7 @@ public sealed class EarthModelView : UserControl, IDisposable
ShowOrbit = true, ShowOrbit = true,
ShowGraticule = true, ShowGraticule = true,
ShowKeyLatitudes = true, ShowKeyLatitudes = true,
FrameRate = 60, FrameRate = 120,
View = IsRevolution ? SceneView.Revolution : SceneView.Rotation View = IsRevolution ? SceneView.Revolution : SceneView.Rotation
}; };
_canvas.JumpToOrbit(StartAngle); _canvas.JumpToOrbit(StartAngle);
@@ -1,5 +1,5 @@
{ {
"app.name": "Earth Model Studio", "app.name": "Morris GC",
"app.tagline": "Astronomy teaching models · visual launcher", "app.tagline": "Astronomy teaching models · visual launcher",
"app.version": "Version", "app.version": "Version",
"app.platform": "Platform", "app.platform": "Platform",
@@ -74,6 +74,7 @@
"set.memory.current": "In use", "set.memory.current": "In use",
"set.memory.unit": "MB", "set.memory.unit": "MB",
"set.memory.hint": "2048 MB or more is recommended; 1024 MB for low-end devices.", "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": "Preload land data at startup",
"set.preallocate.desc": "Faster first frame, slightly slower startup.", "set.preallocate.desc": "Faster first frame, slightly slower startup.",
"set.sources": "Model sources", "set.sources": "Model sources",
@@ -1,5 +1,5 @@
{ {
"app.name": "地球模型工作室", "app.name": "Morris GC",
"app.tagline": "天文教学模型 · 可视化启动器", "app.tagline": "天文教学模型 · 可视化启动器",
"app.version": "版本", "app.version": "版本",
"app.platform": "平台", "app.platform": "平台",
@@ -74,6 +74,7 @@
"set.memory.current": "当前占用", "set.memory.current": "当前占用",
"set.memory.unit": "MB", "set.memory.unit": "MB",
"set.memory.hint": "建议 2048 MB 以上,低配设备可选 1024 MB。", "set.memory.hint": "建议 2048 MB 以上,低配设备可选 1024 MB。",
"set.memory.auto": "自动(根据设备内存分配)",
"set.preallocate": "启动时预加载模型地表数据", "set.preallocate": "启动时预加载模型地表数据",
"set.preallocate.desc": "打开后首帧更快,启动耗时略增。", "set.preallocate.desc": "打开后首帧更快,启动耗时略增。",
"set.sources": "模型源", "set.sources": "模型源",
@@ -13,12 +13,15 @@ public sealed class AppSettings
/// <summary>light | dark</summary> /// <summary>light | dark</summary>
public string Theme { get; set; } = "light"; public string Theme { get; set; } = "light";
/// <summary>渲染帧率:24 / 30 / 60</summary> /// <summary>渲染帧率:24 / 30 / 60 / 90 / 120(上限 120,关闭 VSync 同步)</summary>
public int RenderFps { get; set; } = 30; public int RenderFps { get; set; } = 120;
/// <summary>启动时运行内存分配(MB)——决定场景缓存/纹理预算。</summary> /// <summary>启动时运行内存分配(MB)——决定场景缓存/纹理预算。</summary>
public int MemoryMb { get; set; } = 2048; public int MemoryMb { get; set; } = 2048;
/// <summary>自动模式:根据设备可用内存自动计算预算(忽略 MemoryMb)。</summary>
public bool MemoryAuto { get; set; } = true;
/// <summary>启动时检查模型源更新。</summary> /// <summary>启动时检查模型源更新。</summary>
public bool CheckSourceOnStartup { get; set; } public bool CheckSourceOnStartup { get; set; }
@@ -38,7 +38,8 @@ public sealed class AppServices
var services = new AppServices(paths); var services = new AppServices(paths);
L.I.Initialize(services.Settings.Current.Language); 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; Current = services;
return services; return services;
@@ -25,7 +25,7 @@ public sealed class GitCodeReleaseRemote : IModelRemote
private readonly GitCodeRemote _content; private readonly GitCodeRemote _content;
private readonly HttpClient _http; private readonly HttpClient _http;
private readonly string _releasesUrl; private readonly string _releasesUrl;
private readonly Dictionary<string, (string Url, string? Sha256, long Size)> _assets = new(); private readonly Dictionary<string, (string Url, string? Sha256, long Size, string Name)> _assets = new();
public GitCodeReleaseRemote(string? manifestUrl, string? repository, HttpClient? http = null) 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 (rid == null || string.IsNullOrWhiteSpace(asset.Url)) continue;
// 同名平台取第一个有效附件 // 同名平台取第一个有效附件
if (!_assets.ContainsKey(rid)) if (!_assets.ContainsKey(rid))
_assets[rid] = (asset.Url, asset.Sha256, asset.Size); _assets[rid] = (asset.Url, asset.Sha256, asset.Size, asset.Name);
} }
// 把附件地址写回 packages:有附件就用附件的直链与校验值, // 把附件地址写回 packages:有附件就用附件的直链与校验值,
@@ -114,6 +114,7 @@ public sealed class GitCodeReleaseRemote : IModelRemote
version.Launcher.Packages[rid] = pkg; version.Launcher.Packages[rid] = pkg;
} }
pkg.Url = info.Url; pkg.Url = info.Url;
pkg.AssetName = info.Name;
if (!string.IsNullOrWhiteSpace(info.Sha256)) pkg.Sha256 = info.Sha256; if (!string.IsNullOrWhiteSpace(info.Sha256)) pkg.Sha256 = info.Sha256;
if (info.Size > 0) pkg.Size = info.Size; if (info.Size > 0) pkg.Size = info.Size;
} }
@@ -141,13 +142,17 @@ public sealed class GitCodeReleaseRemote : IModelRemote
{ {
foreach (var a in assets.EnumerateArray()) 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 info.Assets.Add(new ReleaseAsset
{ {
Name = Str(a, "name") ?? Str(a, "file_name") ?? "", Name = Str(a, "name") ?? Str(a, "file_name") ?? "",
BrowserDownloadUrl = Str(a, "browser_download_url"), BrowserDownloadUrl = Str(a, "browser_download_url"),
DownloadUrl = Str(a, "download_url") ?? Str(a, "url"), DownloadUrl = Str(a, "download_url") ?? Str(a, "url"),
Size = Num(a, "size"), Size = Num(a, "size"),
Sha256 = Str(a, "sha256") ?? Str(a, "digest") Sha256 = Str(a, "sha256") ?? Str(a, "digest"),
Type = type
}); });
} }
} }
@@ -21,6 +21,27 @@ public sealed class MemoryBudget
Changed?.Invoke(); Changed?.Invoke();
} }
/// <summary>
/// 自动预算:取设备可用物理内存的一部分(约 1/4),
/// 夹在 512–8192 MB 之间,低配设备也不会因为预算过大而卡顿。
/// </summary>
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;
}
/// <summary>按设置应用:auto 时自动计算,否则用手动值。</summary>
public void ApplyAuto(bool auto, int manualMb)
=> Apply(auto ? AutoComputeMb() : manualMb);
/// <summary>内存情况变化(例如模型窗口开关)时刷新展示。</summary> /// <summary>内存情况变化(例如模型窗口开关)时刷新展示。</summary>
public void Refresh() => Changed?.Invoke(); public void Refresh() => Changed?.Invoke();
@@ -28,9 +28,17 @@ public sealed class ReleaseInfo
// "v1.0.1" / "GC-1.0.1" / "release-1.0.1" -> 取第一段像版本号的部分 // "v1.0.1" / "GC-1.0.1" / "release-1.0.1" -> 取第一段像版本号的部分
foreach (var prefix in new[] { "v", "V", "GC-", "gc-", "release-", "Release-" }) foreach (var prefix in new[] { "v", "V", "GC-", "gc-", "release-", "Release-" })
if (raw.StartsWith(prefix, StringComparison.Ordinal)) { raw = raw[prefix.Length..]; break; } 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('-'); 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; return raw;
} }
} }
@@ -41,11 +49,43 @@ public sealed class ReleaseAsset
public string? BrowserDownloadUrl { get; set; } public string? BrowserDownloadUrl { get; set; }
public string? DownloadUrl { get; set; } public string? DownloadUrl { get; set; }
public long Size { get; set; } public long Size { get; set; }
public string? Sha256 { get; set; } /// <summary>附件类型:GitCode 用 "source" 表示自动生成的源码压缩包,需跳过。</summary>
public string? Type { get; set; }
private string? _sha256;
/// <summary>
/// 校验值。真实 Release 的 digest 形如 "sha256:899fc1...",
/// 这里统一剥掉算法前缀,只留 hex,便于与 SHA256.HashData 结果比较。
/// </summary>
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] [JsonIgnore]
public string Url => BrowserDownloadUrl ?? DownloadUrl ?? ""; public string Url => BrowserDownloadUrl ?? DownloadUrl ?? "";
/// <summary>单文件发布包(.exe 等)不能走解压,需要直接作为 payload 内容。</summary>
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);
}
}
/// <summary>解析附件名里的系统/架构,映射到 .NET RID。</summary> /// <summary>解析附件名里的系统/架构,映射到 .NET RID。</summary>
/// <returns>如 win-x64 / win-arm64 / osx-arm64;无法识别返回 null。</returns> /// <returns>如 win-x64 / win-arm64 / osx-arm64;无法识别返回 null。</returns>
public string? RidFromName(string fullName) public string? RidFromName(string fullName)
@@ -60,8 +100,12 @@ public sealed class ReleaseAsset
if (!win && !mac && !linux) return null; if (!win && !mac && !linux) return null;
bool arm64 = lower.Contains("arm64") || lower.Contains("aarch64") || lower.Contains("win-arm"); bool arm64 = lower.Contains("arm64") || lower.Contains("aarch64") || lower.Contains("win-arm");
bool x86 = lower.Contains("x86") && !lower.Contains("x64") && !lower.Contains("amd64") && !arm64; // x86_64 / x86-64 / amd64 / x64 都是 64 位;只有裸 "x86"/"win-x86" 才是 32 位
// amd64 / x64 / x86_64 都视为 x64 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"; var arch = arm64 ? "arm64" : x86 ? "x86" : "x64";
if (win) return "win-" + arch; if (win) return "win-" + arch;
@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using EarthModelStudio.Models; using EarthModelStudio.Models;
namespace EarthModelStudio.Services; namespace EarthModelStudio.Services;
@@ -17,24 +18,40 @@ public sealed class SettingsService
public void Load() public void Load()
{ {
Current = Json.Read<AppSettings>(_paths.SettingsFile) ?? new AppSettings(); Current = Json.Read<AppSettings>(_paths.SettingsFile) ?? new AppSettings();
if (Current.Sources.Count == 0) SeedSources(); SeedDefaultSource();
if (Current.MemoryMb < 256) Current.MemoryMb = 2048; if (Current.MemoryMb < 256) Current.MemoryMb = 2048;
} }
/// <summary> /// <summary>
/// 自动更新由 UpdateService 负责(版本清单 version.json),这里不预置任何在线源; /// 默认下载源(gitcode 官方仓库)始终内置在列表里,且不允许删除:
/// 只给「下载」页留一条空的自定义源占位。 /// 它是启动器自动更新的同源仓库,用户清掉会导致模型无法回退。
/// 老配置里没有这条时自动补上;已有的用户自定义源保持不变。
/// </summary> /// </summary>
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", Current.Sources.Insert(0, new ModelSource
Name = "自定义源", {
Url = "", Id = DefaultSourceId,
Enabled = false Name = "Morris GC (GitCode)",
}); Url = DefaultSourceUrl,
Save(); Enabled = true,
BuiltIn = true
});
Save();
}
else
{
// 强制保证内置标记与地址,避免旧配置被用户改坏后失去保护
existing.BuiltIn = true;
if (string.IsNullOrWhiteSpace(existing.Url)) existing.Url = DefaultSourceUrl;
}
} }
public void Save() public void Save()
@@ -32,6 +32,8 @@ public sealed class RepoPackage
public string? Path { get; set; } public string? Path { get; set; }
public string? Sha256 { get; set; } public string? Sha256 { get; set; }
public long Size { get; set; } public long Size { get; set; }
/// <summary>Release 附件名(用于判断是 zip 还是单文件 exe / .app.zip)。</summary>
public string? AssetName { get; set; }
} }
public sealed class RepoModel public sealed class RepoModel
@@ -314,24 +314,36 @@ public sealed class UpdateService
Directory.CreateDirectory(_paths.UpdateRoot); Directory.CreateDirectory(_paths.UpdateRoot);
var payload = Path.Combine(_paths.UpdateRoot, "payload"); var payload = Path.Combine(_paths.UpdateRoot, "payload");
if (Directory.Exists(payload)) Directory.Delete(payload, true); if (Directory.Exists(payload)) Directory.Delete(payload, true);
var zip = Path.Combine(_paths.CacheRoot, "launcher-" + Safe(launcher.Version) + ".zip"); Directory.CreateDirectory(payload);
await File.WriteAllBytesAsync(zip, bytes, ct);
try // 单文件发布包(.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 Json.Write(Path.Combine(_paths.UpdateRoot, "pending.json"), new PendingUpdate
{ {
Version = launcher.Version, Version = launcher.Version,
Rid = rid, Rid = rid,
InstallDirectory = _paths.InstallDirectory, InstallDirectory = _paths.InstallDirectory,
Executable = Path.GetFileName(Environment.ProcessPath ?? ""), Executable = executableName,
Payload = "payload", Payload = "payload",
DownloadedAt = DateTime.UtcNow.ToString("O") DownloadedAt = DateTime.UtcNow.ToString("O")
}); });
@@ -246,4 +246,42 @@
<Setter Property="FontSize" Value="12.5" /> <Setter Property="FontSize" Value="12.5" />
</Style> </Style>
<!-- 自建标题栏按钮 -->
<Style Selector="Button.titlebtn">
<Setter Property="Width" Value="38" />
<Setter Property="Height" Value="30" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="#A9B8D4" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="FontSize" Value="13" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="CornerRadius" Value="7" />
<Setter Property="Margin" Value="2,0" />
<Setter Property="Transitions">
<Transitions>
<DoubleTransition Property="Opacity" Duration="0:0:0.12" />
<BrushTransition Property="Background" Duration="0:0:0.12" />
</Transitions>
</Setter>
</Style>
<Style Selector="Button.titlebtn:pointerover">
<Setter Property="Background" Value="#223252" />
<Setter Property="Foreground" Value="#FFFFFF" />
</Style>
<Style Selector="Button.titlebtn.close:pointerover">
<Setter Property="Background" Value="#D64545" />
<Setter Property="Foreground" Value="#FFFFFF" />
</Style>
<!-- 所有按钮按下时的缩放反馈(MENU 按钮同样生效) -->
<Style Selector="Button">
<Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
</Style>
<Style Selector="Button:pressed">
<Setter Property="RenderTransform">
<ScaleTransform ScaleX="0.94" ScaleY="0.94" />
</Setter>
</Style>
</Styles> </Styles>
@@ -93,6 +93,7 @@ public partial class DownloadViewModel : ObservableObject
internal void RemoveSource(SourceItemViewModel source) internal void RemoveSource(SourceItemViewModel source)
{ {
if (source.Model.BuiltIn) return; // 内置默认源不允许删除
_services.Settings.Current.Sources.Remove(source.Model); _services.Settings.Current.Sources.Remove(source.Model);
_services.Settings.Save(); _services.Settings.Save();
var wasSelected = SelectedSource == source; 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 Name => string.IsNullOrWhiteSpace(Model.Name) ? Model.Id : Model.Name;
public string HostText => string.IsNullOrWhiteSpace(Model.Url) ? L.I["dl.noSource"] : Model.DisplayHost; public string HostText => string.IsNullOrWhiteSpace(Model.Url) ? L.I["dl.noSource"] : Model.DisplayHost;
public bool HasUrl => !string.IsNullOrWhiteSpace(Model.Url); public bool HasUrl => !string.IsNullOrWhiteSpace(Model.Url);
/// <summary>内置默认源不可删除(下载页隐藏删除按钮)。</summary>
public bool CanRemove => !Model.BuiltIn;
public bool Enabled public bool Enabled
{ {
@@ -24,11 +24,12 @@ public partial class SettingsViewModel : ObservableObject
public ObservableCollection<SettingsSourceViewModel> Sources { get; } = new(); public ObservableCollection<SettingsSourceViewModel> Sources { get; } = new();
public ObservableCollection<LanguageOption> Languages { get; } = new(); public ObservableCollection<LanguageOption> 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 LanguageOption? _selectedLanguage;
[ObservableProperty] private int _selectedFps = 30; [ObservableProperty] private int _selectedFps = 120;
[ObservableProperty] private double _memoryValue = 2048; [ObservableProperty] private double _memoryValue = 2048;
[ObservableProperty] private bool _memoryAuto = true;
[ObservableProperty] private string _statusMessage = ""; [ObservableProperty] private string _statusMessage = "";
[ObservableProperty] private bool _autoUpdate = true; [ObservableProperty] private bool _autoUpdate = true;
@@ -46,7 +47,9 @@ public partial class SettingsViewModel : ObservableObject
public string PendingText => string.IsNullOrWhiteSpace(_services.Settings.Current.PendingLauncherVersion) public string PendingText => string.IsNullOrWhiteSpace(_services.Settings.Current.PendingLauncherVersion)
? L.I["update.none"] : _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 UsageText => _services.Memory.UsageText;
public string ModelRoot => _services.Paths.ModelRoot; public string ModelRoot => _services.Paths.ModelRoot;
public string DataRoot => _services.Paths.DataRoot; public string DataRoot => _services.Paths.DataRoot;
@@ -69,6 +72,7 @@ public partial class SettingsViewModel : ObservableObject
var settings = _services.Settings.Current; var settings = _services.Settings.Current;
SelectedFps = settings.RenderFps; SelectedFps = settings.RenderFps;
MemoryValue = settings.MemoryMb; MemoryValue = settings.MemoryMb;
MemoryAuto = settings.MemoryAuto;
AutoUpdate = settings.AutoUpdateOnStartup; AutoUpdate = settings.AutoUpdateOnStartup;
Sources.Clear(); Sources.Clear();
@@ -133,6 +137,15 @@ public partial class SettingsViewModel : ObservableObject
OnPropertyChanged(nameof(UsageText)); 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] [RelayCommand]
private void OpenModelFolder() => Shell.OpenFolder(_services.Paths.ModelRoot); private void OpenModelFolder() => Shell.OpenFolder(_services.Paths.ModelRoot);
@@ -160,6 +173,7 @@ public partial class SettingsViewModel : ObservableObject
internal void RemoveSource(SettingsSourceViewModel source) internal void RemoveSource(SettingsSourceViewModel source)
{ {
if (source.Model.BuiltIn) return; // 内置默认源不允许删除
_services.Settings.Current.Sources.Remove(source.Model); _services.Settings.Current.Sources.Remove(source.Model);
_services.Settings.Save(); _services.Settings.Save();
Sources.Remove(source); 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 Name => string.IsNullOrWhiteSpace(Model.Name) ? Model.Id : Model.Name;
public string UrlText => string.IsNullOrWhiteSpace(Model.Url) ? L.I["dl.noSource"] : Model.Url; public string UrlText => string.IsNullOrWhiteSpace(Model.Url) ? L.I["dl.noSource"] : Model.Url;
/// <summary>内置默认源不可删除。</summary>
public bool CanRemove => !Model.BuiltIn;
public bool Enabled public bool Enabled
{ {
@@ -32,7 +32,7 @@
<TextBlock Text="{Binding HostText}" Classes="faint" TextTrimming="CharacterEllipsis" /> <TextBlock Text="{Binding HostText}" Classes="faint" TextTrimming="CharacterEllipsis" />
</StackPanel> </StackPanel>
<Button Grid.Column="1" Classes="ghost small" Content="✕" <Button Grid.Column="1" Classes="ghost small" Content="✕"
Command="{Binding RemoveCommand}" VerticalAlignment="Center" /> IsVisible="{Binding CanRemove}" Command="{Binding RemoveCommand}" VerticalAlignment="Center" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
@@ -6,9 +6,32 @@
Width="1220" Height="800" Width="1220" Height="800"
MinWidth="1040" MinHeight="700" MinWidth="1040" MinHeight="700"
Background="{DynamicResource AppBg}" Background="{DynamicResource AppBg}"
SystemDecorations="None"
WindowStartupLocation="CenterScreen"> WindowStartupLocation="CenterScreen">
<Grid ColumnDefinitions="236,*" RowDefinitions="*,Auto"> <!-- 禁用系统标题栏,改用自建标题栏(第 13/14 项) -->
<Grid RowDefinitions="44,*">
<!-- 自建标题栏 -->
<Border x:Name="TitleBar" Grid.Row="0" Background="{DynamicResource SideBg}"
PointerPressed="OnTitleBarPointerPressed">
<Grid ColumnDefinitions="*,Auto,Auto" Margin="16,0,8,0">
<StackPanel Orientation="Horizontal" Spacing="10" VerticalAlignment="Center">
<Border Width="22" Height="22" CornerRadius="7" Background="#1C2C4C">
<TextBlock Text="◎" FontSize="13" Foreground="#8FB6FF"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<TextBlock Text="{loc:Loc app.name}" Foreground="#F2F6FF" FontSize="12.5"
FontWeight="SemiBold" VerticalAlignment="Center" />
</StackPanel>
<Button x:Name="MinimizeButton" Grid.Column="1" Classes="titlebtn"
Content="—" Click="OnMinimizeClick" />
<Button x:Name="CloseButton" Grid.Column="2" Classes="titlebtn close"
Content="✕" Click="OnCloseClick" />
</Grid>
</Border>
<!-- 原内容整体下移一行 -->
<Grid Grid.Row="1" ColumnDefinitions="236,*" RowDefinitions="*,Auto">
<!-- 侧栏 --> <!-- 侧栏 -->
<Border Grid.Column="0" Grid.RowSpan="2" Background="{DynamicResource SideBg}"> <Border Grid.Column="0" Grid.RowSpan="2" Background="{DynamicResource SideBg}">
@@ -70,5 +93,6 @@
VerticalAlignment="Center" /> VerticalAlignment="Center" />
</Grid> </Grid>
</Border> </Border>
</Grid>
</Grid> </Grid>
</Window> </Window>
@@ -8,6 +8,7 @@ using Avalonia.Animation.Easings;
using Avalonia.Threading; using Avalonia.Threading;
using System.Linq; using System.Linq;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using EarthModelStudio.Models; using EarthModelStudio.Models;
using EarthModelStudio.Services; using EarthModelStudio.Services;
@@ -144,6 +145,35 @@ public partial class MainWindow : Window
window.Activate(); window.Activate();
} }
// ---- 自建标题栏 ------------------------------------------------------
private void OnTitleBarPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
BeginMoveDrag(e);
}
private void OnMinimizeClick(object? sender, global::Avalonia.Interactivity.RoutedEventArgs e)
=> WindowState = WindowState.Minimized;
// 关闭动画:先淡出再真正 Close(第 4 项)
private async void OnCloseClick(object? sender, global::Avalonia.Interactivity.RoutedEventArgs e)
{
if (_isClosing) return;
Opacity = 1;
Transitions = new Transitions
{
new DoubleTransition
{
Property = OpacityProperty,
Duration = TimeSpan.FromMilliseconds(180),
Easing = new CubicEaseIn()
}
};
Opacity = 0;
await Task.Delay(190);
Close();
}
private void OnClosed(object? sender, EventArgs e) private void OnClosed(object? sender, EventArgs e)
{ {
_isClosing = true; _isClosing = true;
@@ -50,7 +50,10 @@
Foreground="{DynamicResource Accent}" VerticalAlignment="Center" /> Foreground="{DynamicResource Accent}" VerticalAlignment="Center" />
</Grid> </Grid>
<TextBlock Classes="muted" Text="{loc:Loc set.memory.desc}" TextWrapping="Wrap" /> <TextBlock Classes="muted" Text="{loc:Loc set.memory.desc}" TextWrapping="Wrap" />
<CheckBox Content="{loc:Loc set.memory.auto}" IsChecked="{Binding MemoryAuto}"
Margin="0,2,0,0" />
<Slider Minimum="512" Maximum="8192" TickFrequency="256" IsSnapToTickEnabled="False" <Slider Minimum="512" Maximum="8192" TickFrequency="256" IsSnapToTickEnabled="False"
IsEnabled="{Binding !MemoryAuto}"
Value="{Binding MemoryValue}" Margin="0,4,0,0" /> Value="{Binding MemoryValue}" Margin="0,4,0,0" />
<Grid ColumnDefinitions="*,Auto"> <Grid ColumnDefinitions="*,Auto">
<TextBlock Classes="faint" Text="{loc:Loc set.memory.hint}" TextWrapping="Wrap" /> <TextBlock Classes="faint" Text="{loc:Loc set.memory.hint}" TextWrapping="Wrap" />
@@ -75,7 +78,7 @@
<TextBlock Text="{Binding UrlText}" Classes="faint" TextTrimming="CharacterEllipsis" MaxWidth="520" /> <TextBlock Text="{Binding UrlText}" Classes="faint" TextTrimming="CharacterEllipsis" MaxWidth="520" />
</StackPanel> </StackPanel>
<Button Grid.Column="2" Classes="ghost small" Content="✕" <Button Grid.Column="2" Classes="ghost small" Content="✕"
Command="{Binding RemoveCommand}" VerticalAlignment="Center" /> IsVisible="{Binding CanRemove}" Command="{Binding RemoveCommand}" VerticalAlignment="Center" />
</Grid> </Grid>
</Border> </Border>
</DataTemplate> </DataTemplate>
@@ -143,14 +146,6 @@
<TextBlock Classes="h3" Text="{loc:Loc set.version}" /> <TextBlock Classes="h3" Text="{loc:Loc set.version}" />
<TextBlock Grid.Column="1" Classes="muted" Text="{Binding VersionText}" /> <TextBlock Grid.Column="1" Classes="muted" Text="{Binding VersionText}" />
</Grid> </Grid>
<Grid ColumnDefinitions="200,*">
<TextBlock Classes="h3" Text="{loc:Loc set.platform}" />
<TextBlock Grid.Column="1" Classes="muted" Text="{Binding PlatformText}" TextWrapping="Wrap" />
</Grid>
<Grid ColumnDefinitions="200,*">
<TextBlock Classes="h3" Text="{loc:Loc set.modelFormat}" />
<TextBlock Grid.Column="1" Classes="muted" Text="{loc:Loc set.modelFormat.desc}" TextWrapping="Wrap" />
</Grid>
<Grid ColumnDefinitions="200,*"> <Grid ColumnDefinitions="200,*">
<TextBlock Classes="h3" Text="{loc:Loc set.license}" /> <TextBlock Classes="h3" Text="{loc:Loc set.license}" />
<TextBlock Grid.Column="1" Classes="muted" Text="{loc:Loc set.licenseValue}" /> <TextBlock Grid.Column="1" Classes="muted" Text="{loc:Loc set.licenseValue}" />