Ejemplo n.º 1
0
 /// <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;
 }
Ejemplo n.º 2
0
        private bool PackArchives(Action<string> statusCallback)
        {
            statusCallback(@"Starting packing processess");
            Application.DoEvents(); // needed to update the UI while running the method
            ArchivePacker attribPacker = new ArchivePacker(ModManager.ModName + "_data.sga", ModManager.ModDataDirectory, false);
            ArchivePackerInfo attribInfo;
            ArchivePacker dataPacker = new ArchivePacker(ModManager.ModName + "_attrib.sga", ModManager.ModAttribDirectory, true);
            ArchivePackerInfo dataInfo;
            try
            {
                dataInfo = dataPacker.PackArchive(m_releaser.GetDataArchivePath().SubstringBeforeLast('\\', true));
                attribInfo = attribPacker.PackArchive(m_releaser.GetAttribArchivePath().SubstringBeforeLast('\\', true));
            }
            catch (Exception ex)
            {
                LoggingManager.SendError("ModPacker - failed to start packer(s)!");
                LoggingManager.HandleException(ex);
                 UIHelper.ShowError("Failed to start archive.exe: " + ex.Message);
                return false;
            }

            statusCallback(@"Waiting for packing-processess to finish...");

            LoggingManager.SendMessage("ModPacker - waiting for packers to finish");
            while (!(dataInfo.IsDone() && attribInfo.IsDone()))
            {
                Thread.Sleep(100);
                Application.DoEvents();
            }
            OnPackersFinished();
            return true;
        }