@@ -14,7 +14,7 @@ public partial class Main : Form
1414 public static string SourceComputer ;
1515 public static string DestinationComputer ;
1616 public static ListSources CurrentListSource = ListSources . Unknown ;
17- private static bool isRunning = false ;
17+ private static RunningTask storeRunningTask = RunningTask . None ;
1818 private string [ ] MainParameters = null ;
1919 private bool CloseRequested = false ;
2020 public Main ( string [ ] parameters )
@@ -27,7 +27,7 @@ public Main(string[] parameters)
2727 lbxUsers . Tag = new string [ 0 ] ;
2828 Icon = Properties . Resources . supergrate ;
2929 }
30- private async void Main_Load ( object sender , EventArgs e )
30+ private void Main_Load ( object sender , EventArgs e )
3131 {
3232 Config . LoadConfig ( MainParameters ) ;
3333 Logger . Success ( "Welcome to Super Grate! v" + Application . ProductVersion ) ;
@@ -39,18 +39,20 @@ private async void Main_Load(object sender, EventArgs e)
3939 /*
4040 Logger.Information("Downloading...");
4141 await new Download("https://github.com/belowaverage-org/SuperGrate/raw/master/USMT/x64.zip", @".\asdf.zip").Start();
42- Logger.Success("Done!");*/
42+ Logger.Success("Done!");
43+ */
4344
4445 }
45- private bool Running {
46+ private RunningTask Running {
4647 get {
47- return isRunning ;
48+ return storeRunningTask ;
4849 }
4950 set {
5051 Progress . Value = 0 ;
51- if ( value )
52+ if ( value != RunningTask . None )
5253 {
53- isRunning = true ;
54+ btStartStop . Text = "Stop" ;
55+ storeRunningTask = value ;
5456 imgLoadLogo . Enabled = true ;
5557 tbSourceComputer . Enabled =
5658 tbDestinationComputer . Enabled =
@@ -64,7 +66,8 @@ private bool Running {
6466 }
6567 else
6668 {
67- isRunning = false ;
69+ btStartStop . Text = "Start" ;
70+ storeRunningTask = value ;
6871 imgLoadLogo . Enabled = false ;
6972 tbSourceComputer . Enabled =
7073 tbDestinationComputer . Enabled =
@@ -82,14 +85,17 @@ private bool Running {
8285 }
8386 private async void BtStartStop_Click ( object sender , EventArgs e )
8487 {
85- if ( Running )
88+ if ( Running == RunningTask . USMT )
8689 {
8790 USMT . Cancel ( ) ;
8891 }
89- else
92+ else if ( Running == RunningTask . RemoteProfileDelete )
93+ {
94+ Misc . CancelRemoteProfileDelete ( SourceComputer ) ;
95+ }
96+ else if ( Running == RunningTask . None )
9097 {
91- Running = true ;
92- btStartStop . Text = "Stop" ;
98+ Running = RunningTask . USMT ;
9399 int count = 0 ;
94100 string [ ] SIDs = new string [ lbxUsers . SelectedIndices . Count ] ;
95101 foreach ( int index in lbxUsers . SelectedIndices )
@@ -100,7 +106,7 @@ private async void BtStartStop_Click(object sender, EventArgs e)
100106 {
101107 await USMT . Do ( USMTMode . ScanState , SIDs ) ;
102108 }
103- if ( tbDestinationComputer . Text != "" && Running )
109+ if ( tbDestinationComputer . Text != "" && Running == RunningTask . USMT )
104110 {
105111 await USMT . Do ( USMTMode . LoadState , SIDs ) ;
106112 bool setting ;
@@ -109,14 +115,13 @@ private async void BtStartStop_Click(object sender, EventArgs e)
109115 await Misc . DeleteFromStore ( SIDs ) ;
110116 }
111117 }
112- btStartStop . Text = "Start" ;
113- Running = false ;
118+ Running = RunningTask . None ;
114119 Logger . Information ( "Done." ) ;
115120 }
116121 }
117122 private async void BtnListSource_Click ( object sender , EventArgs e )
118123 {
119- Running = true ;
124+ Running = RunningTask . Unknown ;
120125 lbxUsers . Items . Clear ( ) ;
121126 lblUserList . Text = "Users on Source Computer:" ;
122127 Dictionary < string , string > users = await Misc . GetUsersFromHost ( tbSourceComputer . Text ) ;
@@ -143,11 +148,11 @@ private async void BtnListSource_Click(object sender, EventArgs e)
143148 CurrentListSource = ListSources . SourceComputer ;
144149 Logger . Success ( "Done!" ) ;
145150 }
146- Running = false ;
151+ Running = RunningTask . None ;
147152 }
148153 private async void BtnListStore_Click ( object sender , EventArgs e )
149154 {
150- Running = true ;
155+ Running = RunningTask . Unknown ;
151156 lbxUsers . Items . Clear ( ) ;
152157 lblUserList . Text = "Users in Migration Store:" ;
153158 Dictionary < string , string > results = await Misc . GetUsersFromStore ( Config . Settings [ "MigrationStorePath" ] ) ;
@@ -157,7 +162,7 @@ private async void BtnListStore_Click(object sender, EventArgs e)
157162 lbxUsers . Items . AddRange ( results . Values . ToArray ( ) ) ;
158163 CurrentListSource = ListSources . MigrationStore ;
159164 }
160- Running = false ;
165+ Running = RunningTask . None ;
161166 }
162167 private void LogBox_DoubleClick ( object sender , EventArgs e )
163168 {
@@ -182,7 +187,7 @@ private void UpdateFormRestrictions(object sender = null, EventArgs e = null)
182187 {
183188 btStartStop . Enabled = true ;
184189 }
185- if ( lbxUsers . SelectedIndices . Count != 0 && CurrentListSource == ListSources . MigrationStore )
190+ if ( lbxUsers . SelectedIndices . Count != 0 )
186191 {
187192 tbSourceComputer . Enabled = btnAFillSrc . Enabled = false ;
188193 btnDelete . Enabled = true ;
@@ -217,15 +222,27 @@ private void TbDestinationComputer_TextChanged(object sender, EventArgs e)
217222 }
218223 private async void BtnDelete_Click ( object sender , EventArgs e )
219224 {
220- Running = true ;
225+ Running = RunningTask . RemoteProfileDelete ;
221226 List < string > SIDs = new List < string > ( ) ;
222227 foreach ( int index in lbxUsers . SelectedIndices )
223228 {
224229 SIDs . Add ( ( ( string [ ] ) lbxUsers . Tag ) [ index ] ) ;
225230 }
226- await Misc . DeleteFromStore ( SIDs . ToArray ( ) ) ;
227- Running = false ;
228- btnListStore . PerformClick ( ) ;
231+ if ( CurrentListSource == ListSources . MigrationStore )
232+ {
233+ btStartStop . Enabled = false ;
234+ await Misc . DeleteFromStore ( SIDs . ToArray ( ) ) ;
235+ btStartStop . Enabled = true ;
236+ Running = RunningTask . None ;
237+ btnListStore . PerformClick ( ) ;
238+ }
239+ else if ( CurrentListSource == ListSources . SourceComputer )
240+ {
241+ await Misc . DeleteFromTarget ( SourceComputer , SIDs . ToArray ( ) ) ;
242+ Running = RunningTask . None ;
243+ btnListSource . PerformClick ( ) ;
244+ }
245+ Running = RunningTask . None ;
229246 }
230247 private void TbSourceComputer_KeyDown ( object sender , KeyEventArgs e )
231248 {
@@ -256,11 +273,11 @@ private async void MiSaveLog_Click(object sender, EventArgs e)
256273 }
257274 private void Main_FormClosing ( object sender , FormClosingEventArgs e )
258275 {
259- if ( Running )
276+ if ( Running != RunningTask . None )
260277 {
261278 e . Cancel = true ;
262279 CloseRequested = true ;
263- USMT . Cancel ( ) ;
280+ BtStartStop_Click ( null , null ) ;
264281 }
265282 }
266283 private void MiAboutSG_Click ( object sender , EventArgs e )
@@ -286,4 +303,11 @@ public enum ListSources
286303 SourceComputer = 1 ,
287304 MigrationStore = 2
288305 }
306+ public enum RunningTask
307+ {
308+ Unknown = - 2 ,
309+ None = - 1 ,
310+ USMT = 1 ,
311+ RemoteProfileDelete = 2
312+ }
289313}
0 commit comments