Ejemplo n.º 1
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);
            }
        }