Skip to content

Commit 472ee70

Browse files
author
RandomEngy
committed
Added file size of preview output to log window.
1 parent d1ac0e5 commit 472ee70

3 files changed

Lines changed: 63 additions & 2 deletions

File tree

VidCoder/Utilities/Utilities.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45
using System.Text;
56
using System.Reflection;
@@ -329,6 +330,64 @@ public static string FormatTimeSpan(TimeSpan span)
329330
return string.Format("{0}s", span.Seconds);
330331
}
331332

333+
public static string FormatFileSize(long bytes)
334+
{
335+
if (bytes < 1024)
336+
{
337+
return bytes.ToString(CultureInfo.InvariantCulture) + " bytes";
338+
}
339+
340+
if (bytes < 1048576)
341+
{
342+
double kilobytes = ((double)bytes) / 1024;
343+
344+
return kilobytes.ToString(GetFormatForFilesize(kilobytes)) + " KB";
345+
}
346+
347+
double megabytes = ((double)bytes) / 1048576;
348+
349+
return megabytes.ToString(GetFormatForFilesize(megabytes)) + " MB";
350+
}
351+
352+
private static string GetFormatForFilesize(double size)
353+
{
354+
int digits = 0;
355+
double num = size;
356+
357+
while (num > 1.0)
358+
{
359+
num /= 10;
360+
digits++;
361+
}
362+
363+
int decimalPlaces = Math.Min(2, 3 - digits);
364+
365+
return "F" + decimalPlaces;
366+
}
367+
368+
//public static string FormatFileSize(long size)
369+
//{
370+
// if (size < 1000)
371+
// {
372+
// return size.ToString(CultureInfo.InvariantCulture) + " bytes";
373+
// }
374+
375+
// double kilobytes = (double)size / 1024;
376+
// if (kilobytes < 1000)
377+
// {
378+
// return kilobytes.ToString("F2", CultureInfo.InvariantCulture) + " KB";
379+
// }
380+
381+
// double megabytes = kilobytes / 1024;
382+
// if (megabytes < 1000)
383+
// {
384+
// return megabytes.ToString("F2", CultureInfo.InvariantCulture) + " MB";
385+
// }
386+
387+
// double gigabytes = kilobytes / 1024;
388+
// return gigabytes.ToString("F2", CultureInfo.InvariantCulture) + " GB";
389+
//}
390+
332391
public static IMessageBoxService MessageBox
333392
{
334393
get

VidCoder/View/PreviewWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
</StackPanel>
8080
</Button>
8181
<ComboBox
82-
Height="22" Width="40" Margin="20,0,0,0"
82+
Height="22" Width="45" Margin="20,0,0,0"
8383
SelectedValue="{Binding PreviewSeconds}"
8484
SelectedValuePath="Content">
8585
<ComboBoxItem>5</ComboBoxItem>

VidCoder/ViewModel/PreviewViewModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,9 @@ private void OnPreviewScanCompleted(object sender, EventArgs eventArgs)
738738
}
739739
else
740740
{
741-
this.logger.Log("Finished preview clip generation");
741+
var previewFileInfo = new FileInfo(this.previewFilePath);
742+
this.logger.Log("Finished preview clip generation. Size: " + Utilities.FormatFileSize(previewFileInfo.Length));
743+
742744
FileService.Instance.LaunchFile(previewFilePath);
743745
}
744746
}

0 commit comments

Comments
 (0)