private static void SetDebugMode(string filepath, bool value) { AGSGameData data = new AGSGameData(); data.LoadFromFile(filepath); //data.setup.options[0] = value ? 1 : 0; //data.SaveToFile(filepath); }
// FIXME(adm244): doesn't support multilib files //public static bool Extract(string filepath, string targetFilepath) //{ // AssetsManager assetsManager = AssetsManager.Create(filepath); // if (assetsManager == null) // return false; // // using (FileStream fileStream = new FileStream(filepath, FileMode.Open, FileAccess.Read)) // { // for (int i = 0; i < assetsManager.Files.Length; ++i) // { // for (int k = 0; k < assetsManager.Files[i].Assets.Count; ++k) // { // string extension = Path.GetExtension(assetsManager.Files[i].Assets[k].Filename); // if (extension == ".dta" || extension == ".crm") // { // long baseOffset = assetsManager.Files[i].Offset; // long assetOffset = assetsManager.Files[i].Assets[k].Offset; // // fileStream.Seek(baseOffset + assetOffset, SeekOrigin.Begin); // // // TODO(adm244): create a substream instead; that way it's easy to handle large data // byte[] buffer = new byte[assetsManager.Files[i].Assets[k].Size]; // int bytesRead = fileStream.Read(buffer, 0, buffer.Length); // Trace.Assert(bytesRead == buffer.Length); // // // HACK(adm244): our API needs some serious attention; too much object allocation // using (MemoryStream memoryStream = new MemoryStream(buffer)) // { // using (BinaryReader binaryReader = new BinaryReader(memoryStream, Encoding.Latin1)) // { // if (extension == ".dta") // { // gameData = new AGSGameData(); // gameData.LoadFromStream(binaryReader); // } // else // { // string name = Path.GetFileNameWithoutExtension(assetsManager.Files[i].Assets[k].Filename); // AGSRoom room = new AGSRoom(name); // room.ReadFromStream(binaryReader); // // rooms.Add(room); // } // } // } // } // } // } // } // // //gameData = assetsManager.GameData; // //rooms.AddRange(assetsManager.Rooms); // // Console.Write("Extracting text lines..."); // PrepareTranslationLines(); // Console.WriteLine(" Done!"); // // Console.Write("Writing translation source file..."); // WriteTranslationFile(targetFilepath, lines); // Console.WriteLine(" Done!"); // // return true; //} public static bool ExtractFromFolder(string sourceFolder, string targetFile) { // FIXME(adm244): exactly the reason to not make it static gameData = new AGSGameData(); rooms = new List <AGSRoom>(); lines = new List <string>(); if (Directory.Exists(sourceFolder)) { string[] filenames = Directory.GetFiles(sourceFolder, "*", SearchOption.AllDirectories); Console.WriteLine("Searching asset files..."); for (int i = 0; i < filenames.Length; ++i) { int index = filenames[i].LastIndexOf('.'); string fileExtension = filenames[i].Substring(index + 1); if (fileExtension == "dta") { Console.Write("\tParsing {0} data file...", Path.GetFileName(filenames[i])); gameData.LoadFromFile(filenames[i]); Console.WriteLine(" Done!"); } else if (fileExtension == "crm") { Console.Write("\tParsing {0} room file...", Path.GetFileName(filenames[i])); AGSRoom room = new AGSRoom(Path.GetFileNameWithoutExtension(filenames[i])); room.ReadFromFile(filenames[i]); rooms.Add(room); Console.WriteLine(" Done!"); } } Console.Write("Extracting text lines..."); PrepareTranslationLines(); Console.WriteLine(" Done!"); Console.Write("Writing translation source file..."); WriteTranslationFile(targetFile, lines); Console.WriteLine(" Done!"); return(true); } else { Console.WriteLine(string.Format("ERROR: Folder {0} does not exist.", sourceFolder)); return(false); } }
// TODO(adm244): rewrite using AssetsManager to support multilib files public static bool ExtractFromFolder(string sourceFolder, string targetFile) { if (Directory.Exists(sourceFolder)) { AGSGameData gameData = new AGSGameData(); string[] filenames = Directory.GetFiles(sourceFolder, "*", SearchOption.AllDirectories); Console.WriteLine("Searching asset files..."); for (int i = 0; i < filenames.Length; ++i) { int index = filenames[i].LastIndexOf('.'); string fileExtension = filenames[i].Substring(index + 1); if (fileExtension == "dta") { Console.Write("\tParsing {0} data file...", Path.GetFileName(filenames[i])); gameData.LoadFromFile(filenames[i]); Console.WriteLine(" Done!"); break; } } Console.Write("Extracting game id..."); string content = string.Format("GameName: {0}\nUniqueID: {1}", gameData.setup.name, gameData.setup.unique_id); File.WriteAllText(targetFile, content, Encoding.Latin1); Console.WriteLine(" Done!"); return(true); } else { Console.WriteLine(string.Format("ERROR: Folder {0} does not exist.", sourceFolder)); return(false); } }