public override bool Execute(IEnumerable <string> arguments) { if (arguments.Count() < 2) { Console.WriteLine("ERROR: Not enough arguments given!"); return(false); } var basePath = arguments.ElementAt(0); var outputDir = arguments.ElementAt(1); if (!Directory.Exists(basePath)) { Console.WriteLine("ERROR: The game base path does not exist!"); return(false); } Directory.CreateDirectory(outputDir); var looseFilePath = Path.Combine(basePath, @"France\loosefiles_BinPC.pack"); if (!File.Exists(looseFilePath)) { Console.WriteLine($"ERROR: Loosefile could not be found under \"{looseFilePath}\"!"); return(false); } var looseFile = new LooseFile(); using (var fs = new FileStream(looseFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) looseFile.Read(fs); var gameTemplatesEntry = looseFile.Files.Where(f => f.Name == "GameTemplates.wsd").FirstOrDefault(); if (gameTemplatesEntry == null) { Console.WriteLine("ERROR: Could not read GameTemplates.wsd from loosefiles!"); return(false); } var gameTemplates = new GameTemplates(); using (var ms = new MemoryStream(gameTemplatesEntry.Data)) gameTemplates.Read(ms); return(true); }
public override bool Execute(IEnumerable <string> arguments) { if (arguments.Count() < 2) { Console.WriteLine("ERROR: Not enough arguments given!"); return(false); } var filePath = arguments.ElementAt(0); var outputFolder = arguments.ElementAt(1); if (!File.Exists(filePath)) { Console.WriteLine("ERROR: Loose file doesn't exist!"); return(false); } Directory.CreateDirectory(outputFolder); var looseFile = new LooseFile(); using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) looseFile.Read(fs); foreach (var file in looseFile.Files) { var outFilePath = Path.Combine(outputFolder, file.Name); var directoryName = Path.GetDirectoryName(outFilePath); Directory.CreateDirectory(directoryName); Console.WriteLine($"Unpacking {file}..."); File.WriteAllBytes(outFilePath, file.Data); } Console.WriteLine("Files successfully unpacked!"); return(true); }
public override bool Execute(IEnumerable <string> arguments) { if (arguments.Count() < 1) { Console.WriteLine("ERROR: Not enough arguments given!"); return(false); } var basePathOrFilePath = arguments.ElementAt(0); var outputFilePath = arguments.Count() > 1 ? arguments.ElementAt(1) : null; byte[] data = null; var attrs = File.GetAttributes(basePathOrFilePath); if ((attrs & FileAttributes.Directory) == FileAttributes.Directory) { var looseFilePath = Path.Combine(basePathOrFilePath, @"France\loosefiles_BinPC.pack"); if (!File.Exists(looseFilePath)) { Console.WriteLine($"ERROR: Loosefile could not be found under \"{looseFilePath}\"!"); return(false); } var looseFile = new LooseFile(); using (var fs = new FileStream(looseFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) looseFile.Read(fs); var gameTemplatesEntry = looseFile.Files.Where(f => f.Name == "GameTemplates.wsd").FirstOrDefault(); if (gameTemplatesEntry == null) { Console.WriteLine("ERROR: Could not read GameTemplates.wsd from loosefiles!"); return(false); } data = gameTemplatesEntry.Data; } else { data = File.ReadAllBytes(basePathOrFilePath); } StreamWriter writer = null; if (outputFilePath != null) { writer = new StreamWriter(new FileStream(outputFilePath, FileMode.Create, FileAccess.Write, FileShare.None)); } var gameTemplates = new GameTemplatesDump(writer); using (var ms = new MemoryStream(data)) gameTemplates.Read(ms); if (writer != null) { writer.Flush(); writer.Close(); } return(true); }
public override bool Execute(IEnumerable <string> arguments) { if (arguments.Count() < 2) { Console.WriteLine("ERROR: Not enough arguments given!"); return(false); } var basePath = arguments.ElementAt(0); var outputDir = arguments.ElementAt(1); if (!Directory.Exists(basePath)) { Console.WriteLine("ERROR: The game base path does not exist!"); return(false); } Directory.CreateDirectory(outputDir); var looseFilePath = Path.Combine(basePath, @"France\loosefiles_BinPC.pack"); if (!File.Exists(looseFilePath)) { Console.WriteLine($"ERROR: Loosefile could not be found under \"{looseFilePath}\"!"); return(false); } foreach (var filePath in Megapacks) { var fullPath = Path.Combine(basePath, filePath); if (!filePath.Contains("patch") && !File.Exists(fullPath)) { Console.WriteLine($"ERROR: Missing non-optional megapack: {filePath}!"); return(false); } } var looseFile = new LooseFile(); using (var fs = new FileStream(looseFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) looseFile.Read(fs); var globalMapEntry = looseFile.Files.Where(f => f.Name == "global.map").FirstOrDefault(); if (globalMapEntry == null) { Console.WriteLine("ERROR: Could not read global.map from loosefiles!"); return(false); } var globalMap = new Map(); using (var ms = new MemoryStream(globalMapEntry.Data)) globalMap.Read(ms); var megapacks = new List <Megapack>(); foreach (var filePath in Megapacks) { var fullPath = Path.Combine(basePath, filePath); if (!File.Exists(fullPath)) { continue; } var megapack = new Megapack(globalMap); using (var fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { Console.WriteLine($"Reading: {Path.GetFileName(fullPath)}"); megapack.Read(fs); } megapacks.Add(megapack); } foreach (var megapack in megapacks) { // TODO: extract when we have the proper file reading methods } Console.WriteLine("Successfully unpacked the global megapacks!"); return(true); }