Skip to content

Commit bea2b75

Browse files
author
zzzprojects
committed
Update setting logic
Update setting logic
1 parent c6db387 commit bea2b75

File tree

6 files changed

+161
-161
lines changed

6 files changed

+161
-161
lines changed

src/FindAndReplace.App/FormData.cs

Lines changed: 67 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,74 @@
1-
using System.Windows.Forms;
2-
using FindAndReplace.App.Properties;
3-
using Microsoft.Win32;
1+
using FindAndReplace.App.Properties;
42

53
namespace 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
}

src/FindAndReplace.App/MainForm.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,11 +880,15 @@ private void btnCancel_Click(object sender, EventArgs e)
880880
private void InitWithRegistryData()
881881
{
882882
var data = new FormData();
883-
if (data.IsEmpty()) //Keep defaults
884-
return;
885883

886884
data.LoadSetting();
887885

886+
if (data.IsFirstTime)
887+
{
888+
data.IsFirstTime = false;
889+
return;
890+
}
891+
888892
txtDir.Text = data.Dir;
889893
chkIncludeSubDirectories.Checked = data.IncludeSubDirectories;
890894
txtFileMask.Text = data.FileMask;
@@ -900,7 +904,6 @@ private void InitWithRegistryData()
900904
chkUseEscapeChars.Checked = data.UseEscapeChars;
901905
chkKeepModifiedDate.Checked = data.IsKeepModifiedDate;
902906

903-
904907
if (!string.IsNullOrEmpty(data.Encoding))
905908
cmbEncoding.SelectedIndex = cmbEncoding.Items.IndexOf(data.Encoding);
906909
}

src/FindAndReplace.App/Properties/AssemblyInfo.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43

54
// General Information about an assembly is controlled through the following
@@ -8,9 +7,9 @@
87
[assembly: AssemblyTitle("fnr.exe")]
98
[assembly: AssemblyDescription("")]
109
[assembly: AssemblyConfiguration("")]
11-
[assembly: AssemblyCompany("ENTech Solutions")]
10+
[assembly: AssemblyCompany("ZZZ Projects")]
1211
[assembly: AssemblyProduct("fnr.exe")]
13-
[assembly: AssemblyCopyright("Copyright © 2014")]
12+
[assembly: AssemblyCopyright("Copyright © 2018")]
1413
[assembly: AssemblyTrademark("")]
1514
[assembly: AssemblyCulture("")]
1615

@@ -32,5 +31,5 @@
3231
// You can specify all the values or you can default the Build and Revision Numbers
3332
// by using the '*' as shown below:
3433
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.7.4")]
36-
[assembly: AssemblyFileVersion("1.7.4")]
34+
[assembly: AssemblyVersion("1.7.6")]
35+
[assembly: AssemblyFileVersion("1.7.6")]

src/FindAndReplace.App/Properties/Settings.Designer.cs

Lines changed: 48 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)