added reset times
This commit is contained in:
parent
01b2c0e5e7
commit
64a14f39c1
@ -18,10 +18,10 @@ namespace PhotoRenamer
|
||||
internal class Renamer
|
||||
{
|
||||
private readonly string _sourcePath;
|
||||
private readonly string _targetPath;
|
||||
private readonly ProgressBarOptions _childOptions;
|
||||
private readonly string _targetPath;
|
||||
private readonly ProgressBarOptions _childOptions;
|
||||
|
||||
public Renamer(IConfiguration configuration)
|
||||
public Renamer(IConfiguration configuration)
|
||||
{
|
||||
_sourcePath = Path.GetFullPath(configuration["Source"]);
|
||||
_targetPath = Path.GetFullPath(configuration["Target"]);
|
||||
@ -44,11 +44,11 @@ namespace PhotoRenamer
|
||||
ForegroundColor = ConsoleColor.Yellow,
|
||||
ForegroundColorDone = ConsoleColor.DarkGreen,
|
||||
BackgroundColor = ConsoleColor.DarkGray,
|
||||
BackgroundCharacter = '\u2593'
|
||||
};
|
||||
BackgroundCharacter = '\u2593'
|
||||
};
|
||||
var i = 0;
|
||||
using var progressBar = new ProgressBar(files.Length, "Copying files", options);
|
||||
var po = new ParallelOptions { MaxDegreeOfParallelism = 4};
|
||||
var po = new ParallelOptions {MaxDegreeOfParallelism = 4};
|
||||
Parallel.ForEach(files, po, file =>
|
||||
{
|
||||
try
|
||||
@ -65,7 +65,7 @@ namespace PhotoRenamer
|
||||
}
|
||||
finally
|
||||
{
|
||||
System.Threading.Interlocked.Increment(ref i);
|
||||
Interlocked.Increment(ref i);
|
||||
progressBar.Tick(i);
|
||||
}
|
||||
});
|
||||
@ -82,7 +82,8 @@ namespace PhotoRenamer
|
||||
using var child = progressBar.Spawn(100, destination.FullName, _childOptions);
|
||||
using var client = new WebClient();
|
||||
|
||||
void OnClientOnDownloadProgressChanged(object o, DownloadProgressChangedEventArgs args) => child.Tick(args.ProgressPercentage);
|
||||
void OnClientOnDownloadProgressChanged(object o, DownloadProgressChangedEventArgs args) =>
|
||||
child.Tick(args.ProgressPercentage);
|
||||
|
||||
client.DownloadProgressChanged += OnClientOnDownloadProgressChanged;
|
||||
client.DownloadFileAsync(new Uri(source.FullName), destination.FullName);
|
||||
@ -90,10 +91,21 @@ namespace PhotoRenamer
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
client.DownloadProgressChanged -= OnClientOnDownloadProgressChanged;
|
||||
ResetTimes(destination, source);
|
||||
|
||||
child.Tick(100);
|
||||
}
|
||||
|
||||
private static void ResetTimes(FileSystemInfo destination, FileSystemInfo source)
|
||||
{
|
||||
destination.LastWriteTime = source.LastWriteTime;
|
||||
destination.LastWriteTimeUtc = source.LastWriteTimeUtc;
|
||||
destination.CreationTime = source.CreationTime;
|
||||
destination.CreationTimeUtc = source.CreationTimeUtc;
|
||||
}
|
||||
|
||||
private string CreateFolder(DateTime dateTime)
|
||||
{
|
||||
var folder = Path.Combine(_targetPath, dateTime.Year.ToString(), dateTime.Month.ToString("D2"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user