/// <summary> /// Download the given mod. Returns the filename it was saved to. /// /// If no filename is provided, the standard_name() will be used. /// /// </summary> /// <param name="filename">Filename.</param> public string Download(CkanModule module, string filename = null) { // Generate a temporary file if none is provided. if (filename == null) { filename = module.StandardName(); } Console.WriteLine(" * Downloading " + filename + "..."); string fullPath = Path.Combine(KSP.DownloadCacheDir(), filename); log.DebugFormat("Downloading {0} to {1}", module.download, fullPath); WebClient agent = new WebClient(); try { agent.DownloadFile(module.download, fullPath); } catch (Exception ex) { // Clean up our file, it's unlikely to be complete. // It's okay if this fails. try { log.DebugFormat("Removing {0} after web error failure", fullPath); File.Delete(fullPath); } catch { // Apparently we need a catch, even if we do nothing. } if (ex is System.Net.WebException && Regex.IsMatch(ex.Message, "authentication or decryption has failed")) { Console.WriteLine("\nOh no! Our download failed!\n"); Console.WriteLine("\t{0}\n", ex.Message); Console.WriteLine("If you're on Linux, try running:\n"); Console.WriteLine("\tmozroots --import --ask-remove\n"); Console.WriteLine("on the command-line to update your certificate store, and try again.\n"); // TODO: Throw an exception that signals we need to exit, rather than // stopping all other code from tidying up. (We do this for now, so // we don't have ugly stack-traces on things we kinda expect.) Environment.Exit(MainClass.EXIT_ERROR); } throw; } return(fullPath); }
public string CachePath(string file) { return(Path.Combine(KSP.DownloadCacheDir(), file)); }