1- using System . Windows . Forms ;
2- using FindAndReplace . App . Properties ;
3- using Microsoft . Win32 ;
1+ using FindAndReplace . App . Properties ;
42
53namespace FindAndReplace . App
64{
7- public class FormData
8- {
9- public bool IsFindOnly { get ; set ; }
10-
11- public string Dir { get ; set ; }
12- public bool IncludeSubDirectories { get ; set ; }
13- public string FileMask { get ; set ; }
14- public string ExcludeFileMask { get ; set ; }
15- public string ExcludeDir { get ; set ; }
5+ public class FormData
6+ {
7+ public bool IsFindOnly { get ; set ; }
8+ public string Dir { get ; set ; }
9+ public bool IncludeSubDirectories { get ; set ; }
10+ public string FileMask { get ; set ; }
11+ public string ExcludeFileMask { get ; set ; }
12+ public string ExcludeDir { get ; set ; }
1613 public string FindText { get ; set ; }
17- public bool IsCaseSensitive { get ; set ; }
18- public bool IsRegEx { get ; set ; }
19- public bool SkipBinaryFileDetection { get ; set ; }
20- public bool ShowEncoding { get ; set ; }
21- public bool IncludeFilesWithoutMatches { get ; set ; }
22- public string ReplaceText { get ; set ; }
23- public bool UseEscapeChars { get ; set ; }
24- public string Encoding { get ; set ; }
25- public bool IsKeepModifiedDate { get ; set ; }
26-
27- private static readonly string _versionIndependentRegKey ;
28-
29- static FormData ( )
30- {
31- _versionIndependentRegKey = GetVersionIndependentRegKey ( ) ;
32- }
33-
34- //Fix for Registry key changing for each new version
35- //http://stackoverflow.com/questions/1515943/application-userappdataregistry-and-version-number
36-
37- private static string GetVersionIndependentRegKey ( )
38- {
39- //Keep using 1.0.0.0 for everything
40- string versionDependent = Application . UserAppDataRegistry . Name ;
41- string versionIndependent = versionDependent . Substring ( 0 , versionDependent . LastIndexOf ( "\\ " ) ) ;
42- versionIndependent = versionIndependent + "\\ 1.0.0.0" ;
43- return versionIndependent ;
44- }
45-
46- public void SaveSetting ( )
47- {
48- Settings . Default [ "Dir" ] = Dir ;
49- Settings . Default [ "IncludeSubDirectories" ] = IncludeSubDirectories . ToString ( ) ;
50- Settings . Default [ "FileMask" ] = FileMask ;
51- Settings . Default [ "ExcludeFileMask" ] = ExcludeFileMask ;
52- Settings . Default [ "ExcludeDir" ] = ExcludeDir ;
53- Settings . Default [ "FindText" ] = FindText ;
54- Settings . Default [ "IsCaseSensitive" ] = IsCaseSensitive . ToString ( ) ;
55- Settings . Default [ "IsRegEx" ] = IsRegEx . ToString ( ) ;
56- Settings . Default [ "SkipBinaryFileDetection" ] = SkipBinaryFileDetection . ToString ( ) ;
57- Settings . Default [ "ShowEncoding" ] = ShowEncoding . ToString ( ) ;
58- Settings . Default [ "IncludeFilesWithoutMatches" ] = IncludeFilesWithoutMatches . ToString ( ) ;
59- Settings . Default [ "ReplaceText" ] = ReplaceText ;
60- Settings . Default [ "UseEscapeChars" ] = UseEscapeChars . ToString ( ) ;
61- Settings . Default [ "Encoding" ] = Encoding ;
62- Settings . Default [ "IsKeepModifiedDate" ] = IsKeepModifiedDate . ToString ( ) ;
63-
64- Settings . Default . Save ( ) ;
65- }
66-
67- public bool IsEmpty ( )
68- {
69- //When saved even once dir will have a non null volue
70- string dir = GetValueFromRegistry ( "Dir" ) ;
71- return dir == null ;
72- }
73-
74- public void LoadSetting ( )
75- {
76- Dir = Settings . Default [ "Dir" ] . ToString ( ) ;
77- IncludeSubDirectories = Settings . Default [ "IncludeSubDirectories" ] . ToString ( ) == "True" ;
78- FileMask = Settings . Default [ "FileMask" ] . ToString ( ) ;
79- ExcludeFileMask = Settings . Default [ "ExcludeFileMask" ] . ToString ( ) ;
80- ExcludeDir = Settings . Default [ "ExcludeDir" ] . ToString ( ) ;
81- FindText = Settings . Default [ "FindText" ] . ToString ( ) ;
82- IsCaseSensitive = Settings . Default [ "IsCaseSensitive" ] . ToString ( ) == "True" ;
83- IsRegEx = Settings . Default [ "IsRegEx" ] . ToString ( ) == "True" ;
84- SkipBinaryFileDetection = Settings . Default [ "SkipBinaryFileDetection" ] . ToString ( ) == "True" ;
85- IncludeFilesWithoutMatches = Settings . Default [ "IncludeFilesWithoutMatches" ] . ToString ( ) == "True" ;
86- ShowEncoding = Settings . Default [ "ShowEncoding" ] . ToString ( ) == "True" ;
87- ReplaceText = Settings . Default [ "ReplaceText" ] . ToString ( ) ;
88- UseEscapeChars = Settings . Default [ "UseEscapeChars" ] . ToString ( ) == "True" ;
89- Encoding = Settings . Default [ "Encoding" ] . ToString ( ) ;
90- IsKeepModifiedDate = Settings . Default [ "IsKeepModifiedDate" ] . ToString ( ) == "True" ;
14+ public bool IsCaseSensitive { get ; set ; }
15+ public bool IsRegEx { get ; set ; }
16+ public bool SkipBinaryFileDetection { get ; set ; }
17+ public bool ShowEncoding { get ; set ; }
18+ public bool IncludeFilesWithoutMatches { get ; set ; }
19+ public string ReplaceText { get ; set ; }
20+ public bool UseEscapeChars { get ; set ; }
21+ public string Encoding { get ; set ; }
22+ public bool IsKeepModifiedDate { get ; set ; }
23+ public bool IsFirstTime { get ; set ; }
24+
25+ public void SaveSetting ( )
26+ {
27+ Settings . Default . Dir = Dir ;
28+ Settings . Default . IncludeSubDirectories = IncludeSubDirectories ;
29+ Settings . Default . FileMask = FileMask ;
30+ Settings . Default . ExcludeFileMask = ExcludeFileMask ;
31+ Settings . Default . ExcludeDir = ExcludeDir ;
32+ Settings . Default . FindText = FindText ;
33+ Settings . Default . IsCaseSensitive = IsCaseSensitive ;
34+ Settings . Default . IsRegEx = IsRegEx ;
35+ Settings . Default . SkipBinaryFileDetection = SkipBinaryFileDetection ;
36+ Settings . Default . IncludeFilesWithoutMatches = IncludeFilesWithoutMatches ;
37+ Settings . Default . ShowEncoding = ShowEncoding ;
38+ Settings . Default . ReplaceText = ReplaceText ;
39+ Settings . Default . UseEscapeChars = UseEscapeChars ;
40+ Settings . Default . Encoding = Encoding ;
41+ Settings . Default . IsKeepModifiedDate = IsKeepModifiedDate ;
42+ Settings . Default . IsFirstTime = IsFirstTime ;
43+
44+ Settings . Default . Save ( ) ;
9145 }
9246
93-
94- private void SaveValueToRegistry ( string name , string value )
95- {
96- Registry . SetValue ( _versionIndependentRegKey , name , value , RegistryValueKind . String ) ;
97- }
98-
99- private string GetValueFromRegistry ( string name )
100- {
101- var value = Registry . GetValue ( _versionIndependentRegKey , name , null ) ;
102-
103- if ( value != null )
104- return value . ToString ( ) ;
105-
106- return null ;
107- }
108-
109-
110- }
111-
47+ public void LoadSetting ( )
48+ {
49+ if ( Settings . Default . UpgradeRequired )
50+ {
51+ Settings . Default . Upgrade ( ) ;
52+ Settings . Default . UpgradeRequired = false ;
53+ Settings . Default . Save ( ) ;
54+ }
55+
56+ Dir = Settings . Default . Dir ;
57+ IncludeSubDirectories = Settings . Default . IncludeSubDirectories ;
58+ FileMask = Settings . Default . FileMask ;
59+ ExcludeFileMask = Settings . Default . ExcludeFileMask ;
60+ ExcludeDir = Settings . Default . ExcludeDir ;
61+ FindText = Settings . Default . FindText ;
62+ IsCaseSensitive = Settings . Default . IsCaseSensitive ;
63+ IsRegEx = Settings . Default . IsRegEx ;
64+ SkipBinaryFileDetection = Settings . Default . SkipBinaryFileDetection ;
65+ IncludeFilesWithoutMatches = Settings . Default . IncludeFilesWithoutMatches ;
66+ ShowEncoding = Settings . Default . ShowEncoding ;
67+ ReplaceText = Settings . Default . ReplaceText ;
68+ UseEscapeChars = Settings . Default . UseEscapeChars ;
69+ Encoding = Settings . Default . Encoding ;
70+ IsKeepModifiedDate = Settings . Default . IsKeepModifiedDate ;
71+ IsFirstTime = Settings . Default . IsFirstTime ;
72+ }
73+ }
11274}
0 commit comments