static public void LoadSGAFile(string path) { CloseAll(); LoggingManager.SendMessage("ModManager - Loading SGA file " + path); DateTime t1 = DateTime.Now; // the tool needs some paths to work with but SGAs of course don't provide these // so you need to set them up manually ModAttribDirectory = path.SubstringBeforeLast('.') + "\\ATTRIB\\"; ModDataDirectory = path.SubstringBeforeLast('.') + "\\DATA\\"; SGAFile sga; try { sga = new SGAFile(path, FileAccess.Read, FileShare.Read); } catch (Exception e) { LoggingManager.SendError("ModManager - Failed to load SGA file!"); LoggingManager.HandleException(e); UIHelper.ShowError("Can't open SGA file: " + e.Message + " See log file for more information"); if (LoadingFailed != null) { LoadingFailed(); } return; } ModAttribArchives.Add(sga); ModDataArchives.Add(sga); ModName = path.SubstringAfterLast('\\'); DateTime t2 = DateTime.Now; LoggingManager.SendMessage("ModManager - SGA file successfully loaded in " + (t2 - t1).TotalSeconds + " seconds"); FileManager.FillTrees(); TryToGetKeyProvider(); if (SGALoaded != null) { SGALoaded(); } }
/// <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; }
static public void LoadSGAFile(string path) { CloseAll(); LoggingManager.SendMessage("ModManager - Loading SGA file " + path); DateTime t1 = DateTime.Now; // the tool needs some paths to work with but SGAs of course don't provide these // so you need to set them up manually ModAttribDirectory = path.SubstringBeforeLast('.') + "\\ATTRIB\\"; ModDataDirectory = path.SubstringBeforeLast('.') + "\\DATA\\"; SGAFile sga; try { sga = new SGAFile(path, FileAccess.Read, FileShare.Read); } catch (Exception e) { LoggingManager.SendError("ModManager - Failed to load SGA file!"); LoggingManager.HandleException(e); UIHelper.ShowError("Can't open SGA file: " + e.Message + " See log file for more information"); if (LoadingFailed != null) LoadingFailed(); return; } ModAttribArchives.Add(sga); ModDataArchives.Add(sga); ModName = path.SubstringAfterLast('\\'); DateTime t2 = DateTime.Now; LoggingManager.SendMessage("ModManager - SGA file successfully loaded in " + (t2 - t1).TotalSeconds + " seconds"); FileManager.FillTrees(); TryToGetKeyProvider(); if (SGALoaded != null) SGALoaded(); }
/// <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); }