mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
(GUI): copy images when no conversion required.
This commit is contained in:
@@ -228,24 +228,39 @@ namespace GARbro.GUI
|
|||||||
var src_format = ImageFormat.FindFormat (file);
|
var src_format = ImageFormat.FindFormat (file);
|
||||||
if (null == src_format)
|
if (null == src_format)
|
||||||
return;
|
return;
|
||||||
if (src_format.Item1 == m_image_format && m_image_format.Extensions.Any (ext => ext == source_ext))
|
Stream output = null;
|
||||||
return;
|
|
||||||
file.Position = 0;
|
|
||||||
var image = src_format.Item1.Read (file, src_format.Item2);
|
|
||||||
var output = CreateNewFile (target_name);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_image_format.Write (output, image);
|
if (src_format.Item1 == m_image_format && m_image_format.Extensions.Any (ext => ext == source_ext))
|
||||||
|
{
|
||||||
|
if (AreSamePaths (filename, target_name))
|
||||||
|
return;
|
||||||
|
output = CreateNewFile (target_name);
|
||||||
|
file.Position = 0;
|
||||||
|
file.AsStream.CopyTo (output);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file.Position = 0;
|
||||||
|
var image = src_format.Item1.Read (file, src_format.Item2);
|
||||||
|
output = CreateNewFile (target_name);
|
||||||
|
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,
|
// FIXME if user chooses to overwrite file, and conversion results in error,
|
||||||
// then original file will be lost.
|
// then original file will be lost.
|
||||||
output.Dispose();
|
output.Dispose();
|
||||||
|
output = null;
|
||||||
File.Delete (target_name);
|
File.Delete (target_name);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
output.Dispose();
|
finally
|
||||||
|
{
|
||||||
|
if (output != null)
|
||||||
|
output.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,5 +279,12 @@ namespace GARbro.GUI
|
|||||||
m_main.ListViewFocus();
|
m_main.ListViewFocus();
|
||||||
m_main.RefreshView();
|
m_main.RefreshView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static internal bool AreSamePaths (string filename1, string filename2)
|
||||||
|
{
|
||||||
|
filename1 = Path.GetFullPath (filename1);
|
||||||
|
filename2 = Path.GetFullPath (filename2);
|
||||||
|
return string.Equals (filename1, filename2, StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user