diff --git a/CreateArchive.xaml.cs b/CreateArchive.xaml.cs index 6d95c9e1..05a8822a 100644 --- a/CreateArchive.xaml.cs +++ b/CreateArchive.xaml.cs @@ -40,6 +40,11 @@ namespace GARbro.GUI if (MessageBoxResult.Yes != rc) return; } + var format = this.ArchiveFormat.SelectedItem as ArchiveFormat; + if (null != format) + { + ArchiveOptions = format.GetOptions (OptionsWidget.Content); + } DialogResult = true; } @@ -97,17 +102,10 @@ namespace GARbro.GUI void OnFormatSelect (object sender, SelectionChangedEventArgs e) { var format = this.ArchiveFormat.SelectedItem as ArchiveFormat; - UIElement widget = null; + object widget = null; if (null != format) { - var options = format.GetOptions(); - ArchiveOptions = options; - if (null != options) - widget = options.Widget as UIElement; - } - else - { - ArchiveOptions = null; + widget = format.GetCreationWidget(); } OptionsWidget.Content = widget; OptionsWidget.Visibility = null != widget ? Visibility.Visible : Visibility.Hidden; diff --git a/GarCreate.cs b/GarCreate.cs index 4d4b098b..8b7036db 100644 --- a/GarCreate.cs +++ b/GarCreate.cs @@ -32,12 +32,13 @@ using System.Windows; using System.Windows.Input; using GameRes; using GARbro.GUI.Strings; +using Ookii.Dialogs.Wpf; namespace GARbro.GUI { public partial class MainWindow : Window { - private void CreateArchiveExec (object sender, ExecutedRoutedEventArgs e) + private void CreateArchiveExec (object sender, ExecutedRoutedEventArgs args) { StopWatchDirectoryChanges(); try @@ -75,14 +76,60 @@ namespace GARbro.GUI file_list = BuildFileList (items, AddFilesFromDir); arc_name = Path.GetFullPath (dialog.ArchiveName.Text); - using (var tmp_file = new GARbro.Shell.TemporaryFile (Path.GetDirectoryName (arc_name), - Path.GetRandomFileName())) + + var createProgressDialog = new ProgressDialog () { - using (var file = File.Create (tmp_file.Name)) - format.Create (file, file_list, dialog.ArchiveOptions); - GARbro.Shell.File.Rename (tmp_file.Name, arc_name); - SetCurrentPosition (new DirectoryPosition (arc_name)); - } + WindowTitle = guiStrings.TextTitle, + Text = string.Format (guiStrings.MsgCreatingArchive, Path.GetFileName (arc_name)), + Description = "", + MinimizeBox = true, + }; + createProgressDialog.DoWork += (s, e) => + { + try + { + using (var tmp_file = new GARbro.Shell.TemporaryFile (Path.GetDirectoryName (arc_name), + Path.GetRandomFileName ())) + { + int total = file_list.Count() + 1; + using (var file = File.Create (tmp_file.Name)) + { + format.Create (file, file_list, dialog.ArchiveOptions, (i, entry, msg) => + { + if (createProgressDialog.CancellationPending) + throw new OperationCanceledException(); + int progress = i*100/total; + string notice = msg; + if (null != entry) + { + if (null != msg) + notice = string.Format ("{0} {1}", msg, entry.Name); + else + notice = entry.Name; + } + createProgressDialog.ReportProgress (progress, null, notice); + return ArchiveOperation.Continue; + }); + } + GARbro.Shell.File.Rename (tmp_file.Name, arc_name); + } + } + catch (OperationCanceledException X) + { + m_watcher.EnableRaisingEvents = true; + SetStatusText (X.Message); + } + catch (Exception X) + { + m_watcher.EnableRaisingEvents = true; + PopupError (X.Message, guiStrings.TextCreateArchiveError); + } + }; + createProgressDialog.RunWorkerCompleted += (s, e) => { + createProgressDialog.Dispose(); + Dispatcher.Invoke (() => SetCurrentPosition (new DirectoryPosition (arc_name))); + }; + createProgressDialog.ShowDialog (this); } catch (Exception X) { diff --git a/Strings/guiStrings.Designer.cs b/Strings/guiStrings.Designer.cs index 6aada000..cd04ca5f 100644 --- a/Strings/guiStrings.Designer.cs +++ b/Strings/guiStrings.Designer.cs @@ -330,6 +330,15 @@ namespace GARbro.GUI.Strings { } } + /// + /// Looks up a localized string similar to Creating archive {0}. + /// + public static string MsgCreatingArchive { + get { + return ResourceManager.GetString("MsgCreatingArchive", resourceCulture); + } + } + /// /// Looks up a localized string similar to Deleted {0}. /// diff --git a/Strings/guiStrings.resx b/Strings/guiStrings.resx index 0d73d843..2f0ae1f8 100644 --- a/Strings/guiStrings.resx +++ b/Strings/guiStrings.resx @@ -327,4 +327,7 @@ Overwrite? Confirm overwrite + + Creating archive {0} + \ No newline at end of file diff --git a/Strings/guiStrings.ru-RU.resx b/Strings/guiStrings.ru-RU.resx index 46572e07..7d8649b0 100644 --- a/Strings/guiStrings.ru-RU.resx +++ b/Strings/guiStrings.ru-RU.resx @@ -330,4 +330,7 @@ Подтвердите перезапись + + Создание архива {0} + \ No newline at end of file