Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ jobs:
with:
dotnet-version: '10.0.x'

- name: Publish self-contained build
run: dotnet publish VISaveManager.csproj -c Release -r ${{ matrix.rid }} --self-contained true -o dist/publish
- name: Install the Native AOT toolchain
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y clang zlib1g-dev

# Linux: Native AOT. Windows: single-file, self-contained, ReadyToRun (set in the .csproj).
- name: Publish release build
run: dotnet publish VISaveManager.csproj -c Release -r ${{ matrix.rid }} -o dist/publish

- name: Verify published files
shell: pwsh
Expand Down
47 changes: 32 additions & 15 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;

namespace VISM;
Expand Down Expand Up @@ -62,7 +63,6 @@ interface IDesktopHost

sealed class SaveManager(IDesktopHost host, bool test, string? saveDirectory)
{
static readonly JsonSerializerOptions Json = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
const string TitleId = SaveLocations.TitleId;
readonly SaveLocations locations = new(test, saveDirectory);
public string ProfileDirectory => locations.ProfileDirectory;
Expand Down Expand Up @@ -92,7 +92,7 @@ async Task CheckUpdateAsync()
var url = (string?)j?["html_url"] ?? $"https://github.com/{Repo}/releases/latest";
var notes = ((string?)j?["body"] ?? "").Trim();
if (notes.Length > 400) notes = notes[..400] + "…";
Send(new { type = "update", version = latest.ToString(), url, notes });
Send(new UpdateMessage("update", latest.ToString(), url, notes));
}
catch { }
}
Expand All @@ -103,7 +103,9 @@ static void OpenRelease(string? url)
try { Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); } catch { }
}

void Send(object value) => host.Post(JsonSerializer.Serialize(value, Json));
// messages to the page: types known at build time, so Native AOT needs no reflection
void Send(UpdateMessage value) => host.Post(JsonSerializer.Serialize(value, VismJson.Default.UpdateMessage));
void Send(SavesMessage value) => host.Post(JsonSerializer.Serialize(value, VismJson.Default.SavesMessage));

public void OnMessage(string raw)
{
Expand Down Expand Up @@ -225,18 +227,16 @@ static bool IsVictory(string value)
void SendSaves(string? note = null, bool ok = true)
{
var dir = SavesDir();
object Item(string d) => new { name = Path.GetFileName(d), size = DirSize(d), gameTime = DirNewest(d).ToString("yyyy-MM-dd HH:mm"), kept = KeptTime(d).ToString("yyyy-MM-dd HH:mm"), note = Note(d), auto = Path.GetFileName(d).StartsWith("auto ") };
SaveItem Item(string d) => new(Path.GetFileName(d), DirSize(d), DirNewest(d).ToString("yyyy-MM-dd HH:mm"), KeptTime(d).ToString("yyyy-MM-dd HH:mm"), Note(d), Path.GetFileName(d).StartsWith("auto "));
var spots = (Directory.Exists(SnapsRoot) ? Directory.GetDirectories(SnapsRoot) : Array.Empty<string>()).OrderByDescending(KeptTime).Select(Item).ToList();
var team = (Directory.Exists(TeamRoot) ? Directory.GetDirectories(TeamRoot) : Array.Empty<string>()).OrderBy(d => d).Select(Item).ToList();
Send(new
{
type = "saves", note, ok, test, canChooseSaveFolder = OperatingSystem.IsLinux() && !test,
saveDirectory = OperatingSystem.IsLinux() ? dir : null,
found = dir != null && DirSize(dir) > 0,
size = dir != null ? DirSize(dir) : 0,
newest = dir != null ? DirNewest(dir).ToString("yyyy-MM-dd HH:mm") : "",
running = GameRunning(), spots, team,
});
Send(new SavesMessage(
"saves", note, ok, test, OperatingSystem.IsLinux() && !test,
OperatingSystem.IsLinux() ? dir : null,
dir != null && DirSize(dir) > 0,
dir != null ? DirSize(dir) : 0,
dir != null ? DirNewest(dir).ToString("yyyy-MM-dd HH:mm") : "",
GameRunning(), spots, team));
}

static DateTime KeptTime(string directory) => OperatingSystem.IsWindows()
Expand Down Expand Up @@ -362,9 +362,9 @@ void Share(string? name, string kind)
if (filename == null) { SendSaves(); return; }
using (var zip = new ZipArchive(File.Create(filename), ZipArchiveMode.Create))
{
var info = new { name = label, note = Note(src), game = "GTA VI (Xbox Series), title " + TitleId, savedAt = DirNewest(src).ToString("yyyy-MM-dd HH:mm"), madeWith = "VI Save Manager" };
var info = new SaveInfo(label, Note(src), "GTA VI (Xbox Series), title " + TitleId, DirNewest(src).ToString("yyyy-MM-dd HH:mm"), "VI Save Manager");
var e = zip.CreateEntry("save-info.json");
using (var w = new StreamWriter(e.Open(), new UTF8Encoding(false))) w.Write(JsonSerializer.Serialize(info, new JsonSerializerOptions { WriteIndented = true }));
using (var w = new StreamWriter(e.Open(), new UTF8Encoding(false))) w.Write(JsonSerializer.Serialize(info, VismJsonIndented.Default.SaveInfo));
foreach (var f in Directory.EnumerateFiles(src, "*", SaveTree))
{
if (Path.GetFileName(f) == "about.txt") continue;
Expand Down Expand Up @@ -418,3 +418,20 @@ void Import()
SendSaves(msg.Trim(), failed.Count == 0);
}
}

// ---- the JSON this app writes, generated at build time (Native AOT has no reflection) ----
record UpdateMessage(string Type, string Version, string Url, string Notes);
record SaveItem(string Name, long Size, string GameTime, string Kept, string Note, bool Auto);
record SavesMessage(string Type, string? Note, bool Ok, bool Test, bool CanChooseSaveFolder, string? SaveDirectory,
bool Found, long Size, string Newest, bool Running, List<SaveItem> Spots, List<SaveItem> Team);
// save-info.json inside a shared zip
record SaveInfo(string Name, string Note, string Game, string SavedAt, string MadeWith);

[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
[JsonSerializable(typeof(UpdateMessage))]
[JsonSerializable(typeof(SavesMessage))]
partial class VismJson : JsonSerializerContext { }

[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, WriteIndented = true)]
[JsonSerializable(typeof(SaveInfo))]
partial class VismJsonIndented : JsonSerializerContext { }
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sudo dnf install gtk3 webkit2gtk4.1 # Nobara / Fedora
sudo apt install libgtk-3-0 libwebkit2gtk-4.1-0 # Debian / Ubuntu
```

Build with the .NET 8 SDK or newer, then launch from the output directory. The default build uses the installed .NET runtime. For a shareable archive that includes .NET, use `./build.sh --release`. Extract that archive into its own folder and run `./VISaveManager`.
Build with the .NET 8 SDK or newer, then launch from the output directory. The default build uses the installed .NET runtime. For a shareable archive, use `./build.sh --release`: it compiles with **Native AOT** into one native `VISaveManager` executable that needs no .NET install (needs `clang` and the zlib headers: `sudo dnf install clang zlib-devel` or `sudo apt install clang zlib1g-dev`). Extract that archive into its own folder and run `./VISaveManager`.

```sh
./build.sh
Expand All @@ -51,8 +51,8 @@ powershell -ExecutionPolicy Bypass -File release.ps1 # make the zip to share
`dotnet build -c Release` defaults to the host OS. You can also target Linux or Windows explicitly with the same checkout. Cross publishing requires the matching SDK/runtime packs, which `dotnet publish` restores from NuGet:

```sh
dotnet publish VISaveManager.csproj -c Release -r linux-x64 --self-contained true -o dist/linux-x64-self-contained
dotnet publish VISaveManager.csproj -c Release -r win-x64 --self-contained true -o dist/win-x64-self-contained
dotnet publish VISaveManager.csproj -c Release -r linux-x64 -o dist/linux-x64 # Native AOT
dotnet publish VISaveManager.csproj -c Release -r win-x64 -o dist/win-x64 # single-file, self-contained, ReadyToRun
```

## Automated builds
Expand All @@ -63,3 +63,8 @@ The **Build VISM** workflow compiles both platforms on pull requests into `main`
- `VISaveManager-win-x64` contains `VISaveManager-win-x64.zip`. Extract it to a folder and run `VISaveManager.exe`. The WebView2 Runtime is required.

Both archives include .NET, the application interface, and the bundled team saves.

Release builds: Linux is compiled with Native AOT (one native executable, no .NET needed). Windows
can't use Native AOT because WinForms and WebView2 don't support it, so it ships as one
self-contained, ReadyToRun-compiled `VISaveManager.exe` instead (no .NET needed either). Both keep
the `ui` and `team-saves` folders next to the executable.
16 changes: 16 additions & 0 deletions VISaveManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
<ApplicationIcon>vism.ico</ApplicationIcon>
<ApplicationHighDpiMode>PerMonitorV2</ApplicationHighDpiMode>
</PropertyGroup>
<!-- Release packages (dotnet publish -c Release -r <rid>):
Linux: Native AOT, one native executable, no .NET needed.
Windows: WinForms and WebView2 can't do Native AOT, so one self-contained,
ReadyToRun-compiled executable instead. The ui and team-saves folders sit beside it. -->
<PropertyGroup Condition="'$(Configuration)' == 'Release' and '$(RuntimeIdentifier)' != '' and '$(TargetFramework)' == 'net8.0'">
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
<StripSymbols>true</StripSymbols>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release' and '$(RuntimeIdentifier)' != '' and '$(TargetFramework)' == 'net8.0-windows'">
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>true</PublishReadyToRun>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-windows'">
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2903.40" />
<Compile Remove="LinuxHost.cs" />
Expand Down
7 changes: 4 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ esac

if [[ $# == 0 ]]; then
output="dist/$rid"
dotnet publish VISaveManager.csproj -c Release -r "$rid" --self-contained false -o "$output"
dotnet publish VISaveManager.csproj -c Release -r "$rid" --self-contained false -p:PublishAot=false -o "$output"
printf 'Launch with ./%s/VISaveManager\n' "$output"
elif [[ $# == 1 && $1 == --release ]]; then
output="dist/$rid-self-contained"
dotnet publish VISaveManager.csproj -c Release -r "$rid" --self-contained true -o "$output"
# Native AOT: needs clang and zlib headers (Fedora: clang zlib-devel, Debian/Ubuntu: clang zlib1g-dev)
output="dist/$rid-native"
dotnet publish VISaveManager.csproj -c Release -r "$rid" -o "$output"
archive="dist/VISaveManager-$rid.tar.gz"
tar -czf "$archive" -C "$output" .
printf 'Built %s\n' "$archive"
Expand Down
4 changes: 2 additions & 2 deletions release.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# The zip to send to the team: a self-contained build (no .NET install needed on their PC),
# The zip to send to the team: one self-contained, ReadyToRun-compiled VISaveManager.exe (no .NET install needed),
# saved as dist\VISaveManager-<version>.zip. Unzip anywhere and run VISaveManager.exe.
# Run: powershell -ExecutionPolicy Bypass -File release.ps1
$ErrorActionPreference = 'Stop'
Set-Location -LiteralPath $PSScriptRoot
$version = ([xml](Get-Content VISaveManager.csproj)).Project.PropertyGroup.Version | Where-Object { $_ } | Select-Object -First 1
$out = Join-Path $PSScriptRoot 'dist\VISaveManager'
if (Test-Path $out) { Remove-Item $out -Recurse -Force }
dotnet publish -c Release -r win-x64 --self-contained true -p:PublishSingleFile=false -o $out
dotnet publish -c Release -r win-x64 -o $out # single-file, self-contained, ReadyToRun (see the .csproj)
if ($LASTEXITCODE -ne 0) { throw "Build failed (exit code $LASTEXITCODE)" }
$zip = Join-Path $PSScriptRoot "dist\VISaveManager-$version.zip"
if (Test-Path $zip) { Remove-Item $zip -Force }
Expand Down
Loading