public Plugin loadPlugin(string PluginPath) { try { string name = new FileInfo(PluginPath).Name; Assembly pluginAssembly = Assembly.LoadFrom(PluginPath); if (name.Contains(".")) { name = name.Split('.')[0]; } Type pluginType = pluginAssembly.GetType(name + "." + name); Plugin plugin = (Plugin)Activator.CreateInstance(pluginType); if (plugin == null) { Console.WriteLine("Error Loading Plugin '" + PluginPath + "'. Is it up to Date?"); } else { plugin.Server = server; plugin.Load(); return plugin; } } catch (Exception exception) { Console.WriteLine("Error Loading Plugin '" + PluginPath + "' : " + exception.ToString()); } return null; }
private string getEstensioneIntoSignedFile(string fullname) { string retValue = string.Empty; // Reperimento del nome del file con estensione string fileName = new System.IO.FileInfo(fullname).Name; string[] items = fileName.Split('.'); // SKIZZO decommentare per icona giusta. for (int i = (items.Length - 1); i >= 0; i--) { if (!(items[i].ToUpper().EndsWith("P7M") || items[i].ToUpper().EndsWith("TSD") || items[i].ToUpper().EndsWith("M7M") )) { retValue = items[i]; break; } } return(retValue); }
string CreateNameFromPath(string path) { var name = new FileInfo(path).Name; var parts = name.Split(new[] { '_' }); if(parts.Length != 4) throw new Exception("Invalid Version found"); return String.Format("v.{0} {1} {2}", parts[1], new DateTime(long.Parse(parts[2])), parts[3].Replace(".xml", "")); }
IVersionInfo CreateVersionInfoFromFilePath(string path, Guid resourceId) { var name = new FileInfo(path).Name; var parts = name.Split(new[] { '_' }); if(parts.Length != 4) throw new Exception("Invalid Version found"); return new VersionInfo(new DateTime(long.Parse(parts[2])), parts[3], "", parts[1], resourceId, Guid.Parse(parts[0])); }
/// <summary> /// Loads the plugin.yml file of a .jar plugin /// </summary> /// <param name="path">the path of the plugin.jar file</param> /// <param name="readCache">if this plugin should be read from cache if possible</param> /// <returns>The InstalledPlugin (me)</returns> /// <remarks></remarks> public InstalledPlugin Loadplugin(string path, bool readCache = true) { try { // to reduce load times and CPU usage, plugin.yml files are cached // location: cache/plugins/plugin_name/plugin.yml // Detect reletive locations and prepend thise with the plugin dir if (path.Contains(":\\") == false) // has to start with C:\ (\\ due to escaping special characters) path = Fl.Location(RequestFile.Plugindir) + "\\" + path; // get a fileinfo object for the plugin FileInfo plugFileInfo = new FileInfo(path); // get a fileinfo object for the cache FileInfo cacheFileInfo = new FileInfo(Fl.Location(RequestFile.Cache) + "/plugins/" + plugFileInfo.Name + "/plugin.yml"); Logger.Log(LogLevel.Info, "InstalledPlugin", "loading plugin (step 1/2): " + plugFileInfo.Name + " - cache allowed:" + readCache); //check if the cache exists, if not, create cache (we need this cache file, it will be read later on) if (cacheFileInfo.Exists & readCache) { // cache exists, ok Logger.Log(LogLevel.Info, "InstalledPlugin", "Reading plugin data from cache..."); } else { // cache doesn't exist or is forcefully invalidated by parameter, create //safety check if (string.IsNullOrEmpty(path) || plugFileInfo.Exists == false) { return null; } Logger.Log(LogLevel.Info, "InstalledPlugin", "Plugin data not available in cache or cache not allowed. Building cache for plugin..."); Compression.Decompress(Fl.Location(RequestFile.Temp) + "/plugin", path); // check if the plugin.yml file was decompressed if (!File.Exists(Fl.Location(RequestFile.Temp) + "/plugin/plugin.yml")) { return null; } if (cacheFileInfo.Directory != null && !cacheFileInfo.Directory.Exists) cacheFileInfo.Directory.Create(); //copy the yml to cache File.Copy(Fl.Location(RequestFile.Temp) + "/plugin/plugin.yml", cacheFileInfo.FullName, true); if (Directory.Exists(Fl.Location(RequestFile.Temp) + "/plugin")) Directory.Delete(Fl.Location(RequestFile.Temp) + "/plugin", true); } // either way is cache now okay, it already existed or was created just now Logger.Log(LogLevel.Info, "InstalledPlugin", "loading plugin (step 2/2): " + plugFileInfo.Name + " - cache allowed:" + readCache); // load the yml file if (File.Exists(cacheFileInfo.FullName)) Loadymlfile(cacheFileInfo.FullName); FileCreationDate = File.GetLastWriteTime(path); FileName = new FileInfo(path).Name; if (Name == null || string.IsNullOrEmpty(Name) && FileName.Contains(".")) Name = FileName.Split('.')[0]; //if name couldn't be read from yml, parse FileName Logger.Log(LogLevel.Info, "InstalledPlugin", "loaded plugin: " + plugFileInfo.Name + " - cache allowed:" + readCache); return this; //return this item } catch (Exception ex) { Logger.Log(LogLevel.Warning, "InstalledPlugin", "An exception occured when trying to load plugin", ex.Message); return null; } }
/// <summary> /// 创建Orc实例(from Directory) /// </summary> /// <param name="offsetX"></param> /// <param name="offsetY"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="resource"></param> /// <returns></returns> public static OrcUtil getInstance(int[] offsetX, int offsetY, int width, int height, String dictPath) { OrcUtil rtn = new OrcUtil(); rtn.offsetX = offsetX; rtn.offsetY = offsetY; rtn.width = width; rtn.height = height; rtn.dict = new Dictionary<Bitmap, String>(); String[] files = System.IO.Directory.GetFiles(dictPath); foreach (String file in files) { String name = new System.IO.FileInfo(file).Name; String[] array = name.Split(new char[] { '.' }); Bitmap bitmap = new Bitmap(file); rtn.dict.Add(bitmap, array[0]); } return rtn; }
/// <summary> /// Processes all Flyspeck linear programs in the current directory /// </summary> static void ProcessFlyspeckLP() { ListHypManager hypermaps = InitializeHypermaps(); // GenerateExamples(); string[] files = Directory.GetFiles(".", "*.lp"); FileStream fs = new FileStream("all_tests.hl", FileMode.Create); StreamWriter w = new StreamWriter(fs); w.WriteLine("let start = Sys.time();;"); int i = 1; foreach (string file in files) { string name = new FileInfo(file).Name; string[] els = name.Split('.'); ListHyp hypermap = hypermaps[els[0]]; hypermap.ComputeAllSets(); ProcessLP(els[0], new LpNumber(12), hypermap); w.WriteLine("\"Case: {0}/{1}\";;", i++, files.Length); w.WriteLine("let _ = needs \"{0}\" in Sys.time() -. start;;", els[0] + "_out.hl"); // break; } w.Flush(); fs.Close(); }