Example #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            versionLabel.Text = string.Format("{0} (built {1})",
                                              versionNumber,
                                              Assembly.GetExecutingAssembly().GetLinkerTime()
                                              .ToString("MMM dd, yyyy (hh:mm tt)", CultureInfo.InvariantCulture));

            this.BeginInvoke((MethodInvoker)async delegate {
                InitialOpen();

                if (_archive.IndexOf(dummyVfsPath) != -1)
                {
                    _archive.CloseReader();
                    if (File.Exists(backupArchivePath))
                    {
                        var dr = MessageBox.Show("Your shaders were already patched. "
                                                 + "Want to restore the originals? You'll be able to re-patch with different settings afterwards.",
                                                 "ffxvDitherPatch",
                                                 MessageBoxButtons.YesNo);
                        if (dr != DialogResult.Yes)
                        {
                            Application.Exit();
                        }
                        // not redundant - Application.Exit() does not stop control flow here
                        else
                        {
                            File.Delete(archivePath);
                            File.Move(backupArchivePath, archivePath);
                            InitialOpen();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Your shaders were already patched and no backup was found. "
                                        + "Please restore the original \"" + archivePath + "\" (e.g. with Steam's Verify Integrity feature).");
                        Application.Exit();
                    }
                }

                progressBar.Maximum = _archive.Count();
                statusLabel.Text    = "Loading archive into memory";
                await _archive.LoadAsync(new Progress <int>(UpdateProgressBar));
                _archive.CloseReader();

                _patcher = new Patcher(_archive);
                processButton.Enabled = true;
                statusLabel.Text      = "Waiting for input";
            });
        }
Example #2
0
        static void Extract(string archivePath, string destinationFolder)
        {
            CrafArchive archive = null;

            try
            {
                archive = CrafArchive.Open(archivePath);
                var task = archive.LoadAsync(new Progress <int>());
                task.Wait();
                archive.CloseReader();
            }
            catch (IOException)
            {
                Console.WriteLine("Could not open archive");
                Environment.Exit(-1);
            }

            var ct = archive.Count();

            try
            {
                Directory.CreateDirectory(destinationFolder);
                for (var i = 0; i < ct; i++)
                {
                    var outputPath = Path.Combine(destinationFolder, archive.DiskPath(i));
                    Console.WriteLine(string.Format("{0} ({1}/{2})", outputPath, i + 1, ct));
                    Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
                    File.WriteAllBytes(outputPath, archive.Get(i));
                }
            }
            catch (IOException ex)
            {
                Console.WriteLine("Error while extracting archive");
                Console.WriteLine("Details: " + ex.Message);
                Environment.Exit(-1);
            }
        }
Example #3
0
        static void ReplaceAll(string archivePath, string replacementFolder, string newArchivePath)
        {
            CrafArchive archive = null;

            try
            {
                archive = CrafArchive.Open(archivePath);
                var task = archive.LoadAsync(new Progress <int>());
                task.Wait();
                archive.CloseReader();
            }
            catch (IOException)
            {
                Console.WriteLine("Could not open archive");
                Environment.Exit(-1);
            }

            var ct = archive.Count();

            Console.WriteLine("Loading replacement files...");
            for (var i = 0; i < ct; i++)
            {
                var fileInArchive = archive.DiskPath(i);
                var combined      = Path.Combine(replacementFolder, fileInArchive);
                if (File.Exists(combined))
                {
                    Console.WriteLine(string.Format("{0} ({1}/{2})", combined, i + 1, ct));
                    try
                    {
                        archive.Replace(i, File.ReadAllBytes(combined));
                    }
                    catch (IOException ex)
                    {
                        Console.WriteLine("Could not read replacement file");
                        Console.WriteLine("Details: " + ex.Message);
                        Environment.Exit(-1);
                    }
                }
            }

            Console.WriteLine("");

            Console.WriteLine("Writing back files...");
            var fivePercent = ct / 20;

            if (fivePercent == 0)
            {
                fivePercent = 1;
            }
            try
            {
                var task2 = archive.SaveAsync(newArchivePath, new Progress <int>((i) =>
                {
                    if (i % fivePercent == 0)
                    {
                        Console.Write(".");
                    }
                }));
                task2.Wait();
            }
            catch (IOException ex)
            {
                Console.WriteLine("");
                Console.WriteLine("Could not write new archive");
                Console.WriteLine("Details: " + ex.Message);
                Environment.Exit(-1);
            }
            Console.WriteLine("");
        }
Example #4
0
        static void Replace(string archivePath, string fileInArchive, string fileOnDisk, string newArchivePath)
        {
            CrafArchive archive = null;

            try
            {
                archive = CrafArchive.Open(archivePath);
                var task = archive.LoadAsync(new Progress <int>());
                task.Wait();
                archive.CloseReader();
            }
            catch (IOException)
            {
                Console.WriteLine("Could not open archive");
                Environment.Exit(-1);
            }

            var id = archive.IndexOfDiskPath(fileInArchive);

            if (id == -1)
            {
                Console.WriteLine("File in archive not found");
                Environment.Exit(-1);
            }

            Console.WriteLine("Loading new file...");
            try
            {
                archive.Replace(id, File.ReadAllBytes(fileOnDisk));
            }
            catch (IOException ex)
            {
                Console.WriteLine("Could not read replacement file");
                Console.WriteLine("Details: " + ex.Message);
                Environment.Exit(-1);
            }

            Console.WriteLine("Writing back files...");
            var fivePercent = archive.Count() / 20;

            if (fivePercent == 0)
            {
                fivePercent = 1;
            }
            try
            {
                var task2 = archive.SaveAsync(newArchivePath, new Progress <int>((i) =>
                {
                    if (i % fivePercent == 0)
                    {
                        Console.Write(".");
                    }
                }));
                task2.Wait();
            }
            catch (IOException ex)
            {
                Console.WriteLine("");
                Console.WriteLine("Could not write new archive");
                Console.WriteLine("Details: " + ex.Message);
                Environment.Exit(-1);
            }
            Console.WriteLine("");
        }