do not show useless texts e.g. "... and 0 files"

This commit is contained in:
Paddy Xu
2017-05-27 00:39:29 +03:00
parent 250e796095
commit cdddb303bd
2 changed files with 27 additions and 10 deletions

View File

@@ -42,23 +42,33 @@ namespace QuickLook.Plugin.ArchiveViewer
{ {
LoadItemsFromArchive(path); LoadItemsFromArchive(path);
var folder = 0; var folders = -1; // do not count root node
var files = 0; var files = 0;
ulong sizeU = 0L; ulong sizeU = 0L;
_fileEntries.ForEach(e => _fileEntries.ForEach(e =>
{ {
if (e.Value.IsFolder) if (e.Value.IsFolder)
folder++; folders++;
else else
files++; files++;
sizeU += e.Value.Size; sizeU += e.Value.Size;
}); });
var s = _solid ? " solid," : ""; var s = _solid ? ", solid" : "";
string t;
var d = folders != 0 ? $"{folders} folders" : string.Empty;
var f = files != 0 ? $"{files} files" : string.Empty;
if (!string.IsNullOrEmpty(d) && !string.IsNullOrEmpty(f))
t = $", {d} and {f}";
else if (string.IsNullOrEmpty(d) && string.IsNullOrEmpty(f))
t = string.Empty;
else
t = $", {d}{f}";
archiveCount.Content = archiveCount.Content =
$"{_type} archive,{s} {folder - 1} folders and {files} files"; // do not count root node $"{_type} archive{s}{t}";
archiveSizeC.Content = $"Compressed size {_totalZippedSize.ToPrettySize(2)}"; archiveSizeC.Content = $"Compressed size {_totalZippedSize.ToPrettySize(2)}";
archiveSizeU.Content = $"Uncompressed size {sizeU.ToPrettySize(2)}"; archiveSizeU.Content = $"Uncompressed size {sizeU.ToPrettySize(2)}";
} }

View File

@@ -71,17 +71,24 @@ namespace QuickLook.Plugin.InfoPanel
} }
else if (Directory.Exists(path)) else if (Directory.Exists(path))
{ {
long totalDirsL; FileHelper.CountFolder(path, ref _stop,
long totalFilesL; out long totalDirsL, out long totalFilesL, out long totalSizeL);
long totalSizeL;
FileHelper.CountFolder(path, ref _stop, out totalDirsL, out totalFilesL, out totalSizeL);
if (!Stop) if (!Stop)
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>
{ {
string t;
var d = totalDirsL != 0 ? $"{totalDirsL} folders" : string.Empty;
var f = totalFilesL != 0 ? $"{totalFilesL} files" : string.Empty;
if (!string.IsNullOrEmpty(d) && !string.IsNullOrEmpty(f))
t = $"({d} and {f})";
else if (string.IsNullOrEmpty(d) && string.IsNullOrEmpty(f))
t = string.Empty;
else
t = $"({d}{f})";
totalSize.Text = totalSize.Text =
$"{totalSizeL.ToPrettySize(2)} ({totalDirsL} folders and {totalFilesL} files)"; $"{totalSizeL.ToPrettySize(2)} {t}";
}); });
} }
}); });