Browse files

Some more error handling (invalid extensions/unable to download file).

It will now ask you for a path to save a map if you dont configure the extension.
  • Loading branch information...
1 parent 15f3ea0 commit dfe84a9dd3737514fc0b1c0e61f26532e1009ea9 @dcramer committed Apr 6, 2010
Showing with 49 additions and 21 deletions.
  1. +28 −11 MapLoader/LoaderForm.cs
  2. +14 −0 MapLoader/PathFinder.cs
  3. +7 −10 MapLoader/Program.cs
View
39 MapLoader/LoaderForm.cs
@@ -40,7 +40,6 @@ private void LoaderForm_Load(object sender, EventArgs e)
pathFinder = new PathFinder();
pathFinder.GatherPathes();
-
// ==========================================================
// Start Download
// ==========================================================
@@ -60,15 +59,23 @@ private void LoaderForm_Load(object sender, EventArgs e)
// ==========================================================
// Check Extension
// ==========================================================
- string fileName = fileUri.Segments[fileUri.Segments.Length - 1];
- string extension = Path.GetExtension(fileName).ToLower().Substring(1);
+ string fileName = fileUri.Segments[fileUri.Segments.Length - 1].Replace('+', ' ');
+ string extension = Path.GetExtension(fileName);
+
+ if (string.IsNullOrEmpty(extension))
+ {
+ MessageBox.Show("The link you followed cannot be handled by Nibbler.", "Nibbler Error", MessageBoxButtons.OK);
+ Application.Exit();
+ }
+
+ extension = extension.ToLower().Substring(1);
if (extConf.IsValidExtension(extension))
{
lblFilename.Text = fileName; // Display filename
//ask user if they want to download file
- if (MessageBox.Show("Do you want to download " + fileName, "Confirm download", MessageBoxButtons.YesNo) == DialogResult.Yes)
+ 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();
@@ -89,7 +96,7 @@ private void LoaderForm_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("Error!", "Timeout!", MessageBoxButtons.OK);
+ MessageBox.Show("Nibbler does not handle files of type " + extension.ToUpper() + ".", "Nibbler Error", MessageBoxButtons.OK);
Application.Exit();
}
}
@@ -103,7 +110,7 @@ private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
// the URL to download the file from
string sUrlToReadFileFrom = fileUri.OriginalString;
// the path to write the file to
- string fileName = fileUri.Segments[fileUri.Segments.Length - 1];
+ string fileName = fileUri.Segments[fileUri.Segments.Length - 1].Replace('+', ' ');
string sFilePathToWriteFileTo = Path.GetTempPath() + "/" + fileName;
// first, we need to get the exact size (in bytes) of the file we are downloading
@@ -169,7 +176,7 @@ private void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
// ==========================================================
private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
- string fileName = fileUri.Segments[fileUri.Segments.Length - 1];
+ string fileName = fileUri.Segments[fileUri.Segments.Length - 1].Replace('+', ' ');
string extension = Path.GetExtension(fileName).ToLower().Substring(1);
// Move
@@ -196,31 +203,41 @@ private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventA
// 1. Check if PathFinder know our Path
string realPath = pathFinder.GetPath(pathIdentfier);
+
+
// 3. Still no path, query the user for setup
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("Missing installation path for " + fileName + ". Would you like configure Nibbler now?", "No path found!", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// 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();
- }
- realPath = pathFinder.GetPath(pathIdentfier);
+ realPath = pathFinder.GetPath(pathIdentfier);
+ }
}
// 4. Still no path?? Okay lets just save the file somewhere else
if (string.IsNullOrEmpty(realPath))
{
moveTo = "";
- break;
}
moveTo = moveTo.Replace(pathIdentfier, realPath);
}
+ if (string.IsNullOrEmpty(moveTo))
+ {
+ SaveFileDialog fileDialog = new SaveFileDialog();
+ fileDialog.FileName = fileName;
+ if (fileDialog.ShowDialog() == DialogResult.OK)
+ {
+ moveTo = fileDialog.FileName.Replace("\\" + fileName, "");
+ }
+ }
if (!string.IsNullOrEmpty(moveTo))
{
View
14 MapLoader/PathFinder.cs
@@ -86,6 +86,13 @@ public void GatherPathes()
string defaultPath = pathToProgramFiles + "/" + "StarCraft II Beta/";
if (File.Exists(pathToProgramFiles + "StarCraft II.exe")) pathToStarcraft2Folder = defaultPath;
}
+
+ // 4. Default to empty path
+ if (string.IsNullOrEmpty(pathToStarcraft2Folder))
+ {
+ pathToStarcraft2Folder = "";
+ }
+
ClientSettings.Default.SC2_INSTALL_PATH = pathToStarcraft2Folder;
}
dictPathIdentifiers.Add("%SC2_INSTALL_PATH%", ClientSettings.Default.SC2_INSTALL_PATH);
@@ -124,6 +131,12 @@ public void GatherPathes()
if (File.Exists(pathToProgramFiles + "StarCraft.exe")) pathToStarcraft1Folder = sc1_defaultPath;
}
+
+ // 3. Default to empty path
+ if (string.IsNullOrEmpty(pathToStarcraft1Folder))
+ {
+ pathToStarcraft1Folder = "";
+ }
ClientSettings.Default.SC1_INSTALL_PATH = pathToStarcraft1Folder;
}
dictPathIdentifiers.Add("%SC1_INSTALL_PATH%", ClientSettings.Default.SC1_INSTALL_PATH);
@@ -154,6 +167,7 @@ public void GatherPathes()
{
pathToWarcraft3Folder = "";
}
+
ClientSettings.Default.WC3_INSTALL_PATH = pathToWarcraft3Folder;
}
dictPathIdentifiers.Add("%WC3_INSTALL_PATH%", ClientSettings.Default.WC3_INSTALL_PATH);
View
17 MapLoader/Program.cs
@@ -16,26 +16,23 @@ static class Program
[STAThread]
static void Main(string[] args)
{
- if (args.Length == 0)
+ /*if (args.Length == 0)
{
Application.Run(new LoaderConfig());
Application.Exit();
return;
}
- string link = args[0];
- //string link = "nibbits://wc3.nibbits.com/maps/get/131603/"
-
+ string link = args[0];*/
+ //string link = "nibbits://wc3.nibbits.com/maps/get/131603/";
+ //string link = "nibbits://sc2.nibbits.com/maps/get/132027/";
+ string link = "nibbits://sc.nibbits.com/maps/get/131761/";
+
link = link.Replace("nibbits://", "http://");
-
+
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new LoaderForm(link));
}
-
-
- static void UnhandledException(object sender, UnhandledExceptionEventArgs ex)
- {
- }
}
}

0 comments on commit dfe84a9

Please sign in to comment.