Пример #1
0
        public override void Activate(ChangeArgs args)
        {
            var aivDir = args.AIVDir;

            // create backup
            string backupDir = Path.Combine(args.AIVDir.FullName, Patcher.BackupIdent);

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



            // copy aiv castles
            Assembly asm = Assembly.GetExecutingAssembly();

            foreach (string res in asm.GetManifestResourceNames())
            {
                if (res.StartsWith(resourceFolder, StringComparison.OrdinalIgnoreCase))
                {
                    string path = Path.Combine(aivDir.FullName, res.Substring(resourceFolder.Length + 1));
                    using (Stream stream = asm.GetManifestResourceStream(res))
                        using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
                        {
                            stream.CopyTo(fs);
                        }
                }
            }
        }
Пример #2
0
        public void Activate(ChangeArgs args)
        {
            if (!editList.TrueForAll(e => e.Initialize(args)))
            {
                return;
            }

            editList.ForEach(e => e.Activate(args));
        }
Пример #3
0
 public void Activate(ChangeArgs args)
 {
     foreach (var header in headerList)
     {
         if (header.IsEnabled)
         {
             header.Activate(args);
         }
     }
 }
Пример #4
0
        static void DoChanges(string filePath, DirectoryInfo aivFolder, SetPercentHandler SetPercent)
        {
            List <Change> todo = new List <Change>(Version.Changes.Where(c => c.IsChecked));

            int    index = 0;
            double count = 4 + todo.Count; // +1 from folder backup above, +1 for read, +1 for version edit, +1 for writing data

            SetPercent?.Invoke(++index / count);


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

            ChangeArgs args = new ChangeArgs(data, oriData, aivFolder);

            SetPercent?.Invoke(++index / count);



            // change version display in main menu
            try
            {
                Version.MenuChange.Activate(args);
            }
            catch (Exception e)
            {
                Debug.Error(e);
            }
            SetPercent?.Invoke(++index / count);



            // change stuff
            foreach (Change change in todo)
            {
                change.Activate(args);
                SetPercent?.Invoke(++index / count);
            }

            data = SectionEditor.AttachSection(data);

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

            File.WriteAllBytes(filePath, data);
        }
        static void DoChanges(string filePath, DirectoryInfo aivFolder, SetPercentHandler SetPercent)
        {
            List <Change> todo = new List <Change>(Version.Changes.Where(c => c.IsChecked));

            int    index = 0;
            double count = 4 + todo.Count; // +1 from folder backup above, +1 for read, +1 for version edit, +1 for writing data

            SetPercent?.Invoke(++index / count);



            // read original data & preparation
            byte[]     oriData = File.ReadAllBytes(filePath);
            byte[]     data    = (byte[])oriData.Clone();
            ChangeArgs args    = new ChangeArgs(data, oriData, aivFolder);

            SetPercent?.Invoke(++index / count);



            // change version display in main menu
            var displayResult = Version.MenuChange.Activate(args);

            if (displayResult != EditResult.NoErrors)
            {
                const string str     = "Your version is currently unsupported: {0} in menu display edit.";
                string       message = string.Format(str, displayResult);
                throw new Exception(message);
            }
            SetPercent?.Invoke(++index / count);



            // change stuff
            foreach (Change change in todo)
            {
                change.Activate(args);
                SetPercent?.Invoke(++index / count);
            }



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

            File.WriteAllBytes(filePath, data);
        }
        public override EditResult Activate(ChangeArgs args)
        {
            // find equivalent position in original file
            int count = block.SeekCount(args.OriData, out int address);

            if (count > 1)
            {
                return(EditResult.MultipleBlocks);
            }
            else if (count == 0)
            {
                return(EditResult.BlockNotFound);
            }

            labels.Resolve(address);

            return(DoEdit(address, args.Data, args.OriData));
        }
Пример #7
0
        public override EditResult Activate(ChangeArgs args)
        {
            Assembly asm = Assembly.GetExecutingAssembly();

            foreach (string res in asm.GetManifestResourceNames())
            {
                if (res.StartsWith(resourceFolder, StringComparison.OrdinalIgnoreCase))
                {
                    string path = Path.Combine(args.AIVDir.FullName, res.Substring(resourceFolder.Length + 1));
                    using (Stream stream = asm.GetManifestResourceStream(res))
                        using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
                        {
                            stream.CopyTo(fs);
                        }
                }
            }

            return(EditResult.NoErrors);
        }
        public override void Activate(ChangeArgs args)
        {
            double  value   = Parent is ValueHeader vHeader ? vHeader.Value : 0;
            BinArgs binArgs = new BinArgs(args.Data, this.Parent.Labels, value);

            foreach (BinElement e in elements)
            {
                if (e is IBinCollection group)
                {
                    foreach (BinElement ge in group.Collection)
                    {
                        ge.Write(binArgs);
                    }
                }
                else
                {
                    e.Write(binArgs);
                }
            }
        }
Пример #9
0
        public void Activate(ChangeArgs args)
        {
            ChangeHeader header = GetActiveHeader();

            /*foreach (var edit in editList)
             *  foreach (var element in edit)
             *      if (element is BinValue value)
             *      {
             *          value.Set(valueDict[value.ValueIdent].Value);
             *      }*/

            var list = header.EditList;

            for (int i = 0; i < list.Count; i++)
            {
                var result = list[i].Activate(args);
                if (result != EditResult.NoErrors)
                {
                    const string str     = "Your version is currently unsupported: {0} for {1}/{2}/{3}.";
                    string       message = string.Format(str, result, TitleIdent, ActiveHeaderIndex, i);
                    throw new Exception(message);
                }
            }
        }
        public override bool Initialize(ChangeArgs args)
        {
            if (!GetAddresses(args.OriData, out int rawAddr, out int virtAddr))
            {
                return(false);
            }

            foreach (BinElement e in elements)
            {
                if (e is IBinCollection group)
                {
                    foreach (BinElement ge in group.Collection)
                    {
                        InitElement(ge, ref rawAddr, ref virtAddr, args.OriData);
                    }
                }
                else
                {
                    InitElement(e, ref rawAddr, ref virtAddr, args.OriData);
                }
            }

            return(true);
        }
Пример #11
0
 public abstract bool Initialize(ChangeArgs args);
Пример #12
0
 public abstract void Activate(ChangeArgs args);
 public abstract EditResult Activate(ChangeArgs args);
Пример #14
0
 public override bool Initialize(ChangeArgs args) => true;
Пример #15
0
 public override void Activate(ChangeArgs args)
 {
     args.Data = SectionEditor.GetBuffer();
     base.Activate(args);
 }