@@ -266,88 +266,107 @@ private async void UpdateFromModdedRomFs_Click(object sender, EventArgs e)
266266
267267 if ( folderBrowserDialog . ShowDialog ( ) == DialogResult . OK )
268268 {
269- var moddedRomFsPath = folderBrowserDialog . SelectedPath ;
269+ CreateUpdatedRSTBFromModdedRomFs ( LoadedFile , folderBrowserDialog . SelectedPath ) ;
270270
271- var allFiles = Directory . GetFiles ( moddedRomFsPath , "*" , SearchOption . AllDirectories ) ;
271+ TopMenu . Enabled = true ;
272+ statusBar . Visible = false ;
273+ statusProgressBar . Visible = false ;
274+
275+ PopulateGridView ( ) ;
272276
273- List < string > changedFiles = [ ] ;
274- List < string > addedFiles = [ ] ;
275- int skippedFiles = 0 ;
276- int removedFiles = 0 ;
277+ //foreach (DataGridViewRow row in mainDataGridView.Rows)
278+ //{
279+ // var name = row.Cells[0].Value.ToString();
277280
278- TopMenu . Enabled = false ;
281+ // if (changedFiles.Contains(name))
282+ // row.DefaultCellStyle.BackColor = Color.Yellow;
279283
280- statusLabel . Text = $ "" ;
281- statusBar . Visible = true ;
282- statusProgressBar . Visible = true ;
283- statusProgressBar . Maximum = allFiles . Length ;
284- statusProgressBar . Value = 0 ;
284+ // if (addedFiles.Contains(name))
285+ // row.DefaultCellStyle.BackColor = Color.Green ;
286+ //}
287+ }
288+ }
285289
286- var progress = new Progress < ( int Index , string FileName ) > ( value =>
287- {
288- statusLabel . Text = $ "Getting file size... { value . FileName } ({ value . Index } /{ allFiles . Length } )";
289- statusProgressBar . Value = value . Index ;
290- } ) ;
290+ public async void CreateUpdatedRSTBFromModdedRomFs ( ResourceTable rstb , string moddedRomFsPath , bool showResults = true )
291+ {
292+ var allFiles = Directory . GetFiles ( moddedRomFsPath , "*" , SearchOption . AllDirectories ) ;
293+
294+ List < string > changedFiles = [ ] ;
295+ List < string > addedFiles = [ ] ;
296+ int skippedFiles = 0 ;
297+ int removedFiles = 0 ;
298+
299+ TopMenu . Enabled = false ;
300+
301+ statusLabel . Text = $ "" ;
302+ statusBar . Visible = true ;
303+ statusProgressBar . Visible = true ;
304+ statusProgressBar . Maximum = allFiles . Length ;
305+ statusProgressBar . Value = 0 ;
291306
292- await Task . Run ( ( ) =>
307+ var progress = new Progress < ( int Index , string FileName ) > ( value =>
308+ {
309+ statusLabel . Text = $ "Getting file size... { value . FileName } ({ value . Index } /{ allFiles . Length } )";
310+ statusProgressBar . Value = value . Index ;
311+ } ) ;
312+
313+ await Task . Run ( ( ) =>
314+ {
315+ int currentPosition = 1 ;
316+
317+ foreach ( var originalFile in allFiles )
293318 {
294- int currentPosition = 1 ;
319+ if ( IsDisposed || Disposing ) break ;
295320
296- foreach ( var originalFile in allFiles )
321+ var path = Path . GetRelativePath ( moddedRomFsPath , originalFile ) . Replace ( '\\ ' , '/' ) ;
322+ if ( path == "System/Resource/ResourceSizeTable.srsizetable" || path == "System/Resource/ResourceSizeTable.rsizetable" )
297323 {
298- if ( IsDisposed || Disposing ) break ;
299-
300- var path = Path . GetRelativePath ( moddedRomFsPath , originalFile ) . Replace ( '\\ ' , '/' ) ;
301- if ( path == "System/Resource/ResourceSizeTable.srsizetable" || path == "System/Resource/ResourceSizeTable.rsizetable" )
302- {
303- skippedFiles ++ ;
304- continue ;
305- }
324+ skippedFiles ++ ;
325+ continue ;
326+ }
306327
307- if ( path . EndsWith ( ".byml" ) && path != "EventFlow/Info/EventFlowInfoProduct.byml" )
308- continue ;
309-
328+ if ( path . EndsWith ( ".byml" ) && path != "EventFlow/Info/EventFlowInfoProduct.byml" )
329+ continue ;
310330
311- ( progress as IProgress < ( int , string ) > ) . Report ( ( currentPosition , path ) ) ;
312331
313- if ( path . EndsWith ( ".zs" ) )
314- path = path [ ..^ 3 ] ;
332+ ( progress as IProgress < ( int , string ) > ) . Report ( ( currentPosition , path ) ) ;
315333
316- var fileSize = GetFileSize ( originalFile ) ;
334+ if ( path . EndsWith ( ".zs" ) )
335+ path = path [ ..^ 3 ] ;
317336
318- if ( fileSize < 0 )
319- {
320- // remove unsupported file from rstb
321- if ( fileSize == - 2 )
322- Console . WriteLine ( "Unsupported: {0}" , path ) ;
337+ var fileSize = GetFileSize ( originalFile ) ;
323338
324- LoadedFile . Dictionary . Remove ( path ) ;
325- removedFiles ++ ;
326- }
327- else if ( LoadedFile . Dictionary . TryGetValue ( path , out var result ) && fileSize >= 0 && fileSize != result . FileSize )
328- {
329- result . FileSize = ( uint ) fileSize ;
330- changedFiles . Add ( path ) ;
331- }
339+ if ( fileSize < 0 )
340+ {
341+ // remove unsupported file from rstb
342+ if ( fileSize == - 2 )
343+ Console . WriteLine ( "Unsupported: {0}" , path ) ;
332344
333- else if ( ! LoadedFile . Dictionary . ContainsKey ( path ) && fileSize >= 0 )
334- {
335- LoadedFile . AddEntry ( new ResourceTable . ResourceTableEntry ( path , ( uint ) fileSize , 0 , false ) ) ;
345+ rstb . Dictionary . Remove ( path ) ;
346+ removedFiles ++ ;
347+ }
348+ else if ( rstb . Dictionary . TryGetValue ( path , out var result ) && fileSize >= 0 && fileSize != result . FileSize )
349+ {
350+ result . FileSize = ( uint ) fileSize ;
351+ changedFiles . Add ( path ) ;
352+ }
336353
337- addedFiles . Add ( path ) ;
338- }
354+ else if ( ! rstb . Dictionary . ContainsKey ( path ) && fileSize >= 0 )
355+ {
356+ rstb . AddEntry ( new ResourceTable . ResourceTableEntry ( path , ( uint ) fileSize , 0 , false ) ) ;
339357
340- currentPosition ++ ;
358+ addedFiles . Add ( path ) ;
341359 }
342360
343- if ( IsDisposed || Disposing ) return ;
361+ currentPosition ++ ;
362+ }
344363
345- } ) ;
364+ if ( IsDisposed || Disposing ) return ;
346365
347- TopMenu . Enabled = true ;
348- statusBar . Visible = false ;
349- statusProgressBar . Visible = false ;
366+ } ) ;
350367
368+ if ( showResults )
369+ {
351370 if ( changedFiles . Count > 0 || addedFiles . Count > 0 )
352371 {
353372 MessageBox . Show ( $ "Successfully updated table values!" +
@@ -358,20 +377,6 @@ await Task.Run(() =>
358377 "\n \n You need to manually save your file in File > Save as..." ,
359378 "Complete" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
360379 }
361-
362-
363- PopulateGridView ( ) ;
364-
365- //foreach (DataGridViewRow row in mainDataGridView.Rows)
366- //{
367- // var name = row.Cells[0].Value.ToString();
368-
369- // if (changedFiles.Contains(name))
370- // row.DefaultCellStyle.BackColor = Color.Yellow;
371-
372- // if (addedFiles.Contains(name))
373- // row.DefaultCellStyle.BackColor = Color.Green;
374- //}
375380 }
376381 }
377382
0 commit comments