Ejemplo n.º 1
0
        public void LoadArchive(string path)
        {
            if (_Archive != null)
            {
                _Archive.Dispose();
                _Archive = null;
            }
#if DEBUG
            using (var input = File.OpenRead(path))
            {
                _Archive = new ArchiveFile();
                _Archive.Deserialize(input);
            }
#else
            Thread thread = new Thread(() => ArchiveThreadLoad(path));
            thread.Start();

            while (thread.IsAlive)
            {
                Application.DoEvents();
            }
#endif
            if (_Archive == null)
            {
                return;
            }
            Program.FilePath = path;
            _Descr           = LoadDescriptions(_Archive.ResourceInfoXml);
            BuildEntryTree();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Open an SDS from the FileInfo given.
        /// </summary>
        /// <param name="file">info of SDS.</param>
        private void OpenSDS(FileInfo file)
        {
            //backup file before unpacking..
            if (!Directory.Exists(file.Directory.FullName + "/BackupSDS"))
            {
                Directory.CreateDirectory(file.Directory.FullName + "/BackupSDS");
            }

            //place copy in new folder.
            string time     = string.Format("{0}_{1}_{2}_{3}_{4}", DateTime.Now.TimeOfDay.Hours, DateTime.Now.TimeOfDay.Minutes, DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year);
            string filename = ToolkitSettings.AddTimeDataBackup == true?file.Name.Insert(file.Name.Length - 4, "_" + time) : file.Name;

            File.Copy(file.FullName, file.Directory.FullName + "/BackupSDS/" + filename, true);

            Log.WriteLine("Opening SDS: " + file.Name);
            fileListView.Items.Clear();
            ArchiveFile archiveFile;

            using (var input = File.OpenRead(file.FullName))
            {
                using (Stream data = ArchiveEncryption.Unwrap(input))
                {
                    archiveFile = new ArchiveFile();
                    archiveFile.Deserialize(data ?? input);
                }
            }

            Log.WriteLine("Succesfully unwrapped compressed data");

            archiveFile.SaveResources(file);

            OpenDirectory(new DirectoryInfo(file.Directory.FullName + "/extracted/" + file.Name));
            infoText.Text = "Opened SDS..";
        }
Ejemplo n.º 3
0
        void ArchiveThreadLoad(string path)
        {
            if (InvokeRequired == true)
            {
                Invoke((MethodInvoker) delegate
                {
                    UseWaitCursor              = true;
                    _EntryTreeView.Enabled     = false;
                    _OpenArchiveButton.Enabled = false;
                    _SaveArchiveButton.Enabled = false;
                });
            }

            using (var input = File.OpenRead(path))
            {
                _Archive = new ArchiveFile();
                _Archive.Deserialize(input);
            }

            if (InvokeRequired == true)
            {
                Invoke((MethodInvoker) delegate
                {
                    UseWaitCursor              = false;
                    _EntryTreeView.Enabled     = true;
                    _OpenArchiveButton.Enabled = true;
                    _SaveArchiveButton.Enabled = true;
                });
            }
        }
Ejemplo n.º 4
0
        private void OpenSDS(FileInfo file, bool openDirectory = true)
        {
            string backupFolder    = Path.Combine(file.Directory.FullName, "BackupSDS");
            string extractedFolder = Path.Combine(file.Directory.FullName, "extracted");

            //backup file before unpacking..
            if (!Directory.Exists(backupFolder))
            {
                Directory.CreateDirectory(backupFolder);
            }

            //place copy in new folder.
            string time     = string.Format("{0}_{1}_{2}_{3}_{4}", DateTime.Now.TimeOfDay.Hours, DateTime.Now.TimeOfDay.Minutes, DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year);
            string filename = ToolkitSettings.AddTimeDataBackup == true?file.Name.Insert(file.Name.Length - 4, "_" + time) : file.Name;

            File.Copy(file.FullName, Path.Combine(backupFolder, filename), true);

            Log.WriteLine("Opening SDS: " + file.Name);
            fileListView.Items.Clear();
            ArchiveFile archiveFile;

            using (var input = File.OpenRead(file.FullName))
            {
                using (Stream data = ArchiveEncryption.Unwrap(input))
                {
                    archiveFile = new ArchiveFile();
                    archiveFile.Deserialize(data ?? input);
                }
            }

            Log.WriteLine("Succesfully unwrapped compressed data");

            archiveFile.SaveResources(file);
            if (openDirectory)
            {
                var      directory = file.Directory;
                string   path      = directory.FullName.Remove(0, directory.FullName.IndexOf(originalPath.Name, StringComparison.InvariantCultureIgnoreCase)).TrimEnd('\\');
                TreeNode node      = folderView.Nodes.FindTreeNodeByFullPath(path);

                if (!node.Nodes.ContainsKey("extracted"))
                {
                    var extracted = new TreeNode("extracted");
                    extracted.Tag  = extracted;
                    extracted.Name = "extracted";
                    extracted.Nodes.Add(file.Name);
                    node.Nodes.Add(extracted);
                }
                else
                {
                    node.Nodes["extracted"].Nodes.Add(file.Name);
                }

                OpenDirectory(new DirectoryInfo(Path.Combine(extractedFolder, file.Name)));
                infoText.Text = "Opened SDS..";
            }
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            bool showHelp = false;

            var options = new OptionSet()
            {
                { "h|help", "show this message and exit", v => showHelp = v != null },
            };

            List <string> extras;

            try
            {
                extras = options.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("{0}: ", GetExecutableName());
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName());
                return;
            }

            if (extras.Count < 1 || extras.Count > 2 || showHelp == true)
            {
                Console.WriteLine("Usage: {0} [OPTIONS]+ input_sds [output_sds]", GetExecutableName());
                Console.WriteLine("Decompress specified archive.");
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return;
            }

            var inputPath  = extras[0];
            var outputPath = extras.Count > 1 ? extras[1] : Path.ChangeExtension(inputPath, null) + "_unc.sds";

            ArchiveFile archiveFile;

            using (var input = File.OpenRead(inputPath))
            {
                archiveFile = new ArchiveFile();
                archiveFile.Deserialize(input);
            }

            using (var output = File.Create(outputPath))
            {
                archiveFile.Serialize(output, ArchiveSerializeOptions.OneBlock);
            }
        }
Ejemplo n.º 6
0
        public override bool Open()
        {
            string backupFolder    = Path.Combine(file.Directory.FullName, "BackupSDS");
            string extractedFolder = Path.Combine(file.Directory.FullName, "extracted");

            // Only create backups if enabled.
            if (ToolkitSettings.bBackupEnabled)
            {
                // We should backup file before unpacking..
                if (!Directory.Exists(backupFolder))
                {
                    Directory.CreateDirectory(backupFolder);
                }

                // Place the backup in the folder recently created
                string time     = string.Format("{0}_{1}_{2}_{3}_{4}", DateTime.Now.TimeOfDay.Hours, DateTime.Now.TimeOfDay.Minutes, DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year);
                string filename = ToolkitSettings.AddTimeDataBackup == true?file.Name.Insert(file.Name.Length - 4, "_" + time) : file.Name;

                File.Copy(file.FullName, Path.Combine(backupFolder, filename), true);
            }

            // Begin the unpacking process.
            Log.WriteLine("Opening SDS: " + file.Name);
            ArchiveFile archiveFile;

            using (var input = File.OpenRead(file.FullName))
            {
                using (Stream data = ArchiveEncryption.Unwrap(input))
                {
                    archiveFile = new ArchiveFile();
                    archiveFile.Deserialize(data ?? input);
                }
            }

            Log.WriteLine("Successfully unwrapped compressed data");
            archiveFile.SaveResources(file);

            if (File.Exists(file.FullName + ".patch") && GameStorage.Instance.GetSelectedGame().GameType == GamesEnumerator.MafiaII_DE)
            {
                DialogResult result = MessageBox.Show("Detected Patch file. Would you like to unpack?", "Toolkit", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    archiveFile.ExtractPatch(new FileInfo(file.FullName + ".patch"));
                }
            }

            return(true);
        }
Ejemplo n.º 7
0
        public void LoadArchive(string path)
        {
            ArchiveFile archiveFile;

            using (var input = File.OpenRead(path))
            {
                using (Stream data = ArchiveEncryption.Unwrap(input))
                {
                    archiveFile = new ArchiveFile();
                    archiveFile.Deserialize(data ?? input);
                }
            }

            this._FilePath     = path;
            this._Archive      = archiveFile;
            this._Descriptions = LoadDescriptions(archiveFile.ResourceInfoXml);
            this.BuildEntryTree();
            this.Text += string.Format(": {0}", Path.GetFileName(path));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Open an SDS from the FileInfo given.
        /// </summary>
        /// <param name="file">info of SDS.</param>
        private void OpenSDS(FileInfo file)
        {
            Log.WriteLine("Opening SDS: " + file.Name);
            fileListView.Items.Clear();
            ArchiveFile archiveFile;

            using (var input = File.OpenRead(file.FullName))
            {
                using (Stream data = ArchiveEncryption.Unwrap(input))
                {
                    archiveFile = new ArchiveFile();
                    archiveFile.Deserialize(data ?? input);
                }
            }

            Log.WriteLine("Succesfully unwrapped compressed data");

            archiveFile.SaveResources(file);

            OpenDirectory(new DirectoryInfo(file.Directory.FullName + "/extracted/" + file.Name));
            infoText.Text = "Opened SDS..";
        }
Ejemplo n.º 9
0
        public static void Main(string[] args)
        {
            bool showHelp       = false;
            bool overwriteFiles = false;
            bool verbose        = false;

            var options = new OptionSet()
            {
                { "o|overwrite", "overwrite existing files", v => overwriteFiles = v != null },
                { "v|verbose", "be verbose", v => verbose = v != null },
                { "h|help", "show this message and exit", v => showHelp = v != null },
            };

            List <string> extras;

            try
            {
                extras = options.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("{0}: ", GetExecutableName());
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName());
                return;
            }

            if (extras.Count < 1 || extras.Count > 2 || showHelp == true)
            {
                Console.WriteLine("Usage: {0} [OPTIONS]+ input_par [output_dir]", GetExecutableName());
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return;
            }

            var inputPath  = Path.GetFullPath(extras[0]);
            var outputPath = extras.Count > 1 ? extras[1] : Path.ChangeExtension(inputPath, null) + "_unpack";

            using (var input = File.OpenRead(inputPath))
            {
                var archive = new ArchiveFile();
                archive.Deserialize(input);

                long current = 0;
                long total   = archive.Entries.Count;
                var  padding = total.ToString(CultureInfo.InvariantCulture).Length;

                foreach (var entry in archive.Entries)
                {
                    current++;

                    var entryPath = Path.Combine(outputPath, entry.Path);
                    if (overwriteFiles == false && File.Exists(entryPath) == true)
                    {
                        continue;
                    }

                    if (verbose == true)
                    {
                        Console.WriteLine(
                            "[{0}/{1}] {2}",
                            current.ToString(CultureInfo.InvariantCulture).PadLeft(padding),
                            total,
                            entry.Path);
                    }

                    var entryDirectory = Path.GetDirectoryName(entryPath);
                    if (entryDirectory != null)
                    {
                        Directory.CreateDirectory(entryDirectory);
                    }

                    using (var output = File.Create(entryPath))
                    {
                        input.Seek(entry.DataOffset, SeekOrigin.Begin);

                        if (entry.IsCompressed == false)
                        {
                            output.WriteFromStream(input, entry.DataCompressedSize);
                        }
                        else
                        {
                            Decompress(input, entry, output);
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public static void Main(string[] args)
        {
            bool showHelp       = false;
            bool overwriteFiles = false;
            bool verbose        = false;

            var options = new OptionSet()
            {
                {
                    "o|overwrite",
                    "overwrite existing files",
                    v => overwriteFiles = v != null
                },
                {
                    "v|verbose",
                    "be verbose",
                    v => verbose = v != null
                },
                {
                    "h|help",
                    "show this message and exit",
                    v => showHelp = v != null
                },
            };

            List <string> extras;

            try
            {
                extras = options.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("{0}: ", GetExecutableName());
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName());
                return;
            }

            if (extras.Count < 1 || extras.Count > 2 || showHelp == true)
            {
                Console.WriteLine("Usage: {0} [OPTIONS]+ input_rcf [output_dir]", GetExecutableName());
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return;
            }

            var inputPath  = Path.GetFullPath(extras[0]);
            var outputPath = extras.Count > 1 ? extras[1] : Path.ChangeExtension(inputPath, null) + "_unpack";

            var kft = new KnownFileTypes();

            var kftPath = Path.Combine(GetExecutablePath(), "archive_file_types.cfg");

            if (File.Exists(kftPath) == true)
            {
                kft.Load(kftPath);
            }

            using (var input = File.OpenRead(inputPath))
            {
                var archive = new ArchiveFile();
                archive.Deserialize(input);

                long current = 0;
                long total   = archive.Entries.Count;
                var  padding = total.ToString(CultureInfo.InvariantCulture).Length;

                foreach (var entry in archive.Entries)
                {
                    current++;

                    var entryName = entry.Name;

                    if (kft.Contains(entry.TypeHash) == false)
                    {
                        entryName += ".UNK#" + entry.TypeHash.ToString("X8");
                    }
                    else
                    {
                        entryName += kft.GetExtension(entry.TypeHash) ?? "." + kft.GetName(entry.TypeHash);
                    }

                    var entryPath = Path.Combine(outputPath, entryName);
                    if (overwriteFiles == false &&
                        File.Exists(entryPath) == true)
                    {
                        continue;
                    }

                    if (verbose == true)
                    {
                        Console.WriteLine("[{0}/{1}] {2}",
                                          current.ToString(CultureInfo.InvariantCulture).PadLeft(padding),
                                          total,
                                          entryName);
                    }

                    input.Seek(entry.Offset, SeekOrigin.Begin);

                    var entryDirectory = Path.GetDirectoryName(entryPath);
                    if (entryDirectory != null)
                    {
                        Directory.CreateDirectory(entryDirectory);
                    }

                    using (var output = File.Create(entryPath))
                    {
                        input.Seek(entry.Offset, SeekOrigin.Begin);

                        if (archive.Version == 8)
                        {
                            if (entry.CompressedSize == entry.UncompressedSize)
                            {
                                output.WriteFromStream(input, entry.UncompressedSize);
                            }
                            else
                            {
                                using (var temp = input.ReadToMemoryStream(entry.CompressedSize))
                                {
                                    var zlib = new InflaterInputStream(temp);
                                    output.WriteFromStream(zlib, entry.UncompressedSize);
                                }
                            }
                        }
                        else if (archive.Version == 17)
                        {
                            if (entry.CompressedSize == entry.UncompressedSize)
                            {
                                output.WriteFromStream(input, entry.UncompressedSize);
                            }
                            else
                            {
                                var compressed   = input.ReadBytes(entry.CompressedSize);
                                var uncompressed = new byte[entry.UncompressedSize];

                                using (var context = new XCompression.DecompressionContext(0x8000))
                                {
                                    var compressedSize   = compressed.Length;
                                    var uncompressedSize = uncompressed.Length;

                                    if (
                                        context.Decompress(compressed,
                                                           0,
                                                           ref compressedSize,
                                                           uncompressed,
                                                           0,
                                                           ref uncompressedSize) != XCompression.ErrorCode.None)
                                    {
                                        throw new InvalidOperationException();
                                    }

                                    if (uncompressedSize != uncompressed.Length ||
                                        compressedSize != compressed.Length)
                                    {
                                        throw new InvalidOperationException();
                                    }

                                    output.WriteBytes(uncompressed);
                                }
                            }
                        }
                        else
                        {
                            throw new NotSupportedException();
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public static void Main(string[] args)
        {
            bool verbose  = false;
            bool showHelp = false;

            OptionSet options = new OptionSet()
            {
                {
                    "h|help",
                    "show this message and exit",
                    v => showHelp = v != null
                },
            };

            List <string> extras;

            try
            {
                extras = options.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("{0}: ", GetExecutableName());
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName());
                return;
            }

            if (extras.Count < 1 || extras.Count > 2 || showHelp == true)
            {
                Console.WriteLine("Usage: {0} [OPTIONS]+ input_archive [output_directory]", GetExecutableName());
                Console.WriteLine("Unpack specified archive.");
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return;
            }

            string inputPath  = extras[0];
            string outputPath = extras.Count > 1 ? extras[1] : Path.ChangeExtension(inputPath, null);

            using (var input = File.Open(
                       inputPath,
                       FileMode.Open,
                       FileAccess.Read,
                       FileShare.ReadWrite))
            {
                var archive = new ArchiveFile();
                archive.Deserialize(input);

                Directory.CreateDirectory(outputPath);

                byte[] buffer = new byte[0x4000];

                long counter = 0;
                foreach (var entry in archive.Entries)
                {
                    string entryPath = Path.Combine(outputPath, entry.Path);
                    Directory.CreateDirectory(Path.GetDirectoryName(entryPath));

                    using (Stream output = File.Open(entryPath, FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        input.Seek(entry.Offset, SeekOrigin.Begin);
                        output.WriteFromStream(input, entry.Size);
                    }

                    counter++;
                }
            }
        }