Пример #1
0
        private void BtnInstall_Click(object sender, EventArgs e)
        {
            btnInstall.Enabled = false;
            pb.Minimum         = 0;
            pb.Maximum         = FilesToMod.Count;
            pb.Step            = 1;
            lInstallInfo.Text  = "Creating restore files";
            foreach (var fi in FilesToInstall)
            {
                // If file exists in gamepak, make a backup
                AAPakFileInfo gamefi = gamepak.nullAAPakFileInfo;
                if (gamepak.GetFileByName(fi.name, ref gamefi))
                {
                    var fileBackupStream = gamepak.ExportFileAsStream(fi.name);
                    fileBackupStream.Position = 0;
                    AAPakFileInfo restoreFileInfo = restorepak.nullAAPakFileInfo;
                    if (!restorepak.AddFileFromStream(fi.name, fileBackupStream, DateTime.FromFileTimeUtc(gamefi.createTime), DateTime.FromFileTimeUtc(gamefi.modifyTime), false, out restoreFileInfo))
                    {
                        MessageBox.Show("Error making backup of " + fi.name);
                    }
                }

                var fileModStream = modpak.ExportFileAsStream(fi.name);
                fileModStream.Position = 0;
                AAPakFileInfo newModFile = gamepak.nullAAPakFileInfo;
                if (!gamepak.AddFileFromStream(fi.name, fileModStream, DateTime.FromFileTimeUtc(fi.createTime), DateTime.FromFileTimeUtc(fi.modifyTime), false, out newModFile))
                {
                    MessageBox.Show("Error modding file " + fi.name);
                }

                pb.PerformStep();
                pb.Refresh();
                //System.Threading.Thread.Sleep(50);
            }

            lInstallInfo.Text = "Updating game file header";
            lInstallInfo.Refresh();
            gamepak.SaveHeader();

            lInstallInfo.Text = "Updating restore file data";
            lInstallInfo.Refresh();
            ReadNewFilesFromRestore();
            // Add newly added files to the newfiles.txt
            foreach (var fi in FilesAddedWithInstall)
            {
                if (RestoreNewFilesList.IndexOf(fi.name) < 0)
                {
                    RestoreNewFilesList.Add(fi.name);
                }
            }
            WriteNewFilesForRestore();
            restorepak.SaveHeader();
            pb.Value = pb.Maximum;

            MessageBox.Show("Mod has been installed", "Install", MessageBoxButtons.OK, MessageBoxIcon.Information);
            ValidateInstallOptions();
        }
Пример #2
0
        private void WriteNewFilesForRestore()
        {
            var ms = AAPak.StringToStream(string.Join("\n", RestoreNewFilesList.ToArray()));

            restorepak.AddFileFromStream(ModNewFilesFileName, ms, DateTime.Now, DateTime.Now, false, out var pfi);
        }