IsCommandLineUrl() публичный статический Метод

public static IsCommandLineUrl ( string strUrl ) : bool
strUrl string
Результат bool
Пример #1
0
        internal static string CompileUrl(string strUrlToOpen, PwEntry pe,
                                          bool bAllowOverride, string strBaseRaw, bool?obForceEncCmd)
        {
            MainForm   mf = Program.MainForm;
            PwDatabase pd = null;

            try { if (mf != null)
                  {
                      pd = mf.DocumentManager.SafeFindContainerOf(pe);
                  }
            }
            catch (Exception) { Debug.Assert(false); }

            string strUrlFlt = strUrlToOpen;

            strUrlFlt = strUrlFlt.TrimStart(new char[] { ' ', '\t', '\r', '\n' });

            bool bEncCmd = (obForceEncCmd.HasValue ? obForceEncCmd.Value :
                            WinUtil.IsCommandLineUrl(strUrlFlt));

            SprContext ctx = new SprContext(pe, pd, SprCompileFlags.All, false, bEncCmd);

            ctx.Base          = strBaseRaw;
            ctx.BaseIsEncoded = false;

            string strUrl = SprEngine.Compile(strUrlFlt, ctx);

            string strOvr = Program.Config.Integration.UrlSchemeOverrides.GetOverrideForUrl(
                strUrl);

            if (!bAllowOverride)
            {
                strOvr = null;
            }
            if (strOvr != null)
            {
                bool bEncCmdOvr = WinUtil.IsCommandLineUrl(strOvr);

                SprContext ctxOvr = new SprContext(pe, pd, SprCompileFlags.All,
                                                   false, bEncCmdOvr);
                ctxOvr.Base          = strUrl;
                ctxOvr.BaseIsEncoded = bEncCmd;

                strUrl = SprEngine.Compile(strOvr, ctxOvr);
            }

            return(strUrl);
        }
Пример #2
0
        public static void OpenUrl(string strUrlToOpen, PwEntry peDataSource,
                                   bool bAllowOverride, string strBaseRaw)
        {
            // If URL is null, return, do not throw exception.
            Debug.Assert(strUrlToOpen != null); if (strUrlToOpen == null)
            {
                return;
            }

            string strPrevWorkDir = WinUtil.GetWorkingDirectory();
            string strThisExe     = WinUtil.GetExecutable();

            string strExeDir = UrlUtil.GetFileDirectory(strThisExe, false, true);

            WinUtil.SetWorkingDirectory(strExeDir);

            string strUrlFlt = strUrlToOpen;

            strUrlFlt = strUrlFlt.TrimStart(new char[] { ' ', '\t', '\r', '\n' });

            PwDatabase pwDatabase = null;

            try
            {
                pwDatabase = Program.MainForm.DocumentManager.SafeFindContainerOf(
                    peDataSource);
            }
            catch (Exception) { Debug.Assert(false); }

            bool bCmdQuotes = WinUtil.IsCommandLineUrl(strUrlFlt);

            SprContext ctx = new SprContext(peDataSource, pwDatabase,
                                            SprCompileFlags.All, false, bCmdQuotes);

            ctx.Base          = strBaseRaw;
            ctx.BaseIsEncoded = false;

            string strUrl = SprEngine.Compile(strUrlFlt, ctx);

            string strOvr = Program.Config.Integration.UrlSchemeOverrides.GetOverrideForUrl(
                strUrl);

            if (!bAllowOverride)
            {
                strOvr = null;
            }
            if (strOvr != null)
            {
                bool bCmdQuotesOvr = WinUtil.IsCommandLineUrl(strOvr);

                SprContext ctxOvr = new SprContext(peDataSource, pwDatabase,
                                                   SprCompileFlags.All, false, bCmdQuotesOvr);
                ctxOvr.Base          = strUrl;
                ctxOvr.BaseIsEncoded = bCmdQuotes;

                strUrl = SprEngine.Compile(strOvr, ctxOvr);
            }

            if (WinUtil.IsCommandLineUrl(strUrl))
            {
                string strApp, strArgs;
                StrUtil.SplitCommandLine(WinUtil.GetCommandLineFromUrl(strUrl),
                                         out strApp, out strArgs);

                try
                {
                    if ((strArgs != null) && (strArgs.Length > 0))
                    {
                        Process.Start(strApp, strArgs);
                    }
                    else
                    {
                        Process.Start(strApp);
                    }
                }
                catch (Win32Exception)
                {
                    StartWithoutShellExecute(strApp, strArgs);
                }
                catch (Exception exCmd)
                {
                    string strInf = KPRes.FileOrUrl + ": " + strApp;
                    if ((strArgs != null) && (strArgs.Length > 0))
                    {
                        strInf += MessageService.NewParagraph +
                                  KPRes.Arguments + ": " + strArgs;
                    }

                    MessageService.ShowWarning(strInf, exCmd);
                }
            }
            else             // Standard URL
            {
                try { Process.Start(strUrl); }
                catch (Exception exUrl)
                {
                    MessageService.ShowWarning(strUrl, exUrl);
                }
            }

            // Restore previous working directory
            WinUtil.SetWorkingDirectory(strPrevWorkDir);

            // SprEngine.Compile might have modified the database
            Program.MainForm.UpdateUI(false, null, false, null, false, null, false);
        }
Пример #3
0
        public static void OpenUrl(string strUrlToOpen, PwEntry peDataSource)
        {
            // If URL is null, return false, do not throw exception.
            Debug.Assert(strUrlToOpen != null); if (strUrlToOpen == null)
            {
                return;
            }

            string strPrevWorkDir = Directory.GetCurrentDirectory();
            string strThisExe     = WinUtil.GetExecutable();

            string strExeDir = UrlUtil.GetFileDirectory(strThisExe, false);

            try { Directory.SetCurrentDirectory(strExeDir); }
            catch (Exception) { Debug.Assert(false); }

            string strUrl = strUrlToOpen;

            strUrl = strUrl.TrimStart(new char[] { ' ', '\t', '\r', '\n' });

            PwDatabase pwDatabase = null;

            try { pwDatabase = Program.MainForm.PluginHost.Database; }
            catch (Exception) { Debug.Assert(false); pwDatabase = null; }

            bool bCmdQuotes = WinUtil.IsCommandLineUrl(strUrl);

            strUrl = SprEngine.Compile(strUrl, false, peDataSource, pwDatabase,
                                       false, bCmdQuotes);

            if (WinUtil.IsCommandLineUrl(strUrl))
            {
                string strApp, strArgs;
                StrUtil.SplitCommandLine(WinUtil.GetCommandLineFromUrl(strUrl),
                                         out strApp, out strArgs);

                try
                {
                    if ((strArgs != null) && (strArgs.Length > 0))
                    {
                        Process.Start(strApp, strArgs);
                    }
                    else
                    {
                        Process.Start(strApp);
                    }
                }
                catch (Win32Exception)
                {
                    StartWithoutShellExecute(strApp, strArgs);
                }
                catch (Exception exCmd)
                {
                    string strInf = KPRes.FileOrUrl + ": " + strApp;
                    if ((strArgs != null) && (strArgs.Length > 0))
                    {
                        strInf += MessageService.NewParagraph +
                                  KPRes.Arguments + ": " + strArgs;
                    }

                    MessageService.ShowWarning(strInf, exCmd);
                }
            }
            else
            {
                try { Process.Start(strUrl); }
                catch (Exception exUrl)
                {
                    MessageService.ShowWarning(strUrl, exUrl);
                }
            }

            // Restore previous working directory
            try { Directory.SetCurrentDirectory(strPrevWorkDir); }
            catch (Exception) { Debug.Assert(false); }
        }
Пример #4
0
        private static void OpenUrlPriv(string strUrlToOpen, PwEntry peDataSource,
                                        bool bAllowOverride, string strBaseRaw)
        {
            if (string.IsNullOrEmpty(strUrlToOpen))
            {
                Debug.Assert(false); return;
            }

            if (WinUtil.OpenUrlPre != null)
            {
                OpenUrlEventArgs e = new OpenUrlEventArgs(strUrlToOpen, peDataSource,
                                                          bAllowOverride, strBaseRaw);
                WinUtil.OpenUrlPre(null, e);
                strUrlToOpen = e.Url;

                if (string.IsNullOrEmpty(strUrlToOpen))
                {
                    return;
                }
            }

            string strPrevWorkDir = WinUtil.GetWorkingDirectory();
            string strThisExe     = WinUtil.GetExecutable();

            string strExeDir = UrlUtil.GetFileDirectory(strThisExe, false, true);

            WinUtil.SetWorkingDirectory(strExeDir);

            string strUrl = CompileUrl(strUrlToOpen, peDataSource, bAllowOverride,
                                       strBaseRaw, null);

            if (WinUtil.IsCommandLineUrl(strUrl))
            {
                string strApp, strArgs;
                StrUtil.SplitCommandLine(WinUtil.GetCommandLineFromUrl(strUrl),
                                         out strApp, out strArgs);

                try
                {
                    try { NativeLib.StartProcess(strApp, strArgs); }
                    catch (Win32Exception)
                    {
                        ProcessStartInfo psi = new ProcessStartInfo();
                        psi.FileName = strApp;
                        if (!string.IsNullOrEmpty(strArgs))
                        {
                            psi.Arguments = strArgs;
                        }
                        psi.UseShellExecute = false;

                        NativeLib.StartProcess(psi);
                    }
                }
                catch (Exception exCmd)
                {
                    string strMsg = KPRes.FileOrUrl + ": " + strApp;
                    if (!string.IsNullOrEmpty(strArgs))
                    {
                        strMsg += MessageService.NewParagraph +
                                  KPRes.Arguments + ": " + strArgs;
                    }

                    MessageService.ShowWarning(strMsg, exCmd);
                }
            }
            else             // Standard URL
            {
                try { NativeLib.StartProcess(strUrl); }
                catch (Exception exUrl)
                {
                    MessageService.ShowWarning(strUrl, exUrl);
                }
            }

            // Restore previous working directory
            WinUtil.SetWorkingDirectory(strPrevWorkDir);

            // SprEngine.Compile might have modified the database
            MainForm mf = Program.MainForm;

            if (mf != null)
            {
                mf.UpdateUI(false, null, false, null, false, null, false);
            }
        }
Пример #5
0
        private static void OpenUrlPriv(string strUrlToOpen, PwEntry peDataSource,
                                        bool bAllowOverride, string strBaseRaw)
        {
            if (strUrlToOpen == null)
            {
                Debug.Assert(false); return;
            }

            string strPrevWorkDir = WinUtil.GetWorkingDirectory();
            string strThisExe     = WinUtil.GetExecutable();

            string strExeDir = UrlUtil.GetFileDirectory(strThisExe, false, true);

            WinUtil.SetWorkingDirectory(strExeDir);

            string strUrl = CompileUrl(strUrlToOpen, peDataSource, bAllowOverride,
                                       strBaseRaw);

            Process p = null;

            if (WinUtil.IsCommandLineUrl(strUrl))
            {
                string strApp, strArgs;
                StrUtil.SplitCommandLine(WinUtil.GetCommandLineFromUrl(strUrl),
                                         out strApp, out strArgs);

                try
                {
                    if (!string.IsNullOrEmpty(strArgs))
                    {
                        p = Process.Start(strApp, strArgs);
                    }
                    else
                    {
                        p = Process.Start(strApp);
                    }
                }
                catch (Win32Exception)
                {
                    StartWithoutShellExecute(strApp, strArgs);
                }
                catch (Exception exCmd)
                {
                    string strInf = KPRes.FileOrUrl + ": " + strApp;
                    if ((strArgs != null) && (strArgs.Length > 0))
                    {
                        strInf += StrUtil.NewParagraph +
                                  KPRes.Arguments + ": " + strArgs;
                    }

                    MessageService.ShowWarning(strInf, exCmd);
                }
            }
            else             // Standard URL
            {
                try { p = Process.Start(strUrl); }
                catch (Exception exUrl)
                {
                    MessageService.ShowWarning(strUrl, exUrl);
                }
            }

            try { if (p != null)
                  {
                      p.Dispose();
                  }
            }
            catch (Exception) { Debug.Assert(false); }

            // Restore previous working directory
            WinUtil.SetWorkingDirectory(strPrevWorkDir);

            // SprEngine.Compile might have modified the database
            MainForm mf = Program.MainForm;

            if (mf != null)
            {
                mf.UpdateUI(false, null, false, null, false, null, false);
            }
        }