Permalink
Browse files

added userdefined pathes

  • Loading branch information...
1 parent 83bb470 commit e012f9881273d2a5d347071910b35c43e649f63b @jag2011 jag2011 committed Mar 2, 2010
Showing with 122 additions and 5 deletions.
  1. +6 −0 MapLoader/Form1.Designer.cs
  2. +60 −5 MapLoader/Form1.cs
  3. +3 −0 MapLoader/Form1.resx
  4. +4 −0 MapLoader/PathFinder.cs
  5. +49 −0 MapLoader/PathUserDefined.cs

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

Oops, something went wrong.
View
@@ -15,6 +15,7 @@ public partial class Form1 : Form
{
ExtensionConfiguration extConf;
PathFinder pathFinder;
+ PathUserDefined pathUser;
Uri fileUri;
public Form1()
@@ -35,6 +36,8 @@ private void Form1_Load(object sender, EventArgs e)
// ==========================================================
pathFinder = new PathFinder();
pathFinder.GatherPathes();
+ pathUser = new PathUserDefined();
+
// ==========================================================
// Start Download
@@ -165,17 +168,69 @@ private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventA
{
string fileName = fileUri.Segments[fileUri.Segments.Length - 1];
string extension = Path.GetExtension(fileName).ToLower().Substring(1);
-
-
+
// Move
- if (extConf.GetCopyPathForExtension(extension) != "")
+ string moveTo = extConf.GetCopyPathForExtension(extension);
+
+ // Construct Path
+ while (moveTo.IndexOf("%") != -1)
{
+ int pos1 = moveTo.IndexOf("%");
+ int pos2 = moveTo.IndexOf("%",pos1+1);
+
+ // something is wrong with our XML, save the file somwhere else
+ if (pos2 == -1) {
+ moveTo = "";
+ break;
+ }
+
+ string pathIdentfier = moveTo.Substring(pos1, pos2 - pos1);
+
+ // ==============================================
+ // Translate our PathIdentifier
+ // to the real Path
+ // ==============================================
+
+ // 1. Check if PathFinder know our Path
+ string realPath = pathFinder.GetPath(pathIdentfier);
+
+ // 2. Check if user has defined a custom path
+ if (realPath == "")
+ {
+ pathUser.GetPath(pathIdentfier);
+ }
+ // 3. Still no path, query the user
+ if (realPath == "")
+ {
+ pathUser.QueryUserForPath(this,pathIdentfier);
+ }
- string moveTo = extConf.GetCopyPathForExtension(extension);
+ // 4. Still no path?? Okay lets just save the file somewhere else
+ if (realPath == "")
+ {
+ moveTo = "";
+ break;
+ }
- if (!File.Exists(moveTo + "/" + fileName))
+
+ moveTo.Replace(pathIdentfier, realPath);
+
+ }
+
+
+ if (moveTo != "")
+ {
+ if (!File.Exists(moveTo + "/" + fileName))
+ {
+ // TODO: "File already exists, replace?"
File.Copy(Path.GetTempPath() + "/" + fileName, moveTo + "/" + fileName, false);
+ }
+ }
+ else
+ {
+ // TODO: save somewhere else
}
+
// be gone!
Application.Exit();
View
@@ -120,4 +120,7 @@
<metadata name="bgWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
+ <metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+ <value>123, 17</value>
+ </metadata>
</root>
View
@@ -7,6 +7,10 @@
namespace MapLoader
{
+ /// <summary>
+ /// This class trys to automatically find pathes to game folders etc and
+ /// keeps track of them.
+ /// </summary>
class PathFinder
{
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+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
+ {
+ private Dictionary<string, string> dictPathIdentifiers;
+
+ public PathUserDefined()
+ {
+ dictPathIdentifiers = new Dictionary<string, string>();
+ dictPathIdentifiers.Add("%SC1_INSTALL_PATH%", "");
+ }
+
+ public string GetPath(string pathIdentifier) {
+ if (!dictPathIdentifiers.ContainsKey(pathIdentifier)) return "";
+
+ string path = dictPathIdentifiers[pathIdentifier];
+ return path;
+ }
+
+ public string QueryUserForPath(Form1 form, string pathIdentifier)
+ {
+ string returnValue = "";
+ switch (pathIdentifier)
+ {
+ case "%SC1_INSTALL_PATH%":
+ form.openFileDialog1.CheckFileExists = true;
+ form.openFileDialog1.FileName = "Starcraft.exe";
+ if (form.openFileDialog1.ShowDialog() == DialogResult.OK) {
+ returnValue = form.openFileDialog1.FileName;
+ returnValue = returnValue.ToLower().Replace("starcraft.exe", "");
+ }
+ break;
+ }
+ return returnValue;
+ }
+ }
+}

0 comments on commit e012f98

Please sign in to comment.