@@ -210,7 +210,7 @@ public void DisableAll()
210210 public bool IsActive ( MemoryDomain domain , long address )
211211 => _cheatList . Exists ( cheat => ! cheat . IsSeparator && cheat . Enabled && cheat . Domain == domain && cheat . Contains ( address ) ) ;
212212
213- public void SaveOnClose ( )
213+ public FileWriteResult SaveOnClose ( )
214214 {
215215 if ( _config . AutoSaveOnClose )
216216 {
@@ -221,17 +221,27 @@ public void SaveOnClose()
221221 CurrentFileName = _defaultFileName ;
222222 }
223223
224- SaveFile ( CurrentFileName ) ;
224+ return SaveFile ( CurrentFileName ) ;
225225 }
226226 else if ( _cheatList . Count is 0 && ! string . IsNullOrWhiteSpace ( CurrentFileName ) )
227227 {
228- 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+ }
229236 _config . Recent . Remove ( CurrentFileName ) ;
237+ return new ( ) ;
230238 }
231239 }
240+
241+ return new ( ) ;
232242 }
233243
234- public bool Save ( )
244+ public FileWriteResult Save ( )
235245 {
236246 if ( string . IsNullOrWhiteSpace ( CurrentFileName ) )
237247 {
@@ -241,54 +251,51 @@ public bool Save()
241251 return SaveFile ( CurrentFileName ) ;
242252 }
243253
244- public bool SaveFile ( string path )
254+ public FileWriteResult SaveFile ( string path )
245255 {
246- try
247- {
248- new FileInfo ( path ) . Directory ? . Create ( ) ;
249- var sb = new StringBuilder ( ) ;
256+ var sb = new StringBuilder ( ) ;
250257
251- foreach ( var cheat in _cheatList )
258+ foreach ( var cheat in _cheatList )
259+ {
260+ if ( cheat . IsSeparator )
252261 {
253- if ( cheat . IsSeparator )
254- {
255- sb . AppendLine ( "----" ) ;
256- }
257- else
258- {
259- // Set to hex for saving
260- var tempCheatType = cheat . Type ;
261-
262- cheat . SetType ( WatchDisplayType . Hex ) ;
263-
264- sb
265- . Append ( cheat . AddressStr ) . Append ( '\t ' )
266- . Append ( cheat . ValueStr ) . Append ( '\t ' )
267- . Append ( cheat . Compare is null ? "N" : cheat . CompareStr ) . Append ( '\t ' )
268- . Append ( cheat . Domain != null ? cheat . Domain . Name : "" ) . Append ( '\t ' )
269- . Append ( cheat . Enabled ? '1' : '0' ) . Append ( '\t ' )
270- . Append ( cheat . Name ) . Append ( '\t ' )
271- . Append ( cheat . SizeAsChar ) . Append ( '\t ' )
272- . Append ( cheat . TypeAsChar ) . Append ( '\t ' )
273- . Append ( cheat . BigEndian is true ? '1' : '0' ) . Append ( '\t ' )
274- . Append ( cheat . ComparisonType ) . Append ( '\t ' )
275- . AppendLine ( ) ;
276-
277- cheat . SetType ( tempCheatType ) ;
278- }
262+ sb . AppendLine ( "----" ) ;
279263 }
280-
281- File . WriteAllText ( path , sb . ToString ( ) ) ;
282-
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+ {
283294 CurrentFileName = path ;
284295 _config . Recent . Add ( CurrentFileName ) ;
285296 Changes = false ;
286- return true ;
287- }
288- catch
289- {
290- return false ;
291297 }
298+ return result ;
292299 }
293300
294301 public bool Load ( IMemoryDomains domains , string path , bool append )
0 commit comments