Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RepoM.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=appsettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=bindable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=comparers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=decoratee/@EntryIndexedValue">True</s:Boolean>
Expand Down
93 changes: 0 additions & 93 deletions _ref/RepositoryActions.yaml

This file was deleted.

1 change: 0 additions & 1 deletion _setup/RepoM.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ Section "RepoM"
File /r ..\_output\win\Assemblies\*.*
File ..\_ref\PathEd.exe ; Add PathEd.exe to add the RepoM directory to the system's PATH easily
; File ..\_ref\SendKeys.exe ; Add SendKeys.exe to add the RepoM directory for grr.
File ..\_ref\RepositoryActions.yaml ; Can be copied in-app for the default settings
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}.lnk" $INSTDIR\${PRODUCT_NAME}.exe

; Add the installation folder to the system PATH -> to enable grr.exe
Expand Down
18 changes: 1 addition & 17 deletions src/RepoM.Api/Common/FilesCompareSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,7 @@ private Dictionary<string, IRepositoriesComparerConfiguration> LoadInner()

if (!_fileSystem.File.Exists(file))
{
var templateFilename = _fileSystem.Path.Combine(_appDataPathProvider.AppResourcesPath, FILENAME);
if (_fileSystem.File.Exists(templateFilename))
{
try
{
_fileSystem.File.Copy(templateFilename, file);
}
catch (Exception e)
{
_logger.LogError(e, "Could not copy template file '{TemplateFilename}' to '{File}'", templateFilename, file);
}
}

if (!_fileSystem.File.Exists(file))
{
throw new FileNotFoundException("Comparer configuration file not found", file);
}
throw new FileNotFoundException("Comparer configuration file not found", file);
}

try
Expand Down
18 changes: 1 addition & 17 deletions src/RepoM.Api/Common/FilesFilterSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,7 @@ private Dictionary<string, RepositoryFilterConfiguration> Load()

if (!_fileSystem.File.Exists(file))
{
var templateFilename = _fileSystem.Path.Combine(_appDataPathProvider.AppResourcesPath, FILENAME);
if (_fileSystem.File.Exists(templateFilename))
{
try
{
_fileSystem.File.Copy(templateFilename, file);
}
catch (Exception e)
{
_logger.LogError(e, "Could not copy template file '{TemplateFilename}' to '{File}'", templateFilename, file);
}
}

if (!_fileSystem.File.Exists(file))
{
throw new FileNotFoundException("Filtering configuration file not found", file);
}
throw new FileNotFoundException("Filtering configuration file not found", file);
}

try
Expand Down
53 changes: 53 additions & 0 deletions src/RepoM.Api/EnsureStartup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace RepoM.Api;

using System;
using System.IO;
using System.IO.Abstractions;
using System.Threading.Tasks;
using RepoM.Api.Resources;
using RepoM.Core.Plugin.Common;

public class EnsureStartup
{
private readonly IFileSystem _fileSystem;
private readonly IAppDataPathProvider _appDataProvider;

public EnsureStartup(IFileSystem fileSystem, IAppDataPathProvider appDataProvider)
{
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
_appDataProvider = appDataProvider ?? throw new ArgumentNullException(nameof(appDataProvider));
}

public async Task EnsureFilesAsync()
{
await CheckOrCreateAsync("RepositoryActionsV2.yaml", EmbeddedResources.GetRepositoryActionsV2Yaml).ConfigureAwait(false);
await CheckOrCreateAsync("RepoM.Filtering.yaml", EmbeddedResources.GetFilteringYaml).ConfigureAwait(false);
await CheckOrCreateAsync("RepoM.Ordering.yaml", EmbeddedResources.GetSortingYaml).ConfigureAwait(false);
await CheckOrCreateAsync("appsettings.serilog.json", EmbeddedResources.GetSerilogAppSettings).ConfigureAwait(false);
}

private async Task CheckOrCreateAsync(string filename, Func<Stream> func)
{
var fullFilename = Path.Combine(_appDataProvider.AppDataPath, filename);

if (_fileSystem.File.Exists(fullFilename))
{
return;
}

await using Stream stream = func.Invoke();
await TryCreateAsync(fullFilename, stream).ConfigureAwait(false);

if (!_fileSystem.File.Exists(fullFilename))
{
throw new FileNotFoundException(fullFilename);
}
}

private async Task TryCreateAsync(string filename, Stream content)
{
using var ms = new MemoryStream();
await content.CopyToAsync(ms).ConfigureAwait(false);
await _fileSystem.File.WriteAllBytesAsync(filename, ms.ToArray()).ConfigureAwait(false);
}
}
22 changes: 0 additions & 22 deletions src/RepoM.Api/IO/DefaultAppDataPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace RepoM.Api.IO;
public class DefaultAppDataPathProvider : IAppDataPathProvider
{
private static readonly string _applicationDataRepoM = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RepoM");
private static readonly string _appResourcesPath = GetAppResourcePath();

private DefaultAppDataPathProvider()
{
Expand All @@ -16,25 +15,4 @@ private DefaultAppDataPathProvider()
public static DefaultAppDataPathProvider Instance { get; } = new();

public string AppDataPath => _applicationDataRepoM;


public string AppResourcesPath => _appResourcesPath;

private static string GetAppResourcePath()
{
var entryAssembly = System.Reflection.Assembly.GetEntryAssembly();
if (entryAssembly == null)
{
throw new NotSupportedException("Could not get entry point of assembly.");
}

var result = Path.GetDirectoryName(entryAssembly.Location);

if (result == null)
{
throw new FileNotFoundException("Could not find location of entry assembly");
}

return result;
}
}
7 changes: 7 additions & 0 deletions src/RepoM.Api/RepoM.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@
<ProjectReference Include="..\RepoM.ActionMenu.Interface\RepoM.ActionMenu.Interface.csproj" />
<ProjectReference Include="..\RepoM.Core.Plugin\RepoM.Core.Plugin.csproj" />
</ItemGroup>

<ItemGroup>
<None Remove="Resources\*.*" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\*.*" />
</ItemGroup>
</Project>
37 changes: 37 additions & 0 deletions src/RepoM.Api/Resources/EmbeddedResources.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace RepoM.Api.Resources;

using System.IO;
using System.Reflection;
using LibGit2Sharp;

internal static class EmbeddedResources
{
private static readonly Assembly _assembly = typeof(EmbeddedResources).Assembly;
private static readonly string _namespace = typeof(EmbeddedResources).Namespace!;

public static Stream GetRepositoryActionsV2Yaml()
{
return ResolveFromAssembly("RepositoryActionsV2.yaml");
}

public static Stream GetSortingYaml()
{
return ResolveFromAssembly("RepoM.Sorting.yaml");
}

public static Stream GetFilteringYaml()
{
return ResolveFromAssembly("RepoM.Filtering.yaml");
}

public static Stream GetSerilogAppSettings()
{
return ResolveFromAssembly("appsettings.serilog.json");
}

private static Stream ResolveFromAssembly(string relativeFilename)
{
var embeddedFilename = $"{_namespace}.{relativeFilename}";
return _assembly.GetManifestResourceStream(embeddedFilename) ?? throw new NotFoundException($"{relativeFilename} not found.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ Private:
query: RepoM OR is:pinned
filter:
kind: query@1
query: (-tag:work OR tag:prive)
query: (-tag:work OR tag:private)
File renamed without changes.
Loading