(FileExistsDialog): new modal window.

added FileErrorDialog logic to GarConvert.
This commit is contained in:
morkt 2017-02-03 18:04:35 +04:00
parent f8c63f134b
commit 661e986e85
12 changed files with 332 additions and 60 deletions

View File

@ -16,6 +16,16 @@ namespace GARbro.GUI
this.DataContext = new ViewModel { Title = title, Text = error_text };
}
new public FileErrorDialogResult ShowDialog ()
{
bool dialog_result = base.ShowDialog() ?? false;
return new FileErrorDialogResult
{
Continue = dialog_result,
IgnoreErrors = IgnoreErrors.IsChecked ?? false
};
}
private void ContinueButton_Click (object sender, RoutedEventArgs e)
{
this.DialogResult = true;
@ -73,4 +83,10 @@ namespace GARbro.GUI
public event EventHandler CanExecuteChanged;
}
}
public struct FileErrorDialogResult
{
public bool Continue;
public bool IgnoreErrors;
}
}

21
GUI/FileExistsDialog.xaml Normal file
View File

@ -0,0 +1,21 @@
<w:ModalWindow x:Class="GARbro.GUI.FileExistsDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:w="clr-namespace:Rnd.Windows"
xmlns:s="clr-namespace:GARbro.GUI.Strings"
Title="File already exists" ShowInTaskbar="False" WindowStartupLocation="CenterOwner"
ResizeMode="NoResize" SizeToContent="WidthAndHeight" ShowActivated="True"
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="Notice" Text="File named {0} already exists in destination folder." Margin="10"/>
<TextBlock Text="{x:Static s:guiStrings.LabelDuplicateFileQuestion}" Margin="10"/>
<Separator/>
<CheckBox x:Name="ApplyToAll" Content="{x:Static s:guiStrings.LabelApplyToAll}" Margin="10"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
<Button Content="{x:Static s:guiStrings.ButtonSkip}" Margin="10" Width="75" Height="25" IsDefault="True" Click="SkipButton_Click"/>
<Button Content="{x:Static s:guiStrings.ButtonOverwrite}" Margin="10" Width="75" Height="25" Click="OverwriteButton_Click"/>
<Button Content="{x:Static s:guiStrings.ButtonRename}" Margin="10" Width="75" Height="25" Click="RenameButton_Click"/>
<Button Content="{x:Static s:guiStrings.ButtonAbort}" Margin="10" Width="75" Height="25" IsCancel="True" Click="AbortButton_Click"/>
</StackPanel>
</StackPanel>
</w:ModalWindow>

View File

@ -0,0 +1,72 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace GARbro.GUI
{
/// <summary>
/// Interaction logic for FileExistsDialog.xaml
/// </summary>
public partial class FileExistsDialog : Rnd.Windows.ModalWindow
{
public FileExistsDialog (string title, string text)
{
InitializeComponent ();
this.Title = title;
this.Notice.Text = text;
}
new public FileExistsDialogResult ShowDialog ()
{
bool dialog_result = base.ShowDialog() ?? false;
if (!dialog_result)
FileAction = ExistingFileAction.Abort;
return new FileExistsDialogResult
{
Action = FileAction,
ApplyToAll = ApplyToAll.IsChecked ?? false
};
}
public ExistingFileAction FileAction { get; set; }
private void SkipButton_Click (object sender, RoutedEventArgs e)
{
this.DialogResult = true;
this.FileAction = ExistingFileAction.Skip;
}
private void OverwriteButton_Click (object sender, RoutedEventArgs e)
{
this.DialogResult = true;
this.FileAction = ExistingFileAction.Overwrite;
}
private void RenameButton_Click (object sender, RoutedEventArgs e)
{
this.DialogResult = true;
this.FileAction = ExistingFileAction.Rename;
}
private void AbortButton_Click (object sender, RoutedEventArgs e)
{
this.DialogResult = false;
this.FileAction = ExistingFileAction.Abort;
}
}
public enum ExistingFileAction
{
Skip,
Overwrite,
Rename,
Abort
}
public struct FileExistsDialogResult
{
public ExistingFileAction Action;
public bool ApplyToAll;
}
}

View File

@ -147,6 +147,9 @@
<Compile Include="FileErrorDialog.xaml.cs">
<DependentUpon>FileErrorDialog.xaml</DependentUpon>
</Compile>
<Compile Include="FileExistsDialog.xaml.cs">
<DependentUpon>FileExistsDialog.xaml</DependentUpon>
</Compile>
<Compile Include="GarConvert.cs" />
<Compile Include="GarCreate.cs" />
<Compile Include="GarExtract.cs" />
@ -203,6 +206,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="FileExistsDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>

View File

@ -143,14 +143,15 @@ namespace GARbro.GUI
void ConvertWorker (object sender, DoWorkEventArgs e)
{
m_pending_error = null;
try
{
int total = m_source.Count();
int i = 0;
foreach (var entry in m_source)
{
if (m_progress_dialog.CancellationPending)
throw new OperationCanceledException();
{
m_pending_error = new OperationCanceledException();
break;
}
var filename = entry.Name;
int progress = i++*100/total;
m_progress_dialog.ReportProgress (progress, string.Format (guiStrings.MsgConvertingFile,
@ -162,25 +163,20 @@ namespace GARbro.GUI
else if ("audio" == entry.Type)
ConvertAudio (filename);
}
catch (NotImplementedException X)
{
// target format creation not implemented
m_pending_error = X;
break;
}
catch (Exception X)
{
if (!IgnoreErrors)
throw;
{
var error_text = string.Format (guiStrings.TextErrorConverting, entry.Name, X.Message);
var result = m_main.Dispatcher.Invoke (() => m_main.ShowErrorDialog (guiStrings.TextMediaConvertError, error_text, m_progress_dialog.GetWindowHandle()));
if (!result.Continue)
break;
IgnoreErrors = result.IgnoreErrors;
}
m_failed.Add (Tuple.Create (Path.GetFileName (filename), X.Message));
}
}
}
catch (Exception X)
{
m_pending_error = X;
}
}
public static readonly HashSet<string> CommonAudioFormats = new HashSet<string> { "wav", "mp3", "ogg" };

View File

@ -304,8 +304,10 @@ namespace GARbro.GUI
if (!m_ignore_errors)
{
var error_text = string.Format (guiStrings.TextErrorExtracting, entry.Name, X.Message);
if (!m_main.Dispatcher.Invoke (() => ShowErrorDialog (error_text)))
var result = m_main.Dispatcher.Invoke (() => m_main.ShowErrorDialog (guiStrings.TextExtractionError, error_text, m_progress_dialog.GetWindowHandle()));
if (!result.Continue)
break;
m_ignore_errors = result.IgnoreErrors;
}
++m_skip_count;
}
@ -411,31 +413,6 @@ namespace GARbro.GUI
throw new IOException ("File aready exists");
}
bool ShowErrorDialog (string error_text)
{
var dialog = new FileErrorDialog (guiStrings.TextExtractionError, error_text);
var progress_dialog_hwnd = m_progress_dialog.GetWindowHandle();
if (progress_dialog_hwnd != IntPtr.Zero)
{
var native_dialog = new WindowInteropHelper (dialog);
native_dialog.Owner = progress_dialog_hwnd;
NativeMethods.EnableWindow (progress_dialog_hwnd, false);
EventHandler on_closed = null;
on_closed = (s, e) => {
NativeMethods.EnableWindow (progress_dialog_hwnd, true);
dialog.Closed -= on_closed;
};
dialog.Closed += on_closed;
}
else
{
dialog.Owner = m_main;
}
bool dialog_result = dialog.ShowDialog() ?? false;
m_ignore_errors = dialog.IgnoreErrors.IsChecked ?? false;
return dialog_result;
}
void OnExtractComplete (object sender, RunWorkerCompletedEventArgs e)
{
m_extract_in_progress = false;

View File

@ -1,6 +1,6 @@
// Game Resource Browser
//
// Copyright (C) 2014-2015 by morkt
// Copyright (C) 2014-2017 by morkt
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
@ -35,6 +35,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Threading;
using Microsoft.VisualBasic.FileIO;
using GARbro.GUI.Properties;
@ -195,6 +196,40 @@ namespace GARbro.GUI
Dispatcher.Invoke (() => MessageBox.Show (this, message, title, MessageBoxButton.OK, MessageBoxImage.Error));
}
internal FileErrorDialogResult ShowErrorDialog (string error_title, string error_text, IntPtr parent_hwnd)
{
var dialog = new FileErrorDialog (error_title, error_text);
SetModalWindowParent (dialog, parent_hwnd);
return dialog.ShowDialog();
}
internal FileExistsDialogResult ShowFileExistsDialog (string title, string text, IntPtr parent_hwnd)
{
var dialog = new FileExistsDialog (title, text);
SetModalWindowParent (dialog, parent_hwnd);
return dialog.ShowDialog();
}
private void SetModalWindowParent (Window dialog, IntPtr parent_hwnd)
{
if (parent_hwnd != IntPtr.Zero)
{
var native_dialog = new WindowInteropHelper (dialog);
native_dialog.Owner = parent_hwnd;
NativeMethods.EnableWindow (parent_hwnd, false);
EventHandler on_closed = null;
on_closed = (s, e) => {
NativeMethods.EnableWindow (parent_hwnd, true);
dialog.Closed -= on_closed;
};
dialog.Closed += on_closed;
}
else
{
dialog.Owner = this;
}
}
const int MaxRecentFiles = 9;
LinkedList<string> m_recent_files;

View File

@ -114,6 +114,33 @@ namespace GARbro.GUI.Strings {
}
}
/// <summary>
/// Looks up a localized string similar to _Overwrite.
/// </summary>
public static string ButtonOverwrite {
get {
return ResourceManager.GetString("ButtonOverwrite", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to _Rename.
/// </summary>
public static string ButtonRename {
get {
return ResourceManager.GetString("ButtonRename", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to _Skip.
/// </summary>
public static string ButtonSkip {
get {
return ResourceManager.GetString("ButtonSkip", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to _Close.
/// </summary>
@ -312,6 +339,15 @@ namespace GARbro.GUI.Strings {
}
}
/// <summary>
/// Looks up a localized string similar to A_pply to all duplicate files.
/// </summary>
public static string LabelApplyToAll {
get {
return ResourceManager.GetString("LabelApplyToAll", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Archive format.
/// </summary>
@ -366,6 +402,15 @@ namespace GARbro.GUI.Strings {
}
}
/// <summary>
/// Looks up a localized string similar to What should be done?.
/// </summary>
public static string LabelDuplicateFileQuestion {
get {
return ResourceManager.GetString("LabelDuplicateFileQuestion", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Encoding.
/// </summary>
@ -963,6 +1008,17 @@ namespace GARbro.GUI.Strings {
}
}
/// <summary>
/// Looks up a localized string similar to Error occured while converting file
///{0}
///{1}.
/// </summary>
public static string TextErrorConverting {
get {
return ResourceManager.GetString("TextErrorConverting", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Error occured while extracting file
///{0}

View File

@ -474,4 +474,30 @@
<value>File extraction error</value>
<comment>translation pending</comment>
</data>
<data name="ButtonOverwrite" xml:space="preserve">
<value>Overwrite</value>
<comment>translation pending</comment>
</data>
<data name="ButtonRename" xml:space="preserve">
<value>Rename</value>
<comment>translation pending</comment>
</data>
<data name="ButtonSkip" xml:space="preserve">
<value>Skip</value>
<comment>translation pending</comment>
</data>
<data name="LabelApplyToAll" xml:space="preserve">
<value>Apply to all duplicate files</value>
<comment>translation pending</comment>
</data>
<data name="LabelDuplicateFileQuestion" xml:space="preserve">
<value>What should be done?</value>
<comment>translation pending</comment>
</data>
<data name="TextErrorConverting" xml:space="preserve">
<value>Error occured while converting file
{0}
{1}</value>
<comment>translation pending</comment>
</data>
</root>

View File

@ -474,4 +474,24 @@ Overwrite?</value>
<data name="TextExtractionError" xml:space="preserve">
<value>File extraction error</value>
</data>
<data name="ButtonOverwrite" xml:space="preserve">
<value>_Overwrite</value>
</data>
<data name="ButtonRename" xml:space="preserve">
<value>_Rename</value>
</data>
<data name="ButtonSkip" xml:space="preserve">
<value>_Skip</value>
</data>
<data name="LabelApplyToAll" xml:space="preserve">
<value>A_pply to all duplicate files</value>
</data>
<data name="LabelDuplicateFileQuestion" xml:space="preserve">
<value>What should be done?</value>
</data>
<data name="TextErrorConverting" xml:space="preserve">
<value>Error occured while converting file
{0}
{1}</value>
</data>
</root>

View File

@ -495,4 +495,24 @@
<data name="TextExtractionError" xml:space="preserve">
<value>Ошибка извлечения файла</value>
</data>
<data name="ButtonOverwrite" xml:space="preserve">
<value>Заменить</value>
</data>
<data name="ButtonRename" xml:space="preserve">
<value>Переименовать</value>
</data>
<data name="ButtonSkip" xml:space="preserve">
<value>Пропустить</value>
</data>
<data name="LabelApplyToAll" xml:space="preserve">
<value>Применить ко всем совпадающим файлам</value>
</data>
<data name="LabelDuplicateFileQuestion" xml:space="preserve">
<value>Что делать?</value>
</data>
<data name="TextErrorConverting" xml:space="preserve">
<value>Не удадось конвертировать файл
{0}
{1}</value>
</data>
</root>

View File

@ -476,4 +476,30 @@
<value>File extraction error</value>
<comment>translation pending</comment>
</data>
<data name="ButtonOverwrite" xml:space="preserve">
<value>Overwrite</value>
<comment>translation pending</comment>
</data>
<data name="ButtonRename" xml:space="preserve">
<value>Rename</value>
<comment>translation pending</comment>
</data>
<data name="ButtonSkip" xml:space="preserve">
<value>Skip</value>
<comment>translation pending</comment>
</data>
<data name="LabelApplyToAll" xml:space="preserve">
<value>Apply to all duplicate files</value>
<comment>translation pending</comment>
</data>
<data name="LabelDuplicateFileQuestion" xml:space="preserve">
<value>What should be done?</value>
<comment>translation pending</comment>
</data>
<data name="TextErrorConverting" xml:space="preserve">
<value>Error occured while converting file
{0}
{1}</value>
<comment>translation pending</comment>
</data>
</root>