mirror of
https://github.com/crskycode/GARbro.git
synced 2026-06-06 05:38:48 +08:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -228,24 +228,39 @@ namespace GARbro.GUI
|
||||
var src_format = ImageFormat.FindFormat (file);
|
||||
if (null == src_format)
|
||||
return;
|
||||
if (src_format.Item1 == m_image_format && m_image_format.Extensions.Any (ext => ext == source_ext))
|
||||
return;
|
||||
file.Position = 0;
|
||||
var image = src_format.Item1.Read (file, src_format.Item2);
|
||||
var output = CreateNewFile (target_name);
|
||||
Stream output = null;
|
||||
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
|
||||
{
|
||||
// FIXME if user chooses to overwrite file, and conversion results in error,
|
||||
// then original file will be lost.
|
||||
output.Dispose();
|
||||
output = null;
|
||||
File.Delete (target_name);
|
||||
throw;
|
||||
}
|
||||
output.Dispose();
|
||||
finally
|
||||
{
|
||||
if (output != null)
|
||||
output.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,5 +279,12 @@ namespace GARbro.GUI
|
||||
m_main.ListViewFocus();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ namespace GARbro.GUI
|
||||
{
|
||||
using (var data = VFS.OpenImage (preview.Entry))
|
||||
{
|
||||
SetPreviewImage (preview, data.Image.Bitmap);
|
||||
SetPreviewImage (preview, data.Image.Bitmap, data.SourceFormat);
|
||||
}
|
||||
}
|
||||
catch (Exception X)
|
||||
@@ -250,7 +250,7 @@ namespace GARbro.GUI
|
||||
}
|
||||
}
|
||||
|
||||
void SetPreviewImage (PreviewFile preview, BitmapSource bitmap)
|
||||
void SetPreviewImage (PreviewFile preview, BitmapSource bitmap, ImageFormat format)
|
||||
{
|
||||
if (bitmap.DpiX != Desktop.DpiX || bitmap.DpiY != Desktop.DpiY)
|
||||
{
|
||||
@@ -271,7 +271,7 @@ namespace GARbro.GUI
|
||||
ImageCanvas.Source = bitmap;
|
||||
ApplyDownScaleSetting();
|
||||
SetStatusText (string.Format (guiStrings.MsgImageSize, bitmap.PixelWidth,
|
||||
bitmap.PixelHeight, bitmap.Format.BitsPerPixel));
|
||||
bitmap.PixelHeight, bitmap.Format.BitsPerPixel, format?.Tag ?? "?"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1133,13 +1133,13 @@ namespace GARbro.GUI
|
||||
try
|
||||
{
|
||||
var file_list = items.Select (entry => Path.Combine (CurrentPath, entry.Name));
|
||||
GARbro.Shell.File.Delete (file_list);
|
||||
if (!GARbro.Shell.File.Delete (file_list, new WindowInteropHelper(this).Handle))
|
||||
throw new ApplicationException ("Delete operation failed.");
|
||||
count = file_list.Count();
|
||||
}
|
||||
catch
|
||||
finally
|
||||
{
|
||||
ResumeWatchDirectoryChanges();
|
||||
throw;
|
||||
}
|
||||
RefreshView();
|
||||
SetStatusText (Localization.Format ("MsgDeletedItems", count));
|
||||
|
||||
@@ -51,5 +51,5 @@ using System.Windows;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion ("1.5.44.2904")]
|
||||
[assembly: AssemblyFileVersion ("1.5.44.2904")]
|
||||
[assembly: AssemblyVersion ("1.5.44.2938")]
|
||||
[assembly: AssemblyFileVersion ("1.5.44.2938")]
|
||||
|
||||
93
GUI/Shell.cs
93
GUI/Shell.cs
@@ -119,42 +119,86 @@ namespace GARbro.Shell
|
||||
/// <summary>
|
||||
/// SHFILEOPSTRUCT for SHFileOperation from COM
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)]
|
||||
private struct SHFILEOPSTRUCT
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)]
|
||||
private struct SHFILEOPSTRUCT32
|
||||
{
|
||||
|
||||
public IntPtr hwnd;
|
||||
[MarshalAs(UnmanagedType.U4)]
|
||||
public FileOperationType wFunc;
|
||||
[MarshalAs(UnmanagedType.LPTStr)]
|
||||
public string pFrom;
|
||||
[MarshalAs(UnmanagedType.LPTStr)]
|
||||
public string pTo;
|
||||
public FileOperationFlags fFlags;
|
||||
[MarshalAs(UnmanagedType.Bool)]
|
||||
public bool fAnyOperationsAborted;
|
||||
public IntPtr hNameMappings;
|
||||
[MarshalAs(UnmanagedType.LPTStr)]
|
||||
public string lpszProgressTitle;
|
||||
}
|
||||
|
||||
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
|
||||
private static extern int SHFileOperation (ref SHFILEOPSTRUCT FileOp);
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
public struct SHFILEOPSTRUCT64
|
||||
{
|
||||
public IntPtr hwnd;
|
||||
[MarshalAs(UnmanagedType.U4)]
|
||||
public FileOperationType wFunc;
|
||||
[MarshalAs(UnmanagedType.LPTStr)]
|
||||
public string pFrom;
|
||||
[MarshalAs(UnmanagedType.LPTStr)]
|
||||
public string pTo;
|
||||
public FileOperationFlags fFlags;
|
||||
public bool fAnyOperationsAborted;
|
||||
public IntPtr hNameMappings;
|
||||
[MarshalAs(UnmanagedType.LPTStr)]
|
||||
public string lpszProgressTitle;
|
||||
}
|
||||
|
||||
[DllImport("shell32.dll", EntryPoint = "SHFileOperationW", CharSet = CharSet.Unicode)]
|
||||
private static extern int SHFileOperation32 (ref SHFILEOPSTRUCT32 FileOp);
|
||||
|
||||
[DllImport("shell32.dll", EntryPoint = "SHFileOperationW", CharSet = CharSet.Unicode)]
|
||||
private static extern int SHFileOperation64 (ref SHFILEOPSTRUCT64 lpFileOp);
|
||||
|
||||
private static int SHFileOperation (FileOperationType func, string path, FileOperationFlags flags, IntPtr parent)
|
||||
{
|
||||
if (Marshal.SizeOf(typeof(IntPtr)) == 4)
|
||||
{
|
||||
var fs = new SHFILEOPSTRUCT32
|
||||
{
|
||||
hwnd = parent,
|
||||
wFunc = func,
|
||||
pFrom = path,
|
||||
fFlags = flags
|
||||
};
|
||||
return SHFileOperation32 (ref fs);
|
||||
}
|
||||
else
|
||||
{
|
||||
var fs = new SHFILEOPSTRUCT64
|
||||
{
|
||||
hwnd = parent,
|
||||
wFunc = func,
|
||||
pFrom = path,
|
||||
fFlags = flags
|
||||
};
|
||||
return SHFileOperation64 (ref fs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Send file to recycle bin
|
||||
/// </summary>
|
||||
/// <param name="path">Location of directory or file to recycle</param>
|
||||
/// <param name="flags">FileOperationFlags to add in addition to FOF_ALLOWUNDO</param>
|
||||
public static bool Delete (string path, FileOperationFlags flags)
|
||||
public static bool Delete (string path, FileOperationFlags flags, IntPtr parent = default(IntPtr))
|
||||
{
|
||||
var fs = new SHFILEOPSTRUCT
|
||||
{
|
||||
wFunc = FileOperationType.FO_DELETE,
|
||||
pFrom = path + '\0' + '\0',
|
||||
fFlags = FileOperationFlags.FOF_ALLOWUNDO | flags
|
||||
};
|
||||
return 0 == SHFileOperation (ref fs);
|
||||
return 0 == SHFileOperation (FileOperationType.FO_DELETE, path+'\0'+'\0',
|
||||
FileOperationFlags.FOF_ALLOWUNDO | flags, parent);
|
||||
}
|
||||
|
||||
public static bool Delete (IEnumerable<string> file_list, FileOperationFlags flags)
|
||||
public static bool Delete (IEnumerable<string> file_list, FileOperationFlags flags, IntPtr parent = default(IntPtr))
|
||||
{
|
||||
var files = new StringBuilder();
|
||||
foreach (var file in file_list)
|
||||
@@ -165,36 +209,31 @@ namespace GARbro.Shell
|
||||
if (0 == files.Length)
|
||||
return false;
|
||||
files.Append ('\0');
|
||||
var fs = new SHFILEOPSTRUCT
|
||||
{
|
||||
wFunc = FileOperationType.FO_DELETE,
|
||||
pFrom = files.ToString(),
|
||||
fFlags = FileOperationFlags.FOF_ALLOWUNDO | flags
|
||||
};
|
||||
return 0 == SHFileOperation (ref fs);
|
||||
return 0 == SHFileOperation (FileOperationType.FO_DELETE, files.ToString(),
|
||||
FileOperationFlags.FOF_ALLOWUNDO | flags, parent);
|
||||
}
|
||||
|
||||
public static bool Delete (IEnumerable<string> file_list)
|
||||
public static bool Delete (IEnumerable<string> file_list, IntPtr parent = default(IntPtr))
|
||||
{
|
||||
return Delete (file_list, FileOperationFlags.FOF_WANTNUKEWARNING);
|
||||
return Delete (file_list, FileOperationFlags.FOF_WANTNUKEWARNING, parent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send file to recycle bin. Display dialog, display warning if files are too big to fit (FOF_WANTNUKEWARNING)
|
||||
/// </summary>
|
||||
/// <param name="path">Location of directory or file to recycle</param>
|
||||
public static bool Delete (string path)
|
||||
public static bool Delete (string path, IntPtr parent = default(IntPtr))
|
||||
{
|
||||
return Delete (path, FileOperationFlags.FOF_NOCONFIRMATION | FileOperationFlags.FOF_WANTNUKEWARNING);
|
||||
return Delete (path, FileOperationFlags.FOF_NOCONFIRMATION | FileOperationFlags.FOF_WANTNUKEWARNING, parent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send file silently to recycle bin. Surpress dialog, surpress errors, delete if too large.
|
||||
/// </summary>
|
||||
/// <param name="path">Location of directory or file to recycle</param>
|
||||
public static bool MoveToRecycleBin (string path)
|
||||
public static bool MoveToRecycleBin (string path, IntPtr parent = default(IntPtr))
|
||||
{
|
||||
return Delete (path, FileOperationFlags.FOF_NOCONFIRMATION | FileOperationFlags.FOF_NOERRORUI | FileOperationFlags.FOF_SILENT);
|
||||
return Delete (path, FileOperationFlags.FOF_NOCONFIRMATION | FileOperationFlags.FOF_NOERRORUI | FileOperationFlags.FOF_SILENT, parent);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@
|
||||
<comment>Extracting files from {0} to {1}</comment>
|
||||
</data>
|
||||
<data name="MsgImageSize" xml:space="preserve">
|
||||
<value>イメージ {0} x {1} x {2}bpp</value>
|
||||
<value>イメージ {0} x {1} x {2}bpp [{3}]</value>
|
||||
<comment>Image {0} x {1} x {2}bpp</comment>
|
||||
</data>
|
||||
<data name="MsgNoFiles" xml:space="preserve">
|
||||
|
||||
@@ -232,7 +232,7 @@
|
||||
<value>{0}에서 {1}로 파일 추출하기</value>
|
||||
</data>
|
||||
<data name="MsgImageSize" xml:space="preserve">
|
||||
<value>이미지 {0} x {1} x {2}bpp</value>
|
||||
<value>이미지 {0} x {1} x {2}bpp [{3}]</value>
|
||||
</data>
|
||||
<data name="MsgNoFiles" xml:space="preserve">
|
||||
<value>추출할 파일이 없음</value>
|
||||
|
||||
@@ -232,7 +232,7 @@
|
||||
<value>Extracting files from {0} to {1}</value>
|
||||
</data>
|
||||
<data name="MsgImageSize" xml:space="preserve">
|
||||
<value>Image {0} x {1} x {2}bpp</value>
|
||||
<value>Image {0} x {1} x {2}bpp [{3}]</value>
|
||||
</data>
|
||||
<data name="MsgNoFiles" xml:space="preserve">
|
||||
<value>no files to extract</value>
|
||||
|
||||
@@ -226,7 +226,7 @@
|
||||
<value>Извлекаются файлы из {0} в {1}</value>
|
||||
</data>
|
||||
<data name="MsgImageSize" xml:space="preserve">
|
||||
<value>Изображение {0} x {1} x {2}bpp</value>
|
||||
<value>Изображение {0} x {1} x {2}bpp [{3}]</value>
|
||||
</data>
|
||||
<data name="MsgNoFiles" xml:space="preserve">
|
||||
<value>отсутствуют файлы, удовлетворяющие выбранным критериям</value>
|
||||
|
||||
@@ -232,7 +232,7 @@
|
||||
<value>正在从{0}中提取文件至{1}……</value>
|
||||
</data>
|
||||
<data name="MsgImageSize" xml:space="preserve">
|
||||
<value>图像 {0} x {1} x {2}bpp</value>
|
||||
<value>图像 {0} x {1} x {2}bpp [{3}]</value>
|
||||
</data>
|
||||
<data name="MsgNoFiles" xml:space="preserve">
|
||||
<value>没有可以提取的文件。</value>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NAudio" version="1.10.0" targetFramework="net461" />
|
||||
<package id="WindowsAPICodePack-Core" version="1.1.2" targetFramework="net461" />
|
||||
<package id="WindowsAPICodePack-Shell" version="1.1.1" targetFramework="net461" />
|
||||
<package id="WPFToolkit" version="3.5.50211.1" targetFramework="net461" />
|
||||
<package id="NAudio" version="1.10.0" targetFramework="net46" />
|
||||
<package id="WindowsAPICodePack-Core" version="1.1.2" targetFramework="net46" />
|
||||
<package id="WindowsAPICodePack-Shell" version="1.1.1" targetFramework="net46" />
|
||||
<package id="WPFToolkit" version="3.5.50211.1" targetFramework="net46" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user