mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-05 23:01:06 +08:00
implemented duplicate file actions dialog.
This commit is contained in:
@@ -6,13 +6,17 @@
|
|||||||
Title="{Binding Title}" ShowInTaskbar="False" WindowStartupLocation="CenterOwner"
|
Title="{Binding Title}" ShowInTaskbar="False" WindowStartupLocation="CenterOwner"
|
||||||
ResizeMode="NoResize" SizeToContent="WidthAndHeight" ShowActivated="True"
|
ResizeMode="NoResize" SizeToContent="WidthAndHeight" ShowActivated="True"
|
||||||
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
|
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
|
||||||
<StackPanel Orientation="Vertical">
|
<StackPanel Orientation="Horizontal">
|
||||||
<TextBox x:Name="ErrorText" Text="{Binding Text}" IsReadOnly="True" Background="Transparent" BorderThickness="0" Margin="10"/>
|
<Image Source="Images/64x64/alert.png" Width="64" Height="64" Margin="10"
|
||||||
<Separator/>
|
SnapsToDevicePixels="True" VerticalAlignment="Top" RenderOptions.BitmapScalingMode="HighQuality"/>
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
|
<StackPanel Orientation="Vertical">
|
||||||
<CheckBox x:Name="IgnoreErrors" Content="{x:Static s:guiStrings.LabelIgnoreErrors}" Margin="10" VerticalAlignment="Center"/>
|
<TextBox x:Name="ErrorText" Text="{Binding Text}" IsReadOnly="True" Background="Transparent" BorderThickness="0" Margin="0,10,10,10"/>
|
||||||
<Button Content="{x:Static s:guiStrings.ButtonContinue}" Margin="10" Width="75" Height="25" IsDefault="True" Click="ContinueButton_Click"/>
|
<Separator/>
|
||||||
<Button Content="{x:Static s:guiStrings.ButtonAbort}" Margin="10" Width="75" Height="25" IsCancel="True" Click="AbortButton_Click"/>
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
|
||||||
|
<CheckBox x:Name="IgnoreErrors" Content="{x:Static s:guiStrings.LabelIgnoreErrors}" Margin="0,10,10,10" VerticalAlignment="Center"/>
|
||||||
|
<Button Content="{x:Static s:guiStrings.ButtonContinue}" Margin="10" MinWidth="75" Height="25" IsDefault="True" Click="ContinueButton_Click"/>
|
||||||
|
<Button Content="{x:Static s:guiStrings.ButtonAbort}" Margin="10" MinWidth="75" Height="25" IsCancel="True" Click="AbortButton_Click"/>
|
||||||
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Window.InputBindings>
|
<Window.InputBindings>
|
||||||
|
|||||||
@@ -6,16 +6,20 @@
|
|||||||
Title="File already exists" ShowInTaskbar="False" WindowStartupLocation="CenterOwner"
|
Title="File already exists" ShowInTaskbar="False" WindowStartupLocation="CenterOwner"
|
||||||
ResizeMode="NoResize" SizeToContent="WidthAndHeight" ShowActivated="True"
|
ResizeMode="NoResize" SizeToContent="WidthAndHeight" ShowActivated="True"
|
||||||
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
|
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
|
||||||
<StackPanel Orientation="Vertical">
|
<StackPanel Orientation="Horizontal">
|
||||||
<TextBlock x:Name="Notice" Text="File named {0} already exists in destination folder." Margin="10"/>
|
<Image Source="Images/64x64/actions.png" Width="64" Height="64" Margin="10"
|
||||||
<TextBlock Text="{x:Static s:guiStrings.LabelDuplicateFileQuestion}" Margin="10"/>
|
SnapsToDevicePixels="True" VerticalAlignment="Top" RenderOptions.BitmapScalingMode="HighQuality"/>
|
||||||
<Separator/>
|
<StackPanel Orientation="Vertical">
|
||||||
<CheckBox x:Name="ApplyToAll" Content="{x:Static s:guiStrings.LabelApplyToAll}" Margin="10"/>
|
<TextBlock x:Name="Notice" Text="File named {0} already exists in destination folder." Margin="0,10,10,10"/>
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
|
<TextBlock Text="{x:Static s:guiStrings.LabelDuplicateFileQuestion}" Margin="0,0,10,10"/>
|
||||||
<Button Content="{x:Static s:guiStrings.ButtonSkip}" Margin="10" Width="75" Height="25" IsDefault="True" Click="SkipButton_Click"/>
|
<Separator/>
|
||||||
<Button Content="{x:Static s:guiStrings.ButtonOverwrite}" Margin="10" Width="75" Height="25" Click="OverwriteButton_Click"/>
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
|
||||||
<Button Content="{x:Static s:guiStrings.ButtonRename}" Margin="10" Width="75" Height="25" Click="RenameButton_Click"/>
|
<Button Content="{x:Static s:guiStrings.ButtonSkip}" Margin="0,10,10,10" MinWidth="75" Height="25" IsDefault="True" Click="SkipButton_Click"/>
|
||||||
<Button Content="{x:Static s:guiStrings.ButtonAbort}" Margin="10" Width="75" Height="25" IsCancel="True" Click="AbortButton_Click"/>
|
<Button Content="{x:Static s:guiStrings.ButtonOverwrite}" Margin="10" MinWidth="75" Height="25" Click="OverwriteButton_Click"/>
|
||||||
|
<Button Content="{x:Static s:guiStrings.ButtonRename}" Margin="10" MinWidth="75" Height="25" Click="RenameButton_Click"/>
|
||||||
|
<Button Content="{x:Static s:guiStrings.ButtonAbort}" Margin="10" MinWidth="75" Height="25" IsCancel="True" Click="AbortButton_Click"/>
|
||||||
|
</StackPanel>
|
||||||
|
<CheckBox x:Name="ApplyToAll" Content="{x:Static s:guiStrings.LabelApplyToAll}" Margin="0,10,10,10"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</w:ModalWindow>
|
</w:ModalWindow>
|
||||||
|
|||||||
@@ -153,6 +153,7 @@
|
|||||||
<Compile Include="GarConvert.cs" />
|
<Compile Include="GarConvert.cs" />
|
||||||
<Compile Include="GarCreate.cs" />
|
<Compile Include="GarCreate.cs" />
|
||||||
<Compile Include="GarExtract.cs" />
|
<Compile Include="GarExtract.cs" />
|
||||||
|
<Compile Include="GarOperation.cs" />
|
||||||
<Compile Include="HistoryStack.cs" />
|
<Compile Include="HistoryStack.cs" />
|
||||||
<Compile Include="ImagePreview.cs" />
|
<Compile Include="ImagePreview.cs" />
|
||||||
<Compile Include="ListViewEx.cs" />
|
<Compile Include="ListViewEx.cs" />
|
||||||
@@ -299,6 +300,12 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Resource Include="Images\Cursors\grabbing.cur" />
|
<Resource Include="Images\Cursors\grabbing.cur" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Resource Include="Images\64x64\actions.png" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Resource Include="Images\64x64\alert.png" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PreBuildEvent>perl "$(SolutionDir)inc-revision.pl" "$(ProjectPath)" $(ConfigurationName) "$(SolutionDir)\"
|
<PreBuildEvent>perl "$(SolutionDir)inc-revision.pl" "$(ProjectPath)" $(ConfigurationName) "$(SolutionDir)\"
|
||||||
|
|||||||
@@ -106,21 +106,17 @@ namespace GARbro.GUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class GarConvertMedia
|
internal class GarConvertMedia : GarOperation
|
||||||
{
|
{
|
||||||
private MainWindow m_main;
|
|
||||||
private ProgressDialog m_progress_dialog;
|
|
||||||
private IEnumerable<Entry> m_source;
|
private IEnumerable<Entry> m_source;
|
||||||
private ImageFormat m_image_format;
|
private ImageFormat m_image_format;
|
||||||
private Exception m_pending_error;
|
|
||||||
private List<Tuple<string,string>> m_failed = new List<Tuple<string,string>>();
|
private List<Tuple<string,string>> m_failed = new List<Tuple<string,string>>();
|
||||||
|
|
||||||
public bool IgnoreErrors { get; set; }
|
public bool IgnoreErrors { get; set; }
|
||||||
public IEnumerable<Tuple<string,string>> FailedFiles { get { return m_failed; } }
|
public IEnumerable<Tuple<string,string>> FailedFiles { get { return m_failed; } }
|
||||||
|
|
||||||
public GarConvertMedia (MainWindow parent)
|
public GarConvertMedia (MainWindow parent) : base (parent, guiStrings.TextMediaConvertError)
|
||||||
{
|
{
|
||||||
m_main = parent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Convert (IEnumerable<Entry> images, ImageFormat format)
|
public void Convert (IEnumerable<Entry> images, ImageFormat format)
|
||||||
@@ -163,12 +159,21 @@ namespace GARbro.GUI
|
|||||||
else if ("audio" == entry.Type)
|
else if ("audio" == entry.Type)
|
||||||
ConvertAudio (filename);
|
ConvertAudio (filename);
|
||||||
}
|
}
|
||||||
|
catch (SkipExistingFileException)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException X)
|
||||||
|
{
|
||||||
|
m_pending_error = X;
|
||||||
|
break;
|
||||||
|
}
|
||||||
catch (Exception X)
|
catch (Exception X)
|
||||||
{
|
{
|
||||||
if (!IgnoreErrors)
|
if (!IgnoreErrors)
|
||||||
{
|
{
|
||||||
var error_text = string.Format (guiStrings.TextErrorConverting, entry.Name, X.Message);
|
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()));
|
var result = ShowErrorDialog (error_text);
|
||||||
if (!result.Continue)
|
if (!result.Continue)
|
||||||
break;
|
break;
|
||||||
IgnoreErrors = result.IgnoreErrors;
|
IgnoreErrors = result.IgnoreErrors;
|
||||||
@@ -227,41 +232,20 @@ namespace GARbro.GUI
|
|||||||
return;
|
return;
|
||||||
file.Position = 0;
|
file.Position = 0;
|
||||||
var image = src_format.Item1.Read (file, src_format.Item2);
|
var image = src_format.Item1.Read (file, src_format.Item2);
|
||||||
|
var output = CreateNewFile (target_name);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var output = CreateNewFile (target_name))
|
m_image_format.Write (output, image);
|
||||||
m_image_format.Write (output, image);
|
|
||||||
}
|
}
|
||||||
catch // delete destination file on conversion failure
|
catch // delete destination file on conversion failure
|
||||||
{
|
{
|
||||||
|
// FIXME if user chooses to overwrite file, and conversion results in error,
|
||||||
|
// then original file will be lost.
|
||||||
|
output.Dispose();
|
||||||
File.Delete (target_name);
|
File.Delete (target_name);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
output.Dispose();
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates new file with specified filename, or, if it's already exists, tries to open
|
|
||||||
/// files named "FILENAME.1.EXT", "FILENAME.2.EXT" and so on.
|
|
||||||
/// <exception cref="System.IOException">Throws exception after 100th failed attempt.</exception>
|
|
||||||
/// </summary>
|
|
||||||
|
|
||||||
public static Stream CreateNewFile (string filename)
|
|
||||||
{
|
|
||||||
string name = filename;
|
|
||||||
var ext = new Lazy<string> (() => Path.GetExtension (filename));
|
|
||||||
for (int attempt = 1; ; ++attempt)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return File.Open (name, FileMode.CreateNew);
|
|
||||||
}
|
|
||||||
catch (IOException) // file already exists
|
|
||||||
{
|
|
||||||
if (100 == attempt) // limit number of attempts
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
name = Path.ChangeExtension (filename, attempt.ToString()+ext.Value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,21 +56,17 @@ namespace GARbro.GUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class GarCreate
|
internal class GarCreate : GarOperation
|
||||||
{
|
{
|
||||||
private MainWindow m_main;
|
|
||||||
private string m_arc_name;
|
private string m_arc_name;
|
||||||
private IList<Entry> m_file_list;
|
private IList<Entry> m_file_list;
|
||||||
private ProgressDialog m_progress_dialog;
|
|
||||||
private ArchiveFormat m_format;
|
private ArchiveFormat m_format;
|
||||||
private ResourceOptions m_options;
|
private ResourceOptions m_options;
|
||||||
private Exception m_pending_error;
|
|
||||||
|
|
||||||
delegate void AddFilesEnumerator (IList<Entry> list, string path, DirectoryInfo path_info);
|
delegate void AddFilesEnumerator (IList<Entry> list, string path, DirectoryInfo path_info);
|
||||||
|
|
||||||
public GarCreate (MainWindow parent)
|
public GarCreate (MainWindow parent) : base (parent, guiStrings.TextCreateArchiveError)
|
||||||
{
|
{
|
||||||
m_main = parent;
|
|
||||||
m_arc_name = Settings.Default.appLastCreatedArchive;
|
m_arc_name = Settings.Default.appLastCreatedArchive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -102,9 +102,8 @@ namespace GARbro.GUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed internal class GarExtract : IDisposable
|
sealed internal class GarExtract : GarOperation, IDisposable
|
||||||
{
|
{
|
||||||
private MainWindow m_main;
|
|
||||||
private string m_arc_name;
|
private string m_arc_name;
|
||||||
private ArchiveFileSystem m_fs;
|
private ArchiveFileSystem m_fs;
|
||||||
private readonly bool m_should_ascend;
|
private readonly bool m_should_ascend;
|
||||||
@@ -113,16 +112,14 @@ namespace GARbro.GUI
|
|||||||
private bool m_skip_audio = false;
|
private bool m_skip_audio = false;
|
||||||
private bool m_adjust_image_offset = false;
|
private bool m_adjust_image_offset = false;
|
||||||
private bool m_convert_audio;
|
private bool m_convert_audio;
|
||||||
private bool m_ignore_errors;
|
|
||||||
private ImageFormat m_image_format;
|
private ImageFormat m_image_format;
|
||||||
private int m_extract_count;
|
private int m_extract_count;
|
||||||
private int m_skip_count;
|
private int m_skip_count;
|
||||||
private bool m_extract_in_progress = false;
|
private bool m_extract_in_progress = false;
|
||||||
private ProgressDialog m_progress_dialog;
|
|
||||||
|
|
||||||
public bool IsActive { get { return m_extract_in_progress; } }
|
public bool IsActive { get { return m_extract_in_progress; } }
|
||||||
|
|
||||||
public GarExtract (MainWindow parent, string source)
|
public GarExtract (MainWindow parent, string source) : base (parent, guiStrings.TextExtractionError)
|
||||||
{
|
{
|
||||||
m_arc_name = Path.GetFileName (source);
|
m_arc_name = Path.GetFileName (source);
|
||||||
try
|
try
|
||||||
@@ -135,15 +132,13 @@ namespace GARbro.GUI
|
|||||||
throw new OperationCanceledException (string.Format ("{1}: {0}", X.Message, m_arc_name));
|
throw new OperationCanceledException (string.Format ("{1}: {0}", X.Message, m_arc_name));
|
||||||
}
|
}
|
||||||
m_fs = VFS.Top as ArchiveFileSystem;
|
m_fs = VFS.Top as ArchiveFileSystem;
|
||||||
m_main = parent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GarExtract (MainWindow parent, string source, ArchiveFileSystem fs)
|
public GarExtract (MainWindow parent, string source, ArchiveFileSystem fs) : base (parent, guiStrings.TextExtractionError)
|
||||||
{
|
{
|
||||||
if (null == fs)
|
if (null == fs)
|
||||||
throw new UnknownFormatException();
|
throw new UnknownFormatException();
|
||||||
m_fs = fs;
|
m_fs = fs;
|
||||||
m_main = parent;
|
|
||||||
m_arc_name = Path.GetFileName (source);
|
m_arc_name = Path.GetFileName (source);
|
||||||
m_should_ascend = false;
|
m_should_ascend = false;
|
||||||
}
|
}
|
||||||
@@ -282,7 +277,7 @@ namespace GARbro.GUI
|
|||||||
var arc = m_fs.Source;
|
var arc = m_fs.Source;
|
||||||
int total = file_list.Count();
|
int total = file_list.Count();
|
||||||
int progress_count = 0;
|
int progress_count = 0;
|
||||||
m_ignore_errors = false;
|
bool ignore_errors = false;
|
||||||
foreach (var entry in file_list)
|
foreach (var entry in file_list)
|
||||||
{
|
{
|
||||||
if (m_progress_dialog.CancellationPending)
|
if (m_progress_dialog.CancellationPending)
|
||||||
@@ -299,15 +294,24 @@ namespace GARbro.GUI
|
|||||||
arc.Extract (entry);
|
arc.Extract (entry);
|
||||||
++m_extract_count;
|
++m_extract_count;
|
||||||
}
|
}
|
||||||
|
catch (SkipExistingFileException)
|
||||||
|
{
|
||||||
|
++m_skip_count;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
catch (Exception X)
|
catch (Exception X)
|
||||||
{
|
{
|
||||||
if (!m_ignore_errors)
|
if (!ignore_errors)
|
||||||
{
|
{
|
||||||
var error_text = string.Format (guiStrings.TextErrorExtracting, entry.Name, X.Message);
|
var error_text = string.Format (guiStrings.TextErrorExtracting, entry.Name, X.Message);
|
||||||
var result = m_main.Dispatcher.Invoke (() => m_main.ShowErrorDialog (guiStrings.TextExtractionError, error_text, m_progress_dialog.GetWindowHandle()));
|
var result = ShowErrorDialog (error_text);
|
||||||
if (!result.Continue)
|
if (!result.Continue)
|
||||||
break;
|
break;
|
||||||
m_ignore_errors = result.IgnoreErrors;
|
ignore_errors = result.IgnoreErrors;
|
||||||
}
|
}
|
||||||
++m_skip_count;
|
++m_skip_count;
|
||||||
}
|
}
|
||||||
@@ -320,11 +324,12 @@ namespace GARbro.GUI
|
|||||||
{
|
{
|
||||||
var src_format = decoder.SourceFormat; // could be null
|
var src_format = decoder.SourceFormat; // could be null
|
||||||
string target_ext = target_format.Extensions.FirstOrDefault() ?? "";
|
string target_ext = target_format.Extensions.FirstOrDefault() ?? "";
|
||||||
string outname = FindUniqueFileName (entry.Name, target_ext);
|
string outname = Path.ChangeExtension (entry.Name, target_ext);
|
||||||
|
outname = ArchiveFormat.CreatePath (outname);
|
||||||
if (src_format == target_format)
|
if (src_format == target_format)
|
||||||
{
|
{
|
||||||
// source format is the same as a target, copy file as is
|
// source format is the same as a target, copy file as is
|
||||||
using (var output = ArchiveFormat.CreateFile (outname))
|
using (var output = CreateNewFile (outname))
|
||||||
decoder.Source.CopyTo (output);
|
decoder.Source.CopyTo (output);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -333,7 +338,7 @@ namespace GARbro.GUI
|
|||||||
{
|
{
|
||||||
image = AdjustImageOffset (image);
|
image = AdjustImageOffset (image);
|
||||||
}
|
}
|
||||||
using (var outfile = ArchiveFormat.CreateFile (outname))
|
using (var outfile = CreateNewFile (outname))
|
||||||
{
|
{
|
||||||
target_format.Write (outfile, image);
|
target_format.Write (outfile, image);
|
||||||
}
|
}
|
||||||
@@ -369,7 +374,7 @@ namespace GARbro.GUI
|
|||||||
return new ImageData (bitmap);
|
return new ImageData (bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ExtractAudio (ArcFile arc, Entry entry)
|
void ExtractAudio (ArcFile arc, Entry entry)
|
||||||
{
|
{
|
||||||
using (var file = arc.OpenBinaryEntry (entry))
|
using (var file = arc.OpenBinaryEntry (entry))
|
||||||
using (var sound = AudioFormat.Read (file))
|
using (var sound = AudioFormat.Read (file))
|
||||||
@@ -380,13 +385,14 @@ namespace GARbro.GUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ConvertAudio (string entry_name, SoundInput input)
|
public void ConvertAudio (string filename, SoundInput input)
|
||||||
{
|
{
|
||||||
|
filename = ArchiveFormat.CreatePath (filename);
|
||||||
string source_format = input.SourceFormat;
|
string source_format = input.SourceFormat;
|
||||||
if (GarConvertMedia.CommonAudioFormats.Contains (source_format))
|
if (GarConvertMedia.CommonAudioFormats.Contains (source_format))
|
||||||
{
|
{
|
||||||
string output_name = FindUniqueFileName (entry_name, source_format);
|
var output_name = Path.ChangeExtension (filename, source_format);
|
||||||
using (var output = ArchiveFormat.CreateFile (output_name))
|
using (var output = CreateNewFile (output_name))
|
||||||
{
|
{
|
||||||
input.Source.Position = 0;
|
input.Source.Position = 0;
|
||||||
input.Source.CopyTo (output);
|
input.Source.CopyTo (output);
|
||||||
@@ -394,25 +400,12 @@ namespace GARbro.GUI
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string output_name = FindUniqueFileName (entry_name, "wav");
|
var output_name = Path.ChangeExtension (filename, "wav");
|
||||||
using (var output = ArchiveFormat.CreateFile (output_name))
|
using (var output = CreateNewFile (output_name))
|
||||||
AudioFormat.Wav.Write (input, output);
|
AudioFormat.Wav.Write (input, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string FindUniqueFileName (string source_filename, string target_ext)
|
|
||||||
{
|
|
||||||
string ext = target_ext;
|
|
||||||
for (int attempt = 1; attempt < 100; ++attempt)
|
|
||||||
{
|
|
||||||
string filename = Path.ChangeExtension (source_filename, ext);
|
|
||||||
if (!File.Exists (filename))
|
|
||||||
return filename;
|
|
||||||
ext = string.Format ("{0}.{1}", attempt, target_ext);
|
|
||||||
}
|
|
||||||
throw new IOException ("File aready exists");
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnExtractComplete (object sender, RunWorkerCompletedEventArgs e)
|
void OnExtractComplete (object sender, RunWorkerCompletedEventArgs e)
|
||||||
{
|
{
|
||||||
m_extract_in_progress = false;
|
m_extract_in_progress = false;
|
||||||
|
|||||||
115
GUI/GarOperation.cs
Normal file
115
GUI/GarOperation.cs
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
//! \file GarOperation.cs
|
||||||
|
//! \date Fri Feb 03 19:06:52 2017
|
||||||
|
//! \brief Base class for GARbro file operation.
|
||||||
|
//
|
||||||
|
// Copyright (C) 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
|
||||||
|
// deal in the Software without restriction, including without limitation the
|
||||||
|
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
// sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
// IN THE SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using GARbro.GUI.Strings;
|
||||||
|
|
||||||
|
namespace GARbro.GUI
|
||||||
|
{
|
||||||
|
internal class GarOperation
|
||||||
|
{
|
||||||
|
internal MainWindow m_main;
|
||||||
|
internal ProgressDialog m_progress_dialog;
|
||||||
|
internal Exception m_pending_error;
|
||||||
|
internal FileExistsDialogResult m_duplicate_action;
|
||||||
|
internal string m_title;
|
||||||
|
|
||||||
|
const int MaxRenameAttempts = 100;
|
||||||
|
|
||||||
|
protected GarOperation (MainWindow parent, string dialog_title)
|
||||||
|
{
|
||||||
|
m_main = parent;
|
||||||
|
m_title = dialog_title;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Stream CreateNewFile (string filename)
|
||||||
|
{
|
||||||
|
FileMode open_mode = FileMode.CreateNew;
|
||||||
|
if (m_duplicate_action.ApplyToAll &&
|
||||||
|
m_duplicate_action.Action == ExistingFileAction.Overwrite)
|
||||||
|
open_mode = FileMode.Create;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return File.Open (filename, open_mode);
|
||||||
|
}
|
||||||
|
catch (IOException) // file already exists?
|
||||||
|
{
|
||||||
|
if (!File.Exists (filename) || FileMode.Create == open_mode) // some unforseen I/O error, give up
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
if (!m_duplicate_action.ApplyToAll)
|
||||||
|
{
|
||||||
|
var msg_text = string.Format (guiStrings.TextFileAlreadyExists, Path.GetFileName (filename));
|
||||||
|
m_duplicate_action = m_main.Dispatcher.Invoke (() => m_main.ShowFileExistsDialog (m_title, msg_text, m_progress_dialog.GetWindowHandle()));
|
||||||
|
}
|
||||||
|
switch (m_duplicate_action.Action)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case ExistingFileAction.Abort:
|
||||||
|
throw new OperationCanceledException();
|
||||||
|
case ExistingFileAction.Skip:
|
||||||
|
throw new SkipExistingFileException();
|
||||||
|
case ExistingFileAction.Rename:
|
||||||
|
return CreateRenamedFile (filename);
|
||||||
|
case ExistingFileAction.Overwrite:
|
||||||
|
return File.Open (filename, FileMode.Create);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates new file with specified filename, or, if it's already exists, tries to open
|
||||||
|
/// files named "FILENAME.1.EXT", "FILENAME.2.EXT" and so on.
|
||||||
|
/// <exception cref="System.IOException">Throws exception after 100th failed attempt.</exception>
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
public static Stream CreateRenamedFile (string filename)
|
||||||
|
{
|
||||||
|
var ext = Path.GetExtension (filename);
|
||||||
|
for (int attempt = 1; ; ++attempt)
|
||||||
|
{
|
||||||
|
var name = Path.ChangeExtension (filename, attempt.ToString()+ext);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return File.Open (name, FileMode.CreateNew);
|
||||||
|
}
|
||||||
|
catch (IOException) // file already exists
|
||||||
|
{
|
||||||
|
if (MaxRenameAttempts == attempt) // limit number of attempts
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected FileErrorDialogResult ShowErrorDialog (string error_text)
|
||||||
|
{
|
||||||
|
return m_main.Dispatcher.Invoke (() => m_main.ShowErrorDialog (m_title, error_text, m_progress_dialog.GetWindowHandle()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class SkipExistingFileException : ApplicationException
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
GUI/Images/64x64/actions.png
Normal file
BIN
GUI/Images/64x64/actions.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
BIN
GUI/Images/64x64/alert.png
Normal file
BIN
GUI/Images/64x64/alert.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
9
GUI/Strings/guiStrings.Designer.cs
generated
9
GUI/Strings/guiStrings.Designer.cs
generated
@@ -1075,6 +1075,15 @@ namespace GARbro.GUI.Strings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to File {0} already exists in the destination folder..
|
||||||
|
/// </summary>
|
||||||
|
public static string TextFileAlreadyExists {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("TextFileAlreadyExists", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Multimedia conversion error.
|
/// Looks up a localized string similar to Multimedia conversion error.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -496,4 +496,8 @@
|
|||||||
{1}</value>
|
{1}</value>
|
||||||
<comment>translation pending</comment>
|
<comment>translation pending</comment>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TextFileAlreadyExists" xml:space="preserve">
|
||||||
|
<value>File {0} already exists in the destination folder.</value>
|
||||||
|
<comment>translation pending</comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -494,4 +494,7 @@ Overwrite?</value>
|
|||||||
{0}
|
{0}
|
||||||
{1}</value>
|
{1}</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TextFileAlreadyExists" xml:space="preserve">
|
||||||
|
<value>File {0} already exists in the destination folder.</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -515,4 +515,7 @@
|
|||||||
{0}
|
{0}
|
||||||
{1}</value>
|
{1}</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TextFileAlreadyExists" xml:space="preserve">
|
||||||
|
<value>Файл с именем {0} уже существует.</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -502,4 +502,7 @@
|
|||||||
{1}</value>
|
{1}</value>
|
||||||
<comment>translation pending</comment>
|
<comment>translation pending</comment>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TextFileAlreadyExists" xml:space="preserve">
|
||||||
|
<value>文件{0}已经存在。</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
Reference in New Issue
Block a user