public Task <PluginInstallationResult> install(Uri download, Uri website) { return(Task.Run(async() => { List <FileInfo> dependecys = new List <FileInfo>(); UniversalWebClient client = new UniversalWebClient(); FileInfo tmpFile = new FileInfo(manager.PluginFolder.FullName + "\\plugin.tmp"); await client.DownloadFileTaskAsync(download.ToString(), tmpFile.FullName); ZipFile archive = new ZipFile(tmpFile.FullName); if (archive.TestArchive(true)) { try { RocketPlugin plugin = null; ExtractZipResult res = await extractZip(archive); List <FileInfo> dependencys = new List <FileInfo>(); FileInfo plFile = null; foreach (ExtractEntryResult entry in res.entries) { switch (entry.Type) { case PluginEntryType.Plugin: plFile = entry.File; break; case PluginEntryType.Dependency: dependencys.Add(entry.File); break; case PluginEntryType.Unknown: continue; default: break; } } plugin = new RocketPlugin(plFile, website.ToString(), plugin.ServerVersion, dependencys); archive.Close(); manager.add(plugin); return PluginInstallationResult.OK; } catch (Exception) { return PluginInstallationResult.Failed; } } else { return PluginInstallationResult.FailedNotAZip; } })); }
public SteamInstaller(string folder) { try { Folder = new DirectoryInfo(folder); } catch (Exception ex) { throw ex; } Client = new UniversalWebClient(); Client.DownloadFileCompleted += (sender, e) => { unzipPackage(); }; }
public async Task <RocketModInstallationCompletedType> Install(bool clean = false) { var task = Task.Run(() => { try { bool updateAvailable = IsUpdateAvailable().Result; if (clean | updateAvailable) { string v = GetServerVersion().Result; try { string tmpFile = gamedir.FullName + "\\rocketmod.tmp"; ManualResetEvent waitInstallCompleted = new ManualResetEvent(false); bool failed = false; UniversalWebClient client = new UniversalWebClient(); client.DownloadFileCompleted += (sender, e) => { try { FileInfo info = new FileInfo(tmpFile); if (info.Length > 0) { UtilsGeneral.extractZipSerial(info, gamedir); LocalVersion = v; } else { failed = true; } } catch (Exception) { failed = true; } waitInstallCompleted.Set(); }; if (File.Exists(tmpFile)) { File.Delete(tmpFile); } client.DownloadFileAsync(downloadAddr, tmpFile); waitInstallCompleted.WaitOne(); if (failed) { RocketInstallationCompleted?.Invoke(this, RocketModInstallationCompletedType.FailedUnknownException); return(RocketModInstallationCompletedType.FailedUnknownException); } else { RocketInstallationCompleted?.Invoke(this, RocketModInstallationCompletedType.Success); return(RocketModInstallationCompletedType.Success); } } catch (Exception) { RocketInstallationCompleted?.Invoke(this, RocketModInstallationCompletedType.FailedNoInternetAccessOrNoIOPermissions); return(RocketModInstallationCompletedType.FailedNoInternetAccessOrNoIOPermissions); } } else { RocketInstallationCompleted?.Invoke(this, RocketModInstallationCompletedType.Success); return(RocketModInstallationCompletedType.Success); } } catch (Exception) { RocketInstallationCompleted?.Invoke(this, RocketModInstallationCompletedType.FailedUnknownException); return(RocketModInstallationCompletedType.FailedUnknownException); } }); return(await task); }