Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add windows explorer integration in settings #8010

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 61 additions & 0 deletions GitCommands/Settings/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,67 @@ public static bool AlwaysShowAllCommands
set => WriteBoolRegKey("AlwaysShowAllCommands", value);
}

public static bool EnableExplorerIntegration
{
// TODO write getter - check if dll is registered
// get => ReadBoolRegKey("AlwaysShowAllCommands", false);
set => HandleShellIntegration(null, null, value);
}

private static void HandleShellIntegration(object sender = null, EventArgs e = null, bool register = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move out to own file, call it something like ShellExtensionManager:

public sealed ShellExtensionManager
{
	/// <summary>
	///  Check whether the shell extensions is registered.
	/// </summary>
	/// <returns>
	///  <see langword="true"/> if the shell extensions is registered; otherwise <see langword="false"/>.
	/// </returns>
	public bool CheckRegistered();

	/// <summary>
	///  Registers the shell extensions. Throws an exception, if registration process failed.
	/// </summary>
	public void Register([NotNull] string extensionLocation);

	/// <summary>
	///  Unregisters the shell extensions. Throws an exception, if registration process failed.
	/// </summary>
	public void Unregister([NotNull] string extensionLocation);
}

NB: don't make it static, to reduce risks of race conditions while testing. The implementation should be stateless (as far as our code is concerned), so there is no issue with creating multiple instances of the class.
We can later replace is with MEF DI.

Furthermore, I don't like the functionality of registering/unregestering being placed in AppSettings. It is not a settings, and it is unrelated to the app.
If there is an error while registering or unregistering the shell extensions there is no way to inform a user.
Please move checks and register/unregister to the settings page, where it belongs.

{
const string GitExtensionsShellEx32Name = "GitExtensionsShellEx32.dll";
const string GitExtensionsShellEx64Name = "GitExtensionsShellEx64.dll";
Comment on lines +288 to +289
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move out to the class scope

string path = Path.Combine(AppSettings.GetInstallDir(), GitExtensionsShellEx32Name);

if (!File.Exists(path))
{
path = Assembly.GetExecutingAssembly().Location;
path = Path.GetDirectoryName(path);
path = Path.Combine(path, GitExtensionsShellEx32Name);
}

if (File.Exists(path))
{
try
{
var pi = new ProcessStartInfo
{
FileName = "regsvr32",
Arguments = $"{(!register ? "/u " : "")}" + path.Quote(),
Verb = "RunAs",
UseShellExecute = false,

// TODO confirmation window is not suppressed
CreateNoWindow = true
};

// TODO is IntPtr really the correct way to check architecture here?
if (IntPtr.Size == 8)
{
path = path.Replace(GitExtensionsShellEx32Name, GitExtensionsShellEx64Name);
if (File.Exists(path))
{
pi.Arguments = $"{(!register ? "/u" : "")}" + path.Quote();
}
}
Comment on lines +303 to +322
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❗ Multiple string allocations for no reason.


var process = Process.Start(pi);
process.WaitForExit();
}
catch (System.ComponentModel.Win32Exception)
{
// User cancel operation, continue;
}
}
else
{
// MessageBox.Show(this, string.Format(_cantRegisterShellExtension.Text, CommonLogic.GitExtensionsShellEx32Name), Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}

// CheckSettings();
}

public static bool ShowCurrentBranchInVisualStudio
{
// This setting MUST be set to false by default, otherwise it will not work in Visual Studio without
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected override void PageToSettings()

AppSettings.CascadeShellMenuItems = l_CascadeShellMenuItems;
AppSettings.AlwaysShowAllCommands = cbAlwaysShowAllCommands.Checked;
AppSettings.EnableExplorerIntegration = cbShellIntegration.Checked;
}

private void chlMenuEntries_SelectedValueChanged(object sender, EventArgs e)
Expand Down