diff --git a/SuperGrate/Classes/Config.cs b/SuperGrate/Classes/Config.cs index a8bfc96..aa0418b 100644 --- a/SuperGrate/Classes/Config.cs +++ b/SuperGrate/Classes/Config.cs @@ -7,26 +7,29 @@ namespace SuperGrate { class Config { - public static string MigrationStorePath = null; - public static string ScanStateParameters = null; - public static string LoadStateParameters = null; - - public static Dictionary Data = new Dictionary() { //Make config more automagic - "MigrationStorePath", - "ScanStateParameters", - "LoadStateParameters" + public static Dictionary Settings = new Dictionary() { + {"XComment1", @"The UNC or Direct path to the USMT Migration Store E.g: \\ba-share\s$ or .\STORE."}, + {"MigrationStorePath", @".\STORE"}, + {"XComment2", "ScanState.exe & LoadState.exe CLI Parameters: https://docs.microsoft.com/en-us/windows/deployment/usmt/usmt-command-line-syntax "}, + {"ScanStateParameters", "/config:Config_SettingsOnly.xml /i:MigUser.xml /r:3 /o"}, + {"LoadStateParameters", "/config:Config_SettingsOnly.xml /i:MigUser.xml /r:3"} }; - public static void GenerateConfig() { Logger.Warning("Generating new SuperGrate.xml config."); - new XDocument(new XElement("SuperGrate", - new XComment(@"The UNC or Direct path to the USMT Migration Store E.g: \\ba-share\s$ or .\STORE."), - new XElement("MigrationStorePath", @".\STORE"), - new XComment("ScanState.exe & LoadState.exe CLI Parameters: https://docs.microsoft.com/en-us/windows/deployment/usmt/usmt-command-line-syntax "), - new XElement("ScanStateParameters", "/config:Config_SettingsOnly.xml /i:MigUser.xml /r:3 /o"), - new XElement("LoadStateParameters", "/config:Config_SettingsOnly.xml /i:MigUser.xml /r:3") - )).Save(@".\SuperGrate.xml"); + XElement root = new XElement("SuperGrate"); + foreach(KeyValuePair setting in Settings) + { + if(setting.Key.StartsWith("XComment")) + { + root.Add(new XComment(setting.Value)); + } + else + { + root.Add(new XElement(setting.Key, setting.Value)); + } + } + new XDocument(root).Save(@".\SuperGrate.xml"); } public static void LoadConfig() { @@ -38,42 +41,33 @@ public static void LoadConfig() { XDocument config = XDocument.Load(@".\SuperGrate.xml"); XElement root = config.Element("SuperGrate"); - - - new Dictionary schema = new Dictionary([ - "", - "" - ]); - - - XElement XMigrationStorePath = root.Element("MigrationStorePath"); - XElement XScanStateParameters = root.Element("ScanStateParameters"); - XElement XLoadStateParameters = root.Element("LoadStateParameters"); - if (XMigrationStorePath == null) - { - - } - else - { - MigrationStorePath = XMigrationStorePath.Value; - } - if (XScanStateParameters == null) - { - - } - else + bool success = true; + Dictionary xmlSettings = new Dictionary(); + foreach(KeyValuePair setting in Settings) { - ScanStateParameters = XScanStateParameters.Value; + if (!setting.Key.StartsWith("XComment")) + { + XElement element = root.Element(setting.Key); + if (element == null) + { + success = false; + Logger.Warning("SuperGrate.xml is missing: " + setting.Key + "!"); + } + else + { + xmlSettings[setting.Key] = element.Value; + } + } } - if (XLoadStateParameters == null) + Settings = xmlSettings; + if(success) { - + Logger.Success("Config loaded!"); } else { - LoadStateParameters = XLoadStateParameters.Value; + Logger.Warning("Config loaded, but is using default values for the missing elements."); } - Logger.Success("Config loaded!"); } catch(Exception e) { diff --git a/SuperGrate/Classes/Misc.cs b/SuperGrate/Classes/Misc.cs index b9a4ad9..b08d8c9 100644 --- a/SuperGrate/Classes/Misc.cs +++ b/SuperGrate/Classes/Misc.cs @@ -123,7 +123,7 @@ public static Task DeleteFromStore(string SID) Logger.Information("Deleting '" + name + "' from the Store..."); try { - Directory.Delete(Path.Combine(Config.MigrationStorePath, SID), true); + Directory.Delete(Path.Combine(Config.Settings["MigrationStorePath"], SID), true); Logger.Information("'" + name + "' successfully deleted from the Store."); } catch(Exception e) diff --git a/SuperGrate/Classes/USMT.cs b/SuperGrate/Classes/USMT.cs index b231f24..40d7f71 100644 --- a/SuperGrate/Classes/USMT.cs +++ b/SuperGrate/Classes/USMT.cs @@ -21,13 +21,13 @@ public static Task Do(USMTMode Mode, string[] SIDs) if(Mode == USMTMode.LoadState) { exec = "loadstate.exe"; - configParams = Config.LoadStateParameters; + configParams = Config.Settings["LoadStateParameters"]; CurrentTarget = Main.DestinationComputer; } if(Mode == USMTMode.ScanState) { exec = "scanstate.exe"; - configParams = Config.ScanStateParameters; + configParams = Config.Settings["ScanStateParameters"]; CurrentTarget = Main.SourceComputer; } return Task.Run(async () => { @@ -171,7 +171,7 @@ private static Task UploadToStore(string SID) { return Task.Run(() => { Logger.Information("Uploading user state to the Store..."); - string Destination = Path.Combine(Config.MigrationStorePath, SID); + string Destination = Path.Combine(Config.Settings["MigrationStorePath"], SID); try { Directory.CreateDirectory(Destination); @@ -194,11 +194,11 @@ private static Task DownloadFromStore(string SID) return Task.Run(() => { Logger.Information("Downloading user state to: " + Main.DestinationComputer + "..."); string Destination = Path.Combine(@"\\", Main.DestinationComputer, @"C$\SuperGrate\USMT\"); - try - { - Directory.CreateDirectory(Destination); - Copy.CopyFile( - Path.Combine(Config.MigrationStorePath, SID, "USMT.MIG"), + try + { + Directory.CreateDirectory(Destination); + Copy.CopyFile( + Path.Combine(Config.Settings["MigrationStorePath"], SID, "USMT.MIG"), Path.Combine(Destination, "USMT.MIG") ); Logger.Success("User state successfully transferred."); diff --git a/SuperGrate/Main.cs b/SuperGrate/Main.cs index 841c0ca..ac67aba 100644 --- a/SuperGrate/Main.cs +++ b/SuperGrate/Main.cs @@ -111,7 +111,7 @@ private async void BtnListStore_Click(object sender, EventArgs e) Running = true; lbxUsers.Items.Clear(); lblUserList.Text = "Users in Migration Store:"; - Dictionary results = await Misc.GetUsersFromStore(Config.MigrationStorePath); + Dictionary results = await Misc.GetUsersFromStore(Config.Settings["MigrationStorePath"]); if(results != null) { lbxUsers.Tag = results.Keys.ToArray(); diff --git a/SuperGrate/Properties/AssemblyInfo.cs b/SuperGrate/Properties/AssemblyInfo.cs index 4d9cec3..16b3470 100644 --- a/SuperGrate/Properties/AssemblyInfo.cs +++ b/SuperGrate/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -32,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.0.0.3")] -[assembly: AssemblyFileVersion("0.0.0.3")] +[assembly: AssemblyVersion("0.0.0.4")] +[assembly: AssemblyFileVersion("0.0.0.4")]