mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Store and retrieve USB IDs from databases.
This commit is contained in:
@@ -291,7 +291,6 @@
|
||||
<None Include="int10h.org\.htaccess" />
|
||||
<None Include="int10h.org\vga_squarepx.woff2" />
|
||||
<None Include="Reports\.htaccess" />
|
||||
<None Include="usb.ids" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
@@ -3,7 +3,7 @@ using DiscImageChef.Server.Models;
|
||||
|
||||
namespace DiscImageChef.Server.Migrations
|
||||
{
|
||||
sealed class Configuration : DbMigrationsConfiguration<DicServerContext>
|
||||
public sealed class Configuration : DbMigrationsConfiguration<DicServerContext>
|
||||
{
|
||||
public Configuration()
|
||||
{
|
||||
|
||||
@@ -32,16 +32,13 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using System.Web.UI;
|
||||
using DiscImageChef.CommonTypes.Metadata;
|
||||
using DiscImageChef.Decoders.PCMCIA;
|
||||
using DiscImageChef.Decoders.SCSI;
|
||||
using DiscImageChef.Server.App_Start;
|
||||
using DiscImageChef.Server.Models;
|
||||
using TestedMedia = DiscImageChef.CommonTypes.Metadata.TestedMedia;
|
||||
using Tuple = DiscImageChef.Decoders.PCMCIA.Tuple;
|
||||
|
||||
namespace DiscImageChef.Server
|
||||
@@ -76,8 +73,25 @@ namespace DiscImageChef.Server
|
||||
|
||||
if(report.USB != null)
|
||||
{
|
||||
GetUsbDescriptions(report.USB.VendorID, report.USB.ProductID, out string usbVendorDescription,
|
||||
out string usbProductDescription);
|
||||
string usbVendorDescription = null;
|
||||
string usbProductDescription = null;
|
||||
|
||||
UsbProduct dbProduct =
|
||||
ctx.UsbProducts.FirstOrDefault(p => p.ProductId == report.USB.ProductID &&
|
||||
p.Vendor != null &&
|
||||
p.Vendor.VendorId == report.USB.VendorID);
|
||||
|
||||
if(dbProduct is null)
|
||||
{
|
||||
UsbVendor dbVendor = ctx.UsbVendors.FirstOrDefault(v => v.VendorId == report.USB.VendorID);
|
||||
|
||||
if(!(dbVendor is null)) usbVendorDescription = dbVendor.Vendor;
|
||||
}
|
||||
else
|
||||
{
|
||||
usbProductDescription = dbProduct.Product;
|
||||
usbVendorDescription = dbProduct.Vendor.Vendor;
|
||||
}
|
||||
|
||||
lblUsbManufacturer.Text = HttpUtility.HtmlEncode(report.USB.Manufacturer);
|
||||
lblUsbProduct.Text = HttpUtility.HtmlEncode(report.USB.Product);
|
||||
@@ -497,54 +511,5 @@ namespace DiscImageChef.Server
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void GetUsbDescriptions(ushort vendor, ushort product, out string vendorDescription,
|
||||
out string productDescription)
|
||||
{
|
||||
vendorDescription = null;
|
||||
productDescription = null;
|
||||
|
||||
if(!File.Exists(Path.Combine(HostingEnvironment.MapPath("~") ?? throw new InvalidOperationException(),
|
||||
"usb.ids"))) return;
|
||||
|
||||
StreamReader tocStream =
|
||||
new StreamReader(Path.Combine(HostingEnvironment.MapPath("~") ?? throw new InvalidOperationException(),
|
||||
"usb.ids"));
|
||||
bool inManufacturer = false;
|
||||
|
||||
while(tocStream.Peek() >= 0)
|
||||
{
|
||||
string line = tocStream.ReadLine();
|
||||
|
||||
if(line == null) break;
|
||||
|
||||
if(line.Length == 0 || line[0] == '#') continue;
|
||||
|
||||
ushort number;
|
||||
if(inManufacturer)
|
||||
{
|
||||
// Finished with the manufacturer
|
||||
if(line[0] != '\t') return;
|
||||
|
||||
number = Convert.ToUInt16(line.Substring(1, 4), 16);
|
||||
|
||||
if(number != product) continue;
|
||||
|
||||
productDescription = line.Substring(7);
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip products
|
||||
if(line[0] == '\t') continue;
|
||||
|
||||
try { number = Convert.ToUInt16(line.Substring(0, 4), 16); }
|
||||
catch(FormatException) { continue; }
|
||||
|
||||
if(number != vendor) continue;
|
||||
|
||||
vendorDescription = line.Substring(6);
|
||||
inManufacturer = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
30
DiscImageChef.Server/Web.Debug.config
Normal file
30
DiscImageChef.Server/Web.Debug.config
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!-- For more information on using Web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=301874 -->
|
||||
|
||||
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
|
||||
<!--
|
||||
In the example below, the "SetAttributes" transform will change the value of
|
||||
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
|
||||
finds an attribute "name" that has a value of "MyDB".
|
||||
|
||||
<connectionStrings>
|
||||
<add name="MyDB"
|
||||
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
|
||||
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
|
||||
</connectionStrings>
|
||||
-->
|
||||
<system.web>
|
||||
<!--
|
||||
In the example below, the "Replace" transform will replace the entire
|
||||
<customErrors> section of your Web.config file.
|
||||
Note that because there is only one customErrors section under the
|
||||
<system.web> node, there is no need to use the "xdt:Locator" attribute.
|
||||
|
||||
<customErrors defaultRedirect="GenericError.htm"
|
||||
mode="RemoteOnly" xdt:Transform="Replace">
|
||||
<error statusCode="500" redirect="InternalError.htm"/>
|
||||
</customErrors>
|
||||
-->
|
||||
</system.web>
|
||||
</configuration>
|
||||
31
DiscImageChef.Server/Web.Release.config
Normal file
31
DiscImageChef.Server/Web.Release.config
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!-- For more information on using Web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=301874 -->
|
||||
|
||||
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
|
||||
<!--
|
||||
In the example below, the "SetAttributes" transform will change the value of
|
||||
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
|
||||
finds an attribute "name" that has a value of "MyDB".
|
||||
|
||||
<connectionStrings>
|
||||
<add name="MyDB"
|
||||
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
|
||||
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
|
||||
</connectionStrings>
|
||||
-->
|
||||
<system.web>
|
||||
<compilation xdt:Transform="RemoveAttributes(debug)" />
|
||||
<!--
|
||||
In the example below, the "Replace" transform will replace the entire
|
||||
<customErrors> section of your Web.config file.
|
||||
Note that because there is only one customErrors section under the
|
||||
<system.web> node, there is no need to use the "xdt:Locator" attribute.
|
||||
|
||||
<customErrors defaultRedirect="GenericError.htm"
|
||||
mode="RemoteOnly" xdt:Transform="Replace">
|
||||
<error statusCode="500" redirect="InternalError.htm"/>
|
||||
</customErrors>
|
||||
-->
|
||||
</system.web>
|
||||
</configuration>
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user