diff --git a/.vscode/launch.json b/.vscode/launch.json index 59950b9..b1aea38 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,12 @@ "preLaunchTask": "build", "program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll", "args": [ + "s", + "X", + "C:/Users/phares/AppData/Roaming/FreeFileSync", + "Day-Helper-2025-04-21", + "GlobalSettings.xml", + "LastSync|Config", "s", "X", "L:/Tmp/MET08ANLYSDIFAAST230", diff --git a/ADO2025/PI5/Helper-2025-04-21.cs b/ADO2025/PI5/Helper-2025-04-21.cs new file mode 100644 index 0000000..758c8d6 --- /dev/null +++ b/ADO2025/PI5/Helper-2025-04-21.cs @@ -0,0 +1,47 @@ +using Microsoft.Extensions.Logging; + +namespace File_Folder_Helper.ADO2025.PI5; + +internal static partial class Helper20250421 { + + internal static void FreeFileSyncChangeCreatedDate(ILogger logger, List args) { + string searchPattern = args[2]; + string[] searchPatterns = args[3].Split('|'); + string sourceDirectory = Path.GetFullPath(args[0]); + if (searchPatterns.Length != 2) + throw new NotImplementedException($"Not the correct number of {searchPatterns} were passed!"); + string lastSyncSearch = $"{searchPatterns[0]}=\""; + string configurationFileSearch = $"{searchPatterns[1]}=\""; + string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories); + if (files.Length != 1) + logger.LogWarning("<{files}>(s)", files.Length); + else + ChangeCreatedDate(lastSyncSearch, configurationFileSearch, files[0]); + } + + private static void ChangeCreatedDate(string lastSyncSearch, string configurationFileSearch, string sourceFile) { + long epoch; + string lastSync; + string[] segments; + string[] segmentsB; + DateTime creationTime; + string configurationFile; + string[] lines = File.ReadAllLines(sourceFile); + foreach (string line in lines) { + segments = line.Split(lastSyncSearch); + if (segments.Length != 2) + continue; + segmentsB = line.Split(configurationFileSearch); + if (segmentsB.Length != 2) + continue; + lastSync = segments[1].Split('"')[0]; + if (!long.TryParse(lastSync, out epoch) || epoch == 0) + continue; + configurationFile = segmentsB[1].Split('"')[0]; + if (!File.Exists(configurationFile)) + continue; + creationTime = new(DateTimeOffset.UnixEpoch.AddSeconds(epoch).ToLocalTime().Ticks); + File.SetCreationTime(configurationFile, creationTime); + } + } +} \ No newline at end of file diff --git a/Day/HelperDay.cs b/Day/HelperDay.cs index ba8b357..d155548 100644 --- a/Day/HelperDay.cs +++ b/Day/HelperDay.cs @@ -155,6 +155,8 @@ internal static class HelperDay ADO2025.PI5.Helper20250404.KumaToGatus(logger, args); else if (args[1] == "Day-Helper-2025-04-07") ADO2025.PI5.Helper20250407.Sync(logger, args); + else if (args[1] == "Day-Helper-2025-04-21") + ADO2025.PI5.Helper20250421.FreeFileSyncChangeCreatedDate(logger, args); else throw new Exception(appSettings.Company); }