Exemplo n.º 1
0
        public static Task <bool> Do(USMTMode Mode, string[] IDs)
        {
            Canceled = false;
            Failed   = false;
            string exec         = "";
            string configParams = "";

            if (Mode == USMTMode.LoadState)
            {
                exec          = "loadstate.exe";
                configParams  = Config.Settings["LoadStateParameters"];
                CurrentTarget = Main.DestinationComputer;
            }
            if (Mode == USMTMode.ScanState)
            {
                exec          = "scanstate.exe";
                configParams  = Config.Settings["ScanStateParameters"];
                CurrentTarget = Main.SourceComputer;
            }
            return(Task.Run(async() => {
                DetectedArch = await Misc.GetRemoteArch(CurrentTarget);
                if (Canceled || DetectedArch == Misc.OSArchitecture.Unknown)
                {
                    return false;
                }
                Failed = !await CopyUSMT();
                if (Canceled || Failed)
                {
                    return false;
                }
                Logger.UpdateProgress(0);
                foreach (string ID in IDs)
                {
                    if (Canceled || Failed)
                    {
                        break;
                    }
                    string SID = "";
                    if (Mode == USMTMode.LoadState)
                    {
                        Logger.Information("Applying user state: '" + Misc.GetUserByIdentity(ID) + "' on '" + CurrentTarget + "'...");
                        Failed = !await DownloadFromStore(ID);
                        SID = await Misc.GetSIDFromStore(ID);
                        if (Canceled || Failed || SID == null)
                        {
                            break;
                        }
                    }
                    if (Mode == USMTMode.ScanState)
                    {
                        Logger.Information("Capturing user state: '" + Misc.GetUserByIdentity(ID) + "' on '" + CurrentTarget + "'...");
                        SID = ID;
                    }
                    Failed = !await Remote.StartProcess(CurrentTarget,
                                                        Path.Combine(PayloadPathLocal, exec) + " " +
                                                        PayloadPathLocal + " " +
                                                        @"/ue:*\* " +
                                                        "/ui:" + SID + " " +
                                                        "/l:SuperGrate.log " +
                                                        "/progress:SuperGrate.progress " +
                                                        configParams
                                                        , PayloadPathLocal);
                    if (Canceled || Failed)
                    {
                        break;
                    }
                    Running = true;
                    StartWatchLog("SuperGrate.log");
                    StartWatchLog("SuperGrate.progress");
                    Failed = !await WaitForUsmtExit(exec.Replace(".exe", ""));
                    if (Canceled || Failed)
                    {
                        break;
                    }
                    Logger.UpdateProgress(0);
                    if (Mode == USMTMode.LoadState)
                    {
                        Failed = !await SetStoreExportParameters(ID);
                        if (Canceled || Failed)
                        {
                            break;
                        }
                    }
                    if (Mode == USMTMode.ScanState)
                    {
                        Failed = !await UploadToStore(SID);
                        if (Canceled || Failed)
                        {
                            break;
                        }
                    }
                    Logger.UpdateProgress(0);
                }
                Failed = !await CleaupUSMT();
                if (Canceled || Failed)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }));
        }