public static void NimExeFind(NSPackage pkg) { string[] nimexes = { "nim.exe", "nimsuggest.exe" }; var patharr = new List <string>((Environment.GetEnvironmentVariable("PATH") ?? "").Split(';')); patharr.Add(@"c:\myprogs\nim\bin"); foreach (string nimexe in nimexes) { foreach (string spathi in patharr) { if (NSIni.Get("Main", nimexe) == "") { string sfullpath = Path.Combine(spathi.Trim(), nimexe); if (File.Exists(sfullpath)) { NSIni.Add("Main", nimexe, Path.GetFullPath(sfullpath)); NSIni.Write(); pkg.GetType().GetProperty(nimexe.Replace(".", "")).SetValue(nimexe.Replace(".", ""), sfullpath); break; } } } } }
// menu callback private void MenuItemCallback(object sender, EventArgs e) { //IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); //Guid clsid = Guid.Empty; MenuCommand menucmd = (MenuCommand)sender; if (menucmds[menucmd.CommandID.ID] == "NSMenuCmdOptionsEdit") { Process.Start("notepad.exe", NSIni.inifilepath); } if (menucmds[menucmd.CommandID.ID] == "NSMenuCmdOptionsLoad") { NSIni.Init(NSIni.inifilepath); NSSugInit(); System.Windows.Forms.MessageBox.Show("NimStudio INI loaded.", "NimStudio", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } }
public void Init() { NSUtil.DebugPrint("NimStudio - Nimsuggest init:"); string nimsuggestexe = NSIni.Get("Main", "nimsuggest.exe"); if (nimsuggestexe == "") { NSUtil.DebugPrint("Nimsuggest.exe not set in nimstudio.ini!"); return; } if (!File.Exists(nimsuggestexe)) { NSUtil.DebugPrint("Nimsuggest.exe not found!"); return; } proc = new Process(); proc.StartInfo.CreateNoWindow = true; //proc.StartInfo.WorkingDirectory = @"c:\MyProgs\Nim"; //proc.StartInfo.Arguments = @"--stdin c:\MyProgs\Nim\htmlarc.nim"; //proc.StartInfo.Arguments = @"--stdin " + VSNimLangServ.codefile_path_current; proc.StartInfo.Arguments = @"--stdin " + Path.GetDirectoryName(NSLangServ.codefile_path_current) + @"\nimstudio_base.nim"; //proc.StartInfo.Arguments = @"--stdin " + Path.GetDirectoryName(VSNimLangServ.codefile_path_current) + "\\"; proc.StartInfo.FileName = NSIni.Get("Main", "nimsuggest.exe"); proc.StartInfo.WorkingDirectory = Path.GetDirectoryName(NSLangServ.codefile_path_current); proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.RedirectStandardError = false; proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.UseShellExecute = false; NSUtil.DebugPrint("NimStudio - Nimsuggest load:" + NSLangServ.codefile_path_current); NSUtil.DebugPrint("NimStudio - Nimsuggest working dir:" + proc.StartInfo.WorkingDirectory); proc.EnableRaisingEvents = true; proc.OutputDataReceived += new DataReceivedEventHandler(NSDRHandler); //proc.ErrorDataReceived += new DataReceivedEventHandler(NSDRHandler); proc.Exited += new EventHandler(NSExitHandler); proc.Start(); Thread.Sleep(100); proc.StandardInput.WriteLine(""); proc.BeginOutputReadLine(); Thread.Sleep(300); // allow time for nimsuggest startup lines to be processed }
public void NSSugInit() { string[] nimexes = { "nim.exe", "nimsuggest.exe" }; for (int lexe = 0; lexe < 2; lexe++) { if (NSIni.Get("Main", nimexes[lexe]) == "") { // nim exe not found in INI - try to find it in path, or c:\nim\bin var patharr = new List <string>((Environment.GetEnvironmentVariable("PATH") ?? "").Split(';')); patharr.Add(@"c:\nim\bin"); foreach (string spathi in patharr) { string sfullpath = Path.Combine(spathi.Trim(), nimexes[lexe]); if (File.Exists(sfullpath)) { NSIni.Add("Main", nimexes[lexe], Path.GetFullPath(sfullpath)); NSIni.Write(); break; } } } else { if (!File.Exists(NSIni.Get("Main", nimexes[lexe]))) { System.Diagnostics.Debug.Print("NimStudio warning:" + nimexes[lexe] + " not found!"); } } } if (NSIni.Get("Main", nimexes[0]) == "" || NSIni.Get("Main", nimexes[1]) == "") { string msg = ""; if (NSIni.Get("Main", nimexes[0]) == "" && NSIni.Get("Main", nimexes[1]) == "") { msg = "Path to nim.exe and nimsuggest.exe not found."; } else { msg = String.Format("Path to {0} not found.", (NSIni.Get("Main", nimexes[0]) == "") ? nimexes[0] : nimexes[1]); } msg += "\nEnter path(s) via:\n\n"; msg += "Tools->NimStudio->Options Edit"; msg += "\n Then\n"; msg += "Tools->NimStudio->Options Load"; // write INI so user can edit NSIni.Add("Main", nimexes[0], ""); NSIni.Add("Main", nimexes[1], ""); NSIni.Write(); System.Windows.Forms.MessageBox.Show(msg, "NimStudio configuration", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation); } if (NSIni.Get("Main", nimexes[1]) != "") { if (nimsuggest == null) { nimsuggest = new NimSuggestProc(); } //nimsuggest.Init(); } }
protected override void Initialize() { //Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); base.Initialize(); nspackage = this; #if ivslang LangInfo = new VSNLanguageInfo(); ((IServiceContainer)this).AddService(typeof(VSNLanguageInfo), LangInfo, true); #endif menucmds = new Dictionary <int, string>() { { 0x0100, "NSMenuCmdOptionsEdit" }, { 0x0101, "NSMenuCmdOptionsLoad" } }; // menu commands - .vsct file OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (mcs != null) { foreach (int dkey in menucmds.Keys) { CommandID cmdid = new CommandID(GuidList.NSMenuCmdTopGUID, dkey); MenuCommand menucmd = new MenuCommand(MenuItemCallback, cmdid); mcs.AddCommand(menucmd); } } IServiceContainer ServiceCnt = this as IServiceContainer; NSLangServ ServiceLng = new NSLangServ(); ServiceLng.SetSite(this); ServiceCnt.AddService(typeof(NSLangServ), ServiceLng, true); IOleComponentManager mgr = GetService(typeof(SOleComponentManager)) as IOleComponentManager; if (m_ComponentID == 0 && mgr != null) { OLECRINFO[] crinfo = new OLECRINFO[1]; crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO)); crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime; crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff; crinfo[0].uIdleTimeInterval = 1000; int hr = mgr.FRegisterComponent(this, crinfo, out m_ComponentID); } nimsettingsini = System.IO.Path.Combine(UserDataPath, "nimstudio.ini"); NSIni.Init(nimsettingsini); NSSugInit(); if (NSIni.Get("Main", "exttoolsadded") != "true") { NSIni.Add("Main", "exttoolsadded", "true"); NSIni.Write(); string reg_keyname = "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\12.0\\External Tools"; object reg_ret; bool regstateok = false; reg_ret = Registry.GetValue(reg_keyname, "ToolNumKeys", -1); while (true) { if (reg_ret == null) { break; } if (reg_ret.GetType() != typeof(int)) { break; } int totkeys = (int)reg_ret; if (totkeys == -1) { break; } for (int rloop = 0; rloop < totkeys; rloop++) { reg_ret = Registry.GetValue(reg_keyname, "ToolTitle" + rloop.ToString(), null); if (reg_ret == null) { break; } if (reg_ret.GetType() != typeof(string)) { break; } if (reg_ret == "NimStudio Compile+Run") { break; } if (rloop == totkeys - 1) { regstateok = true; } } if (regstateok) { Registry.SetValue(reg_keyname, "ToolTitle" + totkeys.ToString(), "NimStudio Compile+Run", RegistryValueKind.String); Registry.SetValue(reg_keyname, "ToolSourceKey" + totkeys.ToString(), "", RegistryValueKind.String); Registry.SetValue(reg_keyname, "ToolOpt" + totkeys.ToString(), 26, RegistryValueKind.DWord); Registry.SetValue(reg_keyname, "ToolDir" + totkeys.ToString(), "$(ItemDir)", RegistryValueKind.String); Registry.SetValue(reg_keyname, "ToolCmd" + totkeys.ToString(), "cmd.exe", RegistryValueKind.String); Registry.SetValue(reg_keyname, "ToolArg" + totkeys.ToString(), @"/c """"c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"" & del $(ItemDir)$(ItemFileName).exe 2>nul & ""c:\Nim\bin\nim.exe"" c $(ItemPath) & echo ****Running**** & $(ItemDir)$(ItemFileName).exe""", RegistryValueKind.String); totkeys++; Registry.SetValue(reg_keyname, "ToolTitle" + totkeys.ToString(), "NimStudio Compile", RegistryValueKind.String); Registry.SetValue(reg_keyname, "ToolSourceKey" + totkeys.ToString(), "", RegistryValueKind.String); Registry.SetValue(reg_keyname, "ToolOpt" + totkeys.ToString(), 26, RegistryValueKind.DWord); Registry.SetValue(reg_keyname, "ToolDir" + totkeys.ToString(), "$(ItemDir)", RegistryValueKind.String); Registry.SetValue(reg_keyname, "ToolCmd" + totkeys.ToString(), "cmd.exe", RegistryValueKind.String); Registry.SetValue(reg_keyname, "ToolArg" + totkeys.ToString(), @"/c """"c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"" & del $(ItemDir)$(ItemFileName).exe 2>nul & ""c:\Nim\bin\nim.exe"" c $(ItemPath)""", RegistryValueKind.String); totkeys++; Registry.SetValue(reg_keyname, "ToolNumKeys", totkeys, RegistryValueKind.DWord); } } } }