@@ -36,6 +36,7 @@ public partial class MainWindow : Window
3636
3737 String IP = "" ;
3838 Boolean draggable = true ;
39+ Boolean running = false ;
3940 String exe = System . Reflection . Assembly . GetEntryAssembly ( ) . Location ;
4041 String Songs = "" ;
4142 String Playlists = "" ;
@@ -69,18 +70,34 @@ public MainWindow()
6970 }
7071 getBackups ( ) ;
7172 Update ( ) ;
73+
74+ RSongs . IsChecked = true ;
75+ RPlaylists . IsChecked = true ;
76+ RScores . IsChecked = true ;
77+ RMods . IsChecked = true ;
78+ RReplays . IsChecked = true ;
79+ RSounds . IsChecked = true ;
7280 }
7381
7482
7583 public void Backup ( object sender , RoutedEventArgs e )
7684 {
85+ if ( running )
86+ {
87+ return ;
88+ }
89+ running = true ;
90+
7791 //Create all Backup Folders
7892 BackupFSet ( ) ;
7993
8094 //Scores
95+ txtbox . AppendText ( "\n \n Backing up scores" ) ;
8196 adb ( "pull /sdcard/Android/data/com.beatgames.beatsaber/files/LocalDailyLeaderboards.dat \" " + Scores + "\" " ) ;
8297 adb ( "pull /sdcard/Android/data/com.beatgames.beatsaber/files/LocalLeaderboards.dat \" " + Scores + "\" " ) ;
8398 adb ( "pull /sdcard/Android/data/com.beatgames.beatsaber/files/PlayerData.dat \" " + Scores + "\" " ) ;
99+ txtbox . AppendText ( "\n Backed up scores\n " ) ;
100+ txtbox . ScrollToEnd ( ) ;
84101
85102 //Songs
86103
@@ -90,14 +107,39 @@ public void Backup(object sender, RoutedEventArgs e)
90107
91108 PlaylistB ( ) ;
92109 adb ( "pull /sdcard/BMBFData/Playlists/ \" " + Playlists + "\" " ) ;
110+ txtbox . ScrollToEnd ( ) ;
111+
112+ //Replays
113+
114+ txtbox . AppendText ( "\n \n Backing up replays" ) ;
115+ adb ( "pull /sdcard/Android/data/com.beatgames.beatsaber/files/replays \" " + BackupF + "\" " ) ;
116+ txtbox . AppendText ( "\n Backed up replays\n " ) ;
117+ txtbox . ScrollToEnd ( ) ;
118+
119+ //Sounds
120+
121+ txtbox . AppendText ( "\n \n Backing up sounds" ) ;
122+ adb ( "pull /sdcard/Android/data/com.beatgames.beatsaber/files/sounds \" " + BackupF + "\" " ) ;
123+ txtbox . AppendText ( "\n Backed up sounds\n " ) ;
124+ txtbox . ScrollToEnd ( ) ;
93125
94126 //Mods
95127
96128 ModsB ( ) ;
129+
130+ txtbox . AppendText ( "\n \n \n BMBF and Beat Saber Backup has been made." ) ;
131+ txtbox . ScrollToEnd ( ) ;
132+ running = false ;
97133 }
98134
99135 public void Restore ( object sender , RoutedEventArgs e )
100136 {
137+ if ( running )
138+ {
139+ return ;
140+ }
141+ running = true ;
142+
101143 if ( Backups . SelectedIndex == 0 )
102144 {
103145 txtbox . AppendText ( "\n \n Select a valid Backup!" ) ;
@@ -107,39 +149,100 @@ public void Restore(object sender, RoutedEventArgs e)
107149 //Get Backup Folders
108150 BackupFGet ( ) ;
109151
152+ //Check Quest IP
153+ Boolean good = CheckIP ( ) ;
154+ if ( ! good )
155+ {
156+ txtbox . AppendText ( "\n \n Choose a valid IP!" ) ;
157+ return ;
158+ }
159+
110160 //Scores
111161 if ( ( bool ) RScores . IsChecked == true )
112162 {
113- txtbox . AppendText ( "\n Pushing Scores" ) ;
163+ txtbox . AppendText ( "\n \ n Pushing Scores" ) ;
114164 adb ( "push \" " + Scores + "\\ LocalDailyLeaderboards.dat\" /sdcard/Android/data/com.beatgames.beatsaber/files/LocalDailyLeaderboards.dat" ) ;
115165 adb ( "push \" " + Scores + "\\ LocalLeaderboards.dat\" /sdcard/Android/data/com.beatgames.beatsaber/files/LocalLeaderboards.dat" ) ;
116166 adb ( "push \" " + Scores + "\\ PlayerData.dat\" /sdcard/Android/data/com.beatgames.beatsaber/files/PlayerData.dat" ) ;
117167 txtbox . AppendText ( "\n Pushed Scores" ) ;
168+ txtbox . ScrollToEnd ( ) ;
118169 }
119170
120171 //Playlists
121172 if ( ( bool ) RPlaylists . IsChecked )
122173 {
123174 PlaylistsR ( ) ;
124175 PushPNG ( Playlists + "\\ Playlists" ) ;
176+ txtbox . ScrollToEnd ( ) ;
177+ }
178+
179+ //Replays
180+ if ( ( bool ) RReplays . IsChecked )
181+ {
182+ txtbox . AppendText ( "\n \n Pushing Replays" ) ;
183+ adb ( "push \" " + BackupF + "//replays\" /sdcard/Android/data/com.beatgames.beatsaber/files/" ) ;
184+ txtbox . AppendText ( "\n Finished Pushing Replays" ) ;
185+ txtbox . ScrollToEnd ( ) ;
186+ }
187+
188+ //Sounds
189+ if ( ( bool ) RSounds . IsChecked )
190+ {
191+ txtbox . AppendText ( "\n \n Pushing Sounds" ) ;
192+ adb ( "push \" " + BackupF + "//sounds\" /sdcard/Android/data/com.beatgames.beatsaber/files/" ) ;
193+ txtbox . AppendText ( "\n Finished Pushing Sounds" ) ;
194+ txtbox . ScrollToEnd ( ) ;
125195 }
126196
127197 //Songs
128198 if ( ( bool ) RSongs . IsChecked )
129199 {
130- txtbox . AppendText ( "\n Uploading Songs" ) ;
200+ txtbox . AppendText ( "\n \ n Uploading Songs" ) ;
131201 Upload ( Songs ) ;
132202 txtbox . AppendText ( "\n Uploaded Songs" ) ;
203+ txtbox . ScrollToEnd ( ) ;
133204 }
134205
135206 //Mods
136207 if ( ( bool ) RMods . IsChecked )
137208 {
138- txtbox . AppendText ( "\n Uploading Mods" ) ;
209+ txtbox . AppendText ( "\n \ n Uploading Mods" ) ;
139210 Upload ( Mods ) ;
140211 txtbox . AppendText ( "\n Uploaded Mods" ) ;
212+ txtbox . ScrollToEnd ( ) ;
141213 }
142-
214+
215+ txtbox . AppendText ( "\n \n \n BMBF and Beat Saber has been restored with the selected components." ) ;
216+ txtbox . ScrollToEnd ( ) ;
217+ running = false ;
218+ }
219+
220+ public Boolean CheckIP ( )
221+ {
222+ getQuestIP ( ) ;
223+ if ( IP == "Quest IP" )
224+ {
225+ return false ;
226+ }
227+ IP . Replace ( ":50000" , "" ) ;
228+ IP . Replace ( ":5000" , "" ) ;
229+ IP . Replace ( ":500" , "" ) ;
230+ IP . Replace ( ":500" , "" ) ;
231+ IP . Replace ( ":50" , "" ) ;
232+ IP . Replace ( ":5" , "" ) ;
233+ int count = 0 ;
234+ for ( int i = 0 ; i < IP . Length ; i ++ )
235+ {
236+ if ( IP . Substring ( i , 1 ) == "." )
237+ {
238+ count ++ ;
239+ }
240+ }
241+ if ( count != 3 )
242+ {
243+ return false ;
244+ }
245+ return true ;
143246 }
144247
145248 public void PushPNG ( String Path )
@@ -164,6 +267,7 @@ public void PlaylistsR()
164267 try
165268 {
166269 getQuestIP ( ) ;
270+
167271
168272 String PlaylistsX ;
169273
@@ -244,22 +348,39 @@ public void postChanges(String Config)
244348 client . UploadValues ( "http://" + IP + ":50000/host/beatsaber/commitconfig" , "POST" , client . QueryString ) ;
245349 }
246350 }
351+ public void Sync ( )
352+ {
353+ System . Threading . Thread . Sleep ( 2000 ) ;
354+ using ( WebClient client = new WebClient ( ) )
355+ {
356+ client . QueryString . Add ( "foo" , "foo" ) ;
357+ client . UploadValues ( "http://" + IP + ":50000/host/beatsaber/commitconfig" , "POST" , client . QueryString ) ;
358+ }
359+ }
247360
248361 public void Upload ( String Path )
249362 {
250363 getQuestIP ( ) ;
251364 String [ ] directories = Directory . GetFiles ( Path ) ;
252365
253366
254-
255367 for ( int i = 0 ; i < directories . Length ; i ++ )
256368 {
257369 WebClient client = new WebClient ( ) ;
258-
259- txtbox . AppendText ( "\n Uploading " + directories [ i ] + " to BMBF" ) ;
260- client . UploadFile ( "http://" + IP + ":50000/host/beatsaber/upload?overwrite" , directories [ i ] ) ;
261- Application . Current . Dispatcher . Invoke ( DispatcherPriority . Background , new Action ( delegate { } ) ) ;
370+
371+ txtbox . AppendText ( "\n \n Uploading " + directories [ i ] + " to BMBF" ) ;
372+ Application . Current . Dispatcher . Invoke ( DispatcherPriority . Background , new Action ( delegate {
373+ client . UploadFile ( "http://" + IP + ":50000/host/beatsaber/upload?overwrite" , directories [ i ] ) ;
374+ } ) ) ;
375+
376+ if ( i % 20 == 0 && i != 0 )
377+ {
378+ txtbox . AppendText ( "\n \n Syncing to Beat Saber" ) ;
379+ Application . Current . Dispatcher . Invoke ( DispatcherPriority . Background , new Action ( delegate { } ) ) ;
380+ Sync ( ) ;
381+ }
262382 }
383+ Sync ( ) ;
263384 }
264385
265386 public void BackupFGet ( )
@@ -761,7 +882,7 @@ public void adb(String Argument)
761882 {
762883 // Start the process with the info we specified.
763884 // Call WaitForExit and then the using statement will close.
764- using ( Process exeProcess = Process . Start ( s ) )
885+ using ( Process exeProcess = Process . Start ( se ) )
765886 {
766887 exeProcess . WaitForExit ( ) ;
767888 }
0 commit comments