コード例 #1
0
ファイル: TableForm.cs プロジェクト: dragnilar/reanimator
        public TableForm(PackFile packFile)
        {
            _packFile = packFile;
            TableFormInit();

            try
            {
                _packFile.BeginDatReading();
            }
            catch (Exception e)
            {
                String message = "Unable to open accompanying data file: \n" + _packFile.NameWithoutExtension + ".dat\nYou will be unable to extract any files.\n" + e;
                MessageBox(message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
コード例 #2
0
ファイル: TableForm.cs プロジェクト: dragnilar/reanimator
        private void DoExtractFiles(ProgressForm progressBar, Object param)
        {
            PackFileEntry[] files = (PackFileEntry[])param;

            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog {
                SelectedPath = _packFile.Directory
            };

            if (ShowDialog(folderBrowserDialog) != DialogResult.OK)
            {
                return;
            }

            String       extractToPath = folderBrowserDialog.SelectedPath;
            bool         keepPath      = false;
            DialogResult dr            = MessageBox("Keep directory structure?", "Path", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (dr == DialogResult.Cancel)
            {
                return;
            }
            if (dr == DialogResult.Yes)
            {
                keepPath       = true;
                extractToPath += @"\" + _packFile.NameWithoutExtension;
            }

            progressBar.ConfigBar(0, files.Length, 1);
            progressBar.SetLoadingText("Extracting files to... " + extractToPath);

            int filesSaved = 0;

            _packFile.BeginDatReading();
            foreach (PackFileEntry file in files)
            {
                while (true)
                {
                    try
                    {
                        byte[] buffer = _packFile.GetFileBytes(file);

                        string keepPathString = "\\";
                        if (keepPath)
                        {
                            keepPathString += file.Directory;
                            Directory.CreateDirectory(extractToPath + keepPathString);
                        }

                        progressBar.SetCurrentItemText(file.Name);
                        FileStream fileOut = new FileStream(extractToPath + keepPathString + file.Name, FileMode.Create);
                        fileOut.Write(buffer, 0, buffer.Length);
                        fileOut.Close();
                        filesSaved++;
                        break;
                    }
                    catch (Exception e)
                    {
                        DialogResult failedDr = MessageBox("Failed to extract file from dat!\nFile: " + file.Name + "\n\n" + e.ToString(), "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
                        if (failedDr == DialogResult.Ignore || failedDr == DialogResult.Abort)
                        {
                            break;
                        }
                    }
                }
            }
            _packFile.EndDatAccess();

            MessageBox(filesSaved + " file(s) saved!", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }