public static VersionResult CheckUpdates(bool isConsole) { if (UpdaterDisabled) { if (!_shown) { Logger.Log(LogType.Warning, "Updater is disabled. Will not check for updates. Continuing with current version"); } _shown = true; return(VersionResult.Current); } else { try { Version currentOnline = Version.ToVersion( NetworkUtils.GetUrlSourceAsList("http://gemz.christplay.x10host.com/current_version.txt")); int versionCompare = Version.Compare(LatestStable, currentOnline); switch (versionCompare) { case -1: return(VersionResult.Current); case 0: return(VersionResult.Developer); case 1: return(VersionResult.Outdated); default: return(VersionResult.Current); } } catch { const string message = "Unable to check for updates for GemsCraft. For this session (and maybe more) " + "you will not be able to update and further update checks will be disabled."; Logger.Log(LogType.Warning, message); if (!isConsole) { MessageBox.Show(message); } UpdaterDisabled = true; return(VersionResult.Current); } } }
private void Initialize() { try { if (!Directory.Exists("plugins")) { Directory.CreateDirectory("plugins"); } } catch (Exception ex) { Logger.Log(LogType.Error, "PluginManager.Initialize: " + ex); return; } // Load plugins string[] plugins = Directory.GetFiles("plugins", "*.dll"); if (plugins.Length == 0) { Logger.Log(LogType.ConsoleOutput, "PluginManager: No plugins found"); } else { Logger.Log(LogType.ConsoleOutput, "PluginManager: Loading " + plugins.Length + " plugins"); foreach (string plugin in plugins) { try { Type pluginType = null; string args = plugin.Substring(plugin.LastIndexOf("\\") + 1, plugin.IndexOf(".dll") - plugin.LastIndexOf("\\") - 1); string file = Path.GetFullPath(plugin); if (Path.GetExtension(file) != ".dll") { continue; // Continue to next file } Assembly assembly = Assembly.LoadFile(file); pluginType = assembly.GetType(args + ".Init"); if (pluginType == null) { continue; // Ignore dll's that are not comptatible, including plugins made for other fCraft forks } // Uses a temp variable so we can load the defaults of the plugin later // This prevents the user from modifiying key elements important to the plugin in the config file IPlugin pluginObj = null; IPlugin temp = (IPlugin)Activator.CreateInstance(pluginType); // Checks to make sure the plugin is updated - this is crucial! if (Version.Compare(temp.SoftwareVersion, Updater.LatestStable) != -1) { throw new Exception( $"Plugin {temp.Name} uses an outdated version of GemsCraft. Check with the plugin developer to have it updated."); } // Checks to see if a property file exists for the plugin. string propertyName = $"plugins/{temp.Name}.json"; if (!File.Exists(propertyName)) { Logger.Log(LogType.Warning, $"Property file does not exist for plugin {temp.Name}. Assuming defaults."); } else { pluginObj = JsonConvert.DeserializeObject <IPlugin>(propertyName); } if (pluginObj == null) { pluginObj = temp; } else { // Reinstates the key items as they should be, in case the user modified them in the config pluginObj.Name = temp.Name; pluginObj.Version = temp.Version; pluginObj.FileName = temp.FileName; pluginObj.Author = temp.Author; pluginObj.ReleaseDate = temp.ReleaseDate; } // Adds the plugin to the list. Plugins.Add(pluginObj); } catch (Exception ex) { Logger.Log(LogType.Error, "PluginManager: Unable to load plugin at location " + plugin + ": " + ex); } } LoadPlugins(); } }