Skip to content

Commit

Permalink
added PathFinder
Browse files Browse the repository at this point in the history
added some more config in extension.xml
  • Loading branch information
jag2011 committed Mar 2, 2010
1 parent 616d68c commit 6b9e19f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 10 deletions.
13 changes: 8 additions & 5 deletions MapLoader/Form1.cs
Expand Up @@ -14,24 +14,27 @@ namespace MapLoader
public partial class Form1 : Form public partial class Form1 : Form
{ {
ExtensionConfiguration extConf; ExtensionConfiguration extConf;
PathFinder pathFinder;
Uri fileUri; Uri fileUri;


public Form1() public Form1()
{ {
InitializeComponent(); InitializeComponent();


} }


private void Form1_Load(object sender, EventArgs e) private void Form1_Load(object sender, EventArgs e)
{ {
// ========================================================== // ==========================================================
// REading XML Extension Config // Reading XML Extension Config
// ========================================================== // ==========================================================
extConf = new ExtensionConfiguration(); extConf = new ExtensionConfiguration();
extConf.ReadConfig(); extConf.ReadConfig();



// ==========================================================
// Find Pathes for Game Folders etc.
// ==========================================================
pathFinder = new PathFinder();
pathFinder.GatherPathes();


// ========================================================== // ==========================================================
// Start Download // Start Download
Expand Down
1 change: 1 addition & 0 deletions MapLoader/MapLoader.csproj
Expand Up @@ -55,6 +55,7 @@
<Compile Include="Form1.Designer.cs"> <Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon> <DependentUpon>Form1.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="PathFinder.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx"> <EmbeddedResource Include="Form1.resx">
Expand Down
95 changes: 95 additions & 0 deletions 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;
}

}
}
6 changes: 3 additions & 3 deletions MapLoader/Program.cs
Expand Up @@ -16,9 +16,9 @@ static class Program
[STAThread] [STAThread]
static void Main(string[] args) static void Main(string[] args)
{ {
if (args.Length == 0) { Application.Exit(); return; } //if (args.Length == 0) { Application.Exit(); return; }
NIBBITS_LINK = args[0]; //NIBBITS_LINK = args[0];
//NIBBITS_LINK = "nibbits://www.nibbits.com/sc2/maps/get/131540/"; NIBBITS_LINK = "nibbits://www.nibbits.com/sc2/maps/get/131540/";




Application.EnableVisualStyles(); Application.EnableVisualStyles();
Expand Down
5 changes: 3 additions & 2 deletions MapLoader/extensions.xml
@@ -1,3 +1,4 @@
<extension type="s2ma"> <extension type="s2replay">
<default>C:\Nibbits</default> <default>%DOCUMENTS%\Starcraft II Beta\Replays\Multiplayer\Recent</default>
<windows7>%DOCUMENTS%\Starcraft II Beta\Replays\Multiplayer\Recent</windows7>
</extension> </extension>

0 comments on commit 6b9e19f

Please sign in to comment.