/// <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(NetFileCache 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(urls[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); } } // Signal that we're done. complete_or_canceled.Set(); User.RaiseDownloadsCompleted(urls, filenames, errors); }
/// <summary> /// Downloads the given mod to the cache. Returns the filename it was saved to. /// </summary> public static string Download(Uri url, string filename, NetFileCache cache) { log.Info("Downloading " + filename); string tmp_file = Net.Download(url); return(cache.Store(url, tmp_file, filename, move: 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(NetFileCache cache, Uri[] urls, string[] filenames, Exception[] errors) { if (urls != null) { for (int i = 0; i < errors.Length; i++) { if (errors[i] != null) { User.RaiseError("Failed to download \"{0}\" - error: {1}", urls[i], errors[i].Message); } else { // Even if some of our downloads failed, we want to cache the // ones which succeeded. cache.Store(urls[i], filenames[i], modules[i].StandardName()); } } } // TODO: If we've had our download cancelled, how do we clean our tmpfiles? 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_transaction.Delete(tmpfile); } } // Signal that we're done. lock (download_complete_lock) { Monitor.Pulse(download_complete_lock); } User.RaiseDownloadsCompleted(urls, filenames, errors); }
/// <summary> /// Downloads the given mod to the cache. Returns the filename it was saved to. /// </summary> public static string Download(Uri url, string filename, NetFileCache cache) { log.Info("Downloading " + filename); string tmp_file = Net.Download(url); return cache.Store(url, tmp_file, filename, true); }