Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

...

  • Loading branch information...
commit 83bb470c281bafe54a60038148b73a62d9e81d00 1 parent 6b9e19f
@jag2011 jag2011 authored
View
59 MapLoader/ExtensionConfiguration.cs
@@ -11,10 +11,61 @@ namespace MapLoader
class ExtensionConfiguration
{
- public Dictionary<string, Extension> dictExtConfiguration;
+ private Dictionary<string, Extension> dictExtConfiguration;
+ /// <summary>
+ /// Checks if there's an action defined for this extension
+ /// </summary>
+ /// <returns></returns>
+ public bool IsValidExtension(string extension)
+ {
+ return dictExtConfiguration.ContainsKey(extension);
+ }
+
+
+ /// <summary>
+ /// Returns the path to copy the file to for a given extension.
+ /// Will return a custom path for each OS if specified in extension.xml
+ /// </summary>
+ /// <returns></returns>
+ public string GetCopyPathForExtension(string extension) {
+
+ // check if we have something for this extension in store
+ if (!dictExtConfiguration.ContainsKey(extension.ToLower())) return "";
+
+ Extension currentExtension = dictExtConfiguration[extension.ToLower()];
+
+ // Determining OS
+ OperatingSystem os = System.Environment.OSVersion;
+ Version osVersion = os.Version;
- public class Extension
+ // good ol' Xp
+ if (osVersion.Major == 5)
+ {
+ if (currentExtension.dictActionsPerOS.ContainsKey("xp")) return currentExtension.dictActionsPerOS["xp"];
+ else return currentExtension.dictActionsPerOS["default"];
+ }
+ // Windows Vista
+ else if (osVersion.Major == 6 && osVersion.Minor == 0)
+ {
+ if (currentExtension.dictActionsPerOS.ContainsKey("vista")) return currentExtension.dictActionsPerOS["vista"];
+ else return currentExtension.dictActionsPerOS["default"];
+ }
+ // Windows 7
+ else if (osVersion.Major == 6 && osVersion.Minor == 1)
+ {
+ if (currentExtension.dictActionsPerOS.ContainsKey("windows7")) return currentExtension.dictActionsPerOS["windows7"];
+ else return currentExtension.dictActionsPerOS["default"];
+ }
+
+ return currentExtension.dictActionsPerOS["default"];
+ }
+
+
+ /// <summary>
+ /// Little container class for extensions & there copy-path's per OS
+ /// </summary>
+ class Extension
{
public string ExtensionName;
public Dictionary<string, string> dictActionsPerOS;
@@ -24,7 +75,6 @@ public Extension(string name)
this.ExtensionName = name;
dictActionsPerOS = new Dictionary<string, string>();
}
-
}
public ExtensionConfiguration()
@@ -32,6 +82,9 @@ public ExtensionConfiguration()
dictExtConfiguration = new Dictionary<string, Extension>();
}
+ /// <summary>
+ /// Reads the extension.xml
+ /// </summary>
public void ReadConfig()
{
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
View
17 MapLoader/Form1.cs
@@ -62,11 +62,22 @@ private void Form1_Load(object sender, EventArgs e)
// ==========================================================
string fileName = fileUri.Segments[fileUri.Segments.Length - 1];
string extension = Path.GetExtension(fileName).ToLower().Substring(1);
- if (extConf.dictExtConfiguration.ContainsKey(extension))
+
+ if (extConf.IsValidExtension(extension))
{
lblFilename.Text = fileName; // Display filename
bgWorker.RunWorkerAsync();
}
+
+ else
+ {
+ // No action for this Extension defined
+ // Either link is broken or someone tampered with the XML
+
+ // Quit application, maybe should do something better, like pop-up a message, but
+ // that would be annoying too.. so lets just exit here
+ Application.Exit();
+ }
}
}
@@ -157,10 +168,10 @@ private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventA
// Move
- if (extConf.dictExtConfiguration.ContainsKey(extension))
+ if (extConf.GetCopyPathForExtension(extension) != "")
{
- string moveTo = extConf.dictExtConfiguration[extension].dictActionsPerOS["default"];
+ string moveTo = extConf.GetCopyPathForExtension(extension);
if (!File.Exists(moveTo + "/" + fileName))
File.Copy(Path.GetTempPath() + "/" + fileName, moveTo + "/" + fileName, false);
View
15 MapLoader/PathFinder.cs
@@ -51,8 +51,8 @@ public void GatherPathes()
// 2. Try Default Path
if (pathToStarcraft2Folder == "")
{
- string defaultPath = pathToProgramFiles + "/" + "StarCraft II/";
- if (File.Exists(pathToProgramFiles + "StarCraft II.exe")) pathToStarcraft2Folder = defaultPath;
+ string sc2_defaultPath = pathToProgramFiles + "/" + "StarCraft II/";
+ if (File.Exists(pathToProgramFiles + "StarCraft II.exe")) pathToStarcraft2Folder = sc2_defaultPath;
}
// 3. Try Default Path (Beta)
@@ -63,6 +63,17 @@ public void GatherPathes()
}
dictPathIdentifiers.Add("%SC2_INSTALL_PATH%", pathToStarcraft2Folder);
+
+ // =======================================
+ // STARCRAFT I
+ // (no registry key to my knowledge)
+ // =======================================
+ // 1. Try Default Path
+ string pathToStarcraft1Folder = "";
+ string sc1_defaultPath = pathToProgramFiles + "/" + "StarCraft/";
+ if (File.Exists(pathToProgramFiles + "StarCraft.exe")) pathToStarcraft1Folder = sc1_defaultPath;
+
+ dictPathIdentifiers.Add("%SC1_INSTALL_PATH%", pathToStarcraft1Folder);
}
View
17 MapLoader/extensions.xml
@@ -1,4 +1,15 @@
+<extensions>
+<!-- Starcraft 2 Replays -->
<extension type="s2replay">
-<default>%DOCUMENTS%\Starcraft II Beta\Replays\Multiplayer\Recent</default>
-<windows7>%DOCUMENTS%\Starcraft II Beta\Replays\Multiplayer\Recent</windows7>
-</extension>
+ <default>%DOCUMENTS%\Starcraft II Beta\Replays\Multiplayer\Recent</default>
+ <windows7>%DOCUMENTS%\Starcraft II Beta\Replays\Multiplayer\Recent</windows7>
+</extension>
+<!-- Starcraft 1 Maps -->
+<extension type="scm">
+ <default>%SC1_INSTALL_PATH\maps\BroodWar\</default>
+</extension>
+<!-- Starcraft 1 Replays -->
+<extension type="rep">
+ <default>%SC1_INSTALL_PATH\maps\replays\</default>
+</extension>
+</extensions>
Please sign in to comment.
Something went wrong with that request. Please try again.