Fix reformatting.

This commit is contained in:
2019-11-02 23:52:33 +00:00
parent f6df95b732
commit dcaf51faef
52 changed files with 6663 additions and 5874 deletions

View File

@@ -64,26 +64,27 @@ namespace DiscImageChef.Server.Task
try
{
System.Console.WriteLine("{0}: Retrieving USB IDs from Linux USB...", DateTime.UtcNow);
start = DateTime.UtcNow;
start = DateTime.UtcNow;
client = new WebClient();
var sr = new StringReader(client.DownloadString("http://www.linux-usb.org/usb.ids"));
end = DateTime.UtcNow;
System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds);
UsbVendor vendor = null;
var newVendors = 0;
var newProducts = 0;
var modifiedVendors = 0;
var modifiedProducts = 0;
var counter = 0;
UsbVendor vendor = null;
int newVendors = 0;
int newProducts = 0;
int modifiedVendors = 0;
int modifiedProducts = 0;
int counter = 0;
start = DateTime.UtcNow;
System.Console.WriteLine("{0}: Adding and updating database entries...", DateTime.UtcNow);
do
{
if (counter == 1000)
if(counter == 1000)
{
var start2 = DateTime.UtcNow;
DateTime start2 = DateTime.UtcNow;
System.Console.WriteLine("{0}: Saving changes", start2);
ctx.SaveChanges();
end = DateTime.UtcNow;
@@ -91,52 +92,59 @@ namespace DiscImageChef.Server.Task
counter = 0;
}
var line = sr.ReadLine();
string line = sr.ReadLine();
if (line is null) break;
if(line is null)
break;
if (line.Length == 0 || line[0] == '#') continue;
if(line.Length == 0 ||
line[0] == '#')
continue;
ushort number;
string name;
if (line[0] == '\t')
if(line[0] == '\t')
{
try
{
number = Convert.ToUInt16(line.Substring(1, 4), 16);
}
catch (FormatException)
catch(FormatException)
{
continue;
}
if (number == 0) continue;
if(number == 0)
continue;
name = line.Substring(7);
var product =
ctx.UsbProducts.FirstOrDefault(p => p.ProductId == number && p.Vendor != null &&
UsbProduct product =
ctx.UsbProducts.FirstOrDefault(p => p.ProductId == number && p.Vendor != null &&
p.Vendor.VendorId == vendor.VendorId);
if (product is null)
if(product is null)
{
product = new UsbProduct(vendor, number, name);
ctx.UsbProducts.Add(product);
System.Console.WriteLine("{0}: Will add product {1} with ID {2:X4} and vendor {3} ({4:X4})",
DateTime.UtcNow, product.Product, product.ProductId,
product.Vendor?.Vendor ?? "null", product.Vendor?.VendorId ?? 0);
DateTime.UtcNow, product.Product, product.ProductId,
product.Vendor?.Vendor ?? "null", product.Vendor?.VendorId ?? 0);
newProducts++;
counter++;
}
else if (name != product.Product)
else if(name != product.Product)
{
System.Console
.WriteLine(
"{0}: Will modify product with ID {1:X4} and vendor {2} ({3:X4}) from \"{4}\" to \"{5}\"",
DateTime.UtcNow, product.ProductId, product.Vendor?.Vendor ?? "null",
product.Vendor?.VendorId ?? 0,
product.Product, name);
product.Product = name;
System.Console.
WriteLine("{0}: Will modify product with ID {1:X4} and vendor {2} ({3:X4}) from \"{4}\" to \"{5}\"",
DateTime.UtcNow, product.ProductId, product.Vendor?.Vendor ?? "null",
product.Vendor?.VendorId ?? 0,
product.Product, name);
product.Product = name;
product.ModifiedWhen = DateTime.UtcNow;
modifiedProducts++;
counter++;
@@ -149,37 +157,40 @@ namespace DiscImageChef.Server.Task
{
number = Convert.ToUInt16(line.Substring(0, 4), 16);
}
catch (FormatException)
catch(FormatException)
{
continue;
}
if (number == 0) continue;
if(number == 0)
continue;
name = line.Substring(6);
vendor = ctx.UsbVendors.FirstOrDefault(v => v.VendorId == number);
if (vendor is null)
if(vendor is null)
{
vendor = new UsbVendor(number, name);
ctx.UsbVendors.Add(vendor);
System.Console.WriteLine("{0}: Will add vendor {1} with ID {2:X4}", DateTime.UtcNow,
vendor.Vendor,
vendor.VendorId);
vendor.Vendor, vendor.VendorId);
newVendors++;
counter++;
}
else if (name != vendor.Vendor)
else if(name != vendor.Vendor)
{
System.Console.WriteLine("{0}: Will modify vendor with ID {1:X4} from \"{2}\" to \"{3}\"",
DateTime.UtcNow, vendor.VendorId, vendor.Vendor, name);
vendor.Vendor = name;
DateTime.UtcNow, vendor.VendorId, vendor.Vendor, name);
vendor.Vendor = name;
vendor.ModifiedWhen = DateTime.UtcNow;
modifiedVendors++;
counter++;
}
} while (true);
} while(true);
end = DateTime.UtcNow;
System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds);
@@ -196,36 +207,46 @@ namespace DiscImageChef.Server.Task
System.Console.WriteLine("{0}: {1} products modified.", DateTime.UtcNow, modifiedProducts);
System.Console.WriteLine("{0}: Looking up a vendor", DateTime.UtcNow);
start = DateTime.UtcNow;
start = DateTime.UtcNow;
vendor = ctx.UsbVendors.FirstOrDefault(v => v.VendorId == 0x8086);
if (vendor is null) System.Console.WriteLine("{0}: Error, could not find vendor.", DateTime.UtcNow);
if(vendor is null)
System.Console.WriteLine("{0}: Error, could not find vendor.", DateTime.UtcNow);
else
System.Console.WriteLine("{0}: Found {1}.", DateTime.UtcNow,
vendor.Vendor);
System.Console.WriteLine("{0}: Found {1}.", DateTime.UtcNow, vendor.Vendor);
end = DateTime.UtcNow;
System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds);
System.Console.WriteLine("{0}: Looking up a product", DateTime.UtcNow);
start = DateTime.UtcNow;
var prd =
UsbProduct prd =
ctx.UsbProducts.FirstOrDefault(p => p.ProductId == 0x0001 && p.Vendor.VendorId == 0x8086);
if (prd is null) System.Console.WriteLine("{0}: Error, could not find product.", DateTime.UtcNow);
else System.Console.WriteLine("{0}: Found {1}.", DateTime.UtcNow, prd.Product);
if(prd is null)
System.Console.WriteLine("{0}: Error, could not find product.", DateTime.UtcNow);
else
System.Console.WriteLine("{0}: Found {1}.", DateTime.UtcNow, prd.Product);
end = DateTime.UtcNow;
System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds);
}
catch (Exception ex)
catch(Exception ex)
{
#if DEBUG
if (Debugger.IsAttached) throw;
#endif
#if DEBUG
if(Debugger.IsAttached)
throw;
#endif
System.Console.WriteLine("{0}: Exception {1} filling USB IDs...", DateTime.UtcNow, ex);
}
System.Console.WriteLine("{0}: Fixing all devices without modification time...", DateTime.UtcNow);
start = DateTime.UtcNow;
foreach (var device in ctx.Devices.Where(d => d.ModifiedWhen == null))
foreach(Device device in ctx.Devices.Where(d => d.ModifiedWhen == null))
device.ModifiedWhen = device.AddedWhen;
end = DateTime.UtcNow;
System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds);
@@ -238,11 +259,12 @@ namespace DiscImageChef.Server.Task
try
{
System.Console.WriteLine("{0}: Retrieving CompactDisc read offsets from AccurateRip...",
DateTime.UtcNow);
DateTime.UtcNow);
start = DateTime.UtcNow;
client = new WebClient();
var html = client.DownloadString("http://www.accuraterip.com/driveoffsets.htm");
string html = client.DownloadString("http://www.accuraterip.com/driveoffsets.htm");
end = DateTime.UtcNow;
System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds);
@@ -252,133 +274,147 @@ namespace DiscImageChef.Server.Task
var doc = new HtmlDocument();
doc.LoadHtml(html);
var firstTable = doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/table[1]");
HtmlNode firstTable = doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/table[1]");
var firstRow = true;
bool firstRow = true;
var addedOffsets = 0;
var modifiedOffsets = 0;
int addedOffsets = 0;
int modifiedOffsets = 0;
System.Console.WriteLine("{0}: Processing offsets...", DateTime.UtcNow);
start = DateTime.UtcNow;
foreach (var row in firstTable.Descendants("tr"))
{
var columns = row.Descendants("td").ToArray();
if (columns.Length != 4)
foreach(HtmlNode row in firstTable.Descendants("tr"))
{
HtmlNode[] columns = row.Descendants("td").ToArray();
if(columns.Length != 4)
{
System.Console.WriteLine("{0}: Row does not have correct number of columns...",
DateTime.UtcNow);
DateTime.UtcNow);
continue;
}
var column0 = columns[0].InnerText;
var column1 = columns[1].InnerText;
var column2 = columns[2].InnerText;
var column3 = columns[3].InnerText;
string column0 = columns[0].InnerText;
string column1 = columns[1].InnerText;
string column2 = columns[2].InnerText;
string column3 = columns[3].InnerText;
if (firstRow)
if(firstRow)
{
if (column0.ToLowerInvariant() != "cd drive")
if(column0.ToLowerInvariant() != "cd drive")
{
System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow,
columns[0].InnerText);
columns[0].InnerText);
break;
}
if (column1.ToLowerInvariant() != "correction offset")
if(column1.ToLowerInvariant() != "correction offset")
{
System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow,
columns[1].InnerText);
columns[1].InnerText);
break;
}
if (column2.ToLowerInvariant() != "submitted by")
if(column2.ToLowerInvariant() != "submitted by")
{
System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow,
columns[2].InnerText);
columns[2].InnerText);
break;
}
if (column3.ToLowerInvariant() != "percentage agree")
if(column3.ToLowerInvariant() != "percentage agree")
{
System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow,
columns[3].InnerText);
columns[3].InnerText);
break;
}
firstRow = false;
continue;
}
string manufacturer;
string model;
if (column0[0] == '-' && column0[1] == ' ')
if(column0[0] == '-' &&
column0[1] == ' ')
{
manufacturer = null;
model = column0.Substring(2).Trim();
model = column0.Substring(2).Trim();
}
else
{
var cutOffset = column0.IndexOf(" - ", StringComparison.Ordinal);
int cutOffset = column0.IndexOf(" - ", StringComparison.Ordinal);
if (cutOffset == -1)
if(cutOffset == -1)
{
manufacturer = null;
model = column0;
model = column0;
}
else
{
manufacturer = column0.Substring(0, cutOffset).Trim();
model = column0.Substring(cutOffset + 3).Trim();
model = column0.Substring(cutOffset + 3).Trim();
}
}
switch (manufacturer)
switch(manufacturer)
{
case "Lite-ON":
case"Lite-ON":
manufacturer = "JLMS";
break;
case "LG Electronics":
case"LG Electronics":
manufacturer = "HL-DT-ST";
break;
case "Panasonic":
case"Panasonic":
manufacturer = "MATSHITA";
break;
}
var cdOffset =
CompactDiscOffset cdOffset =
ctx.CdOffsets.FirstOrDefault(o => o.Manufacturer == manufacturer && o.Model == model);
if (column1.ToLowerInvariant() == "[purged]")
if(column1.ToLowerInvariant() == "[purged]")
{
if (cdOffset != null) ctx.CdOffsets.Remove(cdOffset);
if(cdOffset != null)
ctx.CdOffsets.Remove(cdOffset);
continue;
}
if (!short.TryParse(column1, out var offset)) continue;
if (!int.TryParse(column2, out var submissions)) continue;
if(!short.TryParse(column1, out short offset))
continue;
if (column3[column3.Length - 1] != '%') continue;
if(!int.TryParse(column2, out int submissions))
continue;
if(column3[column3.Length - 1] != '%')
continue;
column3 = column3.Substring(0, column3.Length - 1);
if (!float.TryParse(column3, out var percentage)) continue;
if(!float.TryParse(column3, out float percentage))
continue;
percentage /= 100;
if (cdOffset is null)
if(cdOffset is null)
{
cdOffset = new CompactDiscOffset
{
AddedWhen = DateTime.UtcNow,
ModifiedWhen = DateTime.UtcNow,
Agreement = percentage,
Manufacturer = manufacturer,
Model = model,
Offset = offset,
Submissions = submissions
AddedWhen = DateTime.UtcNow, ModifiedWhen = DateTime.UtcNow, Agreement = percentage,
Manufacturer = manufacturer, Model = model, Offset = offset,
Submissions = submissions
};
ctx.CdOffsets.Add(cdOffset);
@@ -386,40 +422,44 @@ namespace DiscImageChef.Server.Task
}
else
{
if (Math.Abs(cdOffset.Agreement - percentage) > 0)
if(Math.Abs(cdOffset.Agreement - percentage) > 0)
{
cdOffset.Agreement = percentage;
cdOffset.Agreement = percentage;
cdOffset.ModifiedWhen = DateTime.UtcNow;
}
if (cdOffset.Offset != offset)
if(cdOffset.Offset != offset)
{
cdOffset.Offset = offset;
cdOffset.Offset = offset;
cdOffset.ModifiedWhen = DateTime.UtcNow;
}
if (cdOffset.Submissions != submissions)
if(cdOffset.Submissions != submissions)
{
cdOffset.Submissions = submissions;
cdOffset.Submissions = submissions;
cdOffset.ModifiedWhen = DateTime.UtcNow;
}
if (Math.Abs(cdOffset.Agreement - percentage) > 0 || cdOffset.Offset != offset ||
cdOffset.Submissions != submissions) modifiedOffsets++;
if(Math.Abs(cdOffset.Agreement - percentage) > 0 ||
cdOffset.Offset != offset ||
cdOffset.Submissions != submissions)
modifiedOffsets++;
}
foreach (var device in ctx
.Devices
.Where(d => d.Manufacturer == null && d.Model != null &&
d.Model.Trim() == model)
.Union(ctx.Devices.Where(d => d.Manufacturer != null &&
d.Manufacturer.Trim() == manufacturer &&
d.Model != null &&
d.Model == model)))
foreach(Device device in ctx.
Devices.
Where(d => d.Manufacturer == null && d.Model != null &&
d.Model.Trim() == model).
Union(ctx.Devices.Where(d => d.Manufacturer != null &&
d.Manufacturer.Trim() == manufacturer &&
d.Model != null &&
d.Model == model)))
{
if (device.CdOffset == cdOffset && device.ModifiedWhen == cdOffset.ModifiedWhen) continue;
if(device.CdOffset == cdOffset &&
device.ModifiedWhen == cdOffset.ModifiedWhen)
continue;
device.CdOffset = cdOffset;
device.CdOffset = cdOffset;
device.ModifiedWhen = cdOffset.ModifiedWhen;
}
}
@@ -436,11 +476,12 @@ namespace DiscImageChef.Server.Task
System.Console.WriteLine("{0}: Added {1} offsets", end, addedOffsets);
System.Console.WriteLine("{0}: Modified {1} offsets", end, modifiedOffsets);
}
catch (Exception ex)
catch(Exception ex)
{
#if DEBUG
if (Debugger.IsAttached) throw;
#endif
#if DEBUG
if(Debugger.IsAttached)
throw;
#endif
System.Console.WriteLine("{0}: Exception {1} filling CompactDisc read offsets...", DateTime.UtcNow, ex);
}
}