mirror of
https://github.com/k1tbyte/Wand-Enhancer.git
synced 2026-08-28 17:01:04 +00:00
13759b1db6
- reduce ASAR IO overhead with streamed archive reads, buffered copies, faster relative-path handling and placeholder integrity records - fix in-place app.asar.unpacked packing/extraction self-copy cases that caused locked-file failures - tighten JS patch discovery with candidate bundle filters and search hints - require prebuilt remote-panel dist artifacts and clean up embedded bridge/script packaging - add unified build entrypoints for PowerShell, cmd and bash and move native CMake output under .tmp - add release metadata validation, changelog section extraction, pre-commit hook and GitHub Actions validation/release pipelines - make CHANGELOG the source of truth for release notes and document the tag-driven release flow - add updater release notes UI with latest/full changelog loading and localize the new update strings - modularize bridge renderer scripts, add installed apps and game status sync, and support remote launch/stop commands - centralize bridge protocol, IPC and WebSocket constants and improve LAN IP selection for QR pairing - refactor remote panel controls/state enums, persist accent color, polish library/session UI and refresh assets
102 lines
3.8 KiB
C#
102 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
using AsarSharp.AsarFileSystem;
|
|
using AsarSharp.Integrity;
|
|
using AsarSharp.Utils;
|
|
|
|
namespace AsarSharp
|
|
{
|
|
public class CreateOptions
|
|
{
|
|
public Regex Unpack { get; set; }
|
|
}
|
|
|
|
public class AsarCreator
|
|
{
|
|
private readonly string _folderPath;
|
|
private readonly string _destPath;
|
|
private readonly CreateOptions _options;
|
|
private List<string> _filenames = new List<string>();
|
|
private Dictionary<string, CrawledFileType> _metadata = new Dictionary<string, CrawledFileType>();
|
|
|
|
public AsarCreator(string folderPath, string destPath, CreateOptions options)
|
|
{
|
|
_folderPath = folderPath ?? throw new ArgumentNullException(nameof(folderPath));
|
|
_destPath = destPath ?? throw new ArgumentNullException(nameof(destPath));
|
|
_options = options;
|
|
}
|
|
|
|
public void CreatePackageWithOptions()
|
|
{
|
|
var result = FileSystemCrawler.CrawlFileSystem(_folderPath);
|
|
_filenames = result.filenames;
|
|
_metadata = result.metadata;
|
|
CreatePackageFromFiles();
|
|
}
|
|
|
|
|
|
public void CreatePackageFromFiles()
|
|
{
|
|
var filesystem = new Filesystem(_folderPath);
|
|
var files = new List<Disk.BasicFileInfo>(_filenames.Count);
|
|
|
|
foreach (var filename in _filenames)
|
|
{
|
|
HandleFile(filesystem, filename, files);
|
|
}
|
|
|
|
InsertsDone(filesystem, files);
|
|
}
|
|
|
|
|
|
private void HandleFile(Filesystem filesystem, string filename, List<Disk.BasicFileInfo> files)
|
|
{
|
|
if (!_metadata.TryGetValue(filename, out var file))
|
|
{
|
|
file = FileSystemCrawler.DetermineFileType(filename)
|
|
?? throw new Exception("Unknown file type for file: " + filename);
|
|
_metadata[filename] = file;
|
|
}
|
|
|
|
switch (file.Type)
|
|
{
|
|
case FileType.Directory:
|
|
filesystem.InsertDirectory(filename, false);
|
|
break;
|
|
case FileType.File:
|
|
string parentDir = Path.GetDirectoryName(filename) ?? string.Empty;
|
|
string relParent = Extensions.GetRelativePath(_folderPath, parentDir);
|
|
bool shouldUnpack = ShouldUnpackPath(relParent);
|
|
files.Add(new Disk.BasicFileInfo { Filename = filename, Unpack = shouldUnpack });
|
|
|
|
// Build a placeholder integrity record up front. Real
|
|
// SHA-256 hashes are filled in by Disk.WriteFileSystem
|
|
// during the streamed write — eliminates the second pass
|
|
// over each file (open → hash → close → open → copy → close).
|
|
long size = (file.Stat is FileInfo fi) ? fi.Length : 0;
|
|
var placeholder = IntegrityHelper.CreatePlaceholder(size);
|
|
filesystem.InsertFile(filename, shouldUnpack, file, placeholder);
|
|
break;
|
|
case FileType.Link:
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
private bool ShouldUnpackPath(string relativePath)
|
|
{
|
|
return _options?.Unpack?.IsMatch(relativePath) == true;
|
|
}
|
|
|
|
private void InsertsDone(Filesystem filesystem, List<Disk.BasicFileInfo> files)
|
|
{
|
|
Directory.CreateDirectory(
|
|
Path.GetDirectoryName(_destPath)
|
|
?? throw new InvalidOperationException());
|
|
Disk.WriteFileSystem(_destPath, filesystem,
|
|
new Disk.FilesystemFilesAndLinks { Files = files, Links = null }, _metadata);
|
|
}
|
|
}
|
|
}
|