Skip to content

Commit

Permalink
Merge pull request #8721 from mstv/osshellutils
Browse files Browse the repository at this point in the history
  • Loading branch information
RussKie committed Jan 7, 2021
2 parents 371c4b3 + 7c89f65 commit e0619e4
Show file tree
Hide file tree
Showing 30 changed files with 100 additions and 133 deletions.
20 changes: 16 additions & 4 deletions GitCommands/Git/Executable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ public Executable([NotNull] Func<string> fileNameProvider, [NotNull] string work

/// <inheritdoc />
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public IProcess Start(ArgumentString arguments = default, bool createWindow = false, bool redirectInput = false, bool redirectOutput = false, Encoding outputEncoding = null)
public IProcess Start(ArgumentString arguments = default,
bool createWindow = false,
bool redirectInput = false,
bool redirectOutput = false,
Encoding outputEncoding = null,
bool useShellExecute = false)
{
// TODO should we set these on the child process only?
EnvironmentConfiguration.SetEnvironmentVariables();
Expand All @@ -40,7 +45,7 @@ public IProcess Start(ArgumentString arguments = default, bool createWindow = fa

var fileName = _fileNameProvider();

return new ProcessWrapper(fileName, args, _workingDir, createWindow, redirectInput, redirectOutput, outputEncoding);
return new ProcessWrapper(fileName, args, _workingDir, createWindow, redirectInput, redirectOutput, outputEncoding, useShellExecute);
}

public string GetOutput(ArgumentString arguments)
Expand Down Expand Up @@ -69,7 +74,14 @@ private sealed class ProcessWrapper : IProcess
private bool _disposed;

[SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")]
public ProcessWrapper(string fileName, string arguments, string workDir, bool createWindow, bool redirectInput, bool redirectOutput, [CanBeNull] Encoding outputEncoding)
public ProcessWrapper(string fileName,
string arguments,
string workDir,
bool createWindow,
bool redirectInput,
bool redirectOutput,
[CanBeNull] Encoding outputEncoding,
bool useShellExecute)
{
Debug.Assert(redirectOutput == (outputEncoding != null), "redirectOutput == (outputEncoding != null)");
_redirectInput = redirectInput;
Expand All @@ -80,7 +92,7 @@ public ProcessWrapper(string fileName, string arguments, string workDir, bool cr
EnableRaisingEvents = true,
StartInfo =
{
UseShellExecute = false,
UseShellExecute = useShellExecute,
ErrorDialog = false,
CreateNoWindow = !createWindow,
RedirectStandardInput = redirectInput,
Expand Down
2 changes: 1 addition & 1 deletion GitExtensions/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private static bool LocateMissingGit()

case 1:
{
Process.Start(@"https://github.com/gitextensions/gitextensions/wiki/Application-Dependencies#git");
OsShellUtil.OpenUrlInDefaultBrowser(@"https://github.com/gitextensions/gitextensions/wiki/Application-Dependencies#git");
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion GitUI/BranchTreePanel/RepoObjectsTree.Nodes.Remotes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void OpenRemoteUrlInBrowser()
return;
}

Process.Start(_remote.FetchUrl);
OsShellUtil.OpenUrlInDefaultBrowser(_remote.FetchUrl);
}

public bool IsRemoteUrlUsingHttp => _remote.FetchUrl.IsUrlUsingHttp();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
Expand Down Expand Up @@ -212,18 +211,18 @@ private void dashboard_ParentChanged(object sender, EventArgs e)

private static void TranslateItem_Click(object sender, EventArgs e)
{
Process.Start("https://github.com/gitextensions/gitextensions/wiki/Translations");
OsShellUtil.OpenUrlInDefaultBrowser(@"https://github.com/gitextensions/gitextensions/wiki/Translations");
}

private static void GitHubItem_Click(object sender, EventArgs e)
{
Process.Start(@"https://github.com/gitextensions/gitextensions");
OsShellUtil.OpenUrlInDefaultBrowser(@"https://github.com/gitextensions/gitextensions");
}

private static void IssuesItem_Click(object sender, EventArgs e)
{
UserEnvironmentInformation.CopyInformation();
Process.Start(@"https://github.com/gitextensions/gitextensions/issues");
OsShellUtil.OpenUrlInDefaultBrowser(@"https://github.com/gitextensions/gitextensions/issues");
}

private void openItem_Click(object sender, EventArgs e)
Expand All @@ -247,7 +246,7 @@ private void createItem_Click(object sender, EventArgs e)

private static void DonateItem_Click(object sender, EventArgs e)
{
Process.Start(FormDonate.DonationUrl);
OsShellUtil.OpenUrlInDefaultBrowser(FormDonate.DonationUrl);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -731,16 +730,7 @@ private void tsmiCategoryAdd_Click(object sender, EventArgs e)
}

private void tsmiOpenFolder_Click(object sender, EventArgs e)
{
try
{
RepositoryContextAction(sender as ToolStripMenuItem, selectedRepositoryItem => Process.Start(selectedRepositoryItem.Repository.Path));
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
=> RepositoryContextAction(sender as ToolStripMenuItem, selectedRepositoryItem => OsShellUtil.OpenWithFileExplorer(selectedRepositoryItem.Repository.Path));

private void tsmiRemoveFromList_Click(object sender, EventArgs e)
{
Expand Down
5 changes: 2 additions & 3 deletions GitUI/CommandsDialogs/BrowseDialog/FormDonate.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Drawing;
using ResourceManager;

Expand Down Expand Up @@ -27,7 +26,7 @@ public FormDonate()

private void PictureBox1Click(object sender, EventArgs e)
{
Process.Start(DonationUrl);
OsShellUtil.OpenUrlInDefaultBrowser(DonationUrl);
}
}
}
}
3 changes: 1 addition & 2 deletions GitUI/CommandsDialogs/BrowseDialog/FormGoToCommit.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand Down Expand Up @@ -71,7 +70,7 @@ private void goButton_Click(object sender, EventArgs e)

private void linkGitRevParse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(@"https://git-scm.com/docs/git-rev-parse#_specifying_revisions");
OsShellUtil.OpenUrlInDefaultBrowser(@"https://git-scm.com/docs/git-rev-parse#_specifying_revisions");
}

private Task LoadTagsAsync()
Expand Down
4 changes: 2 additions & 2 deletions GitUI/CommandsDialogs/BrowseDialog/FormUpdates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ private void LaunchUrl(LaunchType launchType)
switch (launchType)
{
case LaunchType.ChangeLog:
Process.Start("https://github.com/gitextensions/gitextensions/blob/master/GitUI/Resources/ChangeLog.md");
OsShellUtil.OpenUrlInDefaultBrowser(@"https://github.com/gitextensions/gitextensions/blob/master/GitUI/Resources/ChangeLog.md");
break;
case LaunchType.DirectDownload:
Process.Start(UpdateUrl);
OsShellUtil.OpenUrlInDefaultBrowser(UpdateUrl);
break;
}
}
Expand Down
3 changes: 1 addition & 2 deletions GitUI/CommandsDialogs/BuildReportTabPageExtension.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -39,7 +38,7 @@ public BuildReportTabPageExtension(Func<IGitModule> getModule, TabControl tabCon
{
if (!string.IsNullOrWhiteSpace(_url))
{
Process.Start(_url);
OsShellUtil.OpenUrlInDefaultBrowser(_url);
}
};
_openReportLink.Font = new Font(_openReportLink.Font.Name, 16F);
Expand Down
7 changes: 3 additions & 4 deletions GitUI/CommandsDialogs/FormAbout.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using GitCommands;
Expand Down Expand Up @@ -30,10 +29,10 @@ public FormAbout()
linkLabelIcons.LinkColor = clrLink;

// Click handlers
_NO_TRANSLATE_labelProductName.LinkClicked += delegate { Process.Start("https://github.com/gitextensions/gitextensions"); };
_NO_TRANSLATE_labelProductName.LinkClicked += delegate { OsShellUtil.OpenUrlInDefaultBrowser(@"https://github.com/gitextensions/gitextensions"); };
_NO_TRANSLATE_ThanksTo.LinkClicked += delegate { ShowContributorsForm(); };
pictureDonate.Click += delegate { Process.Start(FormDonate.DonationUrl); };
linkLabelIcons.LinkClicked += delegate { Process.Start("http://p.yusukekamiyamane.com/"); };
pictureDonate.Click += delegate { OsShellUtil.OpenUrlInDefaultBrowser(FormDonate.DonationUrl); };
linkLabelIcons.LinkClicked += delegate { OsShellUtil.OpenUrlInDefaultBrowser(@"http://p.yusukekamiyamane.com/"); };

var contributorsList = GetContributorList();
var thanksToContributorsText = string.Format(_thanksToContributors.Text, contributorsList.Count);
Expand Down
23 changes: 5 additions & 18 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1829,14 +1829,8 @@ private void CloseToolStripMenuItemClick(object sender, EventArgs e)

private void UserManualToolStripMenuItemClick(object sender, EventArgs e)
{
try
{
// Point to the default documentation, will work also if the old doc version is removed
Process.Start("https://git-extensions-documentation.readthedocs.org");
}
catch (Win32Exception)
{
}
// Point to the default documentation, will work also if the old doc version is removed
OsShellUtil.OpenUrlInDefaultBrowser(@"https://git-extensions-documentation.readthedocs.org");
}

private void CleanupToolStripMenuItemClick(object sender, EventArgs e)
Expand Down Expand Up @@ -1990,19 +1984,12 @@ private void SetGitModule(object sender, GitModuleEventArgs e)

private void TranslateToolStripMenuItemClick(object sender, EventArgs e)
{
Process.Start("https://github.com/gitextensions/gitextensions/wiki/Translations");
OsShellUtil.OpenUrlInDefaultBrowser(@"https://github.com/gitextensions/gitextensions/wiki/Translations");
}

private void FileExplorerToolStripMenuItemClick(object sender, EventArgs e)
{
try
{
Process.Start("explorer.exe", Module.WorkingDir);
}
catch (Exception ex)
{
MessageBoxes.ShowError(this, ex.Message);
}
OsShellUtil.OpenWithFileExplorer(Module.WorkingDir);
}

private void CreateBranchToolStripMenuItemClick(object sender, EventArgs e)
Expand Down Expand Up @@ -2891,7 +2878,7 @@ private void toolStripButtonLevelUp_ButtonClick(object sender, EventArgs e)
private void reportAnIssueToolStripMenuItem_Click(object sender, EventArgs e)
{
UserEnvironmentInformation.CopyInformation();
Process.Start(@"https://github.com/gitextensions/gitextensions/issues");
OsShellUtil.OpenUrlInDefaultBrowser(@"https://github.com/gitextensions/gitextensions/issues");
}

private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down
9 changes: 1 addition & 8 deletions GitUI/CommandsDialogs/FormCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2569,14 +2569,7 @@ private void OpenToolStripMenuItemClick(object sender, EventArgs e)
var fileName = list.SelectedGitItem.Name;
var path = _fullPathResolver.Resolve(fileName).ToNativePath();

try
{
Process.Start(path);
}
catch (System.ComponentModel.Win32Exception)
{
OsShellUtil.OpenAs(path);
}
OsShellUtil.Open(path);
}

private void OpenWithToolStripMenuItemClick(object sender, EventArgs e)
Expand Down
6 changes: 3 additions & 3 deletions GitUI/CommandsDialogs/FormGitIgnore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,17 @@ private void GitIgnoreFileLoaded(object sender, EventArgs e)

private void lnkGitIgnorePatterns_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(@"https://github.com/github/gitignore");
OsShellUtil.OpenUrlInDefaultBrowser(@"https://github.com/github/gitignore");
}

private void lnkGitIgnoreGenerate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(@"https://www.gitignore.io/");
OsShellUtil.OpenUrlInDefaultBrowser(@"https://www.gitignore.io/");
}

private void btnCancel_Click(object sender, EventArgs e)
{
Close();
}
}
}
}
3 changes: 1 addition & 2 deletions GitUI/CommandsDialogs/FormResolveConflicts.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
Expand Down Expand Up @@ -1448,7 +1447,7 @@ private void DisableInvalidEntriesInConflictedFilesContextMenu(string fileName)
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
string fileName = GetFileName();
Process.Start(_fullPathResolver.Resolve(fileName));
OsShellUtil.Open(_fullPathResolver.Resolve(fileName));
}

private void openWithToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down
3 changes: 1 addition & 2 deletions GitUI/CommandsDialogs/RepoHosting/ForkAndCloneForm.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -340,7 +339,7 @@ private void _openGitupPageBtn_Click(object sender, EventArgs e)
}
else
{
Process.Start(CurrentySelectedGitRepo.Homepage);
OsShellUtil.OpenUrlInDefaultBrowser(CurrentySelectedGitRepo.Homepage);
}
}

Expand Down
2 changes: 1 addition & 1 deletion GitUI/CommandsDialogs/RevisionDiffControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ private void diffOpenWorkingDirectoryFileWithToolStripMenuItem_Click(object send

private void diffOpenRevisionFileToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveSelectedItemToTempFile(fileName => Process.Start(fileName));
SaveSelectedItemToTempFile(fileName => OsShellUtil.Open(fileName));
}

private void diffOpenRevisionFileWithToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down
13 changes: 3 additions & 10 deletions GitUI/CommandsDialogs/RevisionFileTreeControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -648,17 +648,10 @@ private void openFileWithToolStripMenuItem_Click(object sender, EventArgs e)

private void openFileToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var fileName = SaveSelectedItemToTempFile();
if (fileName != null)
{
Process.Start(fileName);
}
}
catch (Exception ex)
var fileName = SaveSelectedItemToTempFile();
if (fileName != null)
{
MessageBox.Show(this, ex.Message, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
OsShellUtil.Open(fileName);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
Expand Down Expand Up @@ -209,17 +208,17 @@ private void ClearImageCache_Click(object sender, EventArgs e)

private void helpTranslate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(@"https://github.com/gitextensions/gitextensions/wiki/Translations");
OsShellUtil.OpenUrlInDefaultBrowser(@"https://github.com/gitextensions/gitextensions/wiki/Translations");
}

private void downloadDictionary_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(@"https://github.com/gitextensions/gitextensions/wiki/Spelling");
OsShellUtil.OpenUrlInDefaultBrowser(@"https://github.com/gitextensions/gitextensions/wiki/Spelling");
}

private void pictureAvatarHelp_Click(object sender, EventArgs e)
{
Process.Start(@"http://en.gravatar.com/site/implement/images#default-image");
OsShellUtil.OpenUrlInDefaultBrowser(@"http://en.gravatar.com/site/implement/images#default-image");
}

private void AvatarProvider_SelectedIndexChanged(object sender, EventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ private static void RenderSettingNotRecommended(Button settingButton, Button set

private void GcmDetectedFix_Click(object sender, EventArgs e)
{
Process.Start("https://github.com/gitextensions/gitextensions/wiki/How-To:-fix-GitCredentialWinStore-missing");
OsShellUtil.OpenUrlInDefaultBrowser(@"https://github.com/gitextensions/gitextensions/wiki/How-To:-fix-GitCredentialWinStore-missing");
}
}
}
Loading

0 comments on commit e0619e4

Please sign in to comment.