diff --git a/Builders/Builder.cs b/Builders/Builder.cs index 500dfc2..fddc30c 100644 --- a/Builders/Builder.cs +++ b/Builders/Builder.cs @@ -3,7 +3,9 @@ using System; using System.IO; +using System.IO.Compression; using osu.Desktop.Deploy.Uploaders; +using osu.Framework.IO.Network; namespace osu.Desktop.Deploy.Builders { @@ -44,6 +46,28 @@ protected void RunDotnetPublish(string? extraArgs = null, string? outputDir = nu + $" {Program.ProjectName}"); } + protected void AttachSatoriGC(string? outputDir = null) + { + outputDir ??= Program.StagingPath; + + if (Program.UseSatoriGC) + { + Logger.Write("Downloading Satori GC release..."); + string satoriArchivePath = Path.GetTempFileName(); + using (var req = new FileWebRequest(satoriArchivePath, $"https://github.com/ppy/Satori/releases/latest/download/{RuntimeIdentifier}.zip")) + req.Perform(); + + Logger.Write("Extracting Satori GC into staging folder..."); + + using (var stream = File.OpenRead(satoriArchivePath)) + using (var archive = new ZipArchive(stream)) + { + foreach (var entry in archive.Entries) + entry.ExtractToFile(Path.Combine(outputDir, entry.Name), true); + } + } + } + private static void refreshDirectory(string directory) { if (Directory.Exists(directory)) diff --git a/Builders/LinuxBuilder.cs b/Builders/LinuxBuilder.cs index e1ec99d..627119c 100644 --- a/Builders/LinuxBuilder.cs +++ b/Builders/LinuxBuilder.cs @@ -35,29 +35,29 @@ public override Uploader CreateUploader() } // https://learn.microsoft.com/en-us/dotnet/standard/io/how-to-copy-directories - static void CopyDirectory(string sourceDir, string destinationDir, bool recursive) + private static void copyDirectory(string sourceDir, string destinationDir, bool recursive) { var dir = new DirectoryInfo(sourceDir); - + if (!dir.Exists) throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}"); - + DirectoryInfo[] dirs = dir.GetDirectories(); - + Directory.CreateDirectory(destinationDir); - + foreach (FileInfo file in dir.GetFiles()) { string targetFilePath = Path.Combine(destinationDir, file.Name); file.CopyTo(targetFilePath); } - + if (recursive) { foreach (DirectoryInfo subDir in dirs) { string newDestinationDir = Path.Combine(destinationDir, subDir.Name); - CopyDirectory(subDir.FullName, newDestinationDir, true); + copyDirectory(subDir.FullName, newDestinationDir, true); } } } @@ -67,13 +67,14 @@ public override void Build() if (Directory.Exists(stagingTarget)) Directory.Delete(stagingTarget, true); - CopyDirectory(Path.Combine(Program.TemplatesPath, app_dir), stagingTarget, true); + copyDirectory(Path.Combine(Program.TemplatesPath, app_dir), stagingTarget, true); File.CreateSymbolicLink(Path.Combine(stagingTarget, ".DirIcon"), "osu.png"); Program.RunCommand("chmod", $"+x {stagingTarget}/AppRun"); RunDotnetPublish(outputDir: publishTarget); + AttachSatoriGC(outputDir: publishTarget); } } } diff --git a/Builders/MacOSBuilder.cs b/Builders/MacOSBuilder.cs index 04fadf7..543da81 100644 --- a/Builders/MacOSBuilder.cs +++ b/Builders/MacOSBuilder.cs @@ -62,6 +62,7 @@ public override void Build() Program.RunCommand("cp", $"-r \"{Path.Combine(Program.TemplatesPath, app_dir)}\" \"{stagingTarget}\""); RunDotnetPublish(outputDir: publishTarget); + AttachSatoriGC(outputDir: publishTarget); // without touching the app bundle itself, changes to file associations / icons / etc. will be cached at a macOS level and not updated. Program.RunCommand("touch", $"\"{stagingTarget}\" {Program.StagingPath}", false); diff --git a/Builders/WindowsBuilder.cs b/Builders/WindowsBuilder.cs index 42c6d13..8bad086 100644 --- a/Builders/WindowsBuilder.cs +++ b/Builders/WindowsBuilder.cs @@ -48,7 +48,8 @@ public override Uploader CreateUploader() .Where(File.Exists) .Last(); - extraArgs += $" --signTemplate=\"\\\"{signToolPath}\\\" sign /td sha256 /fd sha256 /dlib \\\"{dllPath}\\\" /dmdf \\\"{Path.GetFullPath(Program.WindowsCodeSigningMetadataPath)}\\\" /tr http://timestamp.acs.microsoft.com {{{{file...}}}}"; + extraArgs += + $" --signTemplate=\"\\\"{signToolPath}\\\" sign /td sha256 /fd sha256 /dlib \\\"{dllPath}\\\" /dmdf \\\"{Path.GetFullPath(Program.WindowsCodeSigningMetadataPath)}\\\" /tr http://timestamp.acs.microsoft.com {{{{file...}}}}"; } return new WindowsVelopackUploader(app_name, os_name, RuntimeIdentifier, channel, extraArgs: extraArgs); @@ -57,6 +58,7 @@ public override Uploader CreateUploader() public override void Build() { RunDotnetPublish(); + AttachSatoriGC(); bool rcEditCommand = Program.RunCommand("tools/rcedit-x64.exe", $"\"{Path.Combine(Program.StagingPath, "osu!.exe")}\"" diff --git a/Program.cs b/Program.cs index 43dbc81..7346463 100644 --- a/Program.cs +++ b/Program.cs @@ -46,6 +46,8 @@ internal static class Program public static bool IncrementVersion => bool.Parse(ConfigurationManager.AppSettings["IncrementVersion"] ?? "true"); + public static bool UseSatoriGC => bool.TryParse(Environment.GetEnvironmentVariable("USE_SATORI_GC"), out bool useSatori) && useSatori; + public static string SolutionPath { get; private set; } = null!; private static bool interactive;