public void BuildArchive() { using var builder = new ArchiveBuilder(); foreach (var fileName in Directory.EnumerateFiles(@"C:\DOS\16\KEEN4")) { builder.AddFile(fileName, Path.GetFileName(fileName)); } using var outputStream = new MemoryStream(); builder.Write(outputStream); outputStream.Position = 0; using var reader = new ArchiveFile(outputStream); foreach (var fileName in Directory.EnumerateFiles(@"C:\DOS\16\KEEN4")) { using (var f = File.OpenRead(fileName)) using (var a = reader.OpenItem(Path.GetFileName(fileName))) { Assert.IsTrue(StreamsEqual(f, a)); } } }
public static int Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Usage: aeonpack <AeonConfig> <PackageName>"); return(1); } var archiveBuilder = new ArchiveBuilder(); var config = AeonConfiguration.Load(args[0]); archiveBuilder.AddFile(GetArchiveConfigStream(config), "Archive.AeonConfig"); int isoIndex = 1; foreach (var drive in config.Drives) { var driveConfig = drive.Value; if (!string.IsNullOrEmpty(driveConfig.HostPath)) { int hostPathLength = driveConfig.HostPath.Length; if (!driveConfig.HostPath.EndsWith('\\') && !driveConfig.HostPath.EndsWith('/')) { hostPathLength++; } var drivePrefix = drive.Key.ToUpperInvariant() + ":\\"; foreach (var sourceFileName in Directory.EnumerateFiles(driveConfig.HostPath, "*", SearchOption.AllDirectories)) { var destPath = getArchivePath(sourceFileName); if (destPath != null) { Console.WriteLine($"Adding {sourceFileName} => {destPath}..."); archiveBuilder.AddFile(sourceFileName, destPath); } } string getArchivePath(string srcPath) { var relativePath = srcPath.Substring(hostPathLength).Trim('\\', '/'); var pathParts = relativePath.Split(Path.DirectorySeparatorChar); if (!pathParts.All(Valid83PathRegex.IsMatch)) { return(null); } return(drivePrefix + relativePath.ToUpperInvariant()); } } else if (!string.IsNullOrWhiteSpace(drive.Value.ImagePath)) { archiveBuilder.AddFile(drive.Value.ImagePath, $"Image{isoIndex}.iso"); isoIndex++; } else { throw new InvalidDataException(); } } Console.WriteLine($"Writing {args[1]}..."); using var outputStream = File.Create(args[1]); Console.CursorVisible = false; archiveBuilder.Write(outputStream, new BuilderProgress(archiveBuilder.DataCount)); Console.CursorVisible = true; return(0); }