-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiskAccess.cs
33 lines (30 loc) · 1.21 KB
/
DiskAccess.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace ApDownloader.DataAccess;
public static class DiskAccess
{
/// <summary>
/// Gets all .zip files that are in the download folder specified.
/// </summary>
/// <param name="dlOptionDownloadFilepath"></param>
/// <returns>Dictionary of filename, file length</returns>
public static Dictionary<string, long> GetAllFilesOnDisk(string dlOptionDownloadFilepath)
{
var addonFolders = new List<string> {"", "Products", "ExtraStock", "BrandingPatches", "LiveryPacks"};
var files = new Dictionary<string, long>();
foreach (var addonFile in addonFolders.SelectMany(folder => GetAddonFiles(dlOptionDownloadFilepath, folder)))
{
files.TryAdd(addonFile.Name, addonFile.Length);
}
return files;
}
private static IEnumerable<FileInfo> GetAddonFiles (string downloadFilepath, string folder)
{
var fullFolderPath = Path.Combine(downloadFilepath, folder);
return Directory.Exists(fullFolderPath) ?
Directory.EnumerateFiles(fullFolderPath, "*.zip").Select(filename => new FileInfo(filename))
: new List<FileInfo>();
}
}