Ejemplo n.º 1
0
        public Patcher(CrafArchive archive)
        {
            _archive      = archive;
            _candidateIds = new List <int>();

            for (var i = 0; i < _archive.Count(); i++)
            {
                var filename = _archive.VfsFilename(i);
                if (filename.StartsWith("g_buffer") && filename.EndsWith(".ps.sb"))
                {
                    _candidateIds.Add(i);
                }
            }
        }
Ejemplo n.º 2
0
 private void InitialOpen()
 {
     try
     {
         _archive = CrafArchive.Open(archivePath);
     }
     catch (IOException ex)
     {
         MessageBox.Show("Shader archive \"" + archivePath + "\" is not readable. "
                         + "Please ensure you are running this program in the game installation folder. "
                         + "If this program is correctly installed and you're still seeing this error, try running as Administrator and/or disabling your antivirus.\n\n"
                         + "Details:\n"
                         + ex.Message);
         Application.Exit();
     }
 }
Ejemplo n.º 3
0
 static void List(string path)
 {
     try
     {
         var archive = CrafArchive.Open(path);
         for (var i = 0; i < archive.Count(); i++)
         {
             Console.WriteLine(archive.DiskPath(i));
         }
     }
     catch (IOException)
     {
         Console.WriteLine("Could not open archive");
         Environment.Exit(-1);
     }
 }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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("");
        }
Ejemplo n.º 6
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("");
        }