mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Security.Cryptography;
|
|
using Newtonsoft.Json.Linq;
|
|
using Newtonsoft.Json;
|
|
using System.IO.Compression;
|
|
|
|
namespace BilibiliEvolved.Build
|
|
{
|
|
partial class ProjectBuilder
|
|
{
|
|
public ProjectBuilder BuildBundle()
|
|
{
|
|
var urlList = from file in Directory.GetFiles("min")
|
|
where !file.Contains("dark-slice")
|
|
select file.Replace(@"\", "/");
|
|
var hashDict = new Dictionary<string, string>();
|
|
var zipName = "min/bundle.zip";
|
|
// if (File.Exists(zipName))
|
|
// {
|
|
// File.Delete(zipName);
|
|
// }
|
|
using (var sha256 = new SHA256Managed())
|
|
using (var zip = ZipFile.Open(zipName, ZipArchiveMode.Update))
|
|
{
|
|
foreach (var url in urlList)
|
|
{
|
|
var filename = Path.GetFileName(url);
|
|
if (filename.StartsWith("bundle.")) {
|
|
continue;
|
|
}
|
|
var hash = string.Join("", sha256.ComputeHash(File.OpenRead(url)).Select(b => b.ToString("X2")).ToArray());
|
|
zip.CreateEntryFromFile(url, filename);
|
|
hashDict.Add(filename, hash);
|
|
}
|
|
}
|
|
File.WriteAllText("min/bundle.json", JsonConvert.SerializeObject(hashDict, Formatting.Indented));
|
|
WriteSuccess("Bundle build complete.");
|
|
return this;
|
|
}
|
|
}
|
|
} |