2020-07-10 17:48:22 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2017-05-28 21:01:17 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Remote.cs
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2017-05-28 21:01:17 +01:00
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Core algorithms.
|
2017-05-28 21:01:17 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2020-02-27 20:38:23 +00:00
|
|
|
|
// Handles connections to Aaru.Server.
|
2017-05-28 21:01:17 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2017-05-28 21:01:17 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 03:50:57 +00:00
|
|
|
|
|
2017-12-21 14:41:38 +00:00
|
|
|
|
using System;
|
2019-01-02 04:05:51 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-12-20 00:16:54 +00:00
|
|
|
|
using System.Diagnostics;
|
2017-06-03 01:18:36 +01:00
|
|
|
|
using System.IO;
|
2019-01-02 04:05:51 +00:00
|
|
|
|
using System.Linq;
|
2017-06-03 01:18:36 +01:00
|
|
|
|
using System.Net;
|
2022-03-26 17:12:46 +00:00
|
|
|
|
using System.Net.Http;
|
2019-01-04 04:10:45 +00:00
|
|
|
|
using System.Text;
|
2022-12-15 02:06:39 +00:00
|
|
|
|
using System.Text.Json;
|
2017-12-19 19:33:46 +00:00
|
|
|
|
using System.Threading;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes.Metadata;
|
|
|
|
|
|
using Aaru.Console;
|
|
|
|
|
|
using Aaru.Database;
|
|
|
|
|
|
using Aaru.Database.Models;
|
|
|
|
|
|
using Aaru.Dto;
|
2019-01-02 04:05:51 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-11-15 15:58:43 +00:00
|
|
|
|
using Spectre.Console;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using CdOffset = Aaru.Database.Models.CdOffset;
|
|
|
|
|
|
using Version = Aaru.CommonTypes.Metadata.Version;
|
2017-06-03 01:18:36 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
namespace Aaru.Core;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <summary>Handles connections to Aaru.Server</summary>
|
|
|
|
|
|
public static class Remote
|
2017-05-28 21:01:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <summary>Submits a device report</summary>
|
|
|
|
|
|
/// <param name="report">Device report</param>
|
2022-12-15 01:47:12 +00:00
|
|
|
|
public static void SubmitReport(DeviceReport report)
|
2017-05-28 21:01:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
var submitThread = new Thread(() =>
|
2018-12-20 00:12:48 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Spectre.ProgressSingleSpinner(ctx =>
|
2018-12-20 00:12:48 +00:00
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
ctx.AddTask(Localization.Core.Uploading_device_report).IsIndeterminate();
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2022-12-16 20:35:28 +00:00
|
|
|
|
string json = JsonSerializer.Serialize(report, typeof(DeviceReport), DeviceReportContext.Default);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
2022-03-26 17:12:46 +00:00
|
|
|
|
var httpClient = new HttpClient();
|
|
|
|
|
|
|
|
|
|
|
|
httpClient.DefaultRequestHeaders.Add("User-Agent",
|
|
|
|
|
|
$"Aaru {typeof(Version).Assembly.GetName().Version}");
|
|
|
|
|
|
|
|
|
|
|
|
httpClient.BaseAddress = new Uri("https://www.aaru.app");
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponseMessage response = httpClient.
|
|
|
|
|
|
PostAsync("/api/uploadreportv2",
|
|
|
|
|
|
new StringContent(json, Encoding.UTF8,
|
2023-10-04 17:34:40 +01:00
|
|
|
|
"application/json")).
|
|
|
|
|
|
GetAwaiter().
|
2022-03-26 17:12:46 +00:00
|
|
|
|
GetResult();
|
|
|
|
|
|
|
|
|
|
|
|
if(!response.IsSuccessStatusCode)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
2022-03-26 17:12:46 +00:00
|
|
|
|
Stream data = response.Content.ReadAsStream();
|
|
|
|
|
|
var reader = new StreamReader(data);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
reader.ReadToEnd();
|
|
|
|
|
|
data.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch(WebException)
|
2018-12-20 00:12:48 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
// Can't connect to the server, do nothing
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once RedundantCatchClause
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
|
if(Debugger.IsAttached)
|
|
|
|
|
|
throw;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
2017-06-03 01:18:36 +01:00
|
|
|
|
});
|
2022-03-06 13:29:38 +00:00
|
|
|
|
});
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
submitThread.Start();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
|
{
|
2022-11-15 15:58:43 +00:00
|
|
|
|
var mctx = AaruContext.Create(Settings.Settings.MainDbPath);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
if(create)
|
|
|
|
|
|
{
|
|
|
|
|
|
mctx.Database.EnsureCreated();
|
|
|
|
|
|
|
|
|
|
|
|
mctx.Database.
|
2023-10-04 17:34:40 +01:00
|
|
|
|
ExecuteSqlRaw("CREATE TABLE IF NOT EXISTS \"__EFMigrationsHistory\" (\"MigrationId\" TEXT PRIMARY KEY, \"ProductVersion\" TEXT)");
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
foreach(string migration in mctx.Database.GetPendingMigrations())
|
2023-10-03 22:57:50 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
mctx.Database.
|
2022-11-15 15:58:43 +00:00
|
|
|
|
ExecuteSqlRaw($"INSERT INTO \"__EFMigrationsHistory\" (MigrationId, ProductVersion) VALUES ('{
|
|
|
|
|
|
migration}', '0.0.0')");
|
2023-10-03 22:57:50 +01:00
|
|
|
|
}
|
2017-05-28 21:01:17 +01:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
else
|
|
|
|
|
|
mctx.Database.Migrate();
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
mctx.SaveChanges();
|
|
|
|
|
|
|
|
|
|
|
|
try
|
2019-01-02 04:05:51 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
long lastUpdate = 0;
|
|
|
|
|
|
DateTime latest = DateTime.MinValue;
|
2020-07-10 17:38:52 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(!create)
|
2020-07-10 17:38:52 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
List<DateTime> latestAll = new();
|
2020-07-10 17:38:52 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(mctx.UsbVendors.Any())
|
|
|
|
|
|
latestAll.Add(mctx.UsbVendors.Max(v => v.ModifiedWhen));
|
|
|
|
|
|
|
|
|
|
|
|
if(mctx.UsbProducts.Any())
|
|
|
|
|
|
latestAll.Add(mctx.UsbProducts.Max(p => p.ModifiedWhen));
|
|
|
|
|
|
|
|
|
|
|
|
if(mctx.CdOffsets.Any())
|
|
|
|
|
|
latestAll.Add(mctx.CdOffsets.Max(o => o.ModifiedWhen));
|
|
|
|
|
|
|
|
|
|
|
|
if(mctx.Devices.Any())
|
|
|
|
|
|
latestAll.Add(mctx.Devices.Max(d => d.LastSynchronized));
|
2020-07-10 17:38:52 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(latestAll.Any())
|
2020-07-10 17:38:52 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
latest = latestAll.Max(t => t);
|
|
|
|
|
|
lastUpdate = (latest.ToFileTimeUtc() - new DateTime(1970, 1, 1).ToFileTimeUtc()) / 10000000;
|
2020-07-10 17:38:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(lastUpdate == 0)
|
2019-01-02 04:05:51 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
create = true;
|
2022-11-23 16:06:46 +00:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Creating_main_database);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Updating_main_database);
|
|
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Last_update_0, latest);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
DateTime updateStart = DateTime.UtcNow;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-26 17:12:46 +00:00
|
|
|
|
var httpClient = new HttpClient();
|
|
|
|
|
|
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();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-26 17:12:46 +00:00
|
|
|
|
if(!response.IsSuccessStatusCode)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
AaruConsole.ErrorWriteLine(Localization.Core.Error_0_when_trying_to_get_updated_entities,
|
|
|
|
|
|
response.StatusCode);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-26 17:12:46 +00:00
|
|
|
|
Stream data = response.Content.ReadAsStream();
|
|
|
|
|
|
var reader = new StreamReader(data);
|
2023-10-03 22:57:50 +01:00
|
|
|
|
SyncDto sync = JsonSerializer.Deserialize<SyncDto>(reader.ReadToEnd()) ?? new SyncDto();
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(create)
|
|
|
|
|
|
{
|
2023-10-04 17:34:40 +01:00
|
|
|
|
AnsiConsole.Progress().
|
|
|
|
|
|
AutoClear(true).
|
|
|
|
|
|
HideCompleted(true).
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
|
|
|
|
|
|
Start(ctx =>
|
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
ProgressTask task = ctx.AddTask(Localization.Core.Adding_USB_vendors);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.MaxValue = sync.UsbVendors.Count;
|
|
|
|
|
|
|
|
|
|
|
|
foreach(UsbVendorDto vendor in sync.UsbVendors)
|
|
|
|
|
|
{
|
|
|
|
|
|
task.Increment(1);
|
|
|
|
|
|
mctx.UsbVendors.Add(new UsbVendor(vendor.VendorId, vendor.Vendor));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Added_0_usb_vendors, sync.UsbVendors.Count);
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
|
AnsiConsole.Progress().
|
|
|
|
|
|
AutoClear(true).
|
|
|
|
|
|
HideCompleted(true).
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
|
|
|
|
|
|
Start(ctx =>
|
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
ProgressTask task = ctx.AddTask(Localization.Core.Adding_USB_products);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.MaxValue = sync.UsbProducts.Count;
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
foreach(UsbProductDto product in sync.UsbProducts)
|
|
|
|
|
|
{
|
|
|
|
|
|
task.Increment(1);
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
mctx.UsbProducts.Add(new UsbProduct(product.VendorId, product.ProductId,
|
|
|
|
|
|
product.Product));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Added_0_usb_products, sync.UsbProducts.Count);
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
|
AnsiConsole.Progress().
|
|
|
|
|
|
AutoClear(true).
|
|
|
|
|
|
HideCompleted(true).
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
|
|
|
|
|
|
Start(ctx =>
|
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
ProgressTask task = ctx.AddTask(Localization.Core.Adding_CompactDisc_read_offsets);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.MaxValue = sync.Offsets.Count;
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
foreach(CdOffsetDto offset in sync.Offsets)
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.Increment(1);
|
2021-09-13 02:48:17 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
mctx.CdOffsets.Add(new CdOffset(offset)
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Id = offset.Id
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Added_0_CompactDisc_read_offsets, sync.Offsets.Count);
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
|
AnsiConsole.Progress().
|
|
|
|
|
|
AutoClear(true).
|
|
|
|
|
|
HideCompleted(true).
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
|
|
|
|
|
|
Start(ctx =>
|
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
ProgressTask task = ctx.AddTask(Localization.Core.Adding_known_devices);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.MaxValue = sync.Devices.Count;
|
|
|
|
|
|
|
|
|
|
|
|
foreach(DeviceDto device in sync.Devices)
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.Increment(1);
|
2021-09-13 02:48:17 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
mctx.Devices.Add(new Device(device)
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Id = device.Id
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Added_0_known_devices, sync.Devices.Count);
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
|
AnsiConsole.Progress().
|
|
|
|
|
|
AutoClear(true).
|
|
|
|
|
|
HideCompleted(true).
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
|
|
|
|
|
|
Start(ctx =>
|
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
ProgressTask task = ctx.AddTask(Localization.Core.Adding_known_iNES_NES_2_0_headers);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.MaxValue = sync.NesHeaders?.Count ?? 0;
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
foreach(NesHeaderDto header in sync.NesHeaders ?? new List<NesHeaderDto>())
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.Increment(1);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
mctx.NesHeaders.Add(new NesHeaderInfo
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
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
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Added_0_known_iNES_NES_2_0_headers,
|
|
|
|
|
|
sync.NesHeaders?.Count ?? 0);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
long addedVendors = 0;
|
|
|
|
|
|
long addedProducts = 0;
|
|
|
|
|
|
long addedOffsets = 0;
|
|
|
|
|
|
long addedDevices = 0;
|
|
|
|
|
|
long addedNesHeaders = 0;
|
|
|
|
|
|
long modifiedVendors = 0;
|
|
|
|
|
|
long modifiedProducts = 0;
|
|
|
|
|
|
long modifiedOffsets = 0;
|
|
|
|
|
|
long modifiedDevices = 0;
|
|
|
|
|
|
long modifiedNesHeaders = 0;
|
|
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
|
AnsiConsole.Progress().
|
|
|
|
|
|
AutoClear(true).
|
|
|
|
|
|
HideCompleted(true).
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
|
|
|
|
|
|
Start(ctx =>
|
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
ProgressTask task = ctx.AddTask(Localization.Core.Updating_USB_vendors);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.MaxValue = sync.UsbVendors.Count;
|
|
|
|
|
|
|
|
|
|
|
|
foreach(UsbVendorDto vendor in sync.UsbVendors)
|
|
|
|
|
|
{
|
|
|
|
|
|
task.Increment(1);
|
2021-09-13 02:48:17 +01:00
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
|
UsbVendor existing = mctx.UsbVendors.FirstOrDefault(v => v.Id == vendor.VendorId);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
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));
|
2021-09-13 02:48:17 +01:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2023-10-03 22:57:50 +01:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Added_0_usb_vendors, addedVendors);
|
2022-11-23 16:06:46 +00:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Modified_0_USB_vendors, modifiedVendors);
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
|
AnsiConsole.Progress().
|
|
|
|
|
|
AutoClear(true).
|
|
|
|
|
|
HideCompleted(true).
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
|
|
|
|
|
|
Start(ctx =>
|
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
ProgressTask task = ctx.AddTask(Localization.Core.Updating_USB_products);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.MaxValue = sync.UsbVendors.Count;
|
|
|
|
|
|
|
|
|
|
|
|
foreach(UsbProductDto product in sync.UsbProducts)
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.Increment(1);
|
2021-09-13 02:48:17 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
UsbProduct existing =
|
|
|
|
|
|
mctx.UsbProducts.FirstOrDefault(p => p.VendorId == product.VendorId &&
|
|
|
|
|
|
p.ProductId == product.ProductId);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(existing != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
modifiedProducts++;
|
|
|
|
|
|
existing.Product = product.Product;
|
|
|
|
|
|
existing.ModifiedWhen = updateStart;
|
|
|
|
|
|
mctx.UsbProducts.Update(existing);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
addedProducts++;
|
2021-09-13 02:48:17 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
mctx.UsbProducts.Add(new UsbProduct(product.VendorId, product.ProductId,
|
|
|
|
|
|
product.Product));
|
2021-09-13 02:48:17 +01:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2023-10-03 22:57:50 +01:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Added_0_usb_products, addedProducts);
|
2022-11-23 16:06:46 +00:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Modified_0_USB_products, modifiedProducts);
|
2021-12-08 20:34:36 +00:00
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
|
AnsiConsole.Progress().
|
|
|
|
|
|
AutoClear(true).
|
|
|
|
|
|
HideCompleted(true).
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
|
|
|
|
|
|
Start(ctx =>
|
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
ProgressTask task = ctx.AddTask(Localization.Core.Updating_CompactDisc_read_offsets);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.MaxValue = sync.Offsets.Count;
|
|
|
|
|
|
|
|
|
|
|
|
foreach(CdOffsetDto offset in sync.Offsets)
|
2021-12-08 20:34:36 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
CdOffset existing = mctx.CdOffsets.FirstOrDefault(o => o.Id == offset.Id);
|
|
|
|
|
|
task.Increment(1);
|
2021-12-08 20:34:36 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(existing != null)
|
2021-12-08 20:34:36 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
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);
|
2021-12-08 20:34:36 +00:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
else
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
addedOffsets++;
|
2021-09-13 02:48:17 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
mctx.CdOffsets.Add(new CdOffset(offset)
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Id = offset.Id
|
|
|
|
|
|
});
|
2021-09-13 02:48:17 +01:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2023-10-03 22:57:50 +01:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Added_0_CompactDisc_read_offsets, addedOffsets);
|
2022-11-23 16:06:46 +00:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Modified_0_CompactDisc_read_offsets, modifiedOffsets);
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
|
AnsiConsole.Progress().
|
|
|
|
|
|
AutoClear(true).
|
|
|
|
|
|
HideCompleted(true).
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
|
|
|
|
|
|
Start(ctx =>
|
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
ProgressTask task = ctx.AddTask(Localization.Core.Updating_known_devices);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.MaxValue = sync.Offsets.Count;
|
|
|
|
|
|
|
|
|
|
|
|
foreach(DeviceDto device in sync.Devices)
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.Increment(1);
|
|
|
|
|
|
Device existing = mctx.Devices.FirstOrDefault(d => d.Id == device.Id);
|
2021-09-13 02:48:17 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(existing != null)
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
modifiedDevices++;
|
2021-09-13 02:48:17 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
mctx.Remove(existing);
|
2021-09-13 02:48:17 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
existing = new Device(device)
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Id = device.Id,
|
|
|
|
|
|
OptimalMultipleSectorsRead = device.OptimalMultipleSectorsRead,
|
|
|
|
|
|
CanReadGdRomUsingSwapDisc = device.CanReadGdRomUsingSwapDisc
|
|
|
|
|
|
};
|
2021-09-13 02:48:17 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
mctx.Devices.Add(existing);
|
2021-09-13 02:48:17 +01:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
else
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
addedDevices++;
|
2021-09-13 02:48:17 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
mctx.Devices.Add(new Device(device)
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Id = device.Id,
|
|
|
|
|
|
OptimalMultipleSectorsRead = device.OptimalMultipleSectorsRead,
|
|
|
|
|
|
CanReadGdRomUsingSwapDisc = device.CanReadGdRomUsingSwapDisc
|
|
|
|
|
|
});
|
2021-09-13 02:48:17 +01:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2023-10-03 22:57:50 +01:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Added_0_known_devices, addedDevices);
|
2022-11-23 16:06:46 +00:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Modified_0_known_devices, modifiedDevices);
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
|
AnsiConsole.Progress().
|
|
|
|
|
|
AutoClear(true).
|
|
|
|
|
|
HideCompleted(true).
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
|
|
|
|
|
|
Start(ctx =>
|
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
ProgressTask task = ctx.AddTask(Localization.Core.Updating_known_iNES_NES_2_0_headers);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.MaxValue = sync.Offsets.Count;
|
2019-01-02 04:05:51 +00:00
|
|
|
|
|
2022-11-15 01:35:06 +00:00
|
|
|
|
sync.NesHeaders ??= new List<NesHeaderDto>();
|
2022-11-13 14:50:51 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
foreach(NesHeaderDto header in sync.NesHeaders)
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
task.Increment(1);
|
|
|
|
|
|
NesHeaderInfo existing = mctx.NesHeaders.FirstOrDefault(d => d.Id == header.Id);
|
2021-09-13 02:48:17 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(existing != null)
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
modifiedNesHeaders++;
|
|
|
|
|
|
DateTime addedDate = existing.AddedWhen;
|
2021-09-13 02:48:17 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
mctx.Remove(existing);
|
2021-09-13 02:48:17 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
existing = new NesHeaderInfo
|
2021-09-13 02:48:17 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
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);
|
2021-09-13 02:48:17 +01:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
else
|
2021-12-08 20:34:36 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
addedNesHeaders++;
|
2021-12-08 20:34:36 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
mctx.NesHeaders.Add(new NesHeaderInfo
|
2021-12-08 20:34:36 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
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
|
|
|
|
|
|
});
|
2021-12-08 20:34:36 +00:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2021-12-08 20:34:36 +00:00
|
|
|
|
|
2023-10-03 22:57:50 +01:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Added_0_known_iNES_NES_2_0_headers, addedNesHeaders);
|
2022-11-23 16:06:46 +00:00
|
|
|
|
AaruConsole.WriteLine(Localization.Core.Modified_0_known_iNES_NES_2_0_headers, modifiedNesHeaders);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
AaruConsole.ErrorWriteLine(Localization.Core.Exception_0_when_updating_database, ex);
|
2023-10-08 04:10:19 +01:00
|
|
|
|
AaruConsole.WriteException(ex);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
Spectre.ProgressSingleSpinner(ctx =>
|
2019-01-02 04:05:51 +00:00
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
ctx.AddTask(Localization.Core.Saving_changes).IsIndeterminate();
|
2022-03-06 13:29:38 +00:00
|
|
|
|
mctx.SaveChanges();
|
|
|
|
|
|
});
|
2019-01-02 04:05:51 +00:00
|
|
|
|
}
|
2017-05-28 21:01:17 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|