diff --git a/Updator.Birth/Program.cs b/Updator.Birth/Program.cs index fe6da5a..622558d 100644 --- a/Updator.Birth/Program.cs +++ b/Updator.Birth/Program.cs @@ -11,13 +11,14 @@ using ICSharpCode.SharpZipLib.Checksum; using ICSharpCode.SharpZipLib.Zip; using Updator.Birth; +using Updator.Common.CompressionProvider; using Updator.Common.Downloader; using Updator.Downloader.CLI; using Uploader.StorageProvider; using Crc32 = System.IO.Hashing.Crc32; using ZipFile = ICSharpCode.SharpZipLib.Zip.ZipFile; -Console.OutputEncoding = Encoding.UTF8; +Console.OutputEncoding = Encoding.UTF8; // Get projects root from args[0] var birthDir = args[0]; @@ -28,6 +29,15 @@ await JsonSerializer.DeserializeAsync( // I use Tencent COS as a distributor var storage = new TencentCos(config.cos); +async Task DecompressBrotli(byte[] data) { + using var decompressed = new MemoryStream(); + using var compressed = new MemoryStream(data); + var brotli = new Brotli(); + await brotli.Decompress(compressed, decompressed); + decompressed.Position = 0; + return decompressed.ToArray(); +} + ConcurrentBag keys = new(); await Parallel.ForEachAsync(config.projects, new ParallelOptions() { MaxDegreeOfParallelism = 4 }, async (project, _) => { Console.WriteLine($@"Publish {project.name}"); @@ -38,20 +48,48 @@ await JsonSerializer.DeserializeAsync( } using var http = new HttpClient(); - var bin = await http.GetByteArrayAsync($"https://direct.dist.reito.fun/downloader/cli-{project.platform}-x64"); + var bin = await http.GetByteArrayAsync($"https://direct.dist.reito.fun/downloader/ui-{project.platform}"); + bin = await DecompressBrotli(bin); using var ms = new MemoryStream(); var zip = ZipFile.Create(ms); + zip.BeginUpdate(); + zip.SetComment("请解压至任意文件夹使用,不要直接在压缩包中打开!"); + var name = string.IsNullOrWhiteSpace(project.display) ? project.name : project.display; - var exe = new ZipEntry( - $"{name}/{name}{config.suffix}{(project.platform == "win" ? ".exe" : string.Empty)}") { - IsUnicodeText = true, - HostSystem = 3, - ExternalFileAttributes = 0x81ed << 16, - Size = bin.Length, - Crc = BitConverter.ToInt32(Crc32.Hash(bin)) - }; + if (project.platform == "osx") { + var temp = Path.GetTempFileName(); + var dir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()).Replace("\\", "/"); + Directory.CreateDirectory(dir); + File.WriteAllBytes(temp, bin); + System.IO.Compression.ZipFile.ExtractToDirectory(temp, dir, Encoding.UTF8, true); + + var files = Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories); + foreach (string file in files) { + var relativePath = file.Replace("\\", "/").Replace(dir, string.Empty); + var bytes = File.ReadAllBytes(file); + var e = new ZipEntry( + $"{name}/{name}{config.suffix}.app{relativePath}") { + IsUnicodeText = true, + HostSystem = 3, + ExternalFileAttributes = relativePath.EndsWith("Contents/MacOS/Updator.Downloader.UI") ? 0x81ed << 16 : 0x81a4 << 16, + Size = bytes.Length, + Crc = BitConverter.ToInt32(Crc32.Hash(bytes)) + }; + zip.Add(new MemoryDataSource(bytes), e); + } + } else { + var exe = new ZipEntry( + $"{name}/{name}{config.suffix}{(project.platform == "win" ? ".exe" : string.Empty)}") { + IsUnicodeText = true, + HostSystem = 3, + ExternalFileAttributes = 0x81ed << 16, + Size = bin.Length, + Crc = BitConverter.ToInt32(Crc32.Hash(bin)) + }; + zip.Add(new MemoryDataSource(bin), exe); + } var sources = File.ReadAllBytes(path); var src = new ZipEntry($"{name}/sources.json") { @@ -62,16 +100,13 @@ await JsonSerializer.DeserializeAsync( Crc = BitConverter.ToInt32(Crc32.Hash(sources)) }; - zip.BeginUpdate(); - zip.SetComment("请解压至任意文件夹使用,不要直接在压缩包中打开!"); - zip.Add(new MemoryDataSource(bin), exe); zip.Add(new MemoryDataSource(sources), src); zip.CommitUpdate(); zip.Close(); var z = ms.ToArray(); - + File.WriteAllBytes(Path.Combine(birthDir, project.name, $"{project.name}.zip"), z); Console.WriteLine($@"Upload Tencent Cos {project.name}"); diff --git a/Updator.Common/Downloader/Meta.cs b/Updator.Common/Downloader/Meta.cs index 60d9d50..4512337 100644 --- a/Updator.Common/Downloader/Meta.cs +++ b/Updator.Common/Downloader/Meta.cs @@ -2,9 +2,9 @@ namespace Updator.Common.Downloader; public class Meta { - public const int WinVersion = 59; - public const int MacVersion = 59; - public const int LinuxVersion = 59; + public const int WinVersion = 60; + public const int MacVersion = 60; + public const int LinuxVersion = 60; public static int RuntimeVersion { get { diff --git a/Updator.Downloader.Publish/Program.cs b/Updator.Downloader.Publish/Program.cs index 68b71a4..df6f888 100644 --- a/Updator.Downloader.Publish/Program.cs +++ b/Updator.Downloader.Publish/Program.cs @@ -56,7 +56,7 @@ async Task PublishWin() { var proc = Process.Start(new ProcessStartInfo() { FileName = "dotnet", Arguments = - $"publish -r {runtime}-x64 -c Release --self-contained --framework net7.0 -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:PublishTrimmed=true -p:IncludeAllContentForSelfExtract=true", + $"publish -r {runtime}-x64 -c Release --self-contained --framework net7.0", WorkingDirectory = projectDir, UseShellExecute = false })!; @@ -80,6 +80,14 @@ async Task PublishMac() { var runtime = "osx"; Console.WriteLine($@"Publish {runtime}"); var proc = Process.Start(new ProcessStartInfo() { + FileName = "dotnet", + Arguments = + $"publish -r {runtime}-x64 -c Release --self-contained --framework net7.0", + WorkingDirectory = projectDir, + UseShellExecute = false + })!; + await proc.WaitForExitAsync(); + proc = Process.Start(new ProcessStartInfo() { FileName = "dotnet", Arguments = $"msbuild -t:BundleApp -p:CFBundleShortVersionString={Meta.MacVersion} -p:Configuration=Release -p:RuntimeIdentifier=osx-x64 -p:SelfContained=true",