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