Permalink
Browse files

Added setup in Formsetup.

Mod Form1.cs if no path, ask user for setup, then restart
Mod Form1.cs if file exist ask for overwrite
If you start without arguments Formsetup will load.
If you start with arguments Form1 will load.
  • Loading branch information...
1 parent 765a6f6 commit 7e8b31d604c33256f7a1c3d02abb2c05a3a09736 @pooslice pooslice committed Mar 18, 2010
View
@@ -9,7 +9,7 @@
using System.Net;
using System.IO;
using Microsoft.Win32;
-using Utility.ModifyRegistry;
+using System.Threading;
namespace MapLoader
{
@@ -38,7 +38,6 @@ private void Form1_Load(object sender, EventArgs e)
// Find Pathes for Game Folders etc.
// ==========================================================
pathFinder = new PathFinder();
-
pathFinder.GatherPathes();
pathUser = new PathUserDefined();
@@ -96,7 +95,7 @@ private void Form1_Load(object sender, EventArgs e)
// that would be annoying too.. so lets just exit here...
// or not. waiting for program to do nothing then quit is stupid
// show user a popup!
- MessageBox.Show("Timeout!", "Timeout!", MessageBoxButtons.OK);
+ MessageBox.Show("Error!", "Timeout!", MessageBoxButtons.OK);
Application.Exit();
}
}
@@ -208,7 +207,6 @@ private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventA
// Translate our PathIdentifier
// to the real Path
// ==============================================
-
// 1. Check if PathFinder know our Path
string realPath = pathFinder.GetPath(pathIdentfier);
@@ -217,19 +215,31 @@ private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventA
{
realPath = pathUser.GetPath(pathIdentfier);
}
- // 3. Still no path, query the user
+ // 3. Still no path, query the user for setup
if (realPath == "")
{
- realPath = pathUser.QueryUserForPath(this, pathIdentfier);
-
- if (realPath != "")
+ if (MessageBox.Show("No path was found to save " + fileName + " to. Do you want to go to setup?", "No path found!", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
- //Save path to registry
- ModifyRegistry mysc1Registry = new ModifyRegistry();
- mysc1Registry.BaseRegistryKey = Registry.CurrentUser;
- mysc1Registry.SubKey = "Software\\Blizzard Entertainment\\Starcraft\\";
- mysc1Registry.Write("InstallPath", realPath);
+ // open setup if user say yes
+ System.Threading.Thread setup = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc));
+ setup.SetApartmentState(ApartmentState.STA);
+ setup.Start();
+ setup.Join();
+ //RESTART APPLICATION
+ //TODO: the same arguments need to be returned.
+
+ // Get the parameters/arguments passed to program if any
+ string arguments = string.Empty;
+ string[] args = Environment.GetCommandLineArgs();
+ for (int i = 1; i < args.Length; i++) // args[0] is always exe path/filename
+ arguments += args[i] + " ";
+
+
+ Application.Exit();
+ System.Diagnostics.Process.Start(Application.ExecutablePath, arguments);
}
+
+ realPath = pathFinder.GetPath(pathIdentfier);
}
// 4. Still no path?? Okay lets just save the file somewhere else
@@ -249,18 +259,29 @@ private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventA
{
if (!File.Exists(moveTo + "/" + fileName))
{
- // TODO: "File already exists, replace?"
+ // If the file does not excist. Copy it to the correct folder
File.Copy(Path.GetTempPath() + "/" + fileName, moveTo + "/" + fileName, false);
}
+
+ else
+ {
+
+ // If file excist, ask for overwrite.
+ if (MessageBox.Show("Do you want to overwrite " + fileName, "File already excist!", MessageBoxButtons.YesNo) == DialogResult.Yes)
+ {
+ // a 'DialogResult.Yes' value was returned from the MessageBox
+ File.Copy(Path.GetTempPath() + "/" + fileName, moveTo + "/" + fileName, true);
+ }
+ }
}
- else
- {
- // TODO: save somewhere else
- }
-
// be gone!
- // Application.Exit();
+ Application.Exit();
+ }
+
+ public static void ThreadProc()
+ {
+ Application.Run(new Formsetup());
}
}
}

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

Oops, something went wrong.
View
@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+using System.IO;
+
+namespace MapLoader
+{
+ public partial class Formsetup : Form
+ {
+ ExtensionConfiguration extConf;
+ PathFinder pathFinder;
+ PathUserDefined pathUser;
+
+ public Formsetup()
+ {
+ InitializeComponent();
+ }
+
+ private void btn_ok_Click(object sender, EventArgs e)
+ {
+ Application.Exit();
+ }
+
+ private void Formsetup_Load(object sender, EventArgs e)
+ {
+ // ==========================================================
+ // Reading XML Extension Config
+ // ==========================================================
+ extConf = new ExtensionConfiguration();
+ extConf.ReadConfig();
+
+ // ==========================================================
+ // Find Pathes for Game Folders etc.
+ // ==========================================================
+ 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;
+
+ string sc2 = pathFinder.GetPath("%SC2_INSTALL_PATH%");
+ tb_sc2dir.Text = sc2;
+
+ string wc3 = pathFinder.GetPath("%WC3_INSTALL_PATH%");
+ tb_wc3dir.Text = wc3;
+ }
+
+ private void btn_sc1dir_Click(object sender, EventArgs e)
+ {
+ string sc1 = pathUser.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%");
+ tb_sc2dir.Text = sc2;
+ }
+
+ private void btn_wc3dir_Click(object sender, EventArgs e)
+ {
+ string wc3 = pathUser.QueryUserForPath(this, "%WC3_INSTALL_PATH%");
+ tb_wc3dir.Text = wc3;
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 7e8b31d

Please sign in to comment.