@@ -88,20 +88,10 @@ public bool AttemptToLoadCheatFile(IMemoryDomains domains)
8888 return file . Exists && Load ( domains , file . FullName , false ) ;
8989 }
9090
91- public void NewList ( string defaultFileName , bool autosave = false )
91+ public void NewList ( string defaultFileName )
9292 {
9393 _defaultFileName = defaultFileName ;
9494
95- if ( autosave && _changes && _cheatList . Count is not 0 )
96- {
97- if ( string . IsNullOrEmpty ( CurrentFileName ) )
98- {
99- CurrentFileName = _defaultFileName ;
100- }
101-
102- Save ( ) ;
103- }
104-
10595 _cheatList . Clear ( ) ;
10696 CurrentFileName = "" ;
10797 Changes = false ;
@@ -220,7 +210,7 @@ public void DisableAll()
220210 public bool IsActive ( MemoryDomain domain , long address )
221211 => _cheatList . Exists ( cheat => ! cheat . IsSeparator && cheat . Enabled && cheat . Domain == domain && cheat . Contains ( address ) ) ;
222212
223- public void SaveOnClose ( )
213+ public FileWriteResult SaveOnClose ( )
224214 {
225215 if ( _config . AutoSaveOnClose )
226216 {
@@ -231,17 +221,27 @@ public void SaveOnClose()
231221 CurrentFileName = _defaultFileName ;
232222 }
233223
234- SaveFile ( CurrentFileName ) ;
224+ return SaveFile ( CurrentFileName ) ;
235225 }
236226 else if ( _cheatList . Count is 0 && ! string . IsNullOrWhiteSpace ( CurrentFileName ) )
237227 {
238- File . Delete ( CurrentFileName ) ;
228+ try
229+ {
230+ File . Delete ( CurrentFileName ) ;
231+ }
232+ catch ( Exception ex )
233+ {
234+ return new ( FileWriteEnum . FailedToDeleteGeneric , new ( CurrentFileName , "" ) , ex ) ;
235+ }
239236 _config . Recent . Remove ( CurrentFileName ) ;
237+ return new ( ) ;
240238 }
241239 }
240+
241+ return new ( ) ;
242242 }
243243
244- public bool Save ( )
244+ public FileWriteResult Save ( )
245245 {
246246 if ( string . IsNullOrWhiteSpace ( CurrentFileName ) )
247247 {
@@ -251,54 +251,51 @@ public bool Save()
251251 return SaveFile ( CurrentFileName ) ;
252252 }
253253
254- public bool SaveFile ( string path )
254+ public FileWriteResult SaveFile ( string path )
255255 {
256- try
257- {
258- new FileInfo ( path ) . Directory ? . Create ( ) ;
259- var sb = new StringBuilder ( ) ;
256+ var sb = new StringBuilder ( ) ;
260257
261- foreach ( var cheat in _cheatList )
258+ foreach ( var cheat in _cheatList )
259+ {
260+ if ( cheat . IsSeparator )
262261 {
263- if ( cheat . IsSeparator )
264- {
265- sb . AppendLine ( "----" ) ;
266- }
267- else
268- {
269- // Set to hex for saving
270- var tempCheatType = cheat . Type ;
271-
272- cheat . SetType ( WatchDisplayType . Hex ) ;
273-
274- sb
275- . Append ( cheat . AddressStr ) . Append ( '\t ' )
276- . Append ( cheat . ValueStr ) . Append ( '\t ' )
277- . Append ( cheat . Compare is null ? "N" : cheat . CompareStr ) . Append ( '\t ' )
278- . Append ( cheat . Domain != null ? cheat . Domain . Name : "" ) . Append ( '\t ' )
279- . Append ( cheat . Enabled ? '1' : '0' ) . Append ( '\t ' )
280- . Append ( cheat . Name ) . Append ( '\t ' )
281- . Append ( cheat . SizeAsChar ) . Append ( '\t ' )
282- . Append ( cheat . TypeAsChar ) . Append ( '\t ' )
283- . Append ( cheat . BigEndian is true ? '1' : '0' ) . Append ( '\t ' )
284- . Append ( cheat . ComparisonType ) . Append ( '\t ' )
285- . AppendLine ( ) ;
286-
287- cheat . SetType ( tempCheatType ) ;
288- }
262+ sb . AppendLine ( "----" ) ;
289263 }
290-
291- File . WriteAllText ( path , sb . ToString ( ) ) ;
292-
264+ else
265+ {
266+ // Set to hex for saving
267+ var tempCheatType = cheat . Type ;
268+
269+ cheat . SetType ( WatchDisplayType . Hex ) ;
270+
271+ sb
272+ . Append ( cheat . AddressStr ) . Append ( '\t ' )
273+ . Append ( cheat . ValueStr ) . Append ( '\t ' )
274+ . Append ( cheat . Compare is null ? "N" : cheat . CompareStr ) . Append ( '\t ' )
275+ . Append ( cheat . Domain != null ? cheat . Domain . Name : "" ) . Append ( '\t ' )
276+ . Append ( cheat . Enabled ? '1' : '0' ) . Append ( '\t ' )
277+ . Append ( cheat . Name ) . Append ( '\t ' )
278+ . Append ( cheat . SizeAsChar ) . Append ( '\t ' )
279+ . Append ( cheat . TypeAsChar ) . Append ( '\t ' )
280+ . Append ( cheat . BigEndian is true ? '1' : '0' ) . Append ( '\t ' )
281+ . Append ( cheat . ComparisonType ) . Append ( '\t ' )
282+ . AppendLine ( ) ;
283+
284+ cheat . SetType ( tempCheatType ) ;
285+ }
286+ }
287+ FileWriteResult result = FileWriter . Write ( path , ( fs ) =>
288+ {
289+ StreamWriter sw = new ( fs ) ;
290+ sw . Write ( sb . ToString ( ) ) ;
291+ } ) ;
292+ if ( ! result . IsError )
293+ {
293294 CurrentFileName = path ;
294295 _config . Recent . Add ( CurrentFileName ) ;
295296 Changes = false ;
296- return true ;
297- }
298- catch
299- {
300- return false ;
301297 }
298+ return result ;
302299 }
303300
304301 public bool Load ( IMemoryDomains domains , string path , bool append )
0 commit comments