@@ -103,23 +103,12 @@ public PublishModDialogViewModel(PathTuple<ModConfig> modTuple)
103103 _modTuple = modTuple ;
104104 PackageName = IOEx . ForceValidFilePath ( _modTuple . Config . ModName . Replace ( ' ' , '_' ) ) ;
105105 OutputFolder = Path . Combine ( Path . GetTempPath ( ) , $ "{ IOEx . ForceValidFilePath ( _modTuple . Config . ModId ) } .Publish") ;
106-
107- // Set default Regexes.
108- IgnoreRegexes = new ObservableCollection < StringWrapper > ( )
109- {
110- @".*\.json" , // Config files
111- $ "{ Regex . Escape ( $@ "{ _modTuple . Config . ModId } .nuspec") } "
112- } ;
113-
114- IncludeRegexes = new ObservableCollection < StringWrapper > ( )
115- {
116- Regex . Escape ( ModConfig . ConfigFileName ) ,
117- @"\.deps\.json" ,
118- @"\.runtimeconfig\.json" ,
119- } ;
120-
121- // Set notifications
122- PropertyChanged += ChangeUiVisbilityOnPropertyChanged ;
106+ IgnoreRegexes = new ObservableCollection < StringWrapper > (
107+ _modTuple . Config . IgnoreRegexes . Select ( x => new StringWrapper { Value = x } )
108+ ) ;
109+ IncludeRegexes = new ObservableCollection < StringWrapper > (
110+ _modTuple . Config . IncludeRegexes . Select ( x => new StringWrapper { Value = x } )
111+ ) ;
123112 }
124113
125114 /// <summary>
@@ -129,6 +118,9 @@ public PublishModDialogViewModel(PathTuple<ModConfig> modTuple)
129118 /// <returns>True if a build has started and the operation completed, else false.</returns>
130119 public async Task < bool > BuildAsync ( CancellationToken cancellationToken = default )
131120 {
121+ // Save all changes before building to ensure config is current
122+ await SaveAsync ( ) ;
123+
132124 // Check if Auto Delta can be performed.
133125 if ( AutomaticDelta && ! Singleton < ReleaseMetadata > . Instance . CanReadFromDirectory ( OutputFolder , null , out _ , out _ ) )
134126 {
@@ -148,8 +140,8 @@ await PublishAsync(new PublishArgs()
148140 PublishTarget = PublishTarget ,
149141 OutputFolder = OutputFolder ,
150142 ModTuple = _modTuple ,
151- IgnoreRegexes = IgnoreRegexes . Select ( x => x . Value ) . ToList ( ) ,
152- IncludeRegexes = IncludeRegexes . Select ( x => x . Value ) . ToList ( ) ,
143+ IgnoreRegexes = _modTuple . Config . IgnoreRegexes ,
144+ IncludeRegexes = _modTuple . Config . IncludeRegexes ,
153145 Progress = new Progress < double > ( d => BuildProgress = d * 100 ) ,
154146 AutomaticDelta = AutomaticDelta ,
155147 CompressionLevel = CompressionLevel ,
@@ -286,6 +278,23 @@ public void SetOutputFolder()
286278 /// </summary>
287279 public void SetReadmePath ( ) => ReadmePath = FileSelectors . SelectMarkdownFile ( ) ;
288280
281+ /// <summary>
282+ /// Saves all changes to the mod config.
283+ /// Automatically syncs collections before saving to ensure all in-memory edits are persisted.
284+ /// </summary>
285+ public async Task SaveAsync ( )
286+ {
287+ UpdateConfig ( _modTuple . Config . IgnoreRegexes , IgnoreRegexes ) ;
288+ UpdateConfig ( _modTuple . Config . IncludeRegexes , IncludeRegexes ) ;
289+ await _modTuple . SaveAsync ( ) ;
290+
291+ void UpdateConfig ( List < string > list , ObservableCollection < StringWrapper > collection )
292+ {
293+ list . Clear ( ) ;
294+ list . AddRange ( collection . Select ( x => x . Value ) ) ;
295+ }
296+ }
297+
289298 private string GetModFolder ( ) => Path . GetDirectoryName ( _modTuple . Path ) ! ;
290299
291300
@@ -296,10 +305,4 @@ private void RemoveSelectedOrLastItem(StringWrapper? item, ObservableCollection<
296305 else if ( allItems . Count > 0 )
297306 allItems . RemoveAt ( allItems . Count - 1 ) ;
298307 }
299-
300- private void ChangeUiVisbilityOnPropertyChanged ( object ? sender , PropertyChangedEventArgs e )
301- {
302- if ( e . PropertyName == nameof ( PublishTarget ) )
303- ShowLastVersionUiItems = PublishTarget != PublishTarget . NuGet ;
304- }
305308}
0 commit comments