public static string UnpackDecksAndPacks(YGOPRODraft.Constants strings) { string ret = ""; ret += UnpackZib(strings.YGODATA_PACKS + strings.UNPACKED_SUFFIX, Path.Combine(strings.YGO_DATA_WORKING_FOLDER, strings.YGODATA_PACKS)) + Environment.NewLine; ret += UnpackZib(strings.YGODATA_DECKS + strings.UNPACKED_SUFFIX, Path.Combine(strings.YGO_DATA_WORKING_FOLDER, strings.YGODATA_DECKS)) + Environment.NewLine; return(ret); }
public static string ExtractYGODATA(YGOPRODraft.Constants strings) { try { using (var Reader = new StreamReader(Path.Combine(Properties.Settings.Default.LOTDPath, strings.LOTD_TOC_FILENAME))) { var DatReader = new BinaryReader(File.Open(Path.Combine(Properties.Settings.Default.LOTDPath, strings.LOTD_DAT_FILENAME), FileMode.Open)); Reader.ReadLine(); //Dispose First Line. while (!Reader.EndOfStream) { var Line = Reader.ReadLine(); if (Line == null) { continue; } Line = Line.TrimStart(' '); //Trim Starting Spaces. Line = Regex.Replace(Line, @" +", " ", RegexOptions.Compiled); //Remove All Extra Spaces. var LineData = Line.Split(' '); //Split Into Chunks. //Utilities.Log($"Extracting File: {new FileInfo(LineData[2]).Name} ({LineData[0]} Bytes)", Utilities.Event.Information); //Create Item's Folder. new FileInfo(Path.Combine(strings.YGO_DATA_WORKING_FOLDER, LineData[2])).Directory.Create(); //Check Alignment var ExtraBytes = Utilities.HexToDec(LineData[0]); if (Utilities.HexToDec(LineData[0]) % 4 != 0) { while (ExtraBytes % 4 != 0) { ExtraBytes = ExtraBytes + 1; } } //Write File using (var FileWriter = new BinaryWriter(File.Open(Path.Combine(strings.YGO_DATA_WORKING_FOLDER, LineData[2]), FileMode.Create, FileAccess.Write))) { FileWriter.Write(DatReader.ReadBytes(Utilities.HexToDec(LineData[0]))); FileWriter.Flush(); } //Advance Stream DatReader.BaseStream.Position += ExtraBytes - Utilities.HexToDec(LineData[0]); } } return("Successfully extracted YGO_DATA."); } catch (Exception Ex) { return("Error: could not extract YGO_DATA :( " + "\nException: " + Ex); } }