Skip to content
Browse files

added PathFinder

added some more config in extension.xml
  • Loading branch information...
1 parent 616d68c commit 6b9e19f1d13a757f48d20657971f6b6347d0043d @jag2011 jag2011 committed Mar 2, 2010
Showing with 110 additions and 10 deletions.
  1. +8 −5 MapLoader/Form1.cs
  2. +1 −0 MapLoader/MapLoader.csproj
  3. +95 −0 MapLoader/PathFinder.cs
  4. +3 −3 MapLoader/Program.cs
  5. +3 −2 MapLoader/extensions.xml
View
13 MapLoader/Form1.cs
@@ -14,24 +14,27 @@ namespace MapLoader
public partial class Form1 : Form
{
ExtensionConfiguration extConf;
+ PathFinder pathFinder;
Uri fileUri;
public Form1()
{
- InitializeComponent();
-
-
+ InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// ==========================================================
- // REading XML Extension Config
+ // Reading XML Extension Config
// ==========================================================
extConf = new ExtensionConfiguration();
extConf.ReadConfig();
-
+ // ==========================================================
+ // Find Pathes for Game Folders etc.
+ // ==========================================================
+ pathFinder = new PathFinder();
+ pathFinder.GatherPathes();
// ==========================================================
// Start Download
View
1 MapLoader/MapLoader.csproj
@@ -55,6 +55,7 @@
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
+ <Compile Include="PathFinder.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
View
95 MapLoader/PathFinder.cs
@@ -0,0 +1,95 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.IO;
+using Microsoft.Win32;
+
+namespace MapLoader
+{
+ class PathFinder
+ {
+
+ private Dictionary<string, string> dictPathIdentifiers;
+
+ public PathFinder()
+ {
+ dictPathIdentifiers = new Dictionary<string, string>();
+ }
+
+ /// <summary>
+ /// Tries to find game pathes etc. in the registry or other places
+ /// and stores them in a Dictionary.
+ /// Must be called before pathes are accessed through GetPath.
+ /// </summary>
+ public void GatherPathes()
+ {
+ // =======================================
+ // Misc
+ // =======================================
+ string pathToProgramFiles = Environment.GetEnvironmentVariable("ProgramFiles");
+ string pathToTempFiles = Path.GetTempPath();
+ string pathToAppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
+ string pathToAppDataLocal = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
+ string pathToDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
+
+ dictPathIdentifiers.Add("%PROGRAM_FILES%", pathToProgramFiles);
+ dictPathIdentifiers.Add("%TEMP%", pathToTempFiles);
+ dictPathIdentifiers.Add("%APP_DATA%", pathToAppData);
+ dictPathIdentifiers.Add("%APP_DATA_LOCAL%", pathToAppDataLocal);
+ dictPathIdentifiers.Add("%DOCUMENTS%", pathToDocuments);
+
+ // =======================================
+ // STARCRAFT II
+ // =======================================
+ // Install Path
+ string pathToStarcraft2Folder = "";
+
+ // 1. Try Registry
+ pathToStarcraft2Folder = GetRegistryValueFromLocalMachine("Software\\Blizzard Entertainment\\Starcraft II", "InstallPath");
+
+ // 2. Try Default Path
+ if (pathToStarcraft2Folder == "")
+ {
+ string defaultPath = pathToProgramFiles + "/" + "StarCraft II/";
+ if (File.Exists(pathToProgramFiles + "StarCraft II.exe")) pathToStarcraft2Folder = defaultPath;
+ }
+
+ // 3. Try Default Path (Beta)
+ if (pathToStarcraft2Folder == "")
+ {
+ string defaultPath = pathToProgramFiles + "/" + "StarCraft II Beta/";
+ if (File.Exists(pathToProgramFiles + "StarCraft II.exe")) pathToStarcraft2Folder = defaultPath;
+ }
+
+ dictPathIdentifiers.Add("%SC2_INSTALL_PATH%", pathToStarcraft2Folder);
+ }
+
+
+ public string GetPath(string pathIdentifier)
+ {
+ if (dictPathIdentifiers.ContainsKey(pathIdentifier)) return dictPathIdentifiers[pathIdentifier];
+ else return "";
+ }
+
+
+
+
+ private string GetRegistryValueFromLocalMachine(string key, string value)
+ {
+ RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(key);
+ string retVal = "";
+ if (registryKey != null)
+ {
+ retVal = registryKey.GetValue(value).ToString();
+ }
+ else
+ {
+ retVal = "";
+ }
+ registryKey.Close();
+ return retVal;
+ }
+
+ }
+}
View
6 MapLoader/Program.cs
@@ -16,9 +16,9 @@ static class Program
[STAThread]
static void Main(string[] args)
{
- if (args.Length == 0) { Application.Exit(); return; }
- NIBBITS_LINK = args[0];
- //NIBBITS_LINK = "nibbits://www.nibbits.com/sc2/maps/get/131540/";
+ //if (args.Length == 0) { Application.Exit(); return; }
+ //NIBBITS_LINK = args[0];
+ NIBBITS_LINK = "nibbits://www.nibbits.com/sc2/maps/get/131540/";
Application.EnableVisualStyles();
View
5 MapLoader/extensions.xml
@@ -1,3 +1,4 @@
-<extension type="s2ma">
-<default>C:\Nibbits</default>
+<extension type="s2replay">
+<default>%DOCUMENTS%\Starcraft II Beta\Replays\Multiplayer\Recent</default>
+<windows7>%DOCUMENTS%\Starcraft II Beta\Replays\Multiplayer\Recent</windows7>
</extension>

0 comments on commit 6b9e19f

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