/// <exception cref="CopeException">Extraction successful but still cannot find the RB2 file!</exception> private bool RepackAttribArchive(string filePath) { const string RB2_PATH = "simulation\\attrib\\attribmegabinary.rb2"; const string FLB_PATH = "simulation\\attrib\\fieldnames.flb"; string tmpDir = Application.StartupPath + "\\temp\\"; SGAFile attribSga; try { attribSga = new SGAFile(filePath, FileAccess.Read, FileShare.Read); foreach (var ep in attribSga) { foreach (var f in ep.StoredFiles) { byte[] b = attribSga.ExtractFile(f.Value, attribSga.Stream); string dir = tmpDir + f.Key.SubstringBeforeLast('\\'); if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); var stream = File.Create(tmpDir + f.Key); stream.Write(b, 0, b.Length); stream.Flush(); stream.Close(); } } } catch(Exception ex) { throw new CopeException(ex, "Failed/extract to open GameAttrib.sga!"); } string rb2Path = tmpDir + RB2_PATH; if (!File.Exists(rb2Path)) throw new CopeException("Extraction successful but still cannot find the RB2 file! Searched at: " + rb2Path); string flbPath = tmpDir + FLB_PATH; if (!File.Exists(flbPath)) throw new CopeException("Extraction successful but still cannot find the FLB file! Searched at: " + flbPath); FieldNameFile flb; RB2FileExtractor extractor; try { flb = new FieldNameFile(flbPath); flb.ReadData(); extractor = new RB2FileExtractor(rb2Path, flb); extractor.ReadData(); } catch(Exception ex) { throw new CopeException(ex, "Failed to open the FLB or RB2 file!"); } extractor.ExtractAll(tmpDir + "simulation\\attrib\\", null); extractor.Close(); flb.Close(); File.Delete(rb2Path); try { ArchivePacker attribPacker = new ArchivePacker("GameAttrib_orig.sga", tmpDir, true); var packerInfo = attribPacker.PackArchive(ModManager.GameDirectory + m_sModName + "\\Archives\\"); while (!packerInfo.IsDone()) Thread.Sleep(100); } catch { Directory.Delete(tmpDir, true); throw; } Directory.Delete(tmpDir, true); return true; }
/// <exception cref="CopeException">Extraction successful but still cannot find the RB2 file!</exception> private bool RepackAttribArchive(string filePath) { const string RB2_PATH = "simulation\\attrib\\attribmegabinary.rb2"; const string FLB_PATH = "simulation\\attrib\\fieldnames.flb"; string tmpDir = Application.StartupPath + "\\temp\\"; SGAFile attribSga; try { attribSga = new SGAFile(filePath, FileAccess.Read, FileShare.Read); foreach (var ep in attribSga) { foreach (var f in ep.StoredFiles) { byte[] b = attribSga.ExtractFile(f.Value, attribSga.Stream); string dir = tmpDir + f.Key.SubstringBeforeLast('\\'); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } var stream = File.Create(tmpDir + f.Key); stream.Write(b, 0, b.Length); stream.Flush(); stream.Close(); } } } catch (Exception ex) { throw new CopeException(ex, "Failed/extract to open GameAttrib.sga!"); } string rb2Path = tmpDir + RB2_PATH; if (!File.Exists(rb2Path)) { throw new CopeException("Extraction successful but still cannot find the RB2 file! Searched at: " + rb2Path); } string flbPath = tmpDir + FLB_PATH; if (!File.Exists(flbPath)) { throw new CopeException("Extraction successful but still cannot find the FLB file! Searched at: " + flbPath); } FieldNameFile flb; RB2FileExtractor extractor; try { flb = new FieldNameFile(flbPath); flb.ReadData(); extractor = new RB2FileExtractor(rb2Path, flb); extractor.ReadData(); } catch (Exception ex) { throw new CopeException(ex, "Failed to open the FLB or RB2 file!"); } extractor.ExtractAll(tmpDir + "simulation\\attrib\\", null); extractor.Close(); flb.Close(); File.Delete(rb2Path); try { ArchivePacker attribPacker = new ArchivePacker("GameAttrib_orig.sga", tmpDir, true); var packerInfo = attribPacker.PackArchive(ModManager.GameDirectory + m_sModName + "\\Archives\\"); while (!packerInfo.IsDone()) { Thread.Sleep(100); } } catch { Directory.Delete(tmpDir, true); throw; } Directory.Delete(tmpDir, true); return(true); }