private void ModuleDownloadComplete(Uri url, string filename, Exception error) { if (error != null) { log.Info(error.ToString()); } else { // Cache if this download succeeded try { CkanModule module = modules.First(m => m.download == url); cache.Store(module, filename, module.StandardName()); File.Delete(filename); } catch (InvalidModuleFileKraken kraken) { User.RaiseError(kraken.ToString()); } catch (FileNotFoundException e) { log.WarnFormat("cache.Store(): FileNotFoundException: {0}", e.Message); } } }
/// <summary> /// Stores all of our files in the cache once done. /// Called by NetAsyncDownloader on completion. /// Called with all nulls on download cancellation. /// </summary> private void ModuleDownloadsComplete(NetModuleCache cache, Uri[] urls, string[] filenames, Exception[] errors) { if (filenames != null) { for (int i = 0; i < errors.Length; i++) { if (errors[i] == null) { // Cache the downloads that succeeded. try { cache.Store(modules[i], filenames[i], modules[i].StandardName()); } catch (FileNotFoundException e) { log.WarnFormat("cache.Store(): FileNotFoundException: {0}", e.Message); } } } // Finally, remove all our temp files. // We probably *could* have used Store's integrated move function above, but if we managed // to somehow get two URLs the same in our download set, that could cause right troubles! foreach (string tmpfile in filenames) { log.DebugFormat("Cleaning up {0}", tmpfile); File.Delete(tmpfile); } } }
/// <summary> /// Downloads the given mod to the cache. Returns the filename it was saved to. /// </summary> public static string Download(CkanModule module, string filename, NetModuleCache cache) { log.Info("Downloading " + filename); string tmp_file = Net.Download(module.download); return(cache.Store(module, tmp_file, filename, true)); }
/// <summary> /// Stores all of our files in the cache once done. /// Called by NetAsyncDownloader on completion. /// Called with all nulls on download cancellation. /// </summary> private void ModuleDownloadsComplete(NetModuleCache cache, Uri[] urls, string[] filenames, Exception[] errors) { if (urls != null) { // spawn up to 3 dialogs int errorDialogsLeft = 3; for (int i = 0; i < errors.Length; i++) { if (errors[i] != null) { if (errorDialogsLeft > 0) { User.RaiseError("Failed to download \"{0}\" - error: {1}", urls[i], errors[i].Message); errorDialogsLeft--; } } else { // Even if some of our downloads failed, we want to cache the // ones which succeeded. // This doesn't work :( // for some reason the tmp files get deleted before we get here and we get a nasty exception // not only that but then we try _to install_ the rest of the mods and then CKAN crashes // and the user's registry gets corrupted forever // commenting out until this is resolved // ~ nlight try { cache.Store(modules[i], filenames[i], modules[i].StandardName()); } catch (FileNotFoundException e) { log.WarnFormat("cache.Store(): FileNotFoundException: {0}", e.Message); } } } } if (filenames != null) { // Finally, remove all our temp files. // We probably *could* have used Store's integrated move function above, but if we managed // to somehow get two URLs the same in our download set, that could cause right troubles! foreach (string tmpfile in filenames) { log.DebugFormat("Cleaning up {0}", tmpfile); File.Delete(tmpfile); } } }