added progress window to archive creation process.

This commit is contained in:
morkt 2014-07-27 03:38:25 +04:00
parent 08b8e8a46b
commit 58f97183ac
5 changed files with 77 additions and 17 deletions

View File

@ -40,6 +40,11 @@ namespace GARbro.GUI
if (MessageBoxResult.Yes != rc) if (MessageBoxResult.Yes != rc)
return; return;
} }
var format = this.ArchiveFormat.SelectedItem as ArchiveFormat;
if (null != format)
{
ArchiveOptions = format.GetOptions (OptionsWidget.Content);
}
DialogResult = true; DialogResult = true;
} }
@ -97,17 +102,10 @@ namespace GARbro.GUI
void OnFormatSelect (object sender, SelectionChangedEventArgs e) void OnFormatSelect (object sender, SelectionChangedEventArgs e)
{ {
var format = this.ArchiveFormat.SelectedItem as ArchiveFormat; var format = this.ArchiveFormat.SelectedItem as ArchiveFormat;
UIElement widget = null; object widget = null;
if (null != format) if (null != format)
{ {
var options = format.GetOptions(); widget = format.GetCreationWidget();
ArchiveOptions = options;
if (null != options)
widget = options.Widget as UIElement;
}
else
{
ArchiveOptions = null;
} }
OptionsWidget.Content = widget; OptionsWidget.Content = widget;
OptionsWidget.Visibility = null != widget ? Visibility.Visible : Visibility.Hidden; OptionsWidget.Visibility = null != widget ? Visibility.Visible : Visibility.Hidden;

View File

@ -32,12 +32,13 @@ using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using GameRes; using GameRes;
using GARbro.GUI.Strings; using GARbro.GUI.Strings;
using Ookii.Dialogs.Wpf;
namespace GARbro.GUI namespace GARbro.GUI
{ {
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
private void CreateArchiveExec (object sender, ExecutedRoutedEventArgs e) private void CreateArchiveExec (object sender, ExecutedRoutedEventArgs args)
{ {
StopWatchDirectoryChanges(); StopWatchDirectoryChanges();
try try
@ -75,14 +76,60 @@ namespace GARbro.GUI
file_list = BuildFileList (items, AddFilesFromDir); file_list = BuildFileList (items, AddFilesFromDir);
arc_name = Path.GetFullPath (dialog.ArchiveName.Text); arc_name = Path.GetFullPath (dialog.ArchiveName.Text);
var createProgressDialog = new ProgressDialog ()
{
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), using (var tmp_file = new GARbro.Shell.TemporaryFile (Path.GetDirectoryName (arc_name),
Path.GetRandomFileName ())) Path.GetRandomFileName ()))
{ {
int total = file_list.Count() + 1;
using (var file = File.Create (tmp_file.Name)) using (var file = File.Create (tmp_file.Name))
format.Create (file, file_list, dialog.ArchiveOptions); {
GARbro.Shell.File.Rename (tmp_file.Name, arc_name); format.Create (file, file_list, dialog.ArchiveOptions, (i, entry, msg) =>
SetCurrentPosition (new DirectoryPosition (arc_name)); {
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) catch (Exception X)
{ {

View File

@ -330,6 +330,15 @@ namespace GARbro.GUI.Strings {
} }
} }
/// <summary>
/// Looks up a localized string similar to Creating archive {0}.
/// </summary>
public static string MsgCreatingArchive {
get {
return ResourceManager.GetString("MsgCreatingArchive", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Deleted {0}. /// Looks up a localized string similar to Deleted {0}.
/// </summary> /// </summary>

View File

@ -327,4 +327,7 @@ Overwrite?</value>
<data name="TextConfirmOverwrite" xml:space="preserve"> <data name="TextConfirmOverwrite" xml:space="preserve">
<value>Confirm overwrite</value> <value>Confirm overwrite</value>
</data> </data>
<data name="MsgCreatingArchive" xml:space="preserve">
<value>Creating archive {0}</value>
</data>
</root> </root>

View File

@ -330,4 +330,7 @@
<data name="TextConfirmOverwrite" xml:space="preserve"> <data name="TextConfirmOverwrite" xml:space="preserve">
<value>Подтвердите перезапись</value> <value>Подтвердите перезапись</value>
</data> </data>
<data name="MsgCreatingArchive" xml:space="preserve">
<value>Создание архива {0}</value>
</data>
</root> </root>