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

Paths as string using Directory.EnumerateFiles() #50

Merged
merged 1 commit into from
Oct 4, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace AlsTools.Core.Interfaces;

public interface ILiveProjectFileExtractionHandler
{
LiveProject ExtractProjectFromFile(FileInfo file);
LiveProject ExtractProjectFromFile(string projectFileFullPath);
}
4 changes: 2 additions & 2 deletions src/als-tools.core/Interfaces/ILiveProjectFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace AlsTools.Core.Interfaces;

public interface ILiveProjectFileSystem
{
IReadOnlyList<FileInfo> LoadProjectFilesFromDirectories(IEnumerable<string> folderPaths, bool includeBackupFolder);
IReadOnlyList<string> GetProjectFilesFullPathFromDirectories(IEnumerable<string> folderPaths, bool includeBackupFolder);

IReadOnlyList<FileInfo> LoadProjectFilesFromSetFiles(IEnumerable<string> setFilePaths);
IReadOnlyList<string> GetProjectFilesFullPathFromSetFiles(IEnumerable<string> setFilePaths);
}
11 changes: 5 additions & 6 deletions src/als-tools.core/Services/LiveProjectAsyncService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using AlsTools.Core.Entities;
using AlsTools.Core.Enums;
using AlsTools.Core.Interfaces;
using AlsTools.Core.ValueObjects;
using AlsTools.Core.ValueObjects.Devices;

namespace AlsTools.Core.Services;
Expand Down Expand Up @@ -113,25 +112,25 @@ public async Task<IReadOnlyList<PluginDevice>> GetPluginUsageResults(IList<Plugi

private IReadOnlyList<LiveProject> LoadProjectsFromSetFiles(IEnumerable<string> filePaths)
{
var files = fs.LoadProjectFilesFromSetFiles(filePaths);
var files = fs.GetProjectFilesFullPathFromSetFiles(filePaths);

return ExtractProjectsFromFiles(files);
}

private IReadOnlyList<LiveProject> LoadProjectsFromDirectories(IEnumerable<string> folderPaths, bool includeBackupFolder)
{
var files = fs.LoadProjectFilesFromDirectories(folderPaths, includeBackupFolder);
var files = fs.GetProjectFilesFullPathFromDirectories(folderPaths, includeBackupFolder);

return ExtractProjectsFromFiles(files);
}

private IReadOnlyList<LiveProject> ExtractProjectsFromFiles(IEnumerable<FileInfo> files)
private IReadOnlyList<LiveProject> ExtractProjectsFromFiles(IEnumerable<string> filePaths)
{
var projects = new List<LiveProject>();

foreach (var f in files)
foreach (var filePath in filePaths)
{
var project = extractor.ExtractProjectFromFile(f);
var project = extractor.ExtractProjectFromFile(filePath);
projects.Add(project);
}

Expand Down
25 changes: 12 additions & 13 deletions src/als-tools.infrastructure/FileSystem/LiveProjectFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,42 @@ public LiveProjectFileSystem(UserFolderHandler userFolderHandler)
{
this.userFolderHandler = userFolderHandler;
}
public IReadOnlyList<FileInfo> LoadProjectFilesFromDirectories(IEnumerable<string> folderPaths, bool includeBackupFolder)

public IReadOnlyList<string> GetProjectFilesFullPathFromDirectories(IEnumerable<string> folderPaths, bool includeBackupFolder)
{
var result = new List<FileInfo>();
var result = new List<string>();

foreach (var folderPath in folderPaths)
{
var files = GetProjectFilesFromSingleDirectory(folderPath, includeBackupFolder);
result.AddRange(files);
var fileFullPaths = GetProjectFilesFullPathFromSingleDirectory(folderPath, includeBackupFolder);
result.AddRange(fileFullPaths);
}

return result;
}

public IReadOnlyList<FileInfo> LoadProjectFilesFromSetFiles(IEnumerable<string> setFilePaths)
public IReadOnlyList<string> GetProjectFilesFullPathFromSetFiles(IEnumerable<string> setFilePaths)
{
var result = new List<FileInfo>();
var result = new List<string>();

foreach (var filePath in setFilePaths)
{
var file = GetProjectFileFromSetFile(filePath);
result.Add(file);
result.Add(file.FullName);
}

return result;
}

private IReadOnlyCollection<FileInfo> GetProjectFilesFromSingleDirectory(string folderPath, bool includeBackupFolder)
private IReadOnlyCollection<string> GetProjectFilesFullPathFromSingleDirectory(string folderPath, bool includeBackupFolder)
{
var path = userFolderHandler.GetFullPath(folderPath);
var dirInfo = new DirectoryInfo(path);
var files = dirInfo.GetFiles("*.als", new EnumerationOptions() { RecurseSubdirectories = true }).AsEnumerable();
var fullPaths = Directory.EnumerateFiles(path, "*.als", SearchOption.AllDirectories);

if (!includeBackupFolder)
files = files.Where(x => !x.FullName.Contains(@"/Backup/", StringComparison.InvariantCultureIgnoreCase));
fullPaths = fullPaths.Where(path => !path.Contains(@"/Backup/", StringComparison.InvariantCultureIgnoreCase));

return files.ToList();
return fullPaths.ToList();
}

private FileInfo GetProjectFileFromSetFile(string setFilePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ public LiveProjectFileExtractionHandler(ILogger<LiveProjectFileExtractionHandler
this.locatorExtractionHandler = locatorExtractionHandler;
}

public LiveProject ExtractProjectFromFile(FileInfo file)
public LiveProject ExtractProjectFromFile(string projectFileFullPath)
{
logger.LogDebug("=========================================================================");
logger.LogTrace("Start: ExtractProjectFromFile. File: {@File}", file.FullName);
logger.LogTrace("Start: ExtractProjectFromFile. File: {@File}", projectFileFullPath);

logger.LogTrace("Opening project file as read-only...");
using (FileStream originalFileStream = file.OpenRead())

using (FileStream originalFileStream = File.OpenRead(projectFileFullPath))
{
logger.LogTrace("Unzipping file into memory...");
using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress))
Expand All @@ -47,7 +48,8 @@ public LiveProject ExtractProjectFromFile(FileInfo file)
var nav = xPathDoc.CreateNavigator();

logger.LogTrace("Calling the entry point: ExtractProject()...");
var project = ExtractProject(file.Name, file.FullName, nav);

var project = ExtractProject(Path.GetFileName(projectFileFullPath), projectFileFullPath, nav);
return project;
}
}
Expand Down