public static void Install(string folderPath, Percentage.SetHandler SetPercent, bool overwrite, bool graphical)
        {
            Percentage perc = new Percentage(SetPercent);

            perc.SetTotal(0);

            perc.NextLimit = 0.1;

            try
            {
                AIVChange.DoChange(folderPath, overwrite, graphical);
            } catch (IOException) {
                Debug.Show(Localization.Get("install_abort_io"));
                return;
            } catch (Exception)
            {
                Debug.Show(Localization.Get("install_abort"));
                return;
            }
            perc.Set(1.0);

            DoChanges(folderPath, perc);

            perc.SetTotal(1);
        }
Ejemplo n.º 2
0
        public static void Install(string folderPath, Percentage.SetHandler SetPercent)
        {
            Percentage perc = new Percentage(SetPercent);

            perc.SetTotal(0);

            perc.NextLimit = 0.1;
            AIVChange.DoChange(folderPath);
            perc.Set(1.0);

            DoChanges(folderPath, perc);

            perc.SetTotal(1);
        }
Ejemplo n.º 3
0
        static void DoAIVChange(string folderPath, Percentage perc)
        {
            DirectoryInfo aivDir = new DirectoryInfo(Path.Combine(folderPath, "aiv"));

            // Restore Backup
            RestoreAIVs(folderPath);

            if (AIVChange.ActiveChange != null)
            {
                // create backup of current AIVs
                string bupPath = Path.Combine(aivDir.FullName, BackupIdent);

                Directory.CreateDirectory(bupPath);
                foreach (FileInfo fi in aivDir.EnumerateFiles("*.aiv"))
                {
                    fi.CopyTo(Path.Combine(bupPath, fi.Name), true);
                }

                // copy modded AIVs
                AIVChange.ActiveChange.CopyAIVs(aivDir);
            }

            perc.Set(1.0);
        }
Ejemplo n.º 4
0
        static void DoBinaryChanges(string filePath, bool xtreme, Percentage perc)
        {
            fails.Clear();
            SectionEditor.Reset();

            // only take binary changes
            var           changes  = Version.Changes.Where(c => c.IsChecked && c is Change && !(c is ResourceChange) && !(c is StartTroopChange));
            List <Change> todoList = new List <Change>(changes);

            int    todoIndex = 0;
            double todoCount = 9 + todoList.Count; // +2 for AIprops +3 for read, +1 for version edit, +3 for writing data

            // read original data & section preparation
            byte[] oriData = File.ReadAllBytes(filePath);
            byte[] data    = (byte[])oriData.Clone();
            SectionEditor.Init(data);
            todoIndex += 3;

            perc.Set(todoIndex / todoCount);

            ChangeArgs args = new ChangeArgs(data, oriData);

            // change version display in main menu
            try
            {
                (xtreme ? Version.MenuChange_XT : Version.MenuChange).Activate(args);
            }
            catch (Exception e)
            {
                Debug.Error(e);
            }
            perc.Set(++todoIndex / todoCount);

            // change stuff
            foreach (Change change in todoList)
            {
                change.Activate(args);
                perc.Set(++todoIndex / todoCount);
            }
            AICChange.DoChange(args);
            StartTroopChange.DoChange(args);
            ResourceChange.DoChange(args);

            todoIndex += 2;
            perc.Set(todoIndex / todoCount);



            // Write everything to file
            data = SectionEditor.AttachSection(data);

            if (filePath.EndsWith(BackupFileEnding))
            {
                filePath = filePath.Remove(filePath.Length - BackupFileEnding.Length);
            }
            else
            {
                File.WriteAllBytes(filePath + BackupFileEnding, oriData); // create backup
            }
            File.WriteAllBytes(filePath, data);

            perc.Set(1);

            ShowFailures(filePath);
        }
Ejemplo n.º 5
0
        static void DoChanges(string filePath, bool xtreme, Percentage perc)
        {
            fails.Clear();
            SectionEditor.Reset();

            // only take binary changes
            var           changes  = Version.Changes.Where(c => c.IsChecked && c.GetType() == typeof(Change));
            List <Change> todoList = new List <Change>(changes);

            int    todoIndex = 0;
            double todoCount = 9 + todoList.Count; // +2 for AIprops +3 for read, +1 for version edit, +3 for writing data

            // read original data & section preparation
            byte[] oriData = File.ReadAllBytes(filePath);
            byte[] data    = (byte[])oriData.Clone();
            SectionEditor.Init(data);
            todoIndex += 3;

            perc.Set(todoIndex / todoCount);

            ChangeArgs args = new ChangeArgs(data, oriData);

            // change version display in main menu
            try
            {
                (xtreme ? Version.MenuChange_XT : Version.MenuChange).Activate(args);
            }
            catch (Exception e)
            {
                Debug.Error(e);
            }
            perc.Set(++todoIndex / todoCount);



            // change stuff
            foreach (Change change in todoList)
            {
                change.Activate(args);
                perc.Set(++todoIndex / todoCount);
            }



            // change AI properties
            AICChange.DoEdit(args);
            todoIndex += 2;
            perc.Set(todoIndex / todoCount);



            // Write everything to file

            data = SectionEditor.AttachSection(data);

            if (filePath.EndsWith(BackupFileEnding))
            {
                filePath = filePath.Remove(filePath.Length - BackupFileEnding.Length);
            }
            else
            {
                File.WriteAllBytes(filePath + BackupFileEnding, oriData); // create backup
            }

            File.WriteAllBytes(filePath, data);

            perc.Set(1);

            // Show failures
            if (fails.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("Version Differences in ");
                sb.Append(Path.GetFileName(filePath));
                sb.AppendLine(":");
                foreach (var f in fails)
                {
                    sb.AppendLine(f.Ident + " " + f.Type);
                }

                fails.Clear();
                Debug.Show(sb.ToString());
            }
        }
        static void DoBinaryChanges(string filePath, bool xtreme, Percentage perc)
        {
            fails.Clear();
            SectionEditor.Reset();

            string gameSeedsFolder = Path.Combine(Configuration.Path, GAME_SEEDS_FOLDER);

            if (!Directory.Exists(gameSeedsFolder))
            {
                Directory.CreateDirectory(gameSeedsFolder);
            }

            // Retrieve set of selected binary changes
            var           changes  = Version.Changes.Where(c => c.IsChecked && c is Change && !(c is ResourceChange) && !(c is StartTroopChange));
            List <Change> todoList = new List <Change>(changes);

            int    todoIndex = 0;
            double todoCount = 9 + todoList.Count; // +2 for AIprops +3 for read, +1 for version edit, +3 for writing data

            // Read original data & perform section preparation adding .ucp section to binary
            byte[] oriData = File.ReadAllBytes(filePath);
            byte[] data    = (byte[])oriData.Clone();
            SectionEditor.Init(data);
            todoIndex += 3;

            perc.Set(todoIndex / todoCount);

            ChangeArgs args = new ChangeArgs(data, oriData);

            // Change version display in main menu
            try
            {
                (xtreme ? Version.MenuChange_XT : Version.MenuChange).Activate(args);
            }
            catch (Exception e)
            {
                Debug.Error(e);
            }
            perc.Set(++todoIndex / todoCount);

            // Apply each selected binary change
            foreach (Change change in todoList)
            {
                change.Activate(args);
                perc.Set(++todoIndex / todoCount);
            }

            // Apply changes handled in their respective submodules
            AICChange.DoChange(args);
            StartTroopChange.DoChange(args);
            ResourceChange.DoChange(args);

            todoIndex += 2;
            perc.Set(todoIndex / todoCount);



            // Write everything to file
            data = SectionEditor.AttachSection(data);

            if (filePath.EndsWith(BackupFileEnding))
            {
                filePath = filePath.Remove(filePath.Length - BackupFileEnding.Length);
            }
            else
            {
                File.WriteAllBytes(filePath + BackupFileEnding, oriData); // create backup
            }
            File.WriteAllBytes(filePath, data);

            perc.Set(1);

            ShowFailures(filePath);
        }