@@ -152,6 +152,7 @@ public AboutViewModel About
152152
153153 #region Fields
154154 private SaveLoad _SaveLoad ;
155+ private string _SavePath ;
155156 private SaveFile _SaveFile ;
156157 private readonly ICommand _NewSaveFromPlayerClass ;
157158
@@ -172,6 +173,19 @@ public IEnumerable<PlayerClassDefinition> PlayerClasses
172173 }
173174 }
174175
176+ public string SavePath
177+ {
178+ get { return this . _SavePath ; }
179+ private set
180+ {
181+ if ( this . _SavePath != value )
182+ {
183+ this . _SavePath = value ;
184+ this . NotifyOfPropertyChange ( nameof ( SavePath ) ) ;
185+ }
186+ }
187+ }
188+
175189 public SaveFile SaveFile
176190 {
177191 get { return this . _SaveFile ; }
@@ -350,6 +364,7 @@ public IEnumerable<IResult> ReadSave()
350364 this . Backpack . ImportData ( saveFile . SaveGame , saveFile . Platform ) ;
351365 this . Bank . ImportData ( saveFile . SaveGame , saveFile . Platform ) ;
352366 this . FastTravel . ImportData ( saveFile . SaveGame ) ;
367+ this . SavePath = fileName ;
353368 this . SaveFile = saveFile ;
354369 this . MaybeSwitchToGeneral ( ) ;
355370 }
@@ -388,7 +403,6 @@ public IEnumerable<IResult> ReadSave()
388403 . WithIcon ( MessageBoxImage . Information ) ;
389404 }
390405
391-
392406 if ( this . SaveFile != null &&
393407 this . Backpack . BrokenWeapons . Count > 0 )
394408 {
@@ -416,11 +430,12 @@ public IEnumerable<IResult> ReadSave()
416430 else if ( result == MessageBoxResult . Cancel )
417431 {
418432 var sb = new StringBuilder ( ) ;
419- this . Backpack . BrokenWeapons . ForEach ( kv =>
420- {
421- sb . AppendLine ( kv . Value . ToString ( ) ) ;
422- sb . AppendLine ( ) ;
423- } ) ;
433+ this . Backpack . BrokenWeapons . ForEach (
434+ kv =>
435+ {
436+ sb . AppendLine ( kv . Value . ToString ( ) ) ;
437+ sb . AppendLine ( ) ;
438+ } ) ;
424439 if ( MyClipboard . SetText ( sb . ToString ( ) ) != MyClipboard . Result . Success )
425440 {
426441 MessageBox . Show ( "Clipboard failure." , "Error" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
@@ -457,11 +472,12 @@ public IEnumerable<IResult> ReadSave()
457472 else if ( result == MessageBoxResult . Cancel )
458473 {
459474 var sb = new StringBuilder ( ) ;
460- this . Backpack . BrokenItems . ForEach ( kv =>
461- {
462- sb . AppendLine ( kv . Value . ToString ( ) ) ;
463- sb . AppendLine ( ) ;
464- } ) ;
475+ this . Backpack . BrokenItems . ForEach (
476+ kv =>
477+ {
478+ sb . AppendLine ( kv . Value . ToString ( ) ) ;
479+ sb . AppendLine ( ) ;
480+ } ) ;
465481 if ( MyClipboard . SetText ( sb . ToString ( ) ) != MyClipboard . Result . Success )
466482 {
467483 MessageBox . Show ( "Clipboard failure." , "Error" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
@@ -498,11 +514,12 @@ public IEnumerable<IResult> ReadSave()
498514 else if ( result == MessageBoxResult . Cancel )
499515 {
500516 var sb = new StringBuilder ( ) ;
501- this . Bank . BrokenSlots . ForEach ( kv =>
502- {
503- sb . AppendLine ( kv . Value . ToString ( ) ) ;
504- sb . AppendLine ( ) ;
505- } ) ;
517+ this . Bank . BrokenSlots . ForEach (
518+ kv =>
519+ {
520+ sb . AppendLine ( kv . Value . ToString ( ) ) ;
521+ sb . AppendLine ( ) ;
522+ } ) ;
506523 if ( MyClipboard . SetText ( sb . ToString ( ) ) != MyClipboard . Result . Success )
507524 {
508525 MessageBox . Show ( "Clipboard failure." , "Error" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
@@ -514,20 +531,41 @@ public IEnumerable<IResult> ReadSave()
514531 }
515532
516533 public IEnumerable < IResult > WriteSave ( )
534+ {
535+ if ( this . SaveFile == null || string . IsNullOrEmpty ( this . SavePath ) == true )
536+ {
537+ yield break ;
538+ }
539+
540+ var savePath = this . SavePath ;
541+ var saveFile = this . SaveFile ;
542+
543+ yield return new DelegateResult (
544+ ( ) => WriteSave ( savePath , saveFile ) )
545+ . Rescue ( )
546+ . Execute (
547+ x =>
548+ new MyMessageBox (
549+ $ "An exception was thrown (press Ctrl+C to copy):\n \n { x . ToString ( ) } ",
550+ "Error" )
551+ . WithIcon ( MessageBoxImage . Error ) . AsCoroutine ( ) ) ;
552+ }
553+
554+ public IEnumerable < IResult > WriteSaveAs ( )
517555 {
518556 if ( this . SaveFile == null )
519557 {
520558 yield break ;
521559 }
522560
523- string fileName = null ;
561+ string savePath = null ;
524562
525- foreach ( var result in this . SaveLoad . SaveFile ( s => fileName = s ) )
563+ foreach ( var result in this . SaveLoad . SaveFile ( s => savePath = s ) )
526564 {
527565 yield return result ;
528566 }
529567
530- if ( fileName == null )
568+ if ( savePath == null )
531569 {
532570 yield break ;
533571 }
@@ -537,48 +575,56 @@ public IEnumerable<IResult> WriteSave()
537575 yield return new DelegateResult (
538576 ( ) =>
539577 {
540- this . General . ExportData ( saveFile . SaveGame , out var platform ) ;
541- this . Character . ExportData ( saveFile . SaveGame ) ;
542- this . Vehicle . ExportData ( saveFile . SaveGame ) ;
543- this . CurrencyOnHand . ExportData ( saveFile . SaveGame ) ;
544- this . Backpack . ExportData ( saveFile . SaveGame , platform ) ;
545- this . Bank . ExportData ( saveFile . SaveGame , platform ) ;
546- this . FastTravel . ExportData ( saveFile . SaveGame ) ;
547-
548- if ( saveFile . SaveGame != null &&
549- saveFile . SaveGame . WeaponData != null )
550- {
551- saveFile . SaveGame . WeaponData . RemoveAll (
552- wd =>
553- Blacklisting . IsBlacklistedType ( wd . Type ) == true ||
554- Blacklisting . IsBlacklistedBalance ( wd . Balance ) == true ) ;
555- }
556-
557- if ( saveFile . SaveGame != null &&
558- saveFile . SaveGame . ItemData != null )
559- {
560- saveFile . SaveGame . ItemData . RemoveAll (
561- wd =>
562- Blacklisting . IsBlacklistedType ( wd . Type ) == true ||
563- Blacklisting . IsBlacklistedBalance ( wd . Balance ) == true ) ;
564- }
565-
566- using ( var output = File . Create ( fileName ) )
567- {
568- FileFormats . SaveExpansion . AddExpansionSavedataToUnloadableItemData (
569- saveFile . SaveGame ) ;
570- saveFile . Platform = platform ;
571- saveFile . Serialize ( output ) ;
572- FileFormats . SaveExpansion
573- . ExtractExpansionSavedataFromUnloadableItemData (
574- saveFile . SaveGame ) ;
575- }
576- } ) . Rescue ( ) . Execute (
578+ this . WriteSave ( savePath , saveFile ) ;
579+ this . SavePath = savePath ;
580+ } )
581+ . Rescue ( )
582+ . Execute (
577583 x =>
578584 new MyMessageBox (
579585 $ "An exception was thrown (press Ctrl+C to copy):\n \n { x . ToString ( ) } ",
580586 "Error" )
581587 . WithIcon ( MessageBoxImage . Error ) . AsCoroutine ( ) ) ;
582588 }
589+
590+ private void WriteSave ( string savePath , SaveFile saveFile )
591+ {
592+ this . General . ExportData ( saveFile . SaveGame , out var platform ) ;
593+ this . Character . ExportData ( saveFile . SaveGame ) ;
594+ this . Vehicle . ExportData ( saveFile . SaveGame ) ;
595+ this . CurrencyOnHand . ExportData ( saveFile . SaveGame ) ;
596+ this . Backpack . ExportData ( saveFile . SaveGame , platform ) ;
597+ this . Bank . ExportData ( saveFile . SaveGame , platform ) ;
598+ this . FastTravel . ExportData ( saveFile . SaveGame ) ;
599+
600+ if ( saveFile . SaveGame != null &&
601+ saveFile . SaveGame . WeaponData != null )
602+ {
603+ saveFile . SaveGame . WeaponData . RemoveAll (
604+ wd =>
605+ Blacklisting . IsBlacklistedType ( wd . Type ) == true ||
606+ Blacklisting . IsBlacklistedBalance ( wd . Balance ) == true ) ;
607+ }
608+
609+ if ( saveFile . SaveGame != null &&
610+ saveFile . SaveGame . ItemData != null )
611+ {
612+ saveFile . SaveGame . ItemData . RemoveAll (
613+ wd =>
614+ Blacklisting . IsBlacklistedType ( wd . Type ) == true ||
615+ Blacklisting . IsBlacklistedBalance ( wd . Balance ) == true ) ;
616+ }
617+
618+ using ( var output = File . Create ( savePath ) )
619+ {
620+ FileFormats . SaveExpansion . AddExpansionSavedataToUnloadableItemData (
621+ saveFile . SaveGame ) ;
622+ saveFile . Platform = platform ;
623+ saveFile . Serialize ( output ) ;
624+ FileFormats . SaveExpansion
625+ . ExtractExpansionSavedataFromUnloadableItemData (
626+ saveFile . SaveGame ) ;
627+ }
628+ }
583629 }
584630}
0 commit comments