Example #1
0
 public void HeaderLoaded(PFHeader header)
 {
     count            = header.FileCount;
     progress.Maximum = (int)header.FileCount;
     label.Text       = string.Format("Loading {0}: 0 of {1} files loaded", file, header.FileCount);
     Application.DoEvents();
 }
Example #2
0
 public void HeaderLoaded(PFHeader header)
 {
     codecFileCount += header.FileCount;
     progressReporter.ReportProgressAsync(() =>
     {
         progress.Maximum += (int)header.FileCount;
         label.Text        = string.Format("Loading {0}: 0 of {1} files loaded", file, header.FileCount);
     });
 }
Example #3
0
        public void InstallCurrentMod()
        {
            if (CurrentMod == null)
            {
                throw new InvalidOperationException("No mod set");
            }
            string targetDir = CurrentMod.Game.GameDirectory;

            if (targetDir == null)
            {
                throw new FileNotFoundException(string.Format("Game install directory not found"));
            }
            targetDir = Path.Combine(targetDir, "data");
            if (File.Exists(CurrentMod.FullModPath) && Directory.Exists(targetDir))
            {
                string installPackName = CurrentMod.PackName;
                if (installPackName.Contains(' ') && GameManager.Instance.CurrentGame == Game.R2TW)
                {
                    if (MessageBox.Show(MOD_SPACE_MESSAGE, "Invalid pack file name", MessageBoxButtons.YesNo)
                        == DialogResult.Yes)
                    {
                        installPackName = installPackName.Replace(' ', '_');
                    }
                }
                string targetFile = Path.Combine(targetDir, installPackName);

                // copy to data directory
                File.Copy(CurrentMod.FullModPath, targetFile, true);

                // add entry to user.script.txt if it's a mod file
                PFHeader header = PackFileCodec.ReadHeader(targetFile);
                if (header.Type == PackType.Mod)
                {
                    string        modEntry     = CurrentMod.ModScriptFileEntry;
                    string        scriptFile   = GameManager.Instance.CurrentGame.ScriptFile;
                    List <string> linesToWrite = new List <string>();
                    if (File.Exists(scriptFile))
                    {
                        // retain all other mods in the script file; will add our mod afterwards
                        foreach (string line in File.ReadAllLines(scriptFile, Encoding.Unicode))
                        {
                            if (!line.Contains(modEntry))
                            {
                                linesToWrite.Add(line);
                            }
                        }
                    }
                    if (!linesToWrite.Contains(modEntry))
                    {
                        linesToWrite.Add(modEntry);
                    }
                    File.WriteAllLines(scriptFile, linesToWrite, Encoding.Unicode);
                }
            }
        }
Example #4
0
        /*
         * Main interface method.
         */
        public PackFile CreateOptimizedFile(PackFile toOptimize)
        {
            PFHeader header      = new PFHeader(toOptimize.Header);
            string   newPackName = Path.Combine(Path.GetDirectoryName(toOptimize.Filepath),
                                                string.Format("optimized_{0}", Path.GetFileName(toOptimize.Filepath)));
            PackFile result = new PackFile(newPackName, header);

            foreach (PackedFile file in toOptimize)
            {
                PackedFile optimized = CreateOptimizedFile(file);
                if (optimized != null)
                {
                    result.Add(optimized);
                }
            }
            return(result);
        }
Example #5
0
        /**
         * <summary>Removes all elements identical between the selected game's <see cref="PackFile">PackFiles</see> and passed PackFile.</summary>
         * <remarks>
         * Does not alter non-DB files in the passed <see cref="PackFile"/>.
         * DB files in the passed PackFile have all identical rows removed from the DB file.
         * For rows to be identical the schemas must be the same.
         * <see cref="PackedFile">PackedFiles</see> that have no unique rows are removed from the final <see cref="PackFile"/>.
         * </remarks>
         *
         * <param name="toOptimize">The <see cref="PackFile"/> to be optimized</param>
         * <returns>A new <see cref="PackFile"/> that contains the optimized data of <paramref name="toOptimize"/>.</returns>
         *
         * XXX This could be optimized better by multi-threading the foreach loop if adding <see cref="PackedFile">PackedFiles</see> to a <see cref="PackFile"/> was thread-safe.
         */
        public PackFile CreateOptimizedFile(PackFile toOptimize)
        {
            PFHeader header      = new PFHeader(toOptimize.Header);
            string   newPackName = Path.Combine(Path.GetDirectoryName(toOptimize.Filepath),
                                                string.Format("optimized_{0}", Path.GetFileName(toOptimize.Filepath)));
            PackFile result = new PackFile(newPackName, header);

            ConcurrentDictionary <string, List <DBFile> > gameDBFiles = FindGameDBFiles();
            PackedFile    optimized;
            List <DBFile> referenceFiles;

            foreach (PackedFile file in toOptimize)
            {
                if (file.FullPath.StartsWith("db" + Path.DirectorySeparatorChar))
                {
                    if (gameDBFiles.TryGetValue(DBFile.Typename(file.FullPath), out referenceFiles))
                    {
                        optimized = OptimizePackedDBFile(file, referenceFiles);
                    }
                    else
                    {
                        result.Add(file);
                        continue;
                    }
                    if (optimized != null)
                    {
                        result.Add(optimized);
                    }
                }
                else
                {
                    result.Add(file);
                }
            }
            return(result);
        }
Example #6
0
 /*
  * Create a new pack containing the given files.
  */
 void CreatePack(string packFileName, List <string> containedFiles)
 {
     try {
         PFHeader header = new PFHeader("PFH4")
         {
             Version = 0,
             Type    = PackType.Mod
         };
         PackFile packFile = new PackFile(packFileName, header);
         foreach (string file in containedFiles)
         {
             try {
                 HandlingFile(file);
                 PackedFile toAdd = new PackedFile(file);
                 packFile.Add(toAdd, true);
             } catch (Exception e) {
                 Console.Error.WriteLine("Failed to add {0}: {1}", file, e.Message);
             }
         }
         new PackFileCodec().WriteToFile(packFileName, packFile);
     } catch (Exception e) {
         Console.Error.WriteLine("Failed to write {0}: {1}", packFileName, e.Message);
     }
 }