Skip to content

Commit 5bb1854

Browse files
committed
Async issue debugging, close to release
1 parent 671ea3e commit 5bb1854

File tree

62 files changed

+2756
-79
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2756
-79
lines changed
0 Bytes
Binary file not shown.

.vs/ApDownloader/v17/.futdcache.v1

0 Bytes
Binary file not shown.

.vs/ApDownloader/v17/.suo

27 KB
Binary file not shown.

ApDownloader.DataAccess/DiskAccess.cs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Linq;
4+
5+
namespace ApDownloader.DataAccess;
6+
7+
public static class DiskAccess
8+
{
9+
public static Dictionary<string, long> GetAllFilesOnDisk(string dlOptionDownloadFilepath)
10+
{
11+
Dictionary<string, long> allFiles = new();
12+
List<FileInfo> rootFiles = new();
13+
List<FileInfo> productFiles = new();
14+
List<FileInfo> extraStockFiles = new();
15+
List<FileInfo> brandingPatchFiles = new();
16+
List<FileInfo> liveryPackFiles = new();
17+
if (Directory.Exists(dlOptionDownloadFilepath))
18+
rootFiles = Directory
19+
.EnumerateFiles(dlOptionDownloadFilepath, "*.zip", SearchOption.TopDirectoryOnly)
20+
.Select(file => new FileInfo(file)).ToList();
21+
if (Directory.Exists(Path.Combine(dlOptionDownloadFilepath, "Products")))
22+
productFiles = Directory
23+
.EnumerateFiles(Path.Combine(dlOptionDownloadFilepath, "Products"), "*.zip", SearchOption.TopDirectoryOnly)
24+
.Select(file => new FileInfo(file)).ToList();
25+
if (Directory.Exists(Path.Combine(dlOptionDownloadFilepath, "ExtraStock")))
26+
extraStockFiles = Directory
27+
.EnumerateFiles(Path.Combine(dlOptionDownloadFilepath, "ExtraStock"), "*.zip", SearchOption.TopDirectoryOnly)
28+
.Select(file => new FileInfo(file)).ToList();
29+
if (Directory.Exists(Path.Combine(dlOptionDownloadFilepath, "BrandingPatches")))
30+
brandingPatchFiles = Directory
31+
.EnumerateFiles(Path.Combine(dlOptionDownloadFilepath, "BrandingPatches"), "*.zip",
32+
SearchOption.TopDirectoryOnly)
33+
.Select(file => new FileInfo(file)).ToList();
34+
if (Directory.Exists(Path.Combine(dlOptionDownloadFilepath, "LiveryPacks")))
35+
liveryPackFiles = Directory
36+
.EnumerateFiles(Path.Combine(dlOptionDownloadFilepath, "LiveryPacks"), "*.zip",
37+
SearchOption.TopDirectoryOnly)
38+
.Select(file => new FileInfo(file)).ToList();
39+
foreach (var file in rootFiles) allFiles.TryAdd(file.Name, file.Length);
40+
foreach (var file in productFiles) allFiles.TryAdd(file.Name, file.Length);
41+
foreach (var file in extraStockFiles) allFiles.TryAdd(file.Name, file.Length);
42+
foreach (var file in liveryPackFiles) allFiles.TryAdd(file.Name, file.Length);
43+
return allFiles;
44+
}
45+
}

ApDownloader.UI/MVVM/ViewModels/DownloadViewModel.cs

+1-37
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private async Task LoadUserAddons()
134134
{
135135
_access = new HttpDataAccess(LoginView.Client);
136136
MainViewModel.Products = await _access.GetPurchasedProducts(AllApProducts);
137-
var allFiles = GetAllFilesOnDisk(MainViewModel.DlOption.DownloadFilepath);
137+
var allFiles = DiskAccess.GetAllFilesOnDisk(MainViewModel.DlOption.DownloadFilepath);
138138
foreach (var product in MainViewModel.Products)
139139
{
140140
product.UserContentLength = allFiles.TryGetValue(product.FileName, out var value) ? value : 0;
@@ -147,42 +147,6 @@ private async Task LoadUserAddons()
147147
}
148148
}
149149

150-
private Dictionary<string, long> GetAllFilesOnDisk(string dlOptionDownloadFilepath)
151-
{
152-
Dictionary<string, long> allFiles = new();
153-
List<FileInfo> rootFiles = new();
154-
List<FileInfo> productFiles = new();
155-
List<FileInfo> extraStockFiles = new();
156-
List<FileInfo> brandingPatchFiles = new();
157-
List<FileInfo> liveryPackFiles = new();
158-
if (Directory.Exists(dlOptionDownloadFilepath))
159-
rootFiles = Directory
160-
.EnumerateFiles(dlOptionDownloadFilepath, "*.zip", SearchOption.TopDirectoryOnly)
161-
.Select(file => new FileInfo(file)).ToList();
162-
if (Directory.Exists(Path.Combine(dlOptionDownloadFilepath, "Products")))
163-
productFiles = Directory
164-
.EnumerateFiles(Path.Combine(dlOptionDownloadFilepath, "Products"), "*.zip", SearchOption.TopDirectoryOnly)
165-
.Select(file => new FileInfo(file)).ToList();
166-
if (Directory.Exists(Path.Combine(dlOptionDownloadFilepath, "ExtraStock")))
167-
extraStockFiles = Directory
168-
.EnumerateFiles(Path.Combine(dlOptionDownloadFilepath, "ExtraStock"), "*.zip", SearchOption.TopDirectoryOnly)
169-
.Select(file => new FileInfo(file)).ToList();
170-
if (Directory.Exists(Path.Combine(dlOptionDownloadFilepath, "BrandingPatches")))
171-
brandingPatchFiles = Directory
172-
.EnumerateFiles(Path.Combine(dlOptionDownloadFilepath, "BrandingPatches"), "*.zip",
173-
SearchOption.TopDirectoryOnly)
174-
.Select(file => new FileInfo(file)).ToList();
175-
if (Directory.Exists(Path.Combine(dlOptionDownloadFilepath, "LiveryPacks")))
176-
liveryPackFiles = Directory
177-
.EnumerateFiles(Path.Combine(MainViewModel.DlOption.DownloadFilepath, "LiveryPacks"), "*.zip",
178-
SearchOption.TopDirectoryOnly)
179-
.Select(file => new FileInfo(file)).ToList();
180-
foreach (var file in rootFiles) allFiles.TryAdd(file.Name, file.Length);
181-
foreach (var file in productFiles) allFiles.TryAdd(file.Name, file.Length);
182-
foreach (var file in extraStockFiles) allFiles.TryAdd(file.Name, file.Length);
183-
foreach (var file in liveryPackFiles) allFiles.TryAdd(file.Name, file.Length);
184-
return allFiles;
185-
}
186150

187151
private async Task RenderUserAddons()
188152
{

ApDownloader.UI/MVVM/ViewModels/InstallViewModel.cs

+22-30
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using ApDownloader.DataAccess;
99
using ApDownloader.Model;
1010
using ApDownloader.UI.Core;
11+
using static ApDownloader.UI.Core.AsyncRelayCommand;
1112

1213
namespace ApDownloader.UI.MVVM.ViewModels;
1314

@@ -23,7 +24,6 @@ public class InstallViewModel : ObservableObject
2324
private bool _overlayVisibility;
2425

2526
private bool _selectAllButtonEnabled;
26-
//private DownloadManifest DownloadManifest;
2727

2828
public InstallViewModel()
2929
{
@@ -36,11 +36,10 @@ public InstallViewModel()
3636

3737
_dataService = new SQLiteDataAccess(MainViewModel.AppFolder);
3838
InstallCommand = new RelayCommand(list => Install((IList) list), _ => !MainViewModel.IsNotAdmin);
39-
GetAllPrevDownloadsCommand = new RelayCommand(clickEvent => GetAllPrevDownloads());
40-
RenderUserAddonsCommand = new AsyncRelayCommand.AsyncCommand(Loaded);
39+
PopulateAllPreviousDownloadsCommand = new RelayCommand(async _ => await PopulateAllPrevDownloads(), _ => AllDownloadsEnabled);
40+
Loaded();
4141
}
42-
43-
public RelayCommand GetAllPrevDownloadsCommand { get; set; }
42+
private bool AllDownloadsEnabled { get; set; } = true;
4443

4544
public RelayCommand InstallCommand { get; set; }
4645
public ObservableCollection<Cell> ProductCells { get; } = new();
@@ -75,26 +74,22 @@ public bool SelectAllButtonEnabled
7574
}
7675
}
7776

78-
public AsyncRelayCommand.AsyncCommand RenderUserAddonsCommand { get; set; }
77+
public RelayCommand PopulateAllPreviousDownloadsCommand { get; set; }
7978

80-
private async Task Loaded()
79+
private void Loaded()
8180
{
82-
var products = await _dataService.GetDownloadedProductsOnly(MainViewModel.DlManifest?.ProductIds);
81+
var products = _dataService.GetDownloadedProductsOnly(MainViewModel.DlManifest?.ProductIds).Result;
8382
var builderlist = new List<Cell>();
84-
await Task.Run(() =>
85-
{
86-
foreach (var product in products)
87-
{
88-
var cell = new Cell
89-
(
90-
product.ProductID,
91-
Path.Combine(_previewImagesPath, Path.GetFileName(product.ImageName)),
92-
product.Name
93-
);
94-
builderlist.Add(cell);
95-
}
96-
});
97-
foreach (var cell in builderlist) ProductCells.Add(cell);
83+
foreach (var product in products)
84+
{
85+
var cell = new Cell
86+
(
87+
product.ProductID,
88+
Path.Combine(_previewImagesPath, Path.GetFileName(product.ImageName)),
89+
product.Name
90+
);
91+
ProductCells.Add(cell);
92+
}
9893
}
9994

10095
private async Task Install(IList selectedCells)
@@ -146,27 +141,24 @@ private static void InstallAddons(ApDownloaderConfig downloadOption, IEnumerable
146141
AddonInstaller.AddonInstaller.InstallAddons(downloadOption, extractPath, progress);
147142
}
148143

149-
private async void GetAllPrevDownloads()
144+
private async Task PopulateAllPrevDownloads()
150145
{
151146
if (!Directory.Exists(Path.Combine(MainViewModel.DlOption.DownloadFilepath, "Products"))) return;
152-
var allFiles = Directory
153-
.EnumerateFiles(Path.Combine(MainViewModel.DlOption.DownloadFilepath, "Products"), "*.zip",
154-
SearchOption.AllDirectories)
155-
.Select(file => new FileInfo(file).Name);
156-
_downloadedProducts = await _dataService.GetDownloadedProductsByName(allFiles);
147+
var allfiles = DiskAccess.GetAllFilesOnDisk(MainViewModel.DlOption.DownloadFilepath);
148+
var allFilesList = allfiles.Select(kvp => kvp.Key).ToList();
149+
_downloadedProducts = await _dataService.GetDownloadedProductsByName(allFilesList);
157150

158151
foreach (var product in _downloadedProducts)
159152
{
160153
var cell = new Cell
161154
(
162155
product.ProductID,
163-
Path.Combine(_previewImagesPath, Path.GetFileName(product.ImageName)),
156+
_previewImagesPath + "\\" + product.ImageName,
164157
product.Name
165158
);
166159
if (!ProductCells.Contains(cell))
167160
ProductCells.Add(cell);
168161
}
169-
170162
if (ProductCells.Any())
171163
SelectAllButtonEnabled = true;
172164
}

ApDownloader.UI/MVVM/ViewModels/MainViewModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public class MainViewModel : ObservableObject
2424

2525
public MainViewModel()
2626
{
27-
CheckAdmin();
2827
_dataAccess = new SQLiteDataAccess(AppFolder);
2928
DlOption = _dataAccess.GetUserOptions();
29+
CheckAdmin();
3030

3131
IsNotBusy = true;
3232
LoginVm = new LoginViewModel();

ApDownloader.UI/MVVM/Views/InstallView.xaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@
7373
Margin="20" IsEnabled="{Binding SelectAllButtonEnabled}" Click="ToggleSelected" />
7474
<Button Grid.Column="1" Content="All Downloads"
7575
Style="{StaticResource LoginButton}"
76-
Click="DisablePrevDownloadsAfterClick"
77-
Command="{Binding GetAllPrevDownloadsCommand}"
78-
IsEnabled="{Binding GetAllPrevDownloadsCommand}"
76+
Command="{Binding PopulateAllPreviousDownloadsCommand}"
7977
Margin="20" Name="PreviousDownloadButton" />
8078
<Button Name="InstallButton" Grid.Column="2" Content="Install"
8179
Style="{StaticResource LoginButton}"

ApDownloader.UI/MVVM/Views/InstallView.xaml.cs

-8
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@ public partial class InstallView : UserControl
1616
public InstallView()
1717
{
1818
InitializeComponent();
19-
Loaded += Window_loaded;
2019
}
21-
22-
private async void Window_loaded(object sender, RoutedEventArgs e)
23-
{
24-
var viewmodel = (InstallViewModel) DataContext;
25-
await viewmodel.RenderUserAddonsCommand.ExecuteAsync();
26-
}
27-
2820
public void ToggleSelected(object sender, RoutedEventArgs e)
2921
{
3022
if (!_selectedToggle)
Binary file not shown.

0 commit comments

Comments
 (0)