private void btnUnpack_Click(object sender, EventArgs e) { string tempDir = Path.Combine(PluginPaths.GetPluginTempDirectory(Pointer), "TempUnpack"); if (Directory.Exists(tempDir)) { Directory.Delete(tempDir, true); } Directory.CreateDirectory(tempDir); rtbInputInfo.Text = ""; try { rtbInputInfo.Text += "Unpacking: "; PluginPacker.Unpack(tbInputDir.Text, tempDir); rtbInputInfo.Text += "SUCCESS\nReading Data Format: "; unpackedInputPath = tempDir; inputPtr = PackageDataManager.LoadData(tempDir); rtbInputInfo.Text += "SUCCESS"; panelPack.Enabled = true; } catch (Exception exception) { Directory.Delete(tempDir, true); rtbInputInfo.Text += "FAILED\n"; } }
/// <summary> /// Removes a Package from the Plugin System /// </summary> /// <param name="ptr">Pointer Pointing to the Package that should be removed.</param> /// <param name="keepArchive">When set to false will also delete the backup archive.</param> internal static void RemovePackage(BasePluginPointer ptr, bool keepArchive = true) { //TODO: Check if the Package is in the Installed List. Then we need to wait until the program restarted. List <string> installedPackages = ListHelper.LoadList(PluginPaths.GlobalPluginListFile).ToList(); string package = ptr.ToKeyPair(); if (installedPackages.Contains(package)) { RemovePackageEventArgs args = new RemovePackageEventArgs(ptr, keepArchive, true); OnRemovePackage?.Invoke(args); if (args.Cancel) { return; } keepArchive = args.KeepArchive; installedPackages.Remove(package); ListHelper.SaveList(PluginPaths.GlobalPluginListFile, installedPackages.ToArray()); AfterRemovePackage?.Invoke(new RemovePackageEventArgs(ptr, keepArchive, false)); } PluginPaths.RemovePluginPackageFromDirectoryStructure(ptr, keepArchive); }
private void Application_ApplicationExit(object sender, EventArgs e) { string styleDir = Path.Combine(PluginPaths.GetPluginConfigDirectory(PluginAssemblyData), "styles"); string[] lines = StyleManager.StyleOptions.Where(x => x.HasChanged).Select(x => $"{x.Keyword}: {x.Value}") .ToArray(); File.WriteAllLines(Path.Combine(styleDir, "style.options"), lines); }
/// <summary> /// Initializes the Plugin System. /// </summary> /// <param name="internalConfigPath">The Path that is used by internal config files by the Plugin System</param> /// <param name="pluginDirectory">The Path used as "Install Directory" for Plugins/Packages</param> public static void Initialize( string internalConfigPath, string pluginDirectory, Func <string, string, bool> updateDialog, Action <string, int, int> setStatus, string staticDataConfig = null, bool checkUpdates = true) { if (IsInitialized) { throw new Exception("Can not Initialize the Plugin System Twice"); } SendLog("Initializing Plugin System"); //TODO: Process Things like updates before the plugin system loads the libraries. PluginPaths.InternalSystemConfigPath = Path.GetFullPath(internalConfigPath); PluginPaths.PluginDirectory = Path.GetFullPath(pluginDirectory); PluginPaths.EnsureInternalDirectoriesExist(); PluginPaths.CreateInternalFilesIfMissing(); ErrorHandler.Initialize(); LoadOrder.Initialize(); if (staticDataConfig != null && File.Exists(staticDataConfig)) { StaticData.SetState(File.ReadAllText(staticDataConfig)); } IsInitialized = true; SendLog("Updating.."); PluginHost = new PluginSystemHost(); HelperClass.ReloadDefaultPlugins(); OnInitialized?.Invoke(); if (File.Exists(PluginPaths.InternalStartupInstructionPath)) { SendLog("Running Start Actions.."); ActionRunner.RunActions(); } if (checkUpdates) { ListHelper.LoadList(PluginPaths.PluginListFile).Select(x => new BasePluginPointer(x)).ToList() .ForEach(x => UpdateManager.CheckAndUpdate(x, updateDialog, setStatus)); } SendLog("Registering System Host.."); LoadPlugins(PluginHost); SendLog("Registered System Host.."); SendLogDivider(); //Everything Finished SendLog("Initialization Complete."); SendLogDivider(); }
private void OnShowAppearance() { if (f == null || f.IsDisposed) { string stylePath = Path.Combine(PluginPaths.GetPluginConfigDirectory(PluginAssemblyData), "styles"); f = new EditorThemeSettingsForm(stylePath); f.Show(); } }
public override void OnLoad(PluginAssemblyPointer ptr) { base.OnLoad(ptr); Application.ApplicationExit += Application_ApplicationExit; string styleDir = Path.Combine(PluginPaths.GetPluginConfigDirectory(PluginAssemblyData), "styles"); Directory.CreateDirectory(styleDir); StyleManager_OnReload(); }
public bool CanCheck(BasePluginPointer ptr) { if (ptr.PluginOrigin == "" || !ptr.PluginOrigin.EndsWith(".dll")) { return(false); } Uri origin = ptr.PluginOriginUri; return(origin.Scheme == "file" && File.Exists(PluginPaths.GetPluginAssemblyFile(ptr)) && File.Exists(ptr.PluginOrigin)); }
public void SetExtractPath(Entry entry, string destinationPath) { if (destinationPath != null) { ExtractPaths.Add(entry, destinationPath); if (ArchiveHelpers.IsPlugin(destinationPath)) { PluginPaths.Add(destinationPath); } else if (ArchiveHelpers.IsArchive(destinationPath)) { ArchivePaths.Add(destinationPath); } } }
public override void Install(BasePluginPointer ptr, string folder) { string cdir = GetConfigDir(folder); string bdir = GetBinPath(folder); if (Directory.Exists(cdir)) { HelperClass.CopyTo(cdir, PluginPaths.GetPluginConfigDirectory(ptr)); } if (Directory.Exists(bdir)) { HelperClass.CopyTo(bdir, PluginPaths.GetPluginAssemblyDirectory(ptr)); } }
public override void OnLoad(PluginAssemblyPointer ptr) { base.OnLoad(ptr); if (isEmbedded) { return; } List <string> initList = ListHelper.LoadList(PluginPaths.InitPluginListFile).ToList(); if (!initList.Contains(PluginPaths.GetPluginAssemblyFile(ptr))) { initList.Add(PluginPaths.GetPluginAssemblyFile(ptr)); ListHelper.SaveList(PluginPaths.InitPluginListFile, initList.ToArray()); } }
private void StyleManager_OnReload() { string styleDir = Path.Combine(PluginPaths.GetPluginConfigDirectory(PluginAssemblyData), "styles"); if (File.Exists(Path.Combine(styleDir, "style.options"))) { string[] file = File.ReadAllLines( Path.Combine(styleDir, "style.options") ); foreach (string s in file) { string[] parts = s.Split(':').Select(x => x.Trim()).ToArray(); StyleOption opt = StyleManager.StyleOptions.FirstOrDefault(x => x.Keyword == parts[0]); if (opt != null) { opt.Value = parts[1]; } } } }
public void CheckAndUpdate( BasePluginPointer ptr, Func <string, string, bool> updateDialog, Action <string, int, int> setStatus) { byte[] a = File.ReadAllBytes(PluginPaths.GetPluginAssemblyFile(ptr)); byte[] b = File.ReadAllBytes(ptr.PluginOrigin); bool ret = AreEqual(a, b); if (ret) { return; } if (!updateDialog( $"The file '{ptr.PluginOrigin}' is a different version. Do you want to Update?", "Update: " + ptr.PluginName )) { return; } File.Copy(ptr.PluginOrigin, PluginPaths.GetPluginAssemblyFile(ptr), true); }
private void btnUnpack_Click(object sender, EventArgs e) { string[] files = File.ReadAllLines(tbInputDir.Text); unpackedInputPath = new string[files.Length]; inputPtr = new BasePluginPointer[files.Length]; rtbInputInfo.Text = ""; for (int i = 0; i < files.Length; i++) { string tempDir = Path.Combine(PluginPaths.GetPluginTempDirectory(Pointer), "TempUnpack"); if (Directory.Exists(tempDir)) { Directory.Delete(tempDir, true); } Directory.CreateDirectory(tempDir); try { rtbInputInfo.Text += $"Unpacking({Path.GetFileName(files[i])}): "; PluginPacker.Unpack(files[i], tempDir); rtbInputInfo.Text += "SUCCESS\nReading Data Format: "; inputPtr[i] = PackageDataManager.LoadData(tempDir); string outPath = Path.Combine(PluginPaths.GetPluginTempDirectory(Pointer), inputPtr[i].PluginName); if (Directory.Exists(outPath)) { Directory.Delete(outPath, true); } Directory.Move(tempDir, outPath); unpackedInputPath[i] = outPath; rtbInputInfo.Text += "SUCCESS\n\n"; panelPack.Enabled = true; } catch (Exception exception) { Directory.Delete(tempDir, true); rtbInputInfo.Text += "FAILED\n" + exception.Message + "\n\n"; } } }
/// <summary> /// To String Implementation Listing all Retrievable Information about the Plugin. /// </summary> /// <returns>Information Text about this Object.</returns> public override string ToString() { StringBuilder builder = new StringBuilder(); builder.AppendLine("General:"); builder.AppendLine("\tIs Initialized: " + PluginManager.IsInitialized); builder.AppendLine("\tSystem Config Path: " + PluginPaths.InternalSystemConfigPath); builder.AppendLine("\tPlugin Dir: " + PluginPaths.PluginDirectory); builder.AppendLine("\tInstalled Packages Path: " + PluginPaths.PluginListFile); builder.AppendLine("\tGlobal Packages Path: " + PluginPaths.GlobalPluginListFile); builder.AppendLine(); builder.AppendLine(); builder.AppendLine("Plugin:"); builder.AppendLine("Name: " + PluginName); builder.AppendLine("\tFile: " + PluginName); builder.AppendLine("\tPlugin Directory: " + PluginPaths.GetPluginDirectory(PluginName)); builder.AppendLine("\tPlugin Config Directory: " + PluginPaths.GetPluginConfigDirectory(PluginName)); builder.AppendLine("\tPlugin Assembly Directory: " + PluginPaths.GetPluginAssemblyDirectory(PluginName)); builder.AppendLine("\tPlugin Temp Directory: " + PluginPaths.GetPluginTempDirectory(PluginName)); //builder.AppendLine($"\tPlugin Archive Backup: " + PluginPaths.GetPluginArchiveBackup(PluginName)); //builder.AppendLine($"\t\tPlugin Archive Backup Exists: " + File.Exists(PluginPaths.GetPluginArchiveBackup(PluginName))); builder.AppendLine("\tPlugin Assembly File: " + PluginPaths.GetPluginAssemblyFile(PluginName, PluginFile)); builder.AppendLine( "\t\tPlugin Assembly File Exists: " + File.Exists(PluginPaths.GetPluginAssemblyFile(PluginName, PluginFile)) ); //builder.AppendLine($"\tPlugin Version File: " + PluginPaths.GetPluginVersionFile(PluginName)); //builder.AppendLine($"\t\tPlugin Version File Exists: " + File.Exists(PluginPaths.GetPluginVersionFile(PluginName))); //builder.AppendLine($"\t\tPlugin Version File Key: " + PluginPaths.GetPluginVersion(PluginName)); //builder.AppendLine($"\t\tPlugin Version File Value: " + PluginPaths.GetPluginOriginURL(PluginName)); return(builder.ToString()); }
public void CheckAndUpdate( BasePluginPointer ptr, Func <string, string, bool> updateDialog, Action <string, int, int> setStatus) { setStatus?.Invoke($"[{ptr.PluginName}] Searching Updates.", 0, 1); BasePluginPointer originPtr = GetPointer(ptr.PluginOrigin); if (ptr.PluginVersion >= originPtr.PluginVersion) { setStatus?.Invoke($"[{ptr.PluginName}] Up to date.", 1, 1); return; } setStatus?.Invoke($"[{ptr.PluginName}] Waiting for User Input", 1, 3); if (updateDialog( $"Do you want to update {ptr.PluginName} : {ptr.PluginVersion} to {originPtr.PluginName} : {originPtr.PluginVersion}?", $"Update: {originPtr.PluginVersion}" )) { string tempFile = Path.Combine( PluginPaths.GetPluginTempDirectory(ptr), $"{originPtr.PluginName}_{originPtr.PluginVersion}_.zip" ); setStatus?.Invoke($"[{ptr.PluginName}] Installing Update", 1, 3); DownloadFile(originPtr, tempFile); PluginManager.AddPackage(tempFile, out string name); File.Delete(tempFile); } else { setStatus?.Invoke($"[{ptr.PluginName}] User denied update request.", 1, 3); } }
/// <summary> /// Loads a C# Assembly from a Pointer /// </summary> /// <param name="data">Pointer Data</param> /// <returns>Loaded Assembly</returns> public static Assembly SaveLoadFrom(PluginAssemblyPointer data) { return(SaveLoadFrom(PluginPaths.GetPluginAssemblyFile(data))); }
/// <summary> /// Adds a Package to the Plugin System /// </summary> /// <param name="file">Package Input Path</param> /// <param name="name">When Loaded successfully contains the Name of the Loaded plugin</param> /// <returns>True if the Adding was Successful</returns> internal static bool AddPackage(string file, out string name) { if (!IsInitialized) { throw new Exception("Can not use the plugin System when its not initialized."); } name = null; SendLogDivider(); SendLog("Adding File: " + file); if (PluginPacker.CanLoad(file)) { AddPackageEventArgs <string> args = new AddPackageEventArgs <string>(file, true); OnAddPackage?.Invoke(args); if (args.Cancel) { return(false); } string tempDir = Path.Combine( PluginPaths.GetSystemProcessTempDirectory("Install"), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) ); //TODO: Get temp dir for unpacking Directory.CreateDirectory(tempDir); //TODO: If the package is already installed Write Backup to PluginDir/backup before loading the new package SendLog("Trying to Load File Format: " + Path.GetFileName(file)); PluginPacker.Unpack(file, tempDir); //TODO: Try load Package Data/Plugin Data if (PackageDataManager.CanLoad(tempDir)) { SendLog("Trying to Load Data Format: " + Path.GetFileName(tempDir)); BasePluginPointer ptr = PackageDataManager.LoadData(tempDir); if (ptr != null) { name = ptr.PluginName; ptr.EnsureDirectoriesExist(); AddPackageEventArgs <BasePluginPointer> ptrArgs = new AddPackageEventArgs <BasePluginPointer>(ptr, true); OnAddPackagePointerLoaded?.Invoke(ptrArgs); if (ptrArgs.Cancel) { return(false); } List <string> installedPackages = ListHelper.LoadList(PluginPaths.GlobalPluginListFile).ToList(); List <string> activePackages = ListHelper.LoadList(PluginPaths.PluginListFile).ToList(); string newPackage = ptr.ToKeyPair(); bool isNew = installedPackages.All(x => !x.StartsWith(ptr.PluginName)); if (isNew) { installedPackages.Add(newPackage); } else { if (activePackages.RemoveAll(x => x.StartsWith(ptr.PluginName)) != 0) { activePackages.Add(newPackage); ListHelper.SaveList(PluginPaths.PluginListFile, activePackages.ToArray()); } installedPackages.RemoveAll(x => x.StartsWith(ptr.PluginName)); installedPackages.Add(newPackage); } ListHelper.SaveList(PluginPaths.GlobalPluginListFile, installedPackages.ToArray()); //TODO: Check if the Install would overwrite things. //TODO: Check if the files that are overwritten are in use. //TODO: Make a system that takes instructions from a file at start up to "complete" installations InstallPackageEventArgs iargs = new InstallPackageEventArgs(isNew, ptr, tempDir, true); OnInstallPackage?.Invoke(iargs); if (iargs.Cancel) { return(false); } PackageDataManager.Install(ptr, tempDir); Directory.Delete(tempDir, true); AfterInstallPackage?.Invoke(new InstallPackageEventArgs(isNew, ptr, tempDir, false)); AfterAddPackage?.Invoke(new AfterAddPackageEventArgs(ptr)); return(true); } SendError(new PackageDataException("File Corrupt", file)); } else { SendError(new PackageDataException("Unable to find a Data Serializer", file, null)); } } else { SendError(new PackerException("Unable to find a Packer", file, null)); } return(false); }
private async void TabablzControl_SelectionChanged(object sender, SelectionChangedEventArgs e) { // ##### AviSynth diagnose ##### if (SettingsTab.IsSelected) { SettingsWindow wizardDialog = new SettingsWindow(); wizardDialog.WindowStartupLocation = WindowStartupLocation.CenterScreen; _ = wizardDialog.ShowDialog(); if (wizardDialog != null) { Avs32Paths = wizardDialog.Path32; Avs64Paths = wizardDialog.Path64; if (Avs32Paths != null) { avsrepo.SetPaths(false, new Paths() { Binaries = Avs32Paths.Plugin, Scripts = Avs32Paths.Script, Definitions = avspackages_file }); } if (Avs64Paths != null) { avsrepo.SetPaths(true, new Paths() { Binaries = Avs64Paths.Plugin, Scripts = Avs64Paths.Script, Definitions = avspackages_file }); } CurrentPluginPath = avsrepo.paths[Win64].Binaries; CurrentScriptPath = avsrepo.paths[Win64].Scripts; } await ReloadPluginsAsync(); } if (DiagnoseTab.IsSelected) { AppIsWorking(true); // Textoutput controls init RichTextBox richtextbox = new RichTextBox(); FlowDocument flowdoc = new FlowDocument(); Paragraph tb = new Paragraph(); richtextbox.IsDocumentEnabled = true; richtextbox.IsReadOnly = true; tb.FontFamily = new FontFamily("Lucida Console"); tb.Padding = new Thickness(8); flowdoc.Blocks.Add(tb); richtextbox.Document = flowdoc; var diag = new Diagnose(""); var script_dups = diag.CheckDuplicateAvsScripts(avsrepo.GetPaths(Win64).Scripts); tb.Inlines.Add(new Run("Use ") { FontSize = 15, FontWeight = FontWeights.Bold, Foreground = Brushes.Red }); Hyperlink avsmeter = new Hyperlink() { IsEnabled = true, NavigateUri = new Uri("https://forum.doom9.org/showthread.php?t=173259") }; avsmeter.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(Hyperlink_open); avsmeter.Inlines.Add(new Run("Avisynth Info Tool or AVSMeter") { FontSize = 15, FontWeight = FontWeights.Bold, Foreground = Brushes.Blue }); tb.Inlines.Add(avsmeter); tb.Inlines.Add(new Run(" to detect other Avisynth problems. \n\n") { FontSize = 15, FontWeight = FontWeights.Bold, Foreground = Brushes.Red }); tb.Inlines.Add(new Run("\n\nDuplicate Function Name Detection \n") { FontSize = 14 }); tb.Inlines.Add(new Run("------------------------------------------------------------\n") { Foreground = Brushes.SlateBlue }); tb.Inlines.Add("\nPath of *.avsi files: " + avsrepo.GetPaths(Win64).Scripts); if (script_dups.Count > 0) { tb.Inlines.Add("\nFound " + script_dups.Count + " potential conflicts: \n"); foreach (var dup in script_dups) { tb.Inlines.Add("\nFunction name: "); tb.Inlines.Add(new Run(dup.Key + "\n") { FontWeight = FontWeights.Bold }); foreach (var file in dup.Value) { tb.Inlines.Add(new Run("\t" + Path.GetDirectoryName(file) + @"\") { Foreground = Brushes.Silver }); tb.Inlines.Add(new Run(Path.GetFileName(file) + "\n")); } } } else { tb.Inlines.Add(new Run("\n\nNo duplicate functions found in *.avsi files") { FontWeight = FontWeights.Bold, Foreground = Brushes.Green }); } ScrollViewer.Content = richtextbox; AppIsWorking(false); } }
public void ClearExtractPaths() { ExtractPaths.Clear(); PluginPaths.Clear(); ArchivePaths.Clear(); }
public int Run(string[] args) { ParseArguments(args); if (!PluginPaths.Any() && !PluginNames.Any()) { Console.Write(Path.GetDirectoryName(OmnisharpProjectPath)); return(0); } var defaultFrameworks = JObject.Parse(File.ReadAllText(OmnisharpProjectPath))["frameworks"] .Select(x => x.Path.Replace("frameworks.", "")) .OrderBy(x => x).ToArray(); // Find a repeatable user based location var home = new string[] { Environment.GetEnvironmentVariable("HOME"), Environment.GetEnvironmentVariable("USERPROFILE") }.Where(s => !string.IsNullOrEmpty(s)).First(); var omnisharpHome = Path.Combine(home, ".omnisharp"); if (!Directory.Exists(omnisharpHome)) { Directory.CreateDirectory(omnisharpHome); } if (String.IsNullOrEmpty(OmnisharpPath)) { var md5 = MD5.Create(); var pluginAges = new Dictionary <string, string>(); var sb = new StringBuilder(); // OrderBy ensures consistent hashing foreach (var path in PluginPaths.OrderBy(x => x)) { sb.AppendLine(path); var projectOrPlugins = Directory.EnumerateFiles(path, "project.json", SearchOption.AllDirectories) .Concat(Directory.EnumerateFiles(path, "omnisharp.plugin", SearchOption.AllDirectories)) .OrderBy(x => x) .Where(project => !_nonPlugins.Any(z => project.EndsWith($"{Path.DirectorySeparatorChar}{z}{Path.DirectorySeparatorChar}"))); foreach (var projectOrPlugin in projectOrPlugins) { var writeTime = File.GetLastWriteTime(projectOrPlugin); sb.Append(projectOrPlugin); sb.AppendLine(writeTime.Ticks.ToString()); } } foreach (var path in PluginNames.Select(x => string.Join(":", x.Key, x.Value))) { sb.Append(path); } var hash = string.Join("", Convert.ToBase64String(md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(sb.ToString()))).Except(Path.GetInvalidFileNameChars().Concat(new[] { '=', '+' }))); OmnisharpPath = Path.Combine(omnisharpHome, hash); } if (Directory.Exists(OmnisharpPath)) { Console.Write(Path.Combine(OmnisharpPath, "bootstrap", "Bootstrapper")); return(0); } Directory.CreateDirectory(OmnisharpPath); var globalJobject = new JObject(); globalJobject["projects"] = new JArray(new string[] { "bootstrap" }.Concat(PluginPaths).ToArray()); var sdkJobject = new JObject(); sdkJobject["version"] = new JValue("1.0.0-beta4"); globalJobject["sdk"] = sdkJobject; File.WriteAllText(Path.Combine(OmnisharpPath, "global.json"), globalJobject.ToString()); Directory.CreateDirectory(Path.Combine(OmnisharpPath, "bootstrap")); Directory.CreateDirectory(Path.Combine(OmnisharpPath, "bootstrap", "Bootstrapper")); var pluginDirectories = PluginPaths .SelectMany(pluginPath => Directory.EnumerateDirectories(pluginPath) .Where(directory => File.Exists(Path.Combine(directory, "project.json")) || File.Exists(Path.Combine(directory, "1.0.0", "root", "project.json")))) .Where(directory => !_nonPlugins.Any(z => directory.EndsWith($"{Path.DirectorySeparatorChar}{z}"))) .ToArray(); var allDeps = new Dictionary <string, string>(); allDeps.Add("OmniSharp.Host", "1.0.0-*"); foreach (var pluginPair in PluginNames) { allDeps.Add(pluginPair.Key, pluginPair.Value); } var frameworkDeps = new Dictionary <string, Dictionary <string, string> >(); foreach (var framework in defaultFrameworks) { frameworkDeps.Add(framework, new Dictionary <string, string>()); } foreach (var dir in pluginDirectories) { JObject json = null; var path = Path.Combine(dir, "project.json"); if (!File.Exists(path)) { path = Path.Combine("dir", "1.0.0", "root", "project.json"); } try { json = JObject.Parse(File.ReadAllText(path)); } catch { } if (json != null) { var name = Path.GetFileName(dir); var frameworks = json["frameworks"].Select(x => x.Path.Replace("frameworks.", "")).OrderBy(x => x).ToArray(); if (defaultFrameworks.SequenceEqual(frameworks)) { if (!allDeps.ContainsKey(name)) { allDeps.Add(name, json["version"]?.ToString() ?? "1.0.0-*"); } } else { foreach (var framework in frameworks) { if (defaultFrameworks.Contains(framework)) { Dictionary <string, string> deps = null; if (frameworkDeps.TryGetValue(framework, out deps)) { if (!deps.ContainsKey(name)) { deps.Add(name, json["version"]?.ToString() ?? "1.0.0-*"); } } } } } } } var projectJobject = new JObject(); projectJobject["version"] = new JValue("1.0.0-*"); projectJobject["dependencies"] = JObject.FromObject(allDeps); projectJobject["commands"] = JObject.FromObject(new Dictionary <string, string> { { "Bootstrapper", "Bootstrapper" } }); var frameworksJobject = new JObject(); foreach (var deps in frameworkDeps) { frameworksJobject[deps.Key] = JObject.FromObject(deps.Value); } projectJobject["frameworks"] = frameworksJobject; projectJobject["entryPoint"] = new JValue("OmniSharp.Host"); var bootstrapProjectPath = Path.Combine(OmnisharpPath, "bootstrap", "Bootstrapper", "project.json"); var programPath = Path.Combine(OmnisharpPath, "bootstrap", "Bootstrapper", "Startup.cs"); var bootstrapConfigPath = Path.Combine(OmnisharpPath, "bootstrap", "Bootstrapper", "config.json"); File.WriteAllText(bootstrapProjectPath, projectJobject.ToString()); File.WriteAllText(programPath, @"public class Program { public static void Main(string[] args) { OmniSharp.Program.Main(args); } }"); File.Copy(Path.Combine(Path.GetDirectoryName(OmnisharpProjectPath), "config.json"), bootstrapConfigPath); // Scaffold out an app that uses OmniSharp, has a global.json that references all the Plugins that we want to load. // Put that in a temporary directory // return the full Path to the folder that will Run omnisharp Console.Write(Path.Combine(OmnisharpPath, "bootstrap", "Bootstrapper")); return(0); }
public void ParseArguments(string[] args) { var enumerator = args.GetEnumerator(); while (enumerator.MoveNext()) { var arg = (string)enumerator.Current; if (arg == "--plugins") { enumerator.MoveNext(); PluginPaths.Add((string)enumerator.Current); } if (arg == "--plugin-name") { enumerator.MoveNext(); var v = (string)enumerator.Current; var s = v.Split('@'); if (s.Length > 1) { PluginNames.Add(new KeyValuePair <string, string>(s[0], s[1])); } else { PluginNames.Add(new KeyValuePair <string, string>(s[0], string.Empty)); } } if (arg == "-s") { enumerator.MoveNext(); SolutionRoot = Path.GetFullPath((string)enumerator.Current); } } BootstrapPath = Path.GetDirectoryName(_appEnv.ApplicationBasePath); OmnisharpProjectPath = Path.Combine(BootstrapPath, "OmniSharp.Host", "project.json"); if (!File.Exists(OmnisharpProjectPath)) { OmnisharpProjectPath = Path.Combine(OmnisharpProjectPath, "OmniSharp.Host", "1.0.0", "root", "project.json"); } if (!string.IsNullOrEmpty(SolutionRoot)) { var pluginsFolder = Path.Combine(SolutionRoot, ".omnisharp", "plugins"); if (Directory.Exists(pluginsFolder)) { PluginPaths.Add(pluginsFolder); } var omnisharpJsonPath = Path.Combine(SolutionRoot, "omnisharp.json"); if (File.Exists(omnisharpJsonPath)) { var omnisharpJson = JObject.Parse(File.ReadAllText(omnisharpJsonPath)); if (omnisharpJson["plugins"] != null) { var omnisharpJsonPlugins = omnisharpJson["plugins"]; foreach (var plugin in omnisharpJsonPlugins) { if (plugin is JObject) { var pluginJobject = plugin as JObject; PluginNames.Add(new KeyValuePair <string, string>(pluginJobject["name"].ToString(), pluginJobject["version"].ToString())); } else if (plugin is JToken) { var pluginString = plugin.ToString(); var pluginSplitString = pluginString.Split('@'); if (pluginSplitString.Length > 1) { PluginNames.Add(new KeyValuePair <string, string>(pluginSplitString[0], pluginSplitString[1])); } else { PluginNames.Add(new KeyValuePair <string, string>(pluginSplitString[0], string.Empty)); } } } } } } }