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 bool remove(RocketPlugin plugin) { try { plugin.PluginFileInfo.Delete(); Plugins.Remove(plugin); saveDatabase(); return(true); } catch (Exception) { return(false); } }
private void loadPlugins(RocketPluginStorage storage) { Plugins.Clear(); if (!PluginFolder.Exists) { PluginFolder.Create(); return; } try { foreach (FileInfo pfile in PluginFolder.GetFiles("*.dll")) { try { RocketPlugin plugin = findPlugin(pfile.Name, storage); add(plugin); } catch (Exception) { continue; } } foreach (FileInfo pfile in PluginFolder.GetFiles("*.dll.inactive")) { try { RocketPlugin plugin = findPlugin(pfile.Name, storage); add(plugin); } catch (Exception) { continue; } } } catch (Exception) { storage.save(PluginDatabaseFile); } }
public Task <RocketPlugin> installZip(string zipfile) { return(Task.Run(async() => { RocketPlugin plugin = null; try { ZipFile archive = new ZipFile(zipfile); ExtractZipResult res = await extractZip(archive); archive.Close(); 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, "", "", dependencys); } catch (Exception) { return null; } return plugin; })); }
public bool add(RocketPlugin plugin) { try { RocketPlugin existingPlugin = getPluginByName(plugin.Name); if (existingPlugin != null) { Plugins.Remove(existingPlugin); } Plugins.Add(plugin); saveDatabase(); return(true); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(false); } }