예제 #1
0
        /// <summary>
        /// Method to ave all files
        /// </summary>
        private void SaveAllFiles()
        {
            try
            {
                CommonOpenFileDialog ofd = new CommonOpenFileDialog();
                ofd.IsFolderPicker = true;
                ofd.Title          = "Select a Folder to save all Files...";
                CommonFileDialogResult res = ofd.ShowDialog();
                if (res == CommonFileDialogResult.Ok)
                {
                    bool     fileExists, check;
                    int      errors      = 0;
                    int      skipped     = 0;
                    int      extracted   = 0;
                    int      renamed     = 0;
                    int      overwritten = 0;
                    FileInfo fi;
                    ExistingFileDialog.ResetDialog();
                    foreach (ListViewItem item in CurrentModel.ListViewItems)
                    {
                        fileExists = CheckFileExists(ofd.FileName, item.FileReference, CurrentModel.KeepFolderStructure, out var fileName);
                        if (fileExists == true)
                        {
                            if (ExistingFileDialog.RemeberDecision == null || ExistingFileDialog.RemeberDecision.Value != true)
                            {
                                fi = new FileInfo(fileName);
                                uint crc = Utils.GetCrc(fileName);
                                ExistingFileDialog efd = new ExistingFileDialog(fi.Name, fi.LastWriteTime, fi.Length, crc, item.FileName, item.FileReference.LastChange, item.FileReference.FileSize, item.FileReference.Crc32);
                                efd.ShowDialog();
                            }
                        }

                        if (fileExists)
                        {
                            if (ExistingFileDialog.DialogResult == ExistingFileDialog.Result.Cancel) // Cancel extractor
                            {
                                CurrentModel.StatusText = "The save process was canceled";
                                MessageBox.Show("The save process was canceled", "Canceled", MessageBoxButton.OK, MessageBoxImage.Information);
                                return;
                            }
                            else if (ExistingFileDialog.DialogResult == ExistingFileDialog.Result.Overwrite) // Overwrite existing
                            {
                                check = Save(item.FileReference, fileName, false);
                                if (check == false)
                                {
                                    errors++;
                                }
                                else
                                {
                                    extracted++;
                                    overwritten++;
                                }
                            }
                            else if (ExistingFileDialog.DialogResult == ExistingFileDialog.Result.Rename) // Rename new
                            {
                                fileName = Utils.GetNextFileName(fileName);
                                check    = Save(item.FileReference, fileName, false);
                                if (check == false)
                                {
                                    errors++;
                                }
                                else
                                {
                                    extracted++;
                                    renamed++;
                                }
                            }
                            else if (ExistingFileDialog.DialogResult == ExistingFileDialog.Result.Skip) // Skipp file
                            {
                                skipped++;
                            }
                            else
                            {
                                errors++;
                            }
                        }
                        else
                        {
                            check = Save(item.FileReference, fileName, false);
                            if (check == false)
                            {
                                errors++;
                            }
                            else
                            {
                                extracted++;
                            }
                        }
                    }

                    if (errors > 0 || skipped > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        if (errors == 1)
                        {
                            sb.Append("One file could not be extracted.");
                        }
                        else if (errors > 1)
                        {
                            sb.Append(errors + " files could not be extracted.");
                        }
                        sb.Append("\n");
                        if (skipped == 1)
                        {
                            sb.Append("One file was skipped.");
                        }
                        else if (skipped > 1)
                        {
                            sb.Append(skipped + " files were skipped.");
                        }
                        string message;
                        if (sb[0] == '\n')
                        {
                            message = sb.ToString(1, sb.Length - 1);
                        }
                        else
                        {
                            message = sb.ToString();
                        }
                        CurrentModel.StatusText = extracted + " files extracted (" + overwritten + " overwritten, " + renamed + " renamed), " + skipped + " skipped, " + errors + " not extracted (errors)";
                        MessageBox.Show(message, "Not all files were extracted", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }
                    else
                    {
                        CurrentModel.StatusText = extracted + " files extracted (" + overwritten + " overwritten, " + renamed + " renamed), " + skipped + " skipped";
                    }
                    if (CurrentModel.ShowInExplorer)
                    {
                        bool open = Utils.ShowInExplorer(ofd.FileName);
                        if (open == false)
                        {
                            MessageBox.Show("The path '" + ofd.FileName + "' could not be opened", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("There was an unexpected error during the extraction:\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }
예제 #2
0
        /// <summary>
        /// Method to save all files
        /// </summary>
        private void SaveFileRange(ListViewItem[] items, string dialogMessage)
        {
            try
            {
                CommonOpenFileDialog ofd = new CommonOpenFileDialog();
                ofd.IsFolderPicker = true;
                ofd.Title          = dialogMessage;
                CommonFileDialogResult res = ofd.ShowDialog();
                if (res == CommonFileDialogResult.Ok)
                {
                    bool     fileExists, check;
                    int      errors      = 0;
                    int      skipped     = 0;
                    int      extracted   = 0;
                    int      renamed     = 0;
                    int      overwritten = 0;
                    FileInfo fi;
                    ExistingFileDialog.ResetDialog();
                    foreach (ListViewItem item in items)
                    {
                        fileExists = CheckFileExists(ofd.FileName, item.FileReference, CurrentModel.KeepFolderStructure, out var fileName);
                        if (fileExists && (ExistingFileDialog.RememberDecision == null || !ExistingFileDialog.RememberDecision.Value))
                        {
                            fi = new FileInfo(fileName);
                            uint crc = Utils.GetCrc(fileName);
                            ExistingFileDialog efd = new ExistingFileDialog(fi.Name, fi.LastWriteTime, fi.Length, crc, item.FileName, item.FileReference.LastChange, item.FileReference.FileSize, item.FileReference.Crc32);
                            efd.ShowDialog();
                        }

                        if (fileExists)
                        {
                            if (ExistingFileDialog.DialogResult == ExistingFileDialog.Result.Cancel) // Cancel extractor
                            {
                                CurrentModel.StatusText = I18n.T(I18n.Key.StatusSaveCanceled);
                                MessageBox.Show(I18n.T(I18n.Key.StatusSaveCanceled), I18n.T(I18n.Key.DialogCancelTitle), MessageBoxButton.OK, MessageBoxImage.Information);
                                return;
                            }
                            else if (ExistingFileDialog.DialogResult == ExistingFileDialog.Result.Overwrite) // Overwrite existing
                            {
                                check = Save(item.FileReference, fileName, false);
                                if (!check)
                                {
                                    errors++;
                                }
                                else
                                {
                                    extracted++;
                                    overwritten++;
                                }
                            }
                            else if (ExistingFileDialog.DialogResult == ExistingFileDialog.Result.Rename) // Rename new
                            {
                                fileName = Utils.GetNextFileName(fileName);
                                check    = Save(item.FileReference, fileName, false);
                                if (!check)
                                {
                                    errors++;
                                }
                                else
                                {
                                    extracted++;
                                    renamed++;
                                }
                            }
                            else if (ExistingFileDialog.DialogResult == ExistingFileDialog.Result.Skip) // Skip file
                            {
                                skipped++;
                            }
                            else
                            {
                                errors++;
                            }
                        }
                        else
                        {
                            check = Save(item.FileReference, fileName, false);
                            if (!check)
                            {
                                errors++;
                            }
                            else
                            {
                                extracted++;
                            }
                        }
                    }

                    if (errors > 0 || skipped > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        if (errors == 1)
                        {
                            sb.Append(I18n.T(I18n.Key.TextErrorOneFile));
                        }
                        else if (errors > 1)
                        {
                            sb.Append(I18n.R(I18n.Key.TextErrorMultipleFiles, errors));
                        }
                        sb.Append("\n");
                        if (skipped == 1)
                        {
                            sb.Append(I18n.T(I18n.Key.TextSkippedOneFile));
                        }
                        else if (skipped > 1)
                        {
                            sb.Append(I18n.R(I18n.Key.TextSkippedMultipleFiles, skipped));
                        }
                        string message;
                        if (sb[0] == '\n')
                        {
                            message = sb.ToString(1, sb.Length - 1);
                        }
                        else
                        {
                            message = sb.ToString();
                        }
                        CurrentModel.StatusText = I18n.R(I18n.Key.StatusSaveErrorSummary, extracted, overwritten, renamed, skipped, errors);
                        MessageBox.Show(message, I18n.T(I18n.Key.DialogSaveErrors), MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }
                    else
                    {
                        CurrentModel.StatusText = I18n.R(I18n.Key.StatusSaveSummary, extracted, overwritten, renamed, skipped);
                    }
                    if (CurrentModel.ShowInExplorer)
                    {
                        bool open = Utils.ShowInExplorer(ofd.FileName);
                        if (!open)
                        {
                            MessageBox.Show(I18n.R(I18n.Key.DialogExplorerError, ofd.FileName), I18n.T(I18n.Key.DialogErrorTitle), MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(I18n.T(I18n.Key.DialogUnexpectedError) + "\n" + ex.Message, I18n.T(I18n.Key.DialogErrorTitle), MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }