/// <summary> /// Create a PAK archive from a folder produced by ArchiveTool or PAKTool. /// </summary> static void BuildPAK(string filePath) { Console.WriteLine("Building PAK from folder: {0}", Path.GetFullPath(filePath)); outputPath = Path.Combine(Environment.CurrentDirectory, filePath); Environment.CurrentDirectory = Path.GetDirectoryName(outputPath); string inipath = Path.Combine(Path.GetFileNameWithoutExtension(outputPath), Path.GetFileNameWithoutExtension(outputPath) + ".ini"); if (!File.Exists(inipath)) { Console.WriteLine("PAK INI file not found: {0}", inipath); Console.WriteLine("The folder must contain either index.txt or an INI file to be recognized as a buildable archive folder."); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); return; } PAKFile.PAKIniData list = IniSerializer.Deserialize <PAKFile.PAKIniData>(inipath); PAKFile pak = new PAKFile() { FolderName = list.FolderName }; foreach (KeyValuePair <string, PAKFile.PAKIniItem> item in list.Items) { Console.WriteLine("Adding file: {0}", item.Key); pak.Entries.Add(new PAKFile.PAKEntry(item.Key, item.Value.LongPath, File.ReadAllBytes(Path.Combine(Path.GetFileNameWithoutExtension(outputPath), item.Key)))); } Console.WriteLine("Output file: {0}", Path.ChangeExtension(outputPath, "pak")); pak.Save(Path.ChangeExtension(outputPath, "pak")); Console.WriteLine("Done!"); }
/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { if (args.Length == 0) { args = new string[] { "/?" } } ; switch (args[0].ToLowerInvariant()) { case "/t": Main(ParseCommandLine(File.ReadAllText(args[1]))); break; case "/u": try { string fn = args[1]; Console.WriteLine("Extracting PAK file: {0}", Path.GetFullPath(fn)); string outputPath = Path.Combine(Path.GetDirectoryName(fn), Path.GetFileNameWithoutExtension(fn)); Console.WriteLine("Output folder: {0}", Path.GetFullPath(outputPath)); Directory.CreateDirectory(outputPath); PAKFile pak = new PAKFile(fn); foreach (PAKFile.PAKEntry entry in pak.Entries) { Console.WriteLine("Extracting file: {0}", entry.Name); File.WriteAllBytes(Path.Combine(outputPath, entry.Name), entry.Data); } pak.CreateIndexFile(outputPath); Console.WriteLine("Archive extracted!"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } break; case "/p": try { Console.WriteLine("Building PAK from folder: {0}", Path.GetFullPath(args[1])); string outputPath = Path.Combine(Environment.CurrentDirectory, args[1]); Environment.CurrentDirectory = Path.GetDirectoryName(outputPath); PAKFile.PAKIniData list = IniSerializer.Deserialize <PAKFile.PAKIniData>(Path.Combine(Path.GetFileNameWithoutExtension(outputPath), Path.GetFileNameWithoutExtension(outputPath) + ".ini")); PAKFile pak = new PAKFile() { FolderName = list.FolderName }; foreach (KeyValuePair <string, PAKFile.PAKIniItem> item in list.Items) { Console.WriteLine("Adding file: {0}", item.Key); pak.Entries.Add(new PAKFile.PAKEntry(item.Key, item.Value.LongPath, File.ReadAllBytes(Path.Combine(Path.GetFileNameWithoutExtension(outputPath), item.Key)))); } Console.WriteLine("Output file: {0}", Path.ChangeExtension(outputPath, "pak")); pak.Save(Path.ChangeExtension(outputPath, "pak")); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } break; case "/?": Console.WriteLine("Arguments:"); Console.WriteLine(); Console.WriteLine("/?\tShow this help."); Console.WriteLine(); Console.WriteLine("/t filename\tReads text file filename as a commandline."); Console.WriteLine(); Console.WriteLine("/u filename\tExtracts files from an archive."); Console.WriteLine(); Console.WriteLine("/p filename\tPacks files into an archive."); Console.WriteLine(); break; default: if (args.Length == 0) { goto case "/?"; } char arg = '\0'; while (arg != 'u' & arg != 'p') { Console.Write("Type u to unpack or p to pack: "); arg = Console.ReadKey().KeyChar; Console.WriteLine(); } Main(new string[] { "/" + arg, args[0] }); break; } }