Skip to content

Commit

Permalink
Theming and polish
Browse files Browse the repository at this point in the history
  • Loading branch information
krisdb2009 committed Jun 27, 2019
1 parent 8acc182 commit 78bb4e9
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 156 deletions.
66 changes: 57 additions & 9 deletions SuperGrate/Classes/Config.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Xml.Linq;
using System.IO;
using System;
using System.Collections.Generic;

namespace SuperGrate
{
Expand All @@ -8,13 +10,20 @@ class Config
public static string MigrationStorePath = null;
public static string ScanStateParameters = null;
public static string LoadStateParameters = null;

public static Dictionary<string, string> Data = new Dictionary<string, string>() { //Make config more automagic
"MigrationStorePath",
"ScanStateParameters",
"LoadStateParameters"
};

public static void GenerateConfig()
{
Logger.Warning("Generating new SuperGrate.xml config.");
new XDocument(new XElement("SuperGrate",
new XComment("The UNC path to the USMT Migration Store."),
new XElement("MigrationStorePath", @"\\share\migrationstore$"),
new XComment("ScanState.exe & LoadState.exe CLI Parameters: https://docs.microsoft.com/en-us/windows/deployment/usmt/usmt-command-line-syntax"),
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");
Expand All @@ -25,12 +34,51 @@ public static void LoadConfig()
{
GenerateConfig();
}
XDocument config = XDocument.Load(@".\SuperGrate.xml");
XElement root = config.Element("SuperGrate");
MigrationStorePath = root.Element("MigrationStorePath").Value;
ScanStateParameters = root.Element("ScanStateParameters").Value;
LoadStateParameters = root.Element("LoadStateParameters").Value;
Logger.Success("Config loaded!");
try
{
XDocument config = XDocument.Load(@".\SuperGrate.xml");
XElement root = config.Element("SuperGrate");


new Dictionary<string, string> schema = new Dictionary<string, string>([
"",
""
]);


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
{
ScanStateParameters = XScanStateParameters.Value;
}
if (XLoadStateParameters == null)
{

}
else
{
LoadStateParameters = XLoadStateParameters.Value;
}
Logger.Success("Config loaded!");
}
catch(Exception e)
{
Logger.Exception(e, "Error when loading the Super Grate config file! SuperGrate.xml");
}
}
}
}
12 changes: 4 additions & 8 deletions SuperGrate/Classes/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,23 @@ static public async Task<bool> Ping(string Host)
{
try
{
Logger.Information("Pinging: " + Host + "...");
Ping ping = new Ping();
PingReply reply = await ping.SendPingAsync(Host, 1000);
if (reply.Status == IPStatus.Success)
{
Logger.Success(Host + ": Online.");
return true;
}
else
{
Logger.Error(Host + ": Offline.");
return false;
}
}
catch (PingException e)
{
Logger.Error(e.InnerException.Message);
return false;
}
catch (Exception e)
{
Logger.Error(e.Message);
Logger.Exception(e, "Could not contact: " + Host);
return false;
}
}
Expand All @@ -55,10 +53,8 @@ public static Task<Dictionary<string, string>> GetUsersFromHost(string Host)
{
try
{
Logger.Information("Pinging: " + Host + "...");
if (await Ping(Host))
{
Logger.Success("Host Online!");
Dictionary<string, string> results = new Dictionary<string, string>();
RegistryKey remoteReg = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, Host);
RegistryKey profileList = remoteReg.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", false);
Expand Down
21 changes: 11 additions & 10 deletions SuperGrate/Classes/USMT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public static Task<bool> Do(USMTMode Mode, string[] SIDs)
if(Canceled || Failed) break;
if (Mode == USMTMode.LoadState)
{
Logger.Information("Importing user data for '" + Misc.GetUserByIdentity(SID).Name + "' on '" + CurrentTarget + "'...");
Logger.Information("Applying user state: '" + Misc.GetUserByIdentity(SID).Name + "' on '" + CurrentTarget + "'...");
Failed = !await DownloadFromStore(SID);
if (Canceled || Failed) break;
}
else
{
Logger.Information("Exporting user data: '" + Misc.GetUserByIdentity(SID).Name + "' on '" + CurrentTarget + "'...");
Logger.Information("Capturing user state: '" + Misc.GetUserByIdentity(SID).Name + "' on '" + CurrentTarget + "'...");
}
Failed = !await StartRemoteProcess(
@"C:\SuperGrate\" + exec + " " +
Expand Down Expand Up @@ -147,10 +147,11 @@ public static Task<bool> CleaupUSMT()
{
Logger.Verbose(e.Message);
Logger.Verbose(e.StackTrace);
if (tries++ % 5 == 0)
if (tries % 5 == 0)
{
Logger.Warning("Could not delete, USMT might still be running. Attempt " + tries + "/30.");
}
tries++;
await Task.Delay(1000);
}
}
Expand All @@ -169,7 +170,7 @@ public static Task<bool> CleaupUSMT()
private static Task<bool> UploadToStore(string SID)
{
return Task.Run(() => {
Logger.Information("Uploading user data to the Store...");
Logger.Information("Uploading user state to the Store...");
string Destination = Path.Combine(Config.MigrationStorePath, SID);
try
{
Expand All @@ -178,20 +179,20 @@ private static Task<bool> UploadToStore(string SID)
Path.Combine(@"\\", Main.SourceComputer, @"C$\SuperGrate\USMT\USMT.MIG"),
Path.Combine(Destination, "USMT.MIG")
);
Logger.Success("User data successfully uploaded.");
Logger.Success("User state successfully uploaded.");
return true;
}
catch(Exception e)
{
Logger.Exception(e, "Failed to upload user data to the Store.");
Logger.Exception(e, "Failed to upload user state to the Store.");
return false;
}
});
}
private static Task<bool> DownloadFromStore(string SID)
{
return Task.Run(() => {
Logger.Information("Downloading user data to: " + Main.DestinationComputer + "...");
Logger.Information("Downloading user state to: " + Main.DestinationComputer + "...");
string Destination = Path.Combine(@"\\", Main.DestinationComputer, @"C$\SuperGrate\USMT\");
try
{
Expand All @@ -200,12 +201,12 @@ private static Task<bool> DownloadFromStore(string SID)
Path.Combine(Config.MigrationStorePath, SID, "USMT.MIG"),
Path.Combine(Destination, "USMT.MIG")
);
Logger.Success("User data successfully transferred.");
Logger.Success("User state successfully transferred.");
return true;
}
catch(Exception e)
{
Logger.Exception(e, "Failed to download user data to: " + Main.DestinationComputer + ".");
Logger.Exception(e, "Failed to download state data to: " + Main.DestinationComputer + ".");
return false;
}
});
Expand Down Expand Up @@ -240,7 +241,7 @@ private static Task<bool> WaitForUsmtExit(string ImageName)
{
return Task.Run(async () => {
Running = true;
Logger.Information("Waiting for USMT to finish...");
Logger.Verbose("Waiting for USMT to finish...");
try
{
while (Running)
Expand Down
Loading

0 comments on commit 78bb4e9

Please sign in to comment.