Permalink
Browse files

Refactor settings code to remove registry writes.

Move remaining PathUserDefined function into PathFinder.
  • Loading branch information...
dcramer committed Apr 6, 2010
1 parent 7e8b31d commit eca26d6f3a95d4ac329be973be17489a15147a9c

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -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>

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -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;
}
}
File renamed without changes.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -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());
}
}
}
File renamed without changes.
View
@@ -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
@@ -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;
+ }
}
}
Oops, something went wrong.

0 comments on commit eca26d6

Please sign in to comment.