diff --git a/src/RepoM.Api/Common/AppSettings.cs b/src/RepoM.Api/Common/AppSettings.cs index a152c130..014a6e21 100644 --- a/src/RepoM.Api/Common/AppSettings.cs +++ b/src/RepoM.Api/Common/AppSettings.cs @@ -8,6 +8,7 @@ public class AppSettings public AppSettings() { MenuSize = Size.Default; + ReposRootDirectories= new List(); EnabledSearchProviders = new List(); SonarCloudPersonalAccessToken = string.Empty; AzureDevOps = AzureDevOpsOptions.Default; @@ -21,6 +22,8 @@ public AppSettings() public Size MenuSize { get; set; } + public List ReposRootDirectories { get; set; } + public List EnabledSearchProviders { get; set; } public string SonarCloudPersonalAccessToken { get; set; } @@ -28,13 +31,14 @@ public AppSettings() public AzureDevOpsOptions AzureDevOps { get; set; } public static AppSettings Default => new() - { - AutoFetchMode = AutoFetchMode.Off, - PruneOnFetch = false, - MenuSize = Size.Default, - EnabledSearchProviders = new List(1), - SonarCloudPersonalAccessToken = string.Empty, - AzureDevOps = AzureDevOpsOptions.Default, + { + AutoFetchMode = AutoFetchMode.Off, + PruneOnFetch = false, + MenuSize = Size.Default, + ReposRootDirectories = new(), + EnabledSearchProviders = new List(1), + SonarCloudPersonalAccessToken = string.Empty, + AzureDevOps = AzureDevOpsOptions.Default, }; } diff --git a/src/RepoM.Api/Common/FileAppSettingsService.cs b/src/RepoM.Api/Common/FileAppSettingsService.cs index 75fb88bc..3b8f9f21 100644 --- a/src/RepoM.Api/Common/FileAppSettingsService.cs +++ b/src/RepoM.Api/Common/FileAppSettingsService.cs @@ -175,6 +175,18 @@ public double MenuHeight } } + public List ReposRootDirectories + { + get => Settings.ReposRootDirectories; + set + { + Settings.ReposRootDirectories = value.ToList(); + + NotifyChange(); + Save(); + } + } + public List EnabledSearchProviders { get => Settings.EnabledSearchProviders; diff --git a/src/RepoM.Api/Common/IAppSettingsService.cs b/src/RepoM.Api/Common/IAppSettingsService.cs index e49c1b0e..5e6868c0 100644 --- a/src/RepoM.Api/Common/IAppSettingsService.cs +++ b/src/RepoM.Api/Common/IAppSettingsService.cs @@ -20,6 +20,8 @@ public interface IAppSettingsService double MenuHeight { get; set; } + List ReposRootDirectories { get; set; } + List EnabledSearchProviders { get; set; } string SonarCloudPersonalAccessToken { get; set; } diff --git a/src/RepoM.Api/IO/DefaultAppDataPathProvider.cs b/src/RepoM.Api/IO/DefaultAppDataPathProvider.cs index fbd7e6e4..7b8d83e5 100644 --- a/src/RepoM.Api/IO/DefaultAppDataPathProvider.cs +++ b/src/RepoM.Api/IO/DefaultAppDataPathProvider.cs @@ -16,7 +16,7 @@ private DefaultAppDataPathProvider() public string GetAppDataPath() { - return _applicationDataRepoM ; + return _applicationDataRepoM; } [Obsolete("Not used.")] diff --git a/src/RepoM.Api/IO/DefaultDriveEnumerator.cs b/src/RepoM.Api/IO/DefaultDriveEnumerator.cs index 07ada7f1..64f961f4 100644 --- a/src/RepoM.Api/IO/DefaultDriveEnumerator.cs +++ b/src/RepoM.Api/IO/DefaultDriveEnumerator.cs @@ -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 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(); } } \ No newline at end of file