-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update setting logic
- Loading branch information
zzzprojects
committed
Apr 18, 2018
1 parent
c6db387
commit bea2b75
Showing
6 changed files
with
161 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,74 @@ | ||
using System.Windows.Forms; | ||
using FindAndReplace.App.Properties; | ||
using Microsoft.Win32; | ||
using FindAndReplace.App.Properties; | ||
|
||
namespace FindAndReplace.App | ||
{ | ||
public class FormData | ||
{ | ||
public bool IsFindOnly { get; set; } | ||
|
||
public string Dir { get; set; } | ||
public bool IncludeSubDirectories { get; set; } | ||
public string FileMask { get; set; } | ||
public string ExcludeFileMask { get; set; } | ||
public string ExcludeDir { get; set; } | ||
public class FormData | ||
{ | ||
public bool IsFindOnly { get; set; } | ||
public string Dir { get; set; } | ||
public bool IncludeSubDirectories { get; set; } | ||
public string FileMask { get; set; } | ||
public string ExcludeFileMask { get; set; } | ||
public string ExcludeDir { get; set; } | ||
public string FindText { get; set; } | ||
public bool IsCaseSensitive { get; set; } | ||
public bool IsRegEx { get; set; } | ||
public bool SkipBinaryFileDetection { get; set; } | ||
public bool ShowEncoding { get; set; } | ||
public bool IncludeFilesWithoutMatches { get; set; } | ||
public string ReplaceText { get; set; } | ||
public bool UseEscapeChars { get; set; } | ||
public string Encoding { get; set; } | ||
public bool IsKeepModifiedDate { get; set; } | ||
|
||
private static readonly string _versionIndependentRegKey; | ||
|
||
static FormData() | ||
{ | ||
_versionIndependentRegKey = GetVersionIndependentRegKey(); | ||
} | ||
|
||
//Fix for Registry key changing for each new version | ||
//http://stackoverflow.com/questions/1515943/application-userappdataregistry-and-version-number | ||
|
||
private static string GetVersionIndependentRegKey() | ||
{ | ||
//Keep using 1.0.0.0 for everything | ||
string versionDependent = Application.UserAppDataRegistry.Name; | ||
string versionIndependent = versionDependent.Substring(0, versionDependent.LastIndexOf("\\")); | ||
versionIndependent = versionIndependent + "\\1.0.0.0"; | ||
return versionIndependent; | ||
} | ||
|
||
public void SaveSetting() | ||
{ | ||
Settings.Default["Dir"] = Dir; | ||
Settings.Default["IncludeSubDirectories"] = IncludeSubDirectories.ToString(); | ||
Settings.Default["FileMask"] = FileMask; | ||
Settings.Default["ExcludeFileMask"] = ExcludeFileMask; | ||
Settings.Default["ExcludeDir"] = ExcludeDir; | ||
Settings.Default["FindText"] = FindText; | ||
Settings.Default["IsCaseSensitive"] = IsCaseSensitive.ToString(); | ||
Settings.Default["IsRegEx"] = IsRegEx.ToString(); | ||
Settings.Default["SkipBinaryFileDetection"] = SkipBinaryFileDetection.ToString(); | ||
Settings.Default["ShowEncoding"] = ShowEncoding.ToString(); | ||
Settings.Default["IncludeFilesWithoutMatches"] = IncludeFilesWithoutMatches.ToString(); | ||
Settings.Default["ReplaceText"] = ReplaceText; | ||
Settings.Default["UseEscapeChars"] = UseEscapeChars.ToString(); | ||
Settings.Default["Encoding"] = Encoding; | ||
Settings.Default["IsKeepModifiedDate"] = IsKeepModifiedDate.ToString(); | ||
|
||
Settings.Default.Save(); | ||
} | ||
|
||
public bool IsEmpty() | ||
{ | ||
//When saved even once dir will have a non null volue | ||
string dir = GetValueFromRegistry("Dir"); | ||
return dir == null; | ||
} | ||
|
||
public void LoadSetting() | ||
{ | ||
Dir = Settings.Default["Dir"].ToString(); | ||
IncludeSubDirectories = Settings.Default["IncludeSubDirectories"].ToString() == "True"; | ||
FileMask = Settings.Default["FileMask"].ToString(); | ||
ExcludeFileMask = Settings.Default["ExcludeFileMask"].ToString(); | ||
ExcludeDir = Settings.Default["ExcludeDir"].ToString(); | ||
FindText = Settings.Default["FindText"].ToString(); | ||
IsCaseSensitive = Settings.Default["IsCaseSensitive"].ToString() == "True"; | ||
IsRegEx = Settings.Default["IsRegEx"].ToString() == "True"; | ||
SkipBinaryFileDetection = Settings.Default["SkipBinaryFileDetection"].ToString() == "True"; | ||
IncludeFilesWithoutMatches = Settings.Default["IncludeFilesWithoutMatches"].ToString() == "True"; | ||
ShowEncoding = Settings.Default["ShowEncoding"].ToString() == "True"; | ||
ReplaceText = Settings.Default["ReplaceText"].ToString(); | ||
UseEscapeChars = Settings.Default["UseEscapeChars"].ToString() == "True"; | ||
Encoding = Settings.Default["Encoding"].ToString(); | ||
IsKeepModifiedDate= Settings.Default["IsKeepModifiedDate"].ToString() == "True"; | ||
public bool IsCaseSensitive { get; set; } | ||
public bool IsRegEx { get; set; } | ||
public bool SkipBinaryFileDetection { get; set; } | ||
public bool ShowEncoding { get; set; } | ||
public bool IncludeFilesWithoutMatches { get; set; } | ||
public string ReplaceText { get; set; } | ||
public bool UseEscapeChars { get; set; } | ||
public string Encoding { get; set; } | ||
public bool IsKeepModifiedDate { get; set; } | ||
public bool IsFirstTime { get; set; } | ||
|
||
public void SaveSetting() | ||
{ | ||
Settings.Default.Dir = Dir; | ||
Settings.Default.IncludeSubDirectories = IncludeSubDirectories; | ||
Settings.Default.FileMask = FileMask; | ||
Settings.Default.ExcludeFileMask = ExcludeFileMask; | ||
Settings.Default.ExcludeDir = ExcludeDir; | ||
Settings.Default.FindText = FindText; | ||
Settings.Default.IsCaseSensitive = IsCaseSensitive; | ||
Settings.Default.IsRegEx = IsRegEx; | ||
Settings.Default.SkipBinaryFileDetection = SkipBinaryFileDetection; | ||
Settings.Default.IncludeFilesWithoutMatches = IncludeFilesWithoutMatches; | ||
Settings.Default.ShowEncoding = ShowEncoding; | ||
Settings.Default.ReplaceText = ReplaceText; | ||
Settings.Default.UseEscapeChars = UseEscapeChars; | ||
Settings.Default.Encoding = Encoding; | ||
Settings.Default.IsKeepModifiedDate = IsKeepModifiedDate; | ||
Settings.Default.IsFirstTime = IsFirstTime; | ||
|
||
Settings.Default.Save(); | ||
} | ||
|
||
|
||
private void SaveValueToRegistry(string name, string value) | ||
{ | ||
Registry.SetValue(_versionIndependentRegKey, name, value, RegistryValueKind.String); | ||
} | ||
|
||
private string GetValueFromRegistry(string name) | ||
{ | ||
var value = Registry.GetValue(_versionIndependentRegKey, name, null); | ||
|
||
if (value != null) | ||
return value.ToString(); | ||
|
||
return null; | ||
} | ||
|
||
|
||
} | ||
|
||
public void LoadSetting() | ||
{ | ||
if (Settings.Default.UpgradeRequired) | ||
{ | ||
Settings.Default.Upgrade(); | ||
Settings.Default.UpgradeRequired = false; | ||
Settings.Default.Save(); | ||
} | ||
|
||
Dir = Settings.Default.Dir; | ||
IncludeSubDirectories = Settings.Default.IncludeSubDirectories; | ||
FileMask = Settings.Default.FileMask; | ||
ExcludeFileMask = Settings.Default.ExcludeFileMask; | ||
ExcludeDir = Settings.Default.ExcludeDir; | ||
FindText = Settings.Default.FindText; | ||
IsCaseSensitive = Settings.Default.IsCaseSensitive; | ||
IsRegEx = Settings.Default.IsRegEx; | ||
SkipBinaryFileDetection = Settings.Default.SkipBinaryFileDetection; | ||
IncludeFilesWithoutMatches = Settings.Default.IncludeFilesWithoutMatches; | ||
ShowEncoding = Settings.Default.ShowEncoding; | ||
ReplaceText = Settings.Default.ReplaceText; | ||
UseEscapeChars = Settings.Default.UseEscapeChars; | ||
Encoding = Settings.Default.Encoding; | ||
IsKeepModifiedDate = Settings.Default.IsKeepModifiedDate; | ||
IsFirstTime = Settings.Default.IsFirstTime; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.