Example #1
0
        private static void SaveCompilerResults(PlgxPluginInfo plgx,
                                                StringBuilder sb)
        {
            string strFile = Path.GetTempFileName();

            File.WriteAllText(strFile, sb.ToString(), StrUtil.Utf8);

            string strMsg = plgx.BaseFileName + MessageService.NewParagraph +
                            "Compilation failed. Compiler results have been saved to:" +
                            MessageService.NewLine;

            VistaTaskDialog dlg = new VistaTaskDialog();

            dlg.Content          = strMsg + VistaTaskDialog.CreateLink("F", strFile);
            dlg.DefaultButtonID  = (int)DialogResult.Cancel;
            dlg.EnableHyperlinks = true;
            dlg.SetIcon(VtdIcon.Warning);
            dlg.WindowTitle = PwDefs.ShortProductName;

            dlg.AddButton((int)DialogResult.Cancel, KPRes.Ok, null);
            dlg.LinkClicked += delegate(object sender, LinkClickedEventArgs e)
            {
                if ((e != null) && (e.LinkText == "F") && !NativeLib.IsUnix())
                {
                    NativeLib.StartProcess(WinUtil.LocateSystemApp("Notepad.exe"),
                                           "\"" + SprEncoding.EncodeForCommandLine(strFile) + "\"");
                }
            };

            if (!dlg.ShowDialog())
            {
                MessageService.ShowWarning(strMsg + strFile);
            }
        }
Example #2
0
        public static void OpenUrlWithApp(string strUrlToOpen, PwEntry peDataSource,
                                          string strAppPath)
        {
            if (string.IsNullOrEmpty(strUrlToOpen))
            {
                Debug.Assert(false); return;
            }
            if (string.IsNullOrEmpty(strAppPath))
            {
                Debug.Assert(false); return;
            }

            string strUrl = strUrlToOpen.Trim();

            if (strUrl.Length == 0)
            {
                Debug.Assert(false); return;
            }
            strUrl = SprEncoding.EncodeForCommandLine(strUrl);

            string strApp = strAppPath.Trim();

            if (strApp.Length == 0)
            {
                Debug.Assert(false); return;
            }
            strApp = SprEncoding.EncodeForCommandLine(strApp);

            string str = "cmd://\"" + strApp + "\" \"" + strUrl + "\"";

            OpenUrl(str, peDataSource, false);
        }
Example #3
0
        private void AddAppVariant(OpenWithItem itBase, string strVarName,
                                   string strCmdOpt)
        {
            if (itBase == null)
            {
                Debug.Assert(false); return;
            }
            if (itBase.FilePathType != OwFilePathType.Executable)
            {
                Debug.Assert(false); return;
            }
            if (string.IsNullOrEmpty(strVarName))
            {
                Debug.Assert(false); return;
            }
            if (string.IsNullOrEmpty(strCmdOpt))
            {
                Debug.Assert(false); return;
            }

            string strPath = itBase.FilePath;

            if (string.IsNullOrEmpty(strPath))
            {
                Debug.Assert(false); return;
            }

            AddAppByShellExpand("cmd://\"" + SprEncoding.EncodeForCommandLine(
                                    strPath) + "\" " + strCmdOpt + " \"" + PlhTargetUri + "\"",
                                itBase.Name + " (" + strVarName + ")", strPath);
        }
Example #4
0
        private static void RunBuildCommand(string strCmd, string strTmpDir,
                                            string strCacheDir)
        {
            if (string.IsNullOrEmpty(strCmd))
            {
                return;                                          // No assert
            }
            string str = strCmd;

            if (strTmpDir != null)
            {
                str = StrUtil.ReplaceCaseInsensitive(str, @"{PLGX_TEMP_DIR}",
                                                     SprEncoding.EncodeForCommandLine(strTmpDir));
            }
            if (strCacheDir != null)
            {
                str = StrUtil.ReplaceCaseInsensitive(str, @"{PLGX_CACHE_DIR}",
                                                     SprEncoding.EncodeForCommandLine(strCacheDir));
            }

            // str = UrlUtil.ConvertSeparators(str); // Would convert args
            str = SprEngine.Compile(str, new SprContext(null, null,
                                                        SprCompileFlags.NonActive, false, true));

            string strApp, strArgs;

            StrUtil.SplitCommandLine(str, out strApp, out strArgs, true);

            Process p = null;

            try
            {
                if (!string.IsNullOrEmpty(strArgs))
                {
                    p = Process.Start(strApp, strArgs);
                }
                else
                {
                    p = Process.Start(strApp);
                }
            }
            catch (Exception ex)
            {
                if (Program.CommandLineArgs[AppDefs.CommandLineOptions.Debug] != null)
                {
                    throw new PlgxException(ex.Message);
                }
                throw;
            }
            finally
            {
                try { if (p != null)
                      {
                          p.Dispose();
                      }
                }
                catch (Exception) { Debug.Assert(false); }
            }
        }
Example #5
0
        private static bool ShowHelpLocalKcv(string strQuotedMsIts)
        {
            try
            {
                if (!NativeLib.IsUnix())
                {
                    return(false);
                }

                string strApp = AppLocator.FindAppUnix("kchmviewer");
                if (string.IsNullOrEmpty(strApp))
                {
                    return(false);
                }

                string strFile = StrUtil.GetStringBetween(strQuotedMsIts, 0, ":", "::");
                if (string.IsNullOrEmpty(strFile))
                {
                    strFile = StrUtil.GetStringBetween(strQuotedMsIts, 0, ":", "\"");
                }
                if (string.IsNullOrEmpty(strFile))
                {
                    Debug.Assert(false);
                    return(false);
                }

                string strUrl = StrUtil.GetStringBetween(strQuotedMsIts, 0, "::", "\"");

                // https://www.ulduzsoft.com/linux/kchmviewer/kchmviewer-integration-reference/
                string strArgs = "\"" + SprEncoding.EncodeForCommandLine(strFile) + "\"";
                if (!string.IsNullOrEmpty(strUrl))
                {
                    strArgs = "-showPage \"" + SprEncoding.EncodeForCommandLine(
                        strUrl) + "\" " + strArgs;
                }

                Process p = Process.Start(NativeLib.EncodePath(strApp), strArgs);
                if (p != null)
                {
                    p.Dispose();
                }

                return(true);
            }
            catch (Exception) { Debug.Assert(false); }

            return(false);
        }
Example #6
0
        private void OnOpenUrl(object sender, DynamicMenuEventArgs e)
        {
            if (e == null)
            {
                Debug.Assert(false); return;
            }

            OpenWithItem it = (e.Tag as OpenWithItem);

            if (it == null)
            {
                Debug.Assert(false); return;
            }

            string strApp = it.FilePath;

            PwEntry[] v = Program.MainForm.GetSelectedEntries();
            if (v == null)
            {
                Debug.Assert(false); return;
            }

            foreach (PwEntry pe in v)
            {
                // Get the entry's URL, avoid URL override
                string strUrl = pe.Strings.ReadSafe(PwDefs.UrlField);
                if (string.IsNullOrEmpty(strUrl))
                {
                    continue;
                }

                if (it.FilePathType == OwFilePathType.Executable)
                {
                    WinUtil.OpenUrlWithApp(strUrl, pe, strApp);
                }
                else if (it.FilePathType == OwFilePathType.ShellExpand)
                {
                    string str = strApp.Replace(PlhTargetUri,
                                                SprEncoding.EncodeForCommandLine(strUrl));
                    WinUtil.OpenUrl(str, pe, false);
                }
                else
                {
                    Debug.Assert(false);
                }
            }
        }
Example #7
0
        private static string FixPrintCommandLine(string strCmd)
        {
            string str = strCmd;

            // Workaround for Microsoft Office breaking the 'Print' shell verb;
            // https://sourceforge.net/p/keepass/bugs/1675/
            // https://support.microsoft.com/en-us/help/274527/cannot-print-file-with--htm-extension-from-windows-explorer-by-right-c
            if (str.IndexOf("\\msohtmed.exe", StrUtil.CaseIgnoreCmp) >= 0)
            {
                string strSys = UrlUtil.EnsureTerminatingSeparator(
                    Environment.SystemDirectory, false);
                str = "\"" + SprEncoding.EncodeForCommandLine(strSys +
                                                              "rundll32.exe") + "\" \"" + SprEncoding.EncodeForCommandLine(
                    strSys + "mshtml.dll") + "\",PrintHTML \"%1\"";
            }

            return(str);
        }
Example #8
0
        public static void OpenUrlWithApp(string strUrlToOpen, PwEntry peDataSource,
                                          string strAppPath)
        {
            if (string.IsNullOrEmpty(strUrlToOpen))
            {
                Debug.Assert(false); return;
            }
            if (string.IsNullOrEmpty(strAppPath))
            {
                Debug.Assert(false); return;
            }

            string strUrl = strUrlToOpen.Trim();

            if (strUrl.Length == 0)
            {
                Debug.Assert(false); return;
            }
            if (strUrl.IndexOf('\"') < 0)
            {
                strUrl = "\"" + SprEncoding.EncodeForCommandLine(strUrl) + "\"";
            }

            string strApp = strAppPath.Trim();

            if (strApp.StartsWith("\"") && strApp.EndsWith("\"") && (strApp.Length >= 2))
            {
                strApp = strApp.Substring(1, strApp.Length - 2);
            }
            if (strApp.Length == 0)
            {
                Debug.Assert(false); return;
            }
            strApp = SprEncoding.EncodeForCommandLine(strApp);

            string str = "cmd://\"" + strApp + "\" " + strUrl;

            OpenUrl(str, peDataSource, false);
        }
Example #9
0
        private void FinishOpenWithList()
        {
            OpenWithItem itEdge    = null;          // New (Chromium-based) Edge
            OpenWithItem itVivaldi = null;

            foreach (OpenWithItem it in m_lOpenWith)
            {
                if (it.FilePathType != OwFilePathType.Executable)
                {
                    continue;
                }

                string strFile = it.FilePath;
                if ((strFile.IndexOf("\\Microsoft", StrUtil.CaseIgnoreCmp) >= 0) &&
                    strFile.EndsWith("\\msedge.exe", StrUtil.CaseIgnoreCmp))
                {
                    if ((itEdge == null) || it.Name.Equals("Microsoft Edge", StrUtil.CaseIgnoreCmp))
                    {
                        itEdge = it;
                    }
                    else
                    {
                        Debug.Assert(false);
                    }                                                 // Duplicate?
                }
                else if (strFile.EndsWith("\\vivaldi.exe", StrUtil.CaseIgnoreCmp))
                {
                    if ((itVivaldi == null) || it.Name.Equals("Vivaldi", StrUtil.CaseIgnoreCmp))
                    {
                        itVivaldi = it;
                    }
                    else
                    {
                        Debug.Assert(false);
                    }                                                 // Duplicate?
                }
            }

            if (itEdge != null)
            {
                // The legacy Edge (EdgeHTML) doesn't register itself in the
                // 'StartMenuInternet' registry key, whereas the new one
                // (Chromium) does; so, the one that we found must be the
                // new Edge, which supports a command line option for the
                // private mode
                AddAppByShellExpand("cmd://\"" + SprEncoding.EncodeForCommandLine(
                                        itEdge.FilePath) + "\" --inprivate \"" + PlhTargetUri + "\"",
                                    itEdge.Name + " (" + KPRes.Private + ")", itEdge.FilePath);
            }
            else             // Add the legacy Edge (EdgeHTML), if available
            {
                if (AppLocator.EdgeProtocolSupported)
                {
                    AddAppByShellExpand("microsoft-edge:" + PlhTargetUri,
                                        "Microsoft Edge", AppLocator.EdgePath);
                }
            }

            if (itVivaldi != null)
            {
                AddAppByShellExpand("cmd://\"" + SprEncoding.EncodeForCommandLine(
                                        itVivaldi.FilePath) + "\" --incognito \"" + PlhTargetUri + "\"",
                                    itVivaldi.Name + " (" + KPRes.Private + ")", itVivaldi.FilePath);
            }

            m_lOpenWith.Sort(OpenWithItem.CompareByName);
        }
Example #10
0
        private void FindAppsByKnown()
        {
            string strIE = AppLocator.InternetExplorerPath;

            if (AddAppByFile(strIE, "Internet Explorer"))
            {
                // https://msdn.microsoft.com/en-us/library/hh826025.aspx
                AddAppByShellExpand("cmd://\"" + SprEncoding.EncodeForCommandLine(
                                        strIE) + "\" -private \"" + PlhTargetUri + "\"",
                                    "Internet Explorer (" + KPRes.Private + ")", strIE);
            }

            string strFF = AppLocator.FirefoxPath;

            if (AddAppByFile(strFF, "Firefox"))
            {
                // The command line options -private and -private-window work
                // correctly with Firefox 49.0.1 (before, they did not);
                // https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options
                // https://bugzilla.mozilla.org/show_bug.cgi?id=856839
                // https://bugzilla.mozilla.org/show_bug.cgi?id=829180
                AddAppByShellExpand("cmd://\"" + SprEncoding.EncodeForCommandLine(
                                        strFF) + "\" -private-window \"" + PlhTargetUri + "\"",
                                    "Firefox (" + KPRes.Private + ")", strFF);
            }

            string strCh = AppLocator.ChromePath;

            if (AddAppByFile(strCh, "Google Chrome"))
            {
                // https://www.chromium.org/developers/how-tos/run-chromium-with-flags
                // https://peter.sh/experiments/chromium-command-line-switches/
                AddAppByShellExpand("cmd://\"" + SprEncoding.EncodeForCommandLine(
                                        strCh) + "\" --incognito \"" + PlhTargetUri + "\"",
                                    "Google Chrome (" + KPRes.Private + ")", strCh);
            }

            string strOp = AppLocator.OperaPath;

            if (AddAppByFile(strOp, "Opera"))
            {
                // Doesn't work with Opera 34.0.2036.25:
                // AddAppByShellExpand("cmd://\"" + SprEncoding.EncodeForCommandLine(
                //	strOp) + "\" -newprivatetab \"" + PlhTargetUri + "\"",
                //	"Opera (" + KPRes.Private + ")", strOp);

                // Doesn't work with Opera 36.0.2130.65:
                // AddAppByShellExpand("cmd://\"" + SprEncoding.EncodeForCommandLine(
                //	strOp) + "\" --incognito \"" + PlhTargetUri + "\"",
                //	"Opera (" + KPRes.Private + ")", strOp);

                // Works with Opera 40.0.2308.81:
                AddAppByShellExpand("cmd://\"" + SprEncoding.EncodeForCommandLine(
                                        strOp) + "\" --private \"" + PlhTargetUri + "\"",
                                    "Opera (" + KPRes.Private + ")", strOp);
            }

            AddAppByFile(AppLocator.SafariPath, "Safari");

            if (NativeLib.IsUnix())
            {
                AddAppByFile(AppLocator.FindAppUnix("epiphany-browser"), "Epiphany");
                AddAppByFile(AppLocator.FindAppUnix("galeon"), "Galeon");
                AddAppByFile(AppLocator.FindAppUnix("konqueror"), "Konqueror");
                AddAppByFile(AppLocator.FindAppUnix("rekonq"), "Rekonq");
                AddAppByFile(AppLocator.FindAppUnix("arora"), "Arora");
                AddAppByFile(AppLocator.FindAppUnix("midori"), "Midori");
                AddAppByFile(AppLocator.FindAppUnix("Dooble"), "Dooble");                 // Upper-case
            }
        }