Skip to content

Commit

Permalink
Save
Browse files Browse the repository at this point in the history
  • Loading branch information
reitowo committed Oct 19, 2023
1 parent 20fd826 commit 826811d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 18 deletions.
63 changes: 49 additions & 14 deletions Updator.Birth/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -28,6 +29,15 @@ await JsonSerializer.DeserializeAsync<BirthConfig>(
// I use Tencent COS as a distributor
var storage = new TencentCos(config.cos);

async Task<byte[]> 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<string> keys = new();
await Parallel.ForEachAsync(config.projects, new ParallelOptions() { MaxDegreeOfParallelism = 4 }, async (project, _) => {
Console.WriteLine($@"Publish {project.name}");
Expand All @@ -38,20 +48,48 @@ await JsonSerializer.DeserializeAsync<BirthConfig>(
}

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") {
Expand All @@ -62,16 +100,13 @@ await JsonSerializer.DeserializeAsync<BirthConfig>(
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}");
Expand Down
6 changes: 3 additions & 3 deletions Updator.Common/Downloader/Meta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion Updator.Downloader.Publish/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})!;
Expand All @@ -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",
Expand Down

0 comments on commit 826811d

Please sign in to comment.