mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-12-12 02:00:27 +08:00
Compare commits
2 Commits
copilot/fi
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19bba7f229 | ||
|
|
7a05793bf7 |
@@ -58,64 +58,114 @@ public partial class InfoPanel : UserControl
|
|||||||
Dispatcher.BeginInvoke(new Action(() => image.Source = source));
|
Dispatcher.BeginInvoke(new Action(() => image.Source = source));
|
||||||
});
|
});
|
||||||
|
|
||||||
var name = Path.GetFileName(path);
|
string name;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
name = Path.GetFileName(path);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
// Handle invalid path characters gracefully
|
||||||
|
name = path;
|
||||||
|
}
|
||||||
|
catch (PathTooLongException)
|
||||||
|
{
|
||||||
|
// Handle path too long scenarios
|
||||||
|
name = path;
|
||||||
|
}
|
||||||
filename.Text = string.IsNullOrEmpty(name) ? path : name;
|
filename.Text = string.IsNullOrEmpty(name) ? path : name;
|
||||||
|
|
||||||
var last = File.GetLastWriteTime(path);
|
try
|
||||||
modDate.Text = string.Format(TranslationHelper.Get("InfoPanel_LastModified"),
|
{
|
||||||
last.ToString(CultureInfo.CurrentCulture));
|
var last = File.GetLastWriteTime(path);
|
||||||
|
modDate.Text = string.Format(TranslationHelper.Get("InfoPanel_LastModified"),
|
||||||
|
last.ToString(CultureInfo.CurrentCulture));
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
// Handle invalid path characters gracefully
|
||||||
|
modDate.Text = TranslationHelper.Get("InfoPanel_LastModified_Unavailable") ?? "Last modified: Unavailable";
|
||||||
|
}
|
||||||
|
catch (UnauthorizedAccessException)
|
||||||
|
{
|
||||||
|
// Handle access denied scenarios
|
||||||
|
modDate.Text = TranslationHelper.Get("InfoPanel_LastModified_Unavailable") ?? "Last modified: Unavailable";
|
||||||
|
}
|
||||||
|
catch (PathTooLongException)
|
||||||
|
{
|
||||||
|
// Handle path too long scenarios
|
||||||
|
modDate.Text = TranslationHelper.Get("InfoPanel_LastModified_Unavailable") ?? "Last modified: Unavailable";
|
||||||
|
}
|
||||||
|
|
||||||
Stop = false;
|
Stop = false;
|
||||||
|
|
||||||
_ = Task.Run(() =>
|
_ = Task.Run(() =>
|
||||||
{
|
{
|
||||||
if (File.Exists(path))
|
try
|
||||||
{
|
{
|
||||||
var size = new FileInfo(path).Length;
|
if (File.Exists(path))
|
||||||
|
|
||||||
Dispatcher.Invoke(() => { totalSize.Text = size.ToPrettySize(2); });
|
|
||||||
}
|
|
||||||
else if (Path.GetPathRoot(path) == path) // is this a drive?
|
|
||||||
{
|
|
||||||
FileHelper.GetDriveSpace(path, out var totalSpace, out var totalFreeSpace);
|
|
||||||
|
|
||||||
Dispatcher.Invoke(() =>
|
|
||||||
{
|
{
|
||||||
totalSize.Text =
|
var size = new FileInfo(path).Length;
|
||||||
string.Format(TranslationHelper.Get("InfoPanel_DriveSize"),
|
|
||||||
totalSpace.ToPrettySize(2),
|
Dispatcher.Invoke(() => { totalSize.Text = size.ToPrettySize(2); });
|
||||||
totalFreeSpace.ToPrettySize(2));
|
}
|
||||||
});
|
else if (Path.GetPathRoot(path) == path) // is this a drive?
|
||||||
}
|
{
|
||||||
else if (Directory.Exists(path))
|
FileHelper.GetDriveSpace(path, out var totalSpace, out var totalFreeSpace);
|
||||||
{
|
|
||||||
FileHelper.CountFolder(path, ref _stop,
|
|
||||||
out var totalDirsL, out var totalFilesL, out var totalSizeL);
|
|
||||||
|
|
||||||
if (!Stop)
|
|
||||||
Dispatcher.Invoke(() =>
|
Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
string t;
|
|
||||||
var folders = totalDirsL == 0
|
|
||||||
? string.Empty
|
|
||||||
: string.Format(TranslationHelper.Get(
|
|
||||||
totalDirsL == 1 ? "InfoPanel_Folder" : "InfoPanel_Folders"), totalDirsL);
|
|
||||||
var files = totalFilesL == 0
|
|
||||||
? string.Empty
|
|
||||||
: string.Format(TranslationHelper.Get(
|
|
||||||
totalFilesL == 1 ? "InfoPanel_File" : "InfoPanel_Files"), totalFilesL);
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(folders) && !string.IsNullOrEmpty(files))
|
|
||||||
t = string.Format(
|
|
||||||
TranslationHelper.Get("InfoPanel_FolderAndFile"), folders, files);
|
|
||||||
else if (string.IsNullOrEmpty(folders) && string.IsNullOrEmpty(files))
|
|
||||||
t = string.Empty;
|
|
||||||
else
|
|
||||||
t = $"({folders}{files})";
|
|
||||||
|
|
||||||
totalSize.Text =
|
totalSize.Text =
|
||||||
$"{totalSizeL.ToPrettySize(2)} {t}";
|
string.Format(TranslationHelper.Get("InfoPanel_DriveSize"),
|
||||||
|
totalSpace.ToPrettySize(2),
|
||||||
|
totalFreeSpace.ToPrettySize(2));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
else if (Directory.Exists(path))
|
||||||
|
{
|
||||||
|
FileHelper.CountFolder(path, ref _stop,
|
||||||
|
out var totalDirsL, out var totalFilesL, out var totalSizeL);
|
||||||
|
|
||||||
|
if (!Stop)
|
||||||
|
Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
string t;
|
||||||
|
var folders = totalDirsL == 0
|
||||||
|
? string.Empty
|
||||||
|
: string.Format(TranslationHelper.Get(
|
||||||
|
totalDirsL == 1 ? "InfoPanel_Folder" : "InfoPanel_Folders"), totalDirsL);
|
||||||
|
var files = totalFilesL == 0
|
||||||
|
? string.Empty
|
||||||
|
: string.Format(TranslationHelper.Get(
|
||||||
|
totalFilesL == 1 ? "InfoPanel_File" : "InfoPanel_Files"), totalFilesL);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(folders) && !string.IsNullOrEmpty(files))
|
||||||
|
t = string.Format(
|
||||||
|
TranslationHelper.Get("InfoPanel_FolderAndFile"), folders, files);
|
||||||
|
else if (string.IsNullOrEmpty(folders) && string.IsNullOrEmpty(files))
|
||||||
|
t = string.Empty;
|
||||||
|
else
|
||||||
|
t = $"({folders}{files})";
|
||||||
|
|
||||||
|
totalSize.Text =
|
||||||
|
$"{totalSizeL.ToPrettySize(2)} {t}";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
// Handle invalid path characters gracefully
|
||||||
|
Dispatcher.Invoke(() => { totalSize.Text = "Size: Unavailable"; });
|
||||||
|
}
|
||||||
|
catch (UnauthorizedAccessException)
|
||||||
|
{
|
||||||
|
// Handle access denied scenarios
|
||||||
|
Dispatcher.Invoke(() => { totalSize.Text = "Size: Unavailable"; });
|
||||||
|
}
|
||||||
|
catch (PathTooLongException)
|
||||||
|
{
|
||||||
|
// Handle path too long scenarios
|
||||||
|
Dispatcher.Invoke(() => { totalSize.Text = "Size: Unavailable"; });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user