Skip to content

Commit

Permalink
fix stylecop errors and make additions required for different package…
Browse files Browse the repository at this point in the history
… flavors in appxmanifest
  • Loading branch information
ssparach committed Jul 31, 2024
1 parent ce7aa4c commit e7bc4e1
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public class GitConfiguration : IDisposable
{
public GitExecutableConfigOptions GitExecutableConfigOptions { get; set; }

private readonly FileService fileService;
private readonly FileService _fileService;

private string GitExeInstallPath { get; set; } = string.Empty;

private readonly object fileLock = new();
private readonly object _fileLock = new();

private readonly ILogger log = Log.ForContext<GitDetect>();
private readonly ILogger _log = Log.ForContext<GitDetect>();

private readonly string tempConfigurationFileName = "TemporaryGitConfiguration.json";
private readonly string _tempConfigurationFileName = "TemporaryGitConfiguration.json";

public GitConfiguration(string? path)
{
Expand All @@ -39,22 +39,22 @@ public GitConfiguration(string? path)
GitExecutableConfigFolderPath = folderPath,
};

fileService = new FileService();
_fileService = new FileService();
EnsureConfigFileCreation();
}

public string ReadInstallPath()
{
lock (fileLock)
lock (_fileLock)
{
GitExeInstallPath = fileService.Read<string>(GitExecutableConfigOptions.GitExecutableConfigFolderPath, GitExecutableConfigOptions.GitExecutableConfigFileName);
GitExeInstallPath = _fileService.Read<string>(GitExecutableConfigOptions.GitExecutableConfigFolderPath, GitExecutableConfigOptions.GitExecutableConfigFileName);
return GitExeInstallPath;
}
}

public void EnsureConfigFileCreation()
{
lock (fileLock)
lock (_fileLock)
{
if (!Directory.Exists(GitExecutableConfigOptions.GitExecutableConfigFolderPath))
{
Expand All @@ -64,8 +64,8 @@ public void EnsureConfigFileCreation()
var configFileFullPath = Path.Combine(GitExecutableConfigOptions.GitExecutableConfigFolderPath, GitExecutableConfigOptions.GitExecutableConfigFileName);
if (!File.Exists(configFileFullPath))
{
fileService.Save(GitExecutableConfigOptions.GitExecutableConfigFolderPath, GitExecutableConfigOptions.GitExecutableConfigFileName, string.Empty);
log.Information("The git configuration file did not exists and has just been created");
_fileService.Save(GitExecutableConfigOptions.GitExecutableConfigFolderPath, GitExecutableConfigOptions.GitExecutableConfigFileName, string.Empty);
_log.Information("The git configuration file did not exists and has just been created");
}
}
}
Expand All @@ -77,14 +77,14 @@ public bool IsGitExeInstallPathSet()

public bool StoreGitExeInstallPath(string path)
{
lock (fileLock)
lock (_fileLock)
{
log.Information("Setting Git Exe Install Path");
_log.Information("Setting Git Exe Install Path");
GitExeInstallPath = path;

fileService.Save(GitExecutableConfigOptions.GitExecutableConfigFolderPath, tempConfigurationFileName, GitExeInstallPath);
File.Replace(Path.Combine(GitExecutableConfigOptions.GitExecutableConfigFolderPath, tempConfigurationFileName), Path.Combine(GitExecutableConfigOptions.GitExecutableConfigFolderPath, GitExecutableConfigOptions.GitExecutableConfigFileName), null);
log.Information("Git Exe Install Path stored successfully");
_fileService.Save(GitExecutableConfigOptions.GitExecutableConfigFolderPath, _tempConfigurationFileName, GitExeInstallPath);
File.Replace(Path.Combine(GitExecutableConfigOptions.GitExecutableConfigFolderPath, _tempConfigurationFileName), Path.Combine(GitExecutableConfigOptions.GitExecutableConfigFolderPath, GitExecutableConfigOptions.GitExecutableConfigFileName), null);
_log.Information("Git Exe Install Path stored successfully");
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class GitDetect
{
public GitConfiguration GitConfiguration { get; set; }

private readonly ILogger log = Log.ForContext<GitDetect>();
private readonly ILogger _log = Log.ForContext<GitDetect>();

public GitDetect()
{
Expand Down Expand Up @@ -74,13 +74,13 @@ private string[] FindSubdirectories(string installLocation)
}
else
{
log.Warning("Install location does not exist: {InstallLocation}", installLocation);
_log.Warning("Install location does not exist: {InstallLocation}", installLocation);
return Array.Empty<string>();
}
}
catch (Exception ex)
{
log.Warning(ex, "Failed to find subdirectories in install location: {InstallLocation}", installLocation);
_log.Warning(ex, "Failed to find subdirectories in install location: {InstallLocation}", installLocation);
return Array.Empty<string>();
}
}
Expand All @@ -97,12 +97,12 @@ private bool CheckForExeInPaths(string[] possiblePaths)
if (isValid)
{
GitConfiguration.StoreGitExeInstallPath(gitPath);
log.Information("Git Exe Install Path found");
_log.Information("Git Exe Install Path found");
return true;
}
}

log.Debug("Git.exe not found in paths examined");
_log.Debug("Git.exe not found in paths examined");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public partial class GitExecutableConfigOptions

public string GitExecutableConfigFileName { get; set; } = GitExecutableConfigFileNameDefault;

private readonly string gitExecutableConfigFolderPathDefault = Path.Combine(Path.GetTempPath(), "FileExplorerGitIntegration");
private readonly string _gitExecutableConfigFolderPathDefault = Path.Combine(Path.GetTempPath(), "FileExplorerGitIntegration");

private string? gitExecutableConfigFolderPath;
private string? _gitExecutableConfigFolderPath;

public string GitExecutableConfigFolderPath
{
get => gitExecutableConfigFolderPath is null ? gitExecutableConfigFolderPathDefault : gitExecutableConfigFolderPath;
set => gitExecutableConfigFolderPath = string.IsNullOrEmpty(value) ? gitExecutableConfigFolderPathDefault : value;
get => _gitExecutableConfigFolderPath is null ? _gitExecutableConfigFolderPathDefault : _gitExecutableConfigFolderPath;
set => _gitExecutableConfigFolderPath = string.IsNullOrEmpty(value) ? _gitExecutableConfigFolderPathDefault : value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class GitLocalRepository : ILocalRepository
{
private readonly RepositoryCache? _repositoryCache;

private readonly Serilog.ILogger log = Log.ForContext("SourceContext", nameof(GitLocalRepository));
private readonly Serilog.ILogger _log = Log.ForContext("SourceContext", nameof(GitLocalRepository));

public string RootFolder
{
Expand Down Expand Up @@ -63,7 +63,7 @@ IPropertySet ILocalRepository.GetProperties(string[] properties, string relative

if (repository == null)
{
log.Debug("GetProperties: Repository object is null");
_log.Debug("GetProperties: Repository object is null");
return result;
}

Expand Down Expand Up @@ -161,7 +161,7 @@ IPropertySet ILocalRepository.GetProperties(string[] properties, string relative
}
}

log.Debug("Returning source control properties from git source control extension");
_log.Debug("Returning source control properties from git source control extension");
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ namespace FileExplorerGitIntegration.Models;

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
#if CANARY_BUILD
[Guid("A65E46FF-F979-480d-A379-1FDA3EB5F7C5")]
#elif STABLE_BUILD
[Guid("8A962CBD-530D-4195-8FE3-F0DF3FDDF128")]
#else
[Guid("BDA76685-E749-4f09-8F13-C466D0802DA1")]
#endif
public class GitLocalRepositoryProviderFactory : ILocalRepositoryProvider
{
private readonly RepositoryCache? _repositoryCache;

public string DisplayName => "GitLocalRepositoryProviderFactory";

private readonly StringResource stringResource = new("FileExplorerGitIntegration.pri", "Resources");
private readonly StringResource _stringResource = new("FileExplorerGitIntegration.pri", "Resources");
private readonly string _errorResourceKey = "GetRepositoryError";

GetLocalRepositoryResult ILocalRepositoryProvider.GetRepository(string rootPath)
Expand All @@ -30,7 +36,7 @@ GetLocalRepositoryResult ILocalRepositoryProvider.GetRepository(string rootPath)
{
var log = Log.ForContext("SourceContext", nameof(GitLocalRepositoryProviderFactory));
log.Error("GitLocalRepositoryProviderFactory", "Failed to create GitLocalRepository", ex);
return new GetLocalRepositoryResult(ex, stringResource.GetLocalized(_errorResourceKey), $"Message: {ex.Message} and HRESULT: {ex.HResult}");
return new GetLocalRepositoryResult(ex, _stringResource.GetLocalized(_errorResourceKey), $"Message: {ex.Message} and HRESULT: {ex.HResult}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace FileExplorerGitIntegration.Models;

public sealed class GitLocalRepositoryProviderServer : IDisposable
{
private readonly HashSet<uint> registrationCookies = new();
private readonly Serilog.ILogger log = Log.ForContext("SourceContext", nameof(GitLocalRepositoryProviderServer));
private readonly HashSet<uint> _registrationCookies = new();
private readonly Serilog.ILogger _log = Log.ForContext("SourceContext", nameof(GitLocalRepositoryProviderServer));

[UnconditionalSuppressMessage(
"ReflectionAnalysis",
Expand All @@ -23,9 +23,9 @@ public sealed class GitLocalRepositoryProviderServer : IDisposable
public void RegisterGitRepositoryProviderServer<T>(Func<T> createGitRepositoryProviderServer)
where T : GitLocalRepositoryProviderFactory
{
log.Debug($"Registering class object:");
log.Debug($"CLSID: {typeof(T).GUID:B}");
log.Debug($"Type: {typeof(T)}");
_log.Debug($"Registering class object:");
_log.Debug($"CLSID: {typeof(T).GUID:B}");
_log.Debug($"Type: {typeof(T)}");

uint cookie;
var clsid = typeof(T).GUID;
Expand All @@ -41,8 +41,8 @@ public void RegisterGitRepositoryProviderServer<T>(Func<T> createGitRepositoryPr
Marshal.ThrowExceptionForHR(hr);
}

registrationCookies.Add(cookie);
log.Debug($"Cookie: {cookie}");
_registrationCookies.Add(cookie);
_log.Debug($"Cookie: {cookie}");
hr = PInvoke.CoResumeClassObjects();
if (hr < 0)
{
Expand All @@ -63,10 +63,10 @@ public void Run()

public void Dispose()
{
log.Debug($"Revoking class object registrations:");
foreach (var cookie in registrationCookies)
_log.Debug($"Revoking class object registrations:");
foreach (var cookie in _registrationCookies)
{
log.Debug($"Cookie: {cookie}");
_log.Debug($"Cookie: {cookie}");
var hr = PInvoke.CoRevokeClassObject(cookie);
Debug.Assert(hr >= 0, $"CoRevokeClassObject failed ({hr:x}). Cookie: {cookie}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace FileExplorerGitIntegration.Models;
internal sealed class RepositoryCache : IDisposable
{
private readonly ConcurrentDictionary<string, RepositoryWrapper> _repositoryCache = new();
private readonly Serilog.ILogger log = Log.ForContext("SourceContext", nameof(RepositoryCache));
private bool disposedValue;
private readonly Serilog.ILogger _log = Log.ForContext("SourceContext", nameof(RepositoryCache));
private bool _disposedValue;

public RepositoryWrapper GetRepository(string rootFolder)
{
Expand Down Expand Up @@ -51,7 +51,7 @@ public RepositoryWrapper GetRepository(string rootFolder)

internal void Dispose(bool disposing)
{
if (!disposedValue)
if (!_disposedValue)
{
if (disposing)
{
Expand All @@ -62,7 +62,7 @@ internal void Dispose(bool disposing)
}

_repositoryCache.Clear();
disposedValue = true;
_disposedValue = true;
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/Package-Can.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@
</com:ExeServer>
</com:ComServer>
</com:Extension>
<com:Extension Category="windows.comServer">
<com:ComServer>
<com:ExeServer Executable="DevHome.FileExplorerSourceControlIntegration.exe" Arguments="-RegisterProcessAsComServer" DisplayName="Source Control Core">
<com:Class Id="40FE4D6E-C9A0-48b4-A83E-AAA1D002C0D5" DisplayName="Core Extension" />
</com:ExeServer>
</com:ComServer>
</com:Extension>
<com:Extension Category="windows.comServer">
<com:ComServer>
<com:ExeServer Executable="FileExplorerGitIntegration.exe" Arguments="-RegisterProcessAsComServer" DisplayName="LocalRepositoryProvider">
<com:Class Id="A65E46FF-F979-480d-A379-1FDA3EB5F7C5" DisplayName="LocalRepositoryProvider" />
</com:ExeServer>
</com:ComServer>
</com:Extension>
<uap3:Extension Category="windows.appExtension">
<uap3:AppExtension Name="com.microsoft.devhome" Id="PG-SP-ID1" PublicFolder="Public" DisplayName="ms-resource:AppDisplayNameCoreExt" Description="ms-resource:AppDescriptionCoreExt">
<uap3:Properties>
Expand Down Expand Up @@ -128,6 +142,20 @@
</uap3:Properties>
</uap3:AppExtension>
</uap3:Extension>
<uap3:Extension Category="windows.appExtension">
<uap3:AppExtension Name="com.microsoft.devhome" Id="PG-SP-ID3" PublicFolder="Public" DisplayName="ms-resource:AppDisplayNameGitExt" Description="ms-resource:AppDescriptionGitExt">
<uap3:Properties>
<DevHomeProvider>
<Activation>
<CreateInstance ClassId="A65E46FF-F979-480d-A379-1FDA3EB5F7C5" />
</Activation>
<SupportedInterfaces>
<LocalRepository />
</SupportedInterfaces>
</DevHomeProvider>
</uap3:Properties>
</uap3:AppExtension>
</uap3:Extension>
<uap3:Extension Category="windows.appExtension">
<uap3:AppExtension Name="com.microsoft.windows.widgets" DisplayName="ms-resource:WidgetProviderDisplayNameCanary" Id="CoreWidgetProvider" PublicFolder="Public">
<uap3:Properties>
Expand Down
28 changes: 28 additions & 0 deletions src/Package-Dev.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@
</com:ExeServer>
</com:ComServer>
</com:Extension>
<com:Extension Category="windows.comServer">
<com:ComServer>
<com:ExeServer Executable="DevHome.FileExplorerSourceControlIntegration.exe" Arguments="-RegisterProcessAsComServer" DisplayName="Source Control Core">
<com:Class Id="40FE4D6E-C9A0-48b4-A83E-AAA1D002C0D5" DisplayName="Core Extension" />
</com:ExeServer>
</com:ComServer>
</com:Extension>
<com:Extension Category="windows.comServer">
<com:ComServer>
<com:ExeServer Executable="FileExplorerGitIntegration.exe" Arguments="-RegisterProcessAsComServer" DisplayName="LocalRepositoryProvider">
<com:Class Id="BDA76685-E749-4f09-8F13-C466D0802DA1" DisplayName="LocalRepositoryProvider" />
</com:ExeServer>
</com:ComServer>
</com:Extension>
<uap3:Extension Category="windows.appExtension">
<uap3:AppExtension Name="com.microsoft.devhome" Id="PG-SP-ID1" PublicFolder="Public" DisplayName="ms-resource:AppDisplayNameCoreExt" Description="ms-resource:AppDescriptionCoreExt">
<uap3:Properties>
Expand Down Expand Up @@ -128,6 +142,20 @@
</uap3:Properties>
</uap3:AppExtension>
</uap3:Extension>
<uap3:Extension Category="windows.appExtension">
<uap3:AppExtension Name="com.microsoft.devhome" Id="PG-SP-ID3" PublicFolder="Public" DisplayName="ms-resource:AppDisplayNameGitExt" Description="ms-resource:AppDescriptionGitExt">
<uap3:Properties>
<DevHomeProvider>
<Activation>
<CreateInstance ClassId="BDA76685-E749-4f09-8F13-C466D0802DA1" />
</Activation>
<SupportedInterfaces>
<LocalRepository />
</SupportedInterfaces>
</DevHomeProvider>
</uap3:Properties>
</uap3:AppExtension>
</uap3:Extension>
<uap3:Extension Category="windows.appExtension">
<uap3:AppExtension Name="com.microsoft.windows.widgets" DisplayName="ms-resource:WidgetProviderDisplayNameDev" Id="CoreWidgetProvider" PublicFolder="Public">
<uap3:Properties>
Expand Down
6 changes: 3 additions & 3 deletions src/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<com:Extension Category="windows.comServer">
<com:ComServer>
<com:ExeServer Executable="FileExplorerGitIntegration.exe" Arguments="-RegisterProcessAsComServer" DisplayName="LocalRepositoryProvider">
<com:Class Id="BDA76685-E749-4f09-8F13-C466D0802DA1" DisplayName="LocalRepositoryProvider" />
<com:Class Id="8A962CBD-530D-4195-8FE3-F0DF3FDDF128" DisplayName="LocalRepositoryProvider" />
</com:ExeServer>
</com:ComServer>
</com:Extension>
Expand Down Expand Up @@ -143,11 +143,11 @@
</uap3:AppExtension>
</uap3:Extension>
<uap3:Extension Category="windows.appExtension">
<uap3:AppExtension Name="com.microsoft.devhome" Id="PG-SP-ID3" PublicFolder="Public" DisplayName="Git" Description="ms-resource:AppDescriptionGitExt">
<uap3:AppExtension Name="com.microsoft.devhome" Id="PG-SP-ID3" PublicFolder="Public" DisplayName="ms-resource:AppDisplayNameGitExt" Description="ms-resource:AppDescriptionGitExt">
<uap3:Properties>
<DevHomeProvider>
<Activation>
<CreateInstance ClassId="BDA76685-E749-4f09-8F13-C466D0802DA1" />
<CreateInstance ClassId="8A962CBD-530D-4195-8FE3-F0DF3FDDF128" />
</Activation>
<SupportedInterfaces>
<LocalRepository />
Expand Down
8 changes: 8 additions & 0 deletions src/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,12 @@
<value>Windows Subsystem for Linux</value>
<comment>{Locked="Windows", "Linux"} Extension Description</comment>
</data>
<data name="AppDisplayNameGitExt" xml:space="preserve">
<value>Git</value>
<comment>Git Extension Display Name</comment>
</data>
<data name="AppDescriptionGitExt" xml:space="preserve">
<value>Allows integration of GIt with File Explorer</value>
<comment>Git Extension Description</comment>
</data>
</root>
Loading

0 comments on commit e7bc4e1

Please sign in to comment.