mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-03 11:16:17 +00:00
Compare commits
2 Commits
14a5bea926
...
copilot/fi
Author | SHA1 | Date | |
---|---|---|---|
![]() |
19bba7f229 | ||
![]() |
7a05793bf7 |
@@ -58,64 +58,114 @@ public partial class InfoPanel : UserControl
|
||||
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;
|
||||
|
||||
var last = File.GetLastWriteTime(path);
|
||||
modDate.Text = string.Format(TranslationHelper.Get("InfoPanel_LastModified"),
|
||||
last.ToString(CultureInfo.CurrentCulture));
|
||||
try
|
||||
{
|
||||
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;
|
||||
|
||||
_ = Task.Run(() =>
|
||||
{
|
||||
if (File.Exists(path))
|
||||
try
|
||||
{
|
||||
var size = new FileInfo(path).Length;
|
||||
|
||||
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(() =>
|
||||
if (File.Exists(path))
|
||||
{
|
||||
totalSize.Text =
|
||||
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);
|
||||
var size = new FileInfo(path).Length;
|
||||
|
||||
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);
|
||||
|
||||
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}";
|
||||
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