mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[Core] Use async to update the master database.
This commit is contained in:
@@ -40,6 +40,7 @@ using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Aaru.CommonTypes.Metadata;
|
||||
using Aaru.Console;
|
||||
using Aaru.Database;
|
||||
@@ -110,30 +111,30 @@ public static class Remote
|
||||
|
||||
/// <summary>Updates the main database</summary>
|
||||
/// <param name="create">If <c>true</c> creates the database from scratch, otherwise updates an existing database</param>
|
||||
public static void UpdateMainDatabase(bool create)
|
||||
public static async Task UpdateMainDatabaseAsync(bool create)
|
||||
{
|
||||
var mctx = AaruContext.Create(Settings.Settings.MainDbPath);
|
||||
|
||||
if(create)
|
||||
{
|
||||
mctx.Database.EnsureCreated();
|
||||
await mctx.Database.EnsureCreatedAsync();
|
||||
|
||||
mctx.Database
|
||||
.ExecuteSqlRaw("CREATE TABLE IF NOT EXISTS \"__EFMigrationsHistory\" (\"MigrationId\" TEXT PRIMARY KEY, \"ProductVersion\" TEXT)");
|
||||
await mctx.Database
|
||||
.ExecuteSqlRawAsync("CREATE TABLE IF NOT EXISTS \"__EFMigrationsHistory\" (\"MigrationId\" TEXT PRIMARY KEY, \"ProductVersion\" TEXT)");
|
||||
|
||||
foreach(string migration in mctx.Database.GetPendingMigrations())
|
||||
foreach(string migration in await mctx.Database.GetPendingMigrationsAsync())
|
||||
{
|
||||
mctx.Database
|
||||
await mctx.Database
|
||||
#pragma warning disable EF1002
|
||||
.ExecuteSqlRaw($"INSERT INTO \"__EFMigrationsHistory\" (MigrationId, ProductVersion) VALUES ('{
|
||||
migration}', '0.0.0')");
|
||||
.ExecuteSqlRawAsync($"INSERT INTO \"__EFMigrationsHistory\" (MigrationId, ProductVersion) VALUES ('{
|
||||
migration}', '0.0.0')");
|
||||
#pragma warning restore EF1002
|
||||
}
|
||||
}
|
||||
else
|
||||
mctx.Database.Migrate();
|
||||
await mctx.Database.MigrateAsync();
|
||||
|
||||
mctx.SaveChanges();
|
||||
await mctx.SaveChangesAsync();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -144,13 +145,14 @@ public static class Remote
|
||||
{
|
||||
List<DateTime> latestAll = [];
|
||||
|
||||
if(mctx.UsbVendors.Any()) latestAll.Add(mctx.UsbVendors.Max(v => v.ModifiedWhen));
|
||||
if(await mctx.UsbVendors.AnyAsync()) latestAll.Add(await mctx.UsbVendors.MaxAsync(v => v.ModifiedWhen));
|
||||
|
||||
if(mctx.UsbProducts.Any()) latestAll.Add(mctx.UsbProducts.Max(p => p.ModifiedWhen));
|
||||
if(await mctx.UsbProducts.AnyAsync())
|
||||
latestAll.Add(await mctx.UsbProducts.MaxAsync(p => p.ModifiedWhen));
|
||||
|
||||
if(mctx.CdOffsets.Any()) latestAll.Add(mctx.CdOffsets.Max(o => o.ModifiedWhen));
|
||||
if(await mctx.CdOffsets.AnyAsync()) latestAll.Add(await mctx.CdOffsets.MaxAsync(o => o.ModifiedWhen));
|
||||
|
||||
if(mctx.Devices.Any()) latestAll.Add(mctx.Devices.Max(d => d.LastSynchronized));
|
||||
if(await mctx.Devices.AnyAsync()) latestAll.Add(await mctx.Devices.MaxAsync(d => d.LastSynchronized));
|
||||
|
||||
if(latestAll.Any())
|
||||
{
|
||||
@@ -176,8 +178,7 @@ public static class Remote
|
||||
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Aaru {typeof(Version).Assembly.GetName().Version}");
|
||||
httpClient.BaseAddress = new Uri("https://www.aaru.app");
|
||||
|
||||
HttpResponseMessage response =
|
||||
httpClient.GetAsync($"/api/update?timestamp={lastUpdate}").GetAwaiter().GetResult();
|
||||
HttpResponseMessage response = await httpClient.GetAsync($"/api/update?timestamp={lastUpdate}");
|
||||
|
||||
if(!response.IsSuccessStatusCode)
|
||||
{
|
||||
@@ -187,129 +188,139 @@ public static class Remote
|
||||
return;
|
||||
}
|
||||
|
||||
Stream data = response.Content.ReadAsStream();
|
||||
Stream data = await response.Content.ReadAsStreamAsync();
|
||||
var reader = new StreamReader(data);
|
||||
SyncDto sync = JsonSerializer.Deserialize<SyncDto>(reader.ReadToEnd()) ?? new SyncDto();
|
||||
SyncDto sync = JsonSerializer.Deserialize<SyncDto>(await reader.ReadToEndAsync()) ?? new SyncDto();
|
||||
|
||||
if(create)
|
||||
{
|
||||
AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.Start(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Adding_USB_vendors);
|
||||
task.MaxValue = sync.UsbVendors.Count;
|
||||
await AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.Start(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Adding_USB_vendors);
|
||||
task.MaxValue = sync.UsbVendors.Count;
|
||||
|
||||
foreach(UsbVendorDto vendor in sync.UsbVendors)
|
||||
{
|
||||
task.Increment(1);
|
||||
mctx.UsbVendors.Add(new UsbVendor(vendor.VendorId, vendor.Vendor));
|
||||
}
|
||||
});
|
||||
foreach(UsbVendorDto vendor in sync.UsbVendors)
|
||||
{
|
||||
task.Increment(1);
|
||||
mctx.UsbVendors.Add(new UsbVendor(vendor.VendorId, vendor.Vendor));
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
AaruConsole.WriteLine(Localization.Core.Added_0_usb_vendors, sync.UsbVendors.Count);
|
||||
|
||||
AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.Start(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Adding_USB_products);
|
||||
task.MaxValue = sync.UsbProducts.Count;
|
||||
await AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.Start(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Adding_USB_products);
|
||||
task.MaxValue = sync.UsbProducts.Count;
|
||||
|
||||
foreach(UsbProductDto product in sync.UsbProducts)
|
||||
{
|
||||
task.Increment(1);
|
||||
foreach(UsbProductDto product in sync.UsbProducts)
|
||||
{
|
||||
task.Increment(1);
|
||||
|
||||
mctx.UsbProducts.Add(new UsbProduct(product.VendorId,
|
||||
product.ProductId,
|
||||
product.Product));
|
||||
}
|
||||
});
|
||||
mctx.UsbProducts.Add(new UsbProduct(product.VendorId,
|
||||
product.ProductId,
|
||||
product.Product));
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
AaruConsole.WriteLine(Localization.Core.Added_0_usb_products, sync.UsbProducts.Count);
|
||||
|
||||
AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.Start(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Adding_CompactDisc_read_offsets);
|
||||
task.MaxValue = sync.Offsets.Count;
|
||||
await AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.Start(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Adding_CompactDisc_read_offsets);
|
||||
task.MaxValue = sync.Offsets.Count;
|
||||
|
||||
foreach(CdOffsetDto offset in sync.Offsets)
|
||||
{
|
||||
task.Increment(1);
|
||||
foreach(CdOffsetDto offset in sync.Offsets)
|
||||
{
|
||||
task.Increment(1);
|
||||
|
||||
mctx.CdOffsets.Add(new CdOffset(offset)
|
||||
{
|
||||
Id = offset.Id
|
||||
});
|
||||
}
|
||||
});
|
||||
mctx.CdOffsets.Add(new CdOffset(offset)
|
||||
{
|
||||
Id = offset.Id
|
||||
});
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
AaruConsole.WriteLine(Localization.Core.Added_0_CompactDisc_read_offsets, sync.Offsets.Count);
|
||||
|
||||
AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.Start(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Adding_known_devices);
|
||||
task.MaxValue = sync.Devices.Count;
|
||||
await AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.Start(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Adding_known_devices);
|
||||
task.MaxValue = sync.Devices.Count;
|
||||
|
||||
foreach(DeviceDto device in sync.Devices)
|
||||
foreach(DeviceDto device in sync.Devices)
|
||||
|
||||
{
|
||||
task.Increment(1);
|
||||
{
|
||||
task.Increment(1);
|
||||
|
||||
mctx.Devices.Add(new Device(device)
|
||||
{
|
||||
Id = device.Id
|
||||
});
|
||||
}
|
||||
});
|
||||
mctx.Devices.Add(new Device(device)
|
||||
{
|
||||
Id = device.Id
|
||||
});
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
AaruConsole.WriteLine(Localization.Core.Added_0_known_devices, sync.Devices.Count);
|
||||
|
||||
AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.Start(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Adding_known_iNES_NES_2_0_headers);
|
||||
task.MaxValue = sync.NesHeaders?.Count ?? 0;
|
||||
await AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.Start(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Adding_known_iNES_NES_2_0_headers);
|
||||
task.MaxValue = sync.NesHeaders?.Count ?? 0;
|
||||
|
||||
foreach(NesHeaderDto header in sync.NesHeaders ?? [])
|
||||
{
|
||||
task.Increment(1);
|
||||
foreach(NesHeaderDto header in sync.NesHeaders ?? [])
|
||||
{
|
||||
task.Increment(1);
|
||||
|
||||
mctx.NesHeaders.Add(new NesHeaderInfo
|
||||
{
|
||||
Id = header.Id,
|
||||
AddedWhen = DateTime.UtcNow,
|
||||
BatteryPresent = header.BatteryPresent,
|
||||
ConsoleType = header.ConsoleType,
|
||||
DefaultExpansionDevice = header.DefaultExpansionDevice,
|
||||
ExtendedConsoleType = header.ExtendedConsoleType,
|
||||
FourScreenMode = header.FourScreenMode,
|
||||
Mapper = header.Mapper,
|
||||
ModifiedWhen = DateTime.UtcNow,
|
||||
NametableMirroring = header.NametableMirroring,
|
||||
Sha256 = header.Sha256,
|
||||
Submapper = header.Submapper,
|
||||
TimingMode = header.TimingMode,
|
||||
VsHardwareType = header.VsHardwareType,
|
||||
VsPpuType = header.VsPpuType
|
||||
});
|
||||
}
|
||||
});
|
||||
mctx.NesHeaders.Add(new NesHeaderInfo
|
||||
{
|
||||
Id = header.Id,
|
||||
AddedWhen = DateTime.UtcNow,
|
||||
BatteryPresent = header.BatteryPresent,
|
||||
ConsoleType = header.ConsoleType,
|
||||
DefaultExpansionDevice = header.DefaultExpansionDevice,
|
||||
ExtendedConsoleType = header.ExtendedConsoleType,
|
||||
FourScreenMode = header.FourScreenMode,
|
||||
Mapper = header.Mapper,
|
||||
ModifiedWhen = DateTime.UtcNow,
|
||||
NametableMirroring = header.NametableMirroring,
|
||||
Sha256 = header.Sha256,
|
||||
Submapper = header.Submapper,
|
||||
TimingMode = header.TimingMode,
|
||||
VsHardwareType = header.VsHardwareType,
|
||||
VsPpuType = header.VsPpuType
|
||||
});
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
AaruConsole.WriteLine(Localization.Core.Added_0_known_iNES_NES_2_0_headers,
|
||||
sync.NesHeaders?.Count ?? 0);
|
||||
@@ -327,232 +338,244 @@ public static class Remote
|
||||
long modifiedDevices = 0;
|
||||
long modifiedNesHeaders = 0;
|
||||
|
||||
AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.Start(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Updating_USB_vendors);
|
||||
task.MaxValue = sync.UsbVendors.Count;
|
||||
await AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.StartAsync(async ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Updating_USB_vendors);
|
||||
task.MaxValue = sync.UsbVendors.Count;
|
||||
|
||||
foreach(UsbVendorDto vendor in sync.UsbVendors)
|
||||
{
|
||||
task.Increment(1);
|
||||
foreach(UsbVendorDto vendor in sync.UsbVendors)
|
||||
{
|
||||
task.Increment(1);
|
||||
|
||||
UsbVendor existing = mctx.UsbVendors.FirstOrDefault(v => v.Id == vendor.VendorId);
|
||||
UsbVendor existing =
|
||||
await mctx.UsbVendors.FirstOrDefaultAsync(v => v.Id == vendor.VendorId);
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
modifiedVendors++;
|
||||
existing.Vendor = vendor.Vendor;
|
||||
existing.ModifiedWhen = updateStart;
|
||||
mctx.UsbVendors.Update(existing);
|
||||
}
|
||||
else
|
||||
{
|
||||
addedVendors++;
|
||||
mctx.UsbVendors.Add(new UsbVendor(vendor.VendorId, vendor.Vendor));
|
||||
}
|
||||
}
|
||||
});
|
||||
if(existing != null)
|
||||
{
|
||||
modifiedVendors++;
|
||||
existing.Vendor = vendor.Vendor;
|
||||
existing.ModifiedWhen = updateStart;
|
||||
mctx.UsbVendors.Update(existing);
|
||||
}
|
||||
else
|
||||
{
|
||||
addedVendors++;
|
||||
mctx.UsbVendors.Add(new UsbVendor(vendor.VendorId, vendor.Vendor));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AaruConsole.WriteLine(Localization.Core.Added_0_usb_vendors, addedVendors);
|
||||
AaruConsole.WriteLine(Localization.Core.Modified_0_USB_vendors, modifiedVendors);
|
||||
|
||||
AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.Start(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Updating_USB_products);
|
||||
task.MaxValue = sync.UsbVendors.Count;
|
||||
await AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.StartAsync(async ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Updating_USB_products);
|
||||
task.MaxValue = sync.UsbVendors.Count;
|
||||
|
||||
foreach(UsbProductDto product in sync.UsbProducts)
|
||||
{
|
||||
task.Increment(1);
|
||||
foreach(UsbProductDto product in sync.UsbProducts)
|
||||
{
|
||||
task.Increment(1);
|
||||
|
||||
UsbProduct existing =
|
||||
mctx.UsbProducts.FirstOrDefault(p => p.VendorId == product.VendorId &&
|
||||
p.ProductId == product.ProductId);
|
||||
UsbProduct existing =
|
||||
await mctx.UsbProducts.FirstOrDefaultAsync(p =>
|
||||
p.VendorId == product.VendorId &&
|
||||
p.ProductId == product.ProductId);
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
modifiedProducts++;
|
||||
existing.Product = product.Product;
|
||||
existing.ModifiedWhen = updateStart;
|
||||
mctx.UsbProducts.Update(existing);
|
||||
}
|
||||
else
|
||||
{
|
||||
addedProducts++;
|
||||
if(existing != null)
|
||||
{
|
||||
modifiedProducts++;
|
||||
existing.Product = product.Product;
|
||||
existing.ModifiedWhen = updateStart;
|
||||
mctx.UsbProducts.Update(existing);
|
||||
}
|
||||
else
|
||||
{
|
||||
addedProducts++;
|
||||
|
||||
mctx.UsbProducts.Add(new UsbProduct(product.VendorId,
|
||||
product.ProductId,
|
||||
product.Product));
|
||||
}
|
||||
}
|
||||
});
|
||||
mctx.UsbProducts.Add(new UsbProduct(product.VendorId,
|
||||
product.ProductId,
|
||||
product.Product));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AaruConsole.WriteLine(Localization.Core.Added_0_usb_products, addedProducts);
|
||||
AaruConsole.WriteLine(Localization.Core.Modified_0_USB_products, modifiedProducts);
|
||||
|
||||
AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.Start(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Updating_CompactDisc_read_offsets);
|
||||
task.MaxValue = sync.Offsets.Count;
|
||||
await AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.StartAsync(async ctx =>
|
||||
{
|
||||
ProgressTask task =
|
||||
ctx.AddTask(Localization.Core.Updating_CompactDisc_read_offsets);
|
||||
|
||||
foreach(CdOffsetDto offset in sync.Offsets)
|
||||
{
|
||||
CdOffset existing = mctx.CdOffsets.FirstOrDefault(o => o.Id == offset.Id);
|
||||
task.Increment(1);
|
||||
task.MaxValue = sync.Offsets.Count;
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
modifiedOffsets++;
|
||||
existing.Agreement = offset.Agreement;
|
||||
existing.Manufacturer = offset.Manufacturer;
|
||||
existing.Model = offset.Model;
|
||||
existing.Submissions = offset.Submissions;
|
||||
existing.Offset = offset.Offset;
|
||||
existing.ModifiedWhen = updateStart;
|
||||
mctx.CdOffsets.Update(existing);
|
||||
}
|
||||
else
|
||||
{
|
||||
addedOffsets++;
|
||||
foreach(CdOffsetDto offset in sync.Offsets)
|
||||
{
|
||||
CdOffset existing =
|
||||
await mctx.CdOffsets.FirstOrDefaultAsync(o => o.Id == offset.Id);
|
||||
|
||||
mctx.CdOffsets.Add(new CdOffset(offset)
|
||||
{
|
||||
Id = offset.Id
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
task.Increment(1);
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
modifiedOffsets++;
|
||||
existing.Agreement = offset.Agreement;
|
||||
existing.Manufacturer = offset.Manufacturer;
|
||||
existing.Model = offset.Model;
|
||||
existing.Submissions = offset.Submissions;
|
||||
existing.Offset = offset.Offset;
|
||||
existing.ModifiedWhen = updateStart;
|
||||
mctx.CdOffsets.Update(existing);
|
||||
}
|
||||
else
|
||||
{
|
||||
addedOffsets++;
|
||||
|
||||
mctx.CdOffsets.Add(new CdOffset(offset)
|
||||
{
|
||||
Id = offset.Id
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AaruConsole.WriteLine(Localization.Core.Added_0_CompactDisc_read_offsets, addedOffsets);
|
||||
AaruConsole.WriteLine(Localization.Core.Modified_0_CompactDisc_read_offsets, modifiedOffsets);
|
||||
|
||||
AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.Start(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Updating_known_devices);
|
||||
task.MaxValue = sync.Offsets.Count;
|
||||
await AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.StartAsync(async ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Updating_known_devices);
|
||||
task.MaxValue = sync.Offsets.Count;
|
||||
|
||||
foreach(DeviceDto device in sync.Devices)
|
||||
{
|
||||
task.Increment(1);
|
||||
Device existing = mctx.Devices.FirstOrDefault(d => d.Id == device.Id);
|
||||
foreach(DeviceDto device in sync.Devices)
|
||||
{
|
||||
task.Increment(1);
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
modifiedDevices++;
|
||||
Device existing =
|
||||
await mctx.Devices.FirstOrDefaultAsync(d => d.Id == device.Id);
|
||||
|
||||
mctx.Remove(existing);
|
||||
if(existing != null)
|
||||
{
|
||||
modifiedDevices++;
|
||||
|
||||
existing = new Device(device)
|
||||
{
|
||||
Id = device.Id,
|
||||
OptimalMultipleSectorsRead = device.OptimalMultipleSectorsRead,
|
||||
CanReadGdRomUsingSwapDisc = device.CanReadGdRomUsingSwapDisc
|
||||
};
|
||||
mctx.Remove(existing);
|
||||
|
||||
mctx.Devices.Add(existing);
|
||||
}
|
||||
else
|
||||
{
|
||||
addedDevices++;
|
||||
existing = new Device(device)
|
||||
{
|
||||
Id = device.Id,
|
||||
OptimalMultipleSectorsRead = device.OptimalMultipleSectorsRead,
|
||||
CanReadGdRomUsingSwapDisc = device.CanReadGdRomUsingSwapDisc
|
||||
};
|
||||
|
||||
mctx.Devices.Add(new Device(device)
|
||||
{
|
||||
Id = device.Id,
|
||||
OptimalMultipleSectorsRead = device.OptimalMultipleSectorsRead,
|
||||
CanReadGdRomUsingSwapDisc = device.CanReadGdRomUsingSwapDisc
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
mctx.Devices.Add(existing);
|
||||
}
|
||||
else
|
||||
{
|
||||
addedDevices++;
|
||||
|
||||
mctx.Devices.Add(new Device(device)
|
||||
{
|
||||
Id = device.Id,
|
||||
OptimalMultipleSectorsRead = device.OptimalMultipleSectorsRead,
|
||||
CanReadGdRomUsingSwapDisc = device.CanReadGdRomUsingSwapDisc
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AaruConsole.WriteLine(Localization.Core.Added_0_known_devices, addedDevices);
|
||||
AaruConsole.WriteLine(Localization.Core.Modified_0_known_devices, modifiedDevices);
|
||||
|
||||
AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.Start(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Updating_known_iNES_NES_2_0_headers);
|
||||
task.MaxValue = sync.Offsets.Count;
|
||||
await AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.StartAsync(async ctx =>
|
||||
{
|
||||
ProgressTask task =
|
||||
ctx.AddTask(Localization.Core.Updating_known_iNES_NES_2_0_headers);
|
||||
|
||||
sync.NesHeaders ??= [];
|
||||
task.MaxValue = sync.Offsets.Count;
|
||||
|
||||
foreach(NesHeaderDto header in sync.NesHeaders)
|
||||
{
|
||||
task.Increment(1);
|
||||
NesHeaderInfo existing = mctx.NesHeaders.FirstOrDefault(d => d.Id == header.Id);
|
||||
sync.NesHeaders ??= [];
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
modifiedNesHeaders++;
|
||||
DateTime addedDate = existing.AddedWhen;
|
||||
foreach(NesHeaderDto header in sync.NesHeaders)
|
||||
{
|
||||
task.Increment(1);
|
||||
|
||||
mctx.Remove(existing);
|
||||
NesHeaderInfo existing =
|
||||
await mctx.NesHeaders.FirstOrDefaultAsync(d => d.Id == header.Id);
|
||||
|
||||
existing = new NesHeaderInfo
|
||||
{
|
||||
Id = header.Id,
|
||||
AddedWhen = addedDate,
|
||||
BatteryPresent = header.BatteryPresent,
|
||||
ConsoleType = header.ConsoleType,
|
||||
DefaultExpansionDevice = header.DefaultExpansionDevice,
|
||||
ExtendedConsoleType = header.ExtendedConsoleType,
|
||||
FourScreenMode = header.FourScreenMode,
|
||||
Mapper = header.Mapper,
|
||||
ModifiedWhen = DateTime.UtcNow,
|
||||
NametableMirroring = header.NametableMirroring,
|
||||
Sha256 = header.Sha256,
|
||||
Submapper = header.Submapper,
|
||||
TimingMode = header.TimingMode,
|
||||
VsHardwareType = header.VsHardwareType,
|
||||
VsPpuType = header.VsPpuType
|
||||
};
|
||||
if(existing != null)
|
||||
{
|
||||
modifiedNesHeaders++;
|
||||
DateTime addedDate = existing.AddedWhen;
|
||||
|
||||
mctx.NesHeaders.Add(existing);
|
||||
}
|
||||
else
|
||||
{
|
||||
addedNesHeaders++;
|
||||
mctx.Remove(existing);
|
||||
|
||||
mctx.NesHeaders.Add(new NesHeaderInfo
|
||||
{
|
||||
Id = header.Id,
|
||||
AddedWhen = DateTime.UtcNow,
|
||||
BatteryPresent = header.BatteryPresent,
|
||||
ConsoleType = header.ConsoleType,
|
||||
DefaultExpansionDevice = header.DefaultExpansionDevice,
|
||||
ExtendedConsoleType = header.ExtendedConsoleType,
|
||||
FourScreenMode = header.FourScreenMode,
|
||||
Mapper = header.Mapper,
|
||||
ModifiedWhen = DateTime.UtcNow,
|
||||
NametableMirroring = header.NametableMirroring,
|
||||
Sha256 = header.Sha256,
|
||||
Submapper = header.Submapper,
|
||||
TimingMode = header.TimingMode,
|
||||
VsHardwareType = header.VsHardwareType,
|
||||
VsPpuType = header.VsPpuType
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
existing = new NesHeaderInfo
|
||||
{
|
||||
Id = header.Id,
|
||||
AddedWhen = addedDate,
|
||||
BatteryPresent = header.BatteryPresent,
|
||||
ConsoleType = header.ConsoleType,
|
||||
DefaultExpansionDevice = header.DefaultExpansionDevice,
|
||||
ExtendedConsoleType = header.ExtendedConsoleType,
|
||||
FourScreenMode = header.FourScreenMode,
|
||||
Mapper = header.Mapper,
|
||||
ModifiedWhen = DateTime.UtcNow,
|
||||
NametableMirroring = header.NametableMirroring,
|
||||
Sha256 = header.Sha256,
|
||||
Submapper = header.Submapper,
|
||||
TimingMode = header.TimingMode,
|
||||
VsHardwareType = header.VsHardwareType,
|
||||
VsPpuType = header.VsPpuType
|
||||
};
|
||||
|
||||
mctx.NesHeaders.Add(existing);
|
||||
}
|
||||
else
|
||||
{
|
||||
addedNesHeaders++;
|
||||
|
||||
mctx.NesHeaders.Add(new NesHeaderInfo
|
||||
{
|
||||
Id = header.Id,
|
||||
AddedWhen = DateTime.UtcNow,
|
||||
BatteryPresent = header.BatteryPresent,
|
||||
ConsoleType = header.ConsoleType,
|
||||
DefaultExpansionDevice = header.DefaultExpansionDevice,
|
||||
ExtendedConsoleType = header.ExtendedConsoleType,
|
||||
FourScreenMode = header.FourScreenMode,
|
||||
Mapper = header.Mapper,
|
||||
ModifiedWhen = DateTime.UtcNow,
|
||||
NametableMirroring = header.NametableMirroring,
|
||||
Sha256 = header.Sha256,
|
||||
Submapper = header.Submapper,
|
||||
TimingMode = header.TimingMode,
|
||||
VsHardwareType = header.VsHardwareType,
|
||||
VsPpuType = header.VsPpuType
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AaruConsole.WriteLine(Localization.Core.Added_0_known_iNES_NES_2_0_headers, addedNesHeaders);
|
||||
AaruConsole.WriteLine(Localization.Core.Modified_0_known_iNES_NES_2_0_headers, modifiedNesHeaders);
|
||||
|
||||
@@ -35,6 +35,7 @@ using System.CommandLine;
|
||||
using System.CommandLine.NamingConventionBinder;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
using Aaru.Console;
|
||||
using Aaru.Core;
|
||||
@@ -57,10 +58,10 @@ sealed class UpdateCommand : Command
|
||||
Add(new Option<bool>("--clear", () => false, UI.Clear_existing_main_database));
|
||||
Add(new Option<bool>("--clear-all", () => false, UI.Clear_existing_main_and_local_database));
|
||||
|
||||
Handler = CommandHandler.Create((Func<bool, bool, bool, bool, int>)Invoke);
|
||||
Handler = CommandHandler.Create((Func<bool, bool, bool, bool, Task<int>>)InvokeAsync);
|
||||
}
|
||||
|
||||
int Invoke(bool debug, bool verbose, bool clear, bool clearAll)
|
||||
async Task<int> InvokeAsync(bool debug, bool verbose, bool clear, bool clearAll)
|
||||
{
|
||||
if(_mainDbUpdate) return (int)ErrorNumber.NoError;
|
||||
|
||||
@@ -81,7 +82,7 @@ sealed class UpdateCommand : Command
|
||||
stderrConsole.MarkupLine(format, objects);
|
||||
};
|
||||
|
||||
AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); };
|
||||
AaruConsole.WriteExceptionEvent += ex => stderrConsole.WriteException(ex);
|
||||
}
|
||||
|
||||
if(verbose)
|
||||
@@ -105,13 +106,11 @@ sealed class UpdateCommand : Command
|
||||
File.Delete(Settings.Settings.LocalDbPath);
|
||||
|
||||
var ctx = AaruContext.Create(Settings.Settings.LocalDbPath);
|
||||
ctx.Database.Migrate();
|
||||
ctx.SaveChanges();
|
||||
await ctx.Database.MigrateAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
catch(Exception)
|
||||
catch(Exception) when(!Debugger.IsAttached)
|
||||
{
|
||||
if(Debugger.IsAttached) throw;
|
||||
|
||||
AaruConsole.ErrorWriteLine(UI.Could_not_remove_local_database);
|
||||
|
||||
return (int)ErrorNumber.CannotRemoveDatabase;
|
||||
@@ -124,24 +123,22 @@ sealed class UpdateCommand : Command
|
||||
{
|
||||
File.Delete(Settings.Settings.MainDbPath);
|
||||
}
|
||||
catch(Exception)
|
||||
catch(Exception) when(!Debugger.IsAttached)
|
||||
{
|
||||
if(Debugger.IsAttached) throw;
|
||||
|
||||
AaruConsole.ErrorWriteLine(UI.Could_not_remove_main_database);
|
||||
|
||||
return (int)ErrorNumber.CannotRemoveDatabase;
|
||||
}
|
||||
}
|
||||
|
||||
DoUpdate(clear || clearAll);
|
||||
await DoUpdateAsync(clear || clearAll);
|
||||
|
||||
return (int)ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
internal static void DoUpdate(bool create)
|
||||
internal static async Task DoUpdateAsync(bool create)
|
||||
{
|
||||
Remote.UpdateMainDatabase(create);
|
||||
await Remote.UpdateMainDatabaseAsync(create);
|
||||
Statistics.AddCommand("update");
|
||||
}
|
||||
}
|
||||
@@ -181,7 +181,7 @@ class MainClass
|
||||
if(!File.Exists(Settings.Settings.MainDbPath))
|
||||
{
|
||||
mainDbUpdate = true;
|
||||
UpdateCommand.DoUpdate(true);
|
||||
await UpdateCommand.DoUpdateAsync(true);
|
||||
}
|
||||
|
||||
var mainContext = AaruContext.Create(Settings.Settings.MainDbPath, false);
|
||||
@@ -204,7 +204,7 @@ class MainClass
|
||||
|
||||
await mainContext.Database.CloseConnectionAsync();
|
||||
await mainContext.DisposeAsync();
|
||||
UpdateCommand.DoUpdate(true);
|
||||
await UpdateCommand.DoUpdateAsync(true);
|
||||
}
|
||||
|
||||
// GDPR level compliance does not match and there are no arguments or the arguments are neither GUI neither configure.
|
||||
|
||||
Reference in New Issue
Block a user