public bool UpdatePlugin(string name) { setupService.Repositories.UpdateAllRepositories(new ProgressStatus()); Addin addin = AddinManager.Registry.GetAddins().SingleOrDefault(p => p.Description.LocalId.Equals(name, StringComparison.OrdinalIgnoreCase)); if (addin == null) { Logger.Error("The plugin {0} is not installed!", name); return(false); } AddinRepositoryEntry[] entries = setupService.Repositories.GetAvailableAddinUpdates(addin.LocalId, RepositorySearchFlags.LatestVersionsOnly); if (entries.Any()) { var entry = entries.First(); var property = entry.Addin.Properties.SingleOrDefault(p => p.Name.Equals("sharpstar", StringComparison.OrdinalIgnoreCase)); if (property != null) { Version ver = Assembly.GetEntryAssembly().GetName().Version; string verStr = String.Format("{0}.{1}.{2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision); if (Addin.CompareVersions(verStr, property.Value) <= 0) { Logger.Info("Plugin {0} is now updating to version {1}!", addin.Description.LocalId, entry.Addin.Version); setupService.Install(new ProgressStatus(), entries); AddinManager.Registry.EnableAddin(entry.Addin.Id); AddinManager.Registry.Update(); } else { Logger.Error("Plugin {0} now requires SharpStar version {1}+. Update failed!", addin.Description.LocalId, property.Value); } return(true); } else { Logger.Error("Plugin {0} does not define a minimum SharpStar version requirement. Update failed!", addin.Description.LocalId); } } return(false); }
public void LoadPlugins() { Logger.Info("Loading plugins..."); if (!Directory.Exists(PluginDirectoryPath)) { Directory.CreateDirectory(PluginDirectoryPath); } foreach (FileInfo fInfo in new DirectoryInfo(PluginDirectoryPath).GetFiles()) { LoadPlugin(fInfo.FullName); } _csPluginManager.LoadPlugins(); Logger.Info("Plugins Loaded!"); }
private static void Main(string[] args) { XmlConfigurator.Configure(); Logger = SharpStarLogger.DefaultLogger; SharpStarMain m = SharpStarMain.Instance; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; Version ver = Assembly.GetExecutingAssembly().GetName().Version; Logger.Info("SharpStar Version {0}.{1}.{2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision); if (MonoHelper.IsRunningOnMono()) { string monoVer = MonoHelper.GetMonoVersion(); if (!string.IsNullOrEmpty(monoVer)) { Logger.Info("Running on Mono version {0}", monoVer); if (!monoVer.StartsWith("3.2")) { Logger.Warn("You are running a version of Mono that has not been tested with SharpStar!"); Logger.Warn("SharpStar has been tested with Mono version 3.2.8. Versions other than that are not supported and may cause problems!"); } } } m.Start(); while (true) { string line = Console.ReadLine(); if (string.IsNullOrEmpty(line)) { continue; } string[] cmd = line.Split(' '); if (cmd.Length == 0) { continue; } SharpStarUser user; switch (cmd[0]) { case "loadplugin": if (cmd.Length != 2) { Logger.Info("Syntax: loadplugin <file> (where file is in the \"{0}\" folder)", PluginManager.PluginDirectory); } else { try { m.PluginManager.LoadPlugin(Path.Combine(PluginManager.PluginDirectoryPath, cmd[1])); } catch (Exception ex) { Logger.Error(ex.Message); } } break; case "unloadplugin": if (cmd.Length != 2) { Logger.Info("Syntax: unloadplugin <file>"); } else { try { m.PluginManager.UnloadPlugin(Path.Combine(PluginManager.PluginDirectoryPath, cmd[1])); } catch (Exception ex) { Logger.Error(ex.Message); } } break; case "reloadplugins": m.PluginManager.Reload(); break; case "updateplugins": Logger.Info("Updating Plugins..."); m.PluginManager.CSPluginManager.UpdatePlugins(); Logger.Info("Finished updating plugins!"); break; case "updateplugin": string updPlugin = string.Join(" ", cmd.Skip(1)); if (m.PluginManager.CSPluginManager.UpdatePlugin(updPlugin)) { Logger.Info("Plugin {0} updated!", updPlugin); } else { Logger.Error("Error updating plugin {0}", updPlugin); } break; case "installplugin": string instPlugin = string.Join(" ", cmd.Skip(1)); m.PluginManager.CSPluginManager.InstallPlugin(instPlugin); break; case "uninstallplugin": string uninstPlugin = string.Join(" ", cmd.Skip(1)); m.PluginManager.CSPluginManager.UninstallPlugin(uninstPlugin); break; case "unloadplugins": m.PluginManager.UnloadPlugins(); break; case "exit": m.Shutdown(); Environment.Exit(0); break; case "addperm": if (cmd.Length == 4) { user = m.Database.GetUser(cmd[1]); if (user == null) { Logger.Info("User does not exist!"); } else { bool allowed; bool.TryParse(cmd[3], out allowed); m.Database.AddPlayerPermission(user.Id, cmd[2], allowed); Logger.Info("Added permission to user {0}!", user.Username); } } else { Logger.Info("Syntax: addperm <username> <permission> <allowed>"); } break; case "removeperm": if (cmd.Length == 3) { user = m.Database.GetUser(cmd[1]); if (user == null) { Logger.Info("User does not exist!"); } else { m.Database.DeletePlayerPermission(user.Id, cmd[2]); Logger.Info("Permission removed from {0}!", user.Username); } } else { Logger.Info("Syntax: removeperm <username> <permission>"); } break; case "op": if (cmd.Length == 2) { user = m.Database.GetUser(cmd[1]); if (user == null) { Logger.Info("User does not exist!"); } else { m.Database.ChangeAdminStatus(user.Id, true); Logger.Info("{0} is now an admin!", user.Username); } } break; case "deop": user = m.Database.GetUser(cmd[1]); if (user == null) { Logger.Info("User does not exist!"); } else { m.Database.ChangeAdminStatus(user.Id, false); Logger.Info("{0} is no longer an admin!", user.Username); } break; default: if (cmd.Length > 1) { m.PluginManager.PassConsoleCommand(cmd[0], new string(line.Skip(cmd[0].Length + 1).ToArray()).Split(' ')); } else { m.PluginManager.PassConsoleCommand(cmd[0], new string[0]); } break; } } }