Skip to content
Browse files

Refactor settings code to remove registry writes.

Move remaining PathUserDefined function into PathFinder.
  • Loading branch information...
1 parent 7e8b31d commit eca26d6f3a95d4ac329be973be17489a15147a9c @dcramer committed
View
62 MapLoader/ClientSettings.Designer.cs
@@ -0,0 +1,62 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:2.0.50727.4927
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace MapLoader {
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
+ internal sealed partial class ClientSettings : global::System.Configuration.ApplicationSettingsBase {
+
+ private static ClientSettings defaultInstance = ((ClientSettings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new ClientSettings())));
+
+ public static ClientSettings Default {
+ get {
+ return defaultInstance;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("")]
+ public string SC1_INSTALL_PATH {
+ get {
+ return ((string)(this["SC1_INSTALL_PATH"]));
+ }
+ set {
+ this["SC1_INSTALL_PATH"] = value;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("")]
+ public string SC2_INSTALL_PATH {
+ get {
+ return ((string)(this["SC2_INSTALL_PATH"]));
+ }
+ set {
+ this["SC2_INSTALL_PATH"] = value;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("")]
+ public string WC3_INSTALL_PATH {
+ get {
+ return ((string)(this["WC3_INSTALL_PATH"]));
+ }
+ set {
+ this["WC3_INSTALL_PATH"] = value;
+ }
+ }
+ }
+}
View
15 MapLoader/ClientSettings.settings
@@ -0,0 +1,15 @@
+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="MapLoader" GeneratedClassName="ClientSettings">
+ <Profiles />
+ <Settings>
+ <Setting Name="SC1_INSTALL_PATH" Type="System.String" Scope="User">
+ <Value Profile="(Default)" />
+ </Setting>
+ <Setting Name="SC2_INSTALL_PATH" Type="System.String" Scope="User">
+ <Value Profile="(Default)" />
+ </Setting>
+ <Setting Name="WC3_INSTALL_PATH" Type="System.String" Scope="User">
+ <Value Profile="(Default)" />
+ </Setting>
+ </Settings>
+</SettingsFile>
View
2 MapLoader/Formsetup.Designer.cs → MapLoader/LoaderConfig.Designer.cs
@@ -1,6 +1,6 @@
namespace MapLoader
{
- partial class Formsetup
+ partial class LoaderConfig
{
/// <summary>
/// Required designer variable.
View
21 MapLoader/Formsetup.cs → MapLoader/LoaderConfig.cs
@@ -10,13 +10,12 @@
namespace MapLoader
{
- public partial class Formsetup : Form
+ public partial class LoaderConfig : Form
{
ExtensionConfiguration extConf;
PathFinder pathFinder;
- PathUserDefined pathUser;
- public Formsetup()
+ public LoaderConfig()
{
InitializeComponent();
}
@@ -39,34 +38,30 @@ private void Formsetup_Load(object sender, EventArgs e)
// ==========================================================
pathFinder = new PathFinder();
pathFinder.GatherPathes();
- pathUser = new PathUserDefined();
//Check if we know our dirs
- string sc1 = pathFinder.GetPath("%SC1_INSTALL_PATH%");
- tb_sc1dir.Text = sc1;
+ tb_sc1dir.Text = pathFinder.GetPath("%SC1_INSTALL_PATH%");
- string sc2 = pathFinder.GetPath("%SC2_INSTALL_PATH%");
- tb_sc2dir.Text = sc2;
+ tb_sc2dir.Text = pathFinder.GetPath("%SC2_INSTALL_PATH%");
- string wc3 = pathFinder.GetPath("%WC3_INSTALL_PATH%");
- tb_wc3dir.Text = wc3;
+ tb_wc3dir.Text = pathFinder.GetPath("%WC3_INSTALL_PATH%");
}
private void btn_sc1dir_Click(object sender, EventArgs e)
{
- string sc1 = pathUser.QueryUserForPath(this, "%SC1_INSTALL_PATH%");
+ string sc1 = pathFinder.QueryUserForPath(this, "%SC1_INSTALL_PATH%");
tb_sc1dir.Text = sc1;
}
private void btn_sc2dir_Click(object sender, EventArgs e)
{
- string sc2 = pathUser.QueryUserForPath(this, "%SC2_INSTALL_PATH%");
+ string sc2 = pathFinder.QueryUserForPath(this, "%SC2_INSTALL_PATH%");
tb_sc2dir.Text = sc2;
}
private void btn_wc3dir_Click(object sender, EventArgs e)
{
- string wc3 = pathUser.QueryUserForPath(this, "%WC3_INSTALL_PATH%");
+ string wc3 = pathFinder.QueryUserForPath(this, "%WC3_INSTALL_PATH%");
tb_wc3dir.Text = wc3;
}
}
View
0 MapLoader/Formsetup.resx → MapLoader/LoaderConfig.resx
File renamed without changes.
View
2 MapLoader/Form1.Designer.cs → MapLoader/LoaderForm.Designer.cs
@@ -1,6 +1,6 @@
namespace MapLoader
{
- partial class Form1
+ partial class LoaderForm
{
/// <summary>
/// Required designer variable.
View
24 MapLoader/Form1.cs → MapLoader/LoaderForm.cs
@@ -13,14 +13,13 @@
namespace MapLoader
{
- public partial class Form1 : Form
+ public partial class LoaderForm : Form
{
ExtensionConfiguration extConf;
PathFinder pathFinder;
- PathUserDefined pathUser;
Uri fileUri;
- public Form1()
+ public LoaderForm()
{
InitializeComponent();
}
@@ -39,7 +38,6 @@ private void Form1_Load(object sender, EventArgs e)
// ==========================================================
pathFinder = new PathFinder();
pathFinder.GatherPathes();
- pathUser = new PathUserDefined();
// ==========================================================
@@ -208,13 +206,21 @@ private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventA
// to the real Path
// ==============================================
// 1. Check if PathFinder know our Path
- string realPath = pathFinder.GetPath(pathIdentfier);
+ string realPath = "";
- // 2. Check if user has defined a custom path
- if (realPath == "")
+ switch (pathIdentfier)
{
- realPath = pathUser.GetPath(pathIdentfier);
+ case "WC3_INSTALL_PATH":
+ realPath = MapLoader.ClientSettings.Default.WC3_INSTALL_PATH;
+ break;
+ case "SC1_INSTALL_PATH":
+ realPath = MapLoader.ClientSettings.Default.SC1_INSTALL_PATH;
+ break;
+ case "SC2_INSTALL_PATH":
+ realPath = MapLoader.ClientSettings.Default.SC2_INSTALL_PATH;
+ break;
}
+
// 3. Still no path, query the user for setup
if (realPath == "")
{
@@ -281,7 +287,7 @@ private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventA
public static void ThreadProc()
{
- Application.Run(new Formsetup());
+ Application.Run(new LoaderConfig());
}
}
}
View
0 MapLoader/Form1.resx → MapLoader/LoaderForm.resx
File renamed without changes.
View
36 MapLoader/MapLoader.csproj
@@ -48,30 +48,34 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="ClientSettings.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DesignTimeSharedInput>True</DesignTimeSharedInput>
+ <DependentUpon>ClientSettings.settings</DependentUpon>
+ </Compile>
<Compile Include="ExtensionConfiguration.cs" />
- <Compile Include="Form1.cs">
+ <Compile Include="LoaderForm.cs">
<SubType>Form</SubType>
</Compile>
- <Compile Include="Form1.Designer.cs">
- <DependentUpon>Form1.cs</DependentUpon>
+ <Compile Include="LoaderForm.Designer.cs">
+ <DependentUpon>LoaderForm.cs</DependentUpon>
</Compile>
- <Compile Include="Formsetup.cs">
+ <Compile Include="LoaderConfig.cs">
<SubType>Form</SubType>
</Compile>
- <Compile Include="Formsetup.Designer.cs">
- <DependentUpon>Formsetup.cs</DependentUpon>
+ <Compile Include="LoaderConfig.Designer.cs">
+ <DependentUpon>LoaderConfig.cs</DependentUpon>
</Compile>
<Compile Include="ModifyRegistry.cs" />
<Compile Include="PathFinder.cs" />
- <Compile Include="PathUserDefined.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <EmbeddedResource Include="Form1.resx">
- <DependentUpon>Form1.cs</DependentUpon>
+ <EmbeddedResource Include="LoaderForm.resx">
+ <DependentUpon>LoaderForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
- <EmbeddedResource Include="Formsetup.resx">
- <DependentUpon>Formsetup.cs</DependentUpon>
+ <EmbeddedResource Include="LoaderConfig.resx">
+ <DependentUpon>LoaderConfig.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
@@ -83,15 +87,11 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
- <None Include="Properties\Settings.settings">
+ <None Include="app.config" />
+ <None Include="ClientSettings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
- <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+ <LastGenOutput>ClientSettings.Designer.cs</LastGenOutput>
</None>
- <Compile Include="Properties\Settings.Designer.cs">
- <AutoGen>True</AutoGen>
- <DependentUpon>Settings.settings</DependentUpon>
- <DesignTimeSharedInput>True</DesignTimeSharedInput>
- </Compile>
</ItemGroup>
<ItemGroup>
<Content Include="extensions.xml">
View
53 MapLoader/PathFinder.cs
@@ -164,5 +164,58 @@ public string GetPath(string pathIdentifier)
}
else return "";
}
+
+ public string QueryUserForPath(LoaderConfig form, string pathIdentifier)
+ {
+ string returnValue = "";
+ switch (pathIdentifier)
+ {
+ case "%SC1_INSTALL_PATH%":
+ form.openFileDialog1.CheckFileExists = true;
+ form.openFileDialog1.Filter = "Starcraft.exe|Starcraft.exe";
+ form.openFileDialog1.FileName = "Starcraft.exe";
+ if (form.openFileDialog1.ShowDialog() == DialogResult.OK)
+ {
+ returnValue = form.openFileDialog1.FileName;
+ returnValue = returnValue.ToLower().Replace("starcraft.exe", "");
+ MapLoader.ClientSettings.Default.SC1_INSTALL_PATH = returnValue;
+ MapLoader.ClientSettings.Default.Save();
+ dictPathIdentifiers.Remove(pathIdentifier);
+ dictPathIdentifiers.Add(pathIdentifier, returnValue);
+ }
+ break;
+
+ case "%WC3_INSTALL_PATH%":
+ form.openFileDialog1.CheckFileExists = true;
+ form.openFileDialog1.Filter = "Warcraft III.exe|Warcraft III.exe";
+ form.openFileDialog1.FileName = "Warcraft III.exe";
+ if (form.openFileDialog1.ShowDialog() == DialogResult.OK)
+ {
+ returnValue = form.openFileDialog1.FileName;
+ returnValue = returnValue.ToLower().Replace("warcraft iii.exe", "");
+ MapLoader.ClientSettings.Default.WC3_INSTALL_PATH = returnValue;
+ MapLoader.ClientSettings.Default.Save();
+ dictPathIdentifiers.Remove(pathIdentifier);
+ dictPathIdentifiers.Add(pathIdentifier, returnValue);
+ }
+ break;
+
+ case "%SC2_INSTALL_PATH%":
+ form.openFileDialog1.CheckFileExists = true;
+ form.openFileDialog1.Filter = "Starcraft II.exe|Starcraft II.exe";
+ form.openFileDialog1.FileName = "Starcraft II.exe";
+ if (form.openFileDialog1.ShowDialog() == DialogResult.OK)
+ {
+ returnValue = form.openFileDialog1.FileName;
+ returnValue = returnValue.ToLower().Replace("starcraft ii.exe", "");
+ MapLoader.ClientSettings.Default.SC2_INSTALL_PATH = returnValue;
+ MapLoader.ClientSettings.Default.Save();
+ dictPathIdentifiers.Remove(pathIdentifier);
+ dictPathIdentifiers.Add(pathIdentifier, returnValue);
+ }
+ break;
+ }
+ return returnValue;
+ }
}
}
View
103 MapLoader/PathUserDefined.cs
@@ -1,103 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Windows.Forms;
-using Utility.ModifyRegistry;
-using Microsoft.Win32;
-
-namespace MapLoader
-{
- /// <summary>
- /// This class keeps track of user defined pathes.
- /// e.g. when PathFinder couldn't find the SC1 Path, we query the user to enter the SC1 Path.
- /// The input get saved so next time we don't need to query the user
- ///
- /// </summary>
- class PathUserDefined
- {
- public Dictionary<string, string> dictPathIdentifiers;
-
- public PathUserDefined()
- {
- dictPathIdentifiers = new Dictionary<string, string>();
- //dictPathIdentifiers.Add("%SC1_INSTALL_PATH%", "");
- //dictPathIdentifiers.Add("%SC2_INSTALL_PATH%", "");
- //dictPathIdentifiers.Add("%WC3_INSTALL_PATH%", "");
- }
-
- public string GetPath(string pathIdentifier)
- {
- if (dictPathIdentifiers.ContainsKey(pathIdentifier))
- {
- string path = dictPathIdentifiers[pathIdentifier];
- MessageBox.Show(path, path, MessageBoxButtons.OK);
- return path;
- }
- else return "";
- }
-
- public string QueryUserForPath(Formsetup form, string pathIdentifier)
- {
- string returnValue = "";
- switch (pathIdentifier)
- {
- case "%SC1_INSTALL_PATH%":
- form.openFileDialog1.CheckFileExists = true;
- form.openFileDialog1.Filter = "Starcraft.exe|Starcraft.exe";
- form.openFileDialog1.FileName = "Starcraft.exe";
- if (form.openFileDialog1.ShowDialog() == DialogResult.OK) {
- returnValue = form.openFileDialog1.FileName;
- returnValue = returnValue.ToLower().Replace("starcraft.exe", "");
- //Save path to registry
- ModifyRegistry mysc1Registry = new ModifyRegistry();
- mysc1Registry.BaseRegistryKey = Registry.CurrentUser;
- mysc1Registry.SubKey = "Software\\Blizzard Entertainment\\Starcraft\\";
- mysc1Registry.Write("InstallPath", returnValue);
- dictPathIdentifiers.Remove("%SC1_INSTALL_PATH%");
- dictPathIdentifiers.Add("%SC1_INSTALL_PATH%", returnValue);
- }
- break;
-
- case "%WC3_INSTALL_PATH%":
- form.openFileDialog1.CheckFileExists = true;
- form.openFileDialog1.Filter = "Warcraft III.exe|Warcraft III.exe";
- form.openFileDialog1.FileName = "Warcraft III.exe";
- if (form.openFileDialog1.ShowDialog() == DialogResult.OK)
- {
- returnValue = form.openFileDialog1.FileName;
- returnValue = returnValue.ToLower().Replace("warcraft iii.exe", "");
- //Save path to registry
- ModifyRegistry mysc1Registry = new ModifyRegistry();
- mysc1Registry.BaseRegistryKey = Registry.CurrentUser;
- mysc1Registry.SubKey = "Software\\Blizzard Entertainment\\Warcraft III\\";
- mysc1Registry.Write("InstallPath", returnValue);
- dictPathIdentifiers.Remove("%WC3_INSTALL_PATH%");
- dictPathIdentifiers.Add("%WC3_INSTALL_PATH%", returnValue);
- }
- break;
-
- case "%SC2_INSTALL_PATH%":
- form.openFileDialog1.CheckFileExists = true;
- form.openFileDialog1.Filter = "Starcraft II.exe|Starcraft II.exe";
- form.openFileDialog1.FileName = "Starcraft II.exe";
- if (form.openFileDialog1.ShowDialog() == DialogResult.OK)
- {
- returnValue = form.openFileDialog1.FileName;
- returnValue = returnValue.ToLower().Replace("starcraft ii.exe", "");
- //Save path to registry
- ModifyRegistry mysc1Registry = new ModifyRegistry();
- mysc1Registry.BaseRegistryKey = Registry.CurrentUser;
- mysc1Registry.SubKey = "Software\\Blizzard Entertainment\\Starcraft II\\";
- mysc1Registry.Write("InstallPath", returnValue);
- dictPathIdentifiers.Remove("%SC2_INSTALL_PATH%");
- dictPathIdentifiers.Add("%SC2_INSTALL_PATH%", returnValue);
- }
- break;
-
-
- }
- return returnValue;
- }
- }
-}
View
4 MapLoader/Program.cs
@@ -18,7 +18,7 @@ static void Main(string[] args)
{
if (args.Length == 0)
{
- Application.Run(new Formsetup());
+ Application.Run(new LoaderConfig());
Application.Exit();
return;
}
@@ -31,7 +31,7 @@ static void Main(string[] args)
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1());
+ Application.Run(new LoaderForm());
}
}
}
View
30 MapLoader/Properties/Settings.Designer.cs
@@ -1,30 +0,0 @@
-//------------------------------------------------------------------------------
-// <auto-generated>
-// This code was generated by a tool.
-// Runtime Version:2.0.50727.4927
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-// </auto-generated>
-//------------------------------------------------------------------------------
-
-namespace MapLoader.Properties
-{
-
-
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
- internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
- {
-
- private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
-
- public static Settings Default
- {
- get
- {
- return defaultInstance;
- }
- }
- }
-}
View
7 MapLoader/Properties/Settings.settings
@@ -1,7 +0,0 @@
-<?xml version='1.0' encoding='utf-8'?>
-<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
- <Profiles>
- <Profile Name="(Default)" />
- </Profiles>
- <Settings />
-</SettingsFile>
View
33 MapLoader/app.config
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <configSections>
+ <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
+ <section name="MapLoader.ClientSettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
+ <section name="MapLoader.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
+ </sectionGroup>
+ </configSections>
+ <userSettings>
+ <MapLoader.ClientSettings>
+ <setting name="SC1_INSTALL_PATH" serializeAs="String">
+ <value />
+ </setting>
+ <setting name="SC2_INSTALL_PATH" serializeAs="String">
+ <value />
+ </setting>
+ <setting name="WC3_INSTALL_PATH" serializeAs="String">
+ <value />
+ </setting>
+ </MapLoader.ClientSettings>
+ <MapLoader.Properties.Settings>
+ <setting name="wc3_install_path" serializeAs="String">
+ <value />
+ </setting>
+ <setting name="sc2_install_path" serializeAs="String">
+ <value />
+ </setting>
+ <setting name="sc_install_path" serializeAs="String">
+ <value />
+ </setting>
+ </MapLoader.Properties.Settings>
+ </userSettings>
+</configuration>

0 comments on commit eca26d6

Please sign in to comment.
Something went wrong with that request. Please try again.