private static string FreeDriveIfCurrent(char chDriveLetter) { try { string strCur = WinUtil.GetWorkingDirectory(); if ((strCur == null) || (strCur.Length < 3)) { return(string.Empty); } if (strCur[1] != ':') { return(string.Empty); } if (strCur[2] != '\\') { return(string.Empty); } char chPar = char.ToUpper(chDriveLetter); char chCur = char.ToUpper(strCur[0]); if (chPar != chCur) { return(string.Empty); } string strTemp = UrlUtil.GetTempPath(); WinUtil.SetWorkingDirectory(strTemp); return(strCur); } catch (Exception) { Debug.Assert(false); } return(string.Empty); }
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); } }
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); }
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); } }