static void Pack(PackOptions options) { var data = new List <byte>(150 * 1000 * 1000); var files = Directory.GetFiles(options.SourceFolder).ToDictionary(Path.GetFileName, StringComparer.OrdinalIgnoreCase); var originalJsonFile = JsonDatFile.FromFile(options.SourceJson); var jsonFile = new JsonDatFile(); Directory.CreateDirectory(Path.GetDirectoryName(options.JsonPath)); Directory.CreateDirectory(Path.GetDirectoryName(options.DatPath)); foreach (var origFile in originalJsonFile.Files) { if (files.TryGetValue(origFile.Name, out var file)) { var fileBytes = File.ReadAllBytes(file); int currentOffset = data.Count; var fileEntry = new JsonFileEntry(Path.GetFileName(file), fileBytes.Length, currentOffset); data.AddRange(fileBytes); jsonFile.Files.Add(fileEntry); data.AddPadding(2048); } } // Save (Note: Using FileStream to avoid copying large array) File.WriteAllText(options.JsonPath, jsonFile.ToFile()); using var fileStream = new FileStream(options.DatPath, FileMode.Create); fileStream.Write(CollectionsMarshal.AsSpan(data)); Console.WriteLine($"JSON file for injection written to: {options.JsonPath}"); Console.WriteLine($"New DAT file written to: {options.DatPath}"); }
private static void RipWriteFileToFolder(string outputPath, JsonFileEntry entry, Span <byte> slice) { Directory.CreateDirectory(outputPath); var outputFilePath = Path.Combine(outputPath, entry.Name); using var file = new FileStream(outputFilePath, FileMode.Create, FileAccess.Write); file.Write(slice); Console.WriteLine($"Written file to {outputFilePath}"); }
private static JsonFileEntry RipUserSelectEntryFromList(List <JsonFileEntry> fileInfoList) { JsonFileEntry entry = fileInfoList[0]; // Handle duplicate entries. if (fileInfoList.Count > 1) { Console.WriteLine("Multiple files detected with matching compressed sizes."); Console.WriteLine("Select the file you think you're ripping: "); for (var x = 0; x < fileInfoList.Count; x++) { var fileInfo = fileInfoList[x]; Console.WriteLine($"[{x:00}] {fileInfo.Name,20} | Checksum {fileInfo.Checksum:X}"); } entry = fileInfoList[Convert.ToInt32(Console.ReadLine())]; } return(entry); }