Skip to content

Commit

Permalink
Refactored a lot of the code.
Browse files Browse the repository at this point in the history
PathFinder should now be functioning in all cases.
App no longer restarts itself after you update options.
  • Loading branch information
dcramer committed Apr 6, 2010
1 parent 5e30d4b commit a53efc8
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 188 deletions.
22 changes: 11 additions & 11 deletions MapLoader/LoaderConfig.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion MapLoader/LoaderConfig.cs
Expand Up @@ -22,7 +22,12 @@ public LoaderConfig()


private void btn_ok_Click(object sender, EventArgs e) private void btn_ok_Click(object sender, EventArgs e)
{ {
Application.Exit(); ClientSettings.Default.SC1_INSTALL_PATH = tb_sc1dir.Text;
ClientSettings.Default.SC2_INSTALL_PATH = tb_sc2dir.Text;
ClientSettings.Default.WC3_INSTALL_PATH = tb_wc3dir.Text;
ClientSettings.Default.Save();
this.Close();
// Application.Exit();
} }


private void Formsetup_Load(object sender, EventArgs e) private void Formsetup_Load(object sender, EventArgs e)
Expand Down
28 changes: 24 additions & 4 deletions MapLoader/LoaderForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 44 additions & 83 deletions MapLoader/LoaderForm.cs
Expand Up @@ -18,15 +18,16 @@ public partial class LoaderForm : Form
ExtensionConfiguration extConf; ExtensionConfiguration extConf;
PathFinder pathFinder; PathFinder pathFinder;
Uri fileUri; Uri fileUri;
string fileLink;


public LoaderForm() public LoaderForm(string fileLink)
{ {
this.fileLink = fileLink;
InitializeComponent(); InitializeComponent();
} }


private void LoaderForm_Load(object sender, EventArgs e) private void LoaderForm_Load(object sender, EventArgs e)
{ {

// ========================================================== // ==========================================================
// Reading XML Extension Config // Reading XML Extension Config
// ========================================================== // ==========================================================
Expand All @@ -43,70 +44,57 @@ private void LoaderForm_Load(object sender, EventArgs e)
// ========================================================== // ==========================================================
// Start Download // Start Download
// ========================================================== // ==========================================================
try WebRequest wrGETURL;
{ wrGETURL = WebRequest.Create(this.fileLink);

string link = Program.NIBBITS_LINK.Replace("nibbits://", "http://");


WebRequest wrGETURL; HttpWebResponse resp = (HttpWebResponse)wrGETURL.GetResponse();
wrGETURL = WebRequest.Create(link); int statusCode = (int)resp.StatusCode;

HttpWebResponse resp = (HttpWebResponse)wrGETURL.GetResponse();
int statusCode = (int)resp.StatusCode;


// ==========================================================
// Check Status Code
// ==========================================================
if (statusCode == 200)
{
// Construct URI
fileUri = resp.ResponseUri;
// ========================================================== // ==========================================================
// Check Status Code // Check Extension
// ========================================================== // ==========================================================
if (statusCode == 200) string fileName = fileUri.Segments[fileUri.Segments.Length - 1];
{ string extension = Path.GetExtension(fileName).ToLower().Substring(1);
// Construct URI
fileUri = resp.ResponseUri;
// ==========================================================
// Check Extension
// ==========================================================
string fileName = fileUri.Segments[fileUri.Segments.Length - 1];
string extension = Path.GetExtension(fileName).ToLower().Substring(1);

if (extConf.IsValidExtension(extension))
{
lblFilename.Text = fileName; // Display filename


//ask user if they want to download file if (extConf.IsValidExtension(extension))
if (MessageBox.Show("Do you want to download " + fileName, "Confirm download", MessageBoxButtons.YesNo) == DialogResult.Yes) {
{ lblFilename.Text = fileName; // Display filename
// a 'DialogResult.Yes' value was returned from the MessageBox
bgWorker.RunWorkerAsync();
}
else
{
Application.Exit();
}


//ask user if they want to download file
if (MessageBox.Show("Do you want to download " + fileName, "Confirm download", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// a 'DialogResult.Yes' value was returned from the MessageBox
bgWorker.RunWorkerAsync();
} }

else else
{ {
// No action for this Extension defined Application.Exit();
// 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...
// or not. waiting for program to do nothing then quit is stupid
// show user a popup!
MessageBox.Show("Error!", "Timeout!", MessageBoxButtons.OK);
Application.Exit();
} }
}


}

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...
// or not. waiting for program to do nothing then quit is stupid
// show user a popup!
MessageBox.Show("Error!", "Timeout!", MessageBoxButtons.OK);
Application.Exit();
}
} }
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Application.Exit();
};
} }



// ========================================================== // ==========================================================
// Downloads the File // Downloads the File
// ========================================================== // ==========================================================
Expand Down Expand Up @@ -206,23 +194,10 @@ private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventA
// to the real Path // to the real Path
// ============================================== // ==============================================
// 1. Check if PathFinder know our Path // 1. Check if PathFinder know our Path
string realPath = ""; string realPath = pathFinder.GetPath(pathIdentfier);

switch (pathIdentfier)
{
case "WC3_INSTALL_PATH":
realPath = MapLoader.ClientSettings.Default.WC3_INSTALL_PATH;
break;
case "SC1_INSTALL_PATH":
realPath = MapLoader.ClientSettings.Default.SC1_INSTALL_PATH;
break;
case "SC2_INSTALL_PATH":
realPath = MapLoader.ClientSettings.Default.SC2_INSTALL_PATH;
break;
}


// 3. Still no path, query the user for setup // 3. Still no path, query the user for setup
if (realPath == "") if (string.IsNullOrEmpty(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) 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)
{ {
Expand All @@ -231,37 +206,23 @@ private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventA
setup.SetApartmentState(ApartmentState.STA); setup.SetApartmentState(ApartmentState.STA);
setup.Start(); setup.Start();
setup.Join(); 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); realPath = pathFinder.GetPath(pathIdentfier);
} }


// 4. Still no path?? Okay lets just save the file somewhere else // 4. Still no path?? Okay lets just save the file somewhere else
if (realPath == "") if (string.IsNullOrEmpty(realPath))
{ {
moveTo = ""; moveTo = "";
break; break;
} }



moveTo = moveTo.Replace(pathIdentfier, realPath); moveTo = moveTo.Replace(pathIdentfier, realPath);

} }




if (moveTo != "") if (!string.IsNullOrEmpty(moveTo))
{ {
if (!File.Exists(moveTo + "/" + fileName)) if (!File.Exists(moveTo + "/" + fileName))
{ {
Expand Down
36 changes: 36 additions & 0 deletions MapLoader/LoaderForm.resx
Expand Up @@ -123,4 +123,40 @@
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>123, 17</value> <value>123, 17</value>
</metadata> </metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="pictureBox1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAAa7SURBVFhH7Zh5bBRVHMdREUyAkAjlKi1iS4iBUiiHoiAt
kRYJ0dRo0sREQgwYEQMECEQxIdRCuKIC4VADKPSCYiH0tpWUFugKNJQ7FLZb2m7vdq+Z2Zl5M8/vm2nX
Znc7a8r8wR9ufiGbsr/3Pu93vd/vDRoyNuK5kkHPFQ1g/gcKFSHmW+jlMRMHh4X3JyEjJDjQsImvj4iM
NhD84JXxkwJXx98/Xv21xdZsqQsiZy5dGwgQjngw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