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
18 changes: 11 additions & 7 deletions src/RepoM.Api/Common/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class AppSettings
public AppSettings()
{
MenuSize = Size.Default;
ReposRootDirectories= new List<string>();
EnabledSearchProviders = new List<string>();
SonarCloudPersonalAccessToken = string.Empty;
AzureDevOps = AzureDevOpsOptions.Default;
Expand All @@ -21,20 +22,23 @@ public AppSettings()

public Size MenuSize { get; set; }

public List<string> ReposRootDirectories { get; set; }

public List<string> EnabledSearchProviders { get; set; }

public string SonarCloudPersonalAccessToken { get; set; }

public AzureDevOpsOptions AzureDevOps { get; set; }

public static AppSettings Default => new()
{
AutoFetchMode = AutoFetchMode.Off,
PruneOnFetch = false,
MenuSize = Size.Default,
EnabledSearchProviders = new List<string>(1),
SonarCloudPersonalAccessToken = string.Empty,
AzureDevOps = AzureDevOpsOptions.Default,
{
AutoFetchMode = AutoFetchMode.Off,
PruneOnFetch = false,
MenuSize = Size.Default,
ReposRootDirectories = new(),
EnabledSearchProviders = new List<string>(1),
SonarCloudPersonalAccessToken = string.Empty,
AzureDevOps = AzureDevOpsOptions.Default,
};
}

Expand Down
12 changes: 12 additions & 0 deletions src/RepoM.Api/Common/FileAppSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ public double MenuHeight
}
}

public List<string> ReposRootDirectories
{
get => Settings.ReposRootDirectories;
set
{
Settings.ReposRootDirectories = value.ToList();

NotifyChange();
Save();
}
}

public List<string> EnabledSearchProviders
{
get => Settings.EnabledSearchProviders;
Expand Down
2 changes: 2 additions & 0 deletions src/RepoM.Api/Common/IAppSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public interface IAppSettingsService

double MenuHeight { get; set; }

List<string> ReposRootDirectories { get; set; }

List<string> EnabledSearchProviders { get; set; }

string SonarCloudPersonalAccessToken { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/RepoM.Api/IO/DefaultAppDataPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private DefaultAppDataPathProvider()

public string GetAppDataPath()
{
return _applicationDataRepoM ;
return _applicationDataRepoM;
}

[Obsolete("Not used.")]
Expand Down
35 changes: 31 additions & 4 deletions src/RepoM.Api/IO/DefaultDriveEnumerator.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
namespace RepoM.Api.IO;

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using RepoM.Api.Common;

public class DefaultDriveEnumerator : IPathProvider
{
private readonly IAppSettingsService _appsettings;
private readonly IFileSystem _fileSystem;

public DefaultDriveEnumerator(IFileSystem fileSystem)
public DefaultDriveEnumerator(IAppSettingsService appsettings, IFileSystem fileSystem)
{
_appsettings = appsettings;
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
}

public string[] GetPaths()
{
// Check if the ReposRootDirectories is valid and use that for searching repos
if (_appsettings.ReposRootDirectories.Any())
{
HashSet<string> paths = new();

foreach (var reposRootDirectoryPath in _appsettings.ReposRootDirectories)
{
DirectoryInfo reposRootDirectory = new(reposRootDirectoryPath);

if (reposRootDirectory.Exists)
{
_ = paths.Add(reposRootDirectoryPath);
}
}

if (paths.Any())
{
return paths.ToArray();
}
}

// By default search all drives for repos
return _fileSystem.DriveInfo.GetDrives()
.Where(d => d.DriveType == System.IO.DriveType.Fixed)
.Select(d => d.RootDirectory.FullName)
.ToArray();
.Where(d => d.DriveType == DriveType.Fixed)
.Select(d => d.RootDirectory.FullName)
.ToArray();
}
}