@@ -242,7 +242,7 @@ private void MenuItemSaveInformationAsClick(object sender, EventArgs e)
242242 FileName = File . Exists ( _informationFileName ) ? Path . GetFileName ( _informationFileName ) : "*.txt" ,
243243 DefaultExt = "txt" ,
244244 RestoreDirectory = false ,
245- Filter = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*"
245+ Filter = "Text Documents (*.txt)|*.txt|XML Documents (*.xml)|*.xml| All Files (*.*)|*.*"
246246 } ;
247247
248248 if ( ! File . Exists ( _informationFileName ) )
@@ -253,8 +253,23 @@ private void MenuItemSaveInformationAsClick(object sender, EventArgs e)
253253 if ( dialog . ShowDialog ( ) != DialogResult . Cancel )
254254 {
255255 _informationFileName = dialog . FileName ;
256- var content = gvInformation . Tag != null ? ( ( WindowInformation ) gvInformation . Tag ) . ToString ( ) : string . Empty ;
257- File . WriteAllText ( dialog . FileName , content , Encoding . UTF8 ) ;
256+ var fileExtension = Path . GetExtension ( dialog . FileName ) . ToLower ( ) ;
257+ if ( fileExtension == ".xml" )
258+ {
259+ var information = ( WindowInformation ) gvInformation . Tag ;
260+ var document = new XDocument ( ) ;
261+ var elements = new XElement ( "information" ,
262+ new XElement ( "cursorInformation" , information . CursorDetails . Select ( x => new XElement ( "item" , new XAttribute ( "name" , x . Key ) , new XAttribute ( "value" , x . Value ) ) ) ) ,
263+ new XElement ( "windowInformation" , information . WindowDetails . Select ( x => new XElement ( "item" , new XAttribute ( "name" , x . Key ) , new XAttribute ( "value" , x . Value ) ) ) ) ,
264+ new XElement ( "processInformation" , information . ProcessDetails . Select ( x => new XElement ( "item" , new XAttribute ( "name" , x . Key ) , new XAttribute ( "value" , x . Value ) ) ) ) ) ;
265+ document . Add ( elements ) ;
266+ FileUtils . Save ( dialog . FileName , document ) ;
267+ }
268+ else
269+ {
270+ var content = gvInformation . Tag != null ? ( ( WindowInformation ) gvInformation . Tag ) . ToString ( ) : string . Empty ;
271+ File . WriteAllText ( dialog . FileName , content , Encoding . UTF8 ) ;
272+ }
258273 }
259274 }
260275
@@ -290,10 +305,10 @@ private void MenuItemSaveTextListAsClick(object sender, EventArgs e)
290305 OverwritePrompt = true ,
291306 ValidateNames = true ,
292307 Title = "Save As" ,
293- FileName = File . Exists ( _textListFileName ) ? Path . GetFileName ( _textListFileName ) : "*.xml " ,
294- DefaultExt = "xml " ,
308+ FileName = File . Exists ( _textListFileName ) ? Path . GetFileName ( _textListFileName ) : "*.txt " ,
309+ DefaultExt = "txt " ,
295310 RestoreDirectory = false ,
296- Filter = "XML Documents (*.xml)|*.xml|All Files (*.*)|*.*"
311+ Filter = "Text Documents (*.txt)|*.txt| XML Documents (*.xml)|*.xml|All Files (*.*)|*.*"
297312 } ;
298313
299314 if ( ! File . Exists ( _textListFileName ) )
@@ -304,9 +319,18 @@ private void MenuItemSaveTextListAsClick(object sender, EventArgs e)
304319 if ( dialog . ShowDialog ( ) != DialogResult . Cancel )
305320 {
306321 _textListFileName = dialog . FileName ;
307- var document = new XDocument ( ) ;
308- document . Add ( new XElement ( "items" , gvTextList . Rows . OfType < DataGridViewRow > ( ) . Select ( x => new XElement ( "item" , ( ( string ) x . Cells [ 0 ] . Value ) ?? string . Empty ) ) ) ) ;
309- FileUtils . Save ( _textListFileName , document ) ;
322+ var fileExtension = Path . GetExtension ( dialog . FileName ) . ToLower ( ) ;
323+ if ( fileExtension == ".xml" )
324+ {
325+ var document = new XDocument ( ) ;
326+ document . Add ( new XElement ( "items" , gvTextList . Rows . OfType < DataGridViewRow > ( ) . Select ( x => new XElement ( "item" , ( ( string ) x . Cells [ 0 ] . Value ) ?? string . Empty ) ) ) ) ;
327+ FileUtils . Save ( dialog . FileName , document ) ;
328+ }
329+ else
330+ {
331+ var content = string . Join ( $ "{ Environment . NewLine } { new string ( '-' , 100 ) } { Environment . NewLine } ", gvTextList . Rows . OfType < DataGridViewRow > ( ) . Select ( x => ( ( string ) x . Cells [ 0 ] . Value ) ?? string . Empty ) ) ;
332+ File . WriteAllText ( dialog . FileName , content , Encoding . UTF8 ) ;
333+ }
310334 }
311335 }
312336
@@ -336,7 +360,8 @@ private void MenuItemSaveImageAsClick(object sender, EventArgs e)
336360 fileExtension == ".gif" ? ImageFormat . Gif :
337361 fileExtension == ".jpeg" ? ImageFormat . Jpeg :
338362 fileExtension == ".png" ? ImageFormat . Png :
339- fileExtension == ".tiff" ? ImageFormat . Tiff : ImageFormat . Wmf ;
363+ fileExtension == ".tiff" ? ImageFormat . Tiff :
364+ fileExtension == ".wmf" ? ImageFormat . Wmf : ImageFormat . Bmp ;
340365 pbContent . Image . Save ( dialog . FileName , imageFormat ) ;
341366 }
342367 }
@@ -351,7 +376,7 @@ private void MenuItemSaveEnvironmentAsClick(object sender, EventArgs e)
351376 FileName = File . Exists ( _environmentFileName ) ? Path . GetFileName ( _environmentFileName ) : "*.txt" ,
352377 DefaultExt = "txt" ,
353378 RestoreDirectory = false ,
354- Filter = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*"
379+ Filter = "Text Documents (*.txt)|*.txt|XML Documents (*.xml)|*.xml| All Files (*.*)|*.*"
355380 } ;
356381
357382 if ( ! File . Exists ( _environmentFileName ) )
@@ -362,18 +387,31 @@ private void MenuItemSaveEnvironmentAsClick(object sender, EventArgs e)
362387 if ( dialog . ShowDialog ( ) != DialogResult . Cancel )
363388 {
364389 _environmentFileName = dialog . FileName ;
365- var content = string . Empty ;
366- if ( gvEnvironment . Tag is IDictionary < string , string > variables )
390+ var fileExtension = Path . GetExtension ( dialog . FileName ) . ToLower ( ) ;
391+ if ( fileExtension == ".xml" )
367392 {
368- const int paddingSize = 25 ;
369- var builder = new StringBuilder ( 1024 ) ;
370- foreach ( var variableKey in variables . Keys )
393+ if ( gvEnvironment . Tag is IDictionary < string , string > variables )
371394 {
372- builder . AppendLine ( $ "{ variableKey , - paddingSize } : { variables [ variableKey ] } ") ;
395+ var document = new XDocument ( ) ;
396+ document . Add ( new XElement ( "items" , variables . Select ( x => new XElement ( "item" , new XAttribute ( "name" , x . Key ) , new XAttribute ( "value" , x . Value ) ) ) ) ) ;
397+ FileUtils . Save ( dialog . FileName , document ) ;
398+ }
399+ }
400+ else
401+ {
402+ var content = string . Empty ;
403+ if ( gvEnvironment . Tag is IDictionary < string , string > variables )
404+ {
405+ const int paddingSize = 25 ;
406+ var builder = new StringBuilder ( 1024 ) ;
407+ foreach ( var variableKey in variables . Keys )
408+ {
409+ builder . AppendLine ( $ "{ variableKey , - paddingSize } : { variables [ variableKey ] } ") ;
410+ }
411+ content = builder . ToString ( ) ;
373412 }
374- content = builder . ToString ( ) ;
413+ File . WriteAllText ( dialog . FileName , content , Encoding . UTF8 ) ;
375414 }
376- File . WriteAllText ( dialog . FileName , content , Encoding . UTF8 ) ;
377415 }
378416 }
379417
0 commit comments