CUETools.CTDB: split classes into separate files.

This commit is contained in:
karamanolev
2011-10-24 14:32:51 +00:00
parent ce79dd8641
commit 426f733d19
11 changed files with 306 additions and 250 deletions

View File

@@ -0,0 +1,10 @@
namespace CUETools.CTDB
{
public enum CTDBMetadataSearch
{
None = 0,
Fast = 1,
Default = 2,
Extensive = 3
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Xml.Serialization;
namespace CUETools.CTDB
{
[Serializable]
[XmlRoot(ElementName = "ctdb", Namespace = "http://db.cuetools.net/ns/mmd-1.0#")]
public class CTDBResponse
{
[XmlElement]
public CTDBResponseEntry[] entry;
[XmlElement]
public CTDBResponseMeta[] musicbrainz;
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Xml.Serialization;
namespace CUETools.CTDB
{
[Serializable]
public class CTDBResponseEntry
{
[XmlAttribute]
public string id { get; set; }
[XmlAttribute]
public string crc32 { get; set; }
[XmlAttribute]
public int confidence { get; set; }
[XmlAttribute]
public int npar { get; set; }
[XmlAttribute]
public int stride { get; set; }
[XmlAttribute]
public string hasparity { get; set; }
[XmlAttribute]
public string parity { get; set; }
[XmlAttribute]
public string toc { get; set; }
}
}

View File

@@ -0,0 +1,44 @@
using System;
using System.Xml.Serialization;
namespace CUETools.CTDB
{
[Serializable]
public class CTDBResponseMeta
{
[XmlAttribute]
public string source { get; set; }
[XmlAttribute]
public string id { get; set; }
[XmlAttribute]
public string artist { get; set; }
[XmlAttribute]
public string album { get; set; }
[XmlAttribute]
public string year { get; set; }
[XmlAttribute]
public string genre { get; set; }
[XmlAttribute]
public string extra { get; set; }
[XmlAttribute]
public string country { get; set; }
[XmlAttribute]
public string releasedate { get; set; }
[XmlAttribute]
public string discnumber { get; set; }
[XmlAttribute]
public string disccount { get; set; }
[XmlAttribute]
public string discname { get; set; }
[XmlAttribute]
public string coverarturl { get; set; }
[XmlAttribute]
public string infourl { get; set; }
[XmlAttribute]
public string barcode { get; set; }
[XmlElement]
public CTDBResponseMetaTrack[] track;
[XmlElement]
public CTDBResponseMetaLabel[] label;
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Xml.Serialization;
namespace CUETools.CTDB
{
[Serializable]
public class CTDBResponseMetaLabel
{
[XmlAttribute]
public string name { get; set; }
[XmlAttribute]
public string catno { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Xml.Serialization;
namespace CUETools.CTDB
{
[Serializable]
public class CTDBResponseMetaTrack
{
[XmlAttribute]
public string name { get; set; }
[XmlAttribute]
public string artist { get; set; }
[XmlAttribute]
public string extra { get; set; }
}
}

View File

@@ -59,8 +59,17 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CTDBMetadataSearch.cs" />
<Compile Include="CTDBResponse.cs" />
<Compile Include="CTDBResponseEntry.cs" />
<Compile Include="CTDBResponseMeta.cs" />
<Compile Include="CTDBResponseMetaLabel.cs" />
<Compile Include="CTDBResponseMetaTrack.cs" />
<Compile Include="CUEToolsDB.cs" />
<Compile Include="DBEntry.cs" />
<Compile Include="DBHDR.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReadDB.cs" />
<Compile Include="UploadHelper\HttpUploadHelper.cs" />
<Compile Include="UploadHelper\MimePart.cs" />
<Compile Include="UploadHelper\StreamMimePart.cs" />

View File

@@ -1,17 +1,15 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Management;
using System.Net;
using System.Xml;
using System.Xml.Serialization;
using System.Text;
using System.Security.Cryptography;
using CUETools.CDImage;
using System.Text;
using System.Xml.Serialization;
using CUETools.AccurateRip;
using CUETools.CDImage;
using Krystalware.UploadHelper;
namespace CUETools.CTDB
@@ -578,249 +576,4 @@ namespace CUETools.CTDB
}
}
}
public class DBEntry
{
public byte[] parity;
public int pos;
public int len;
public int conf;
public int npar;
public int stride;
public int offset;
public uint crc;
public bool hasErrors;
public bool canRecover;
public CDRepairFix repair;
public HttpStatusCode httpStatus;
public string id;
public CDImageLayout toc;
public string hasParity;
public DBEntry(byte[] parity, int pos, int len, int conf, int npar, int stride, uint crc, string id, CDImageLayout toc, string hasParity)
{
this.parity = parity;
this.id = id;
this.pos = pos;
this.len = len;
this.conf = conf;
this.crc = crc;
this.npar = npar;
this.stride = stride;
this.toc = toc;
this.hasParity = hasParity;
}
public string Status
{
get
{
if (!hasErrors)
return string.Format("verified OK, confidence {0}", conf);
if (canRecover)
return string.Format("differs in {1} samples, confidence {0}", conf, repair.CorrectableErrors);
if (httpStatus == HttpStatusCode.OK)
return "could not be verified";
return "could not be verified: " + httpStatus.ToString();
}
}
}
internal class ReadDB
{
byte[] contents;
public int pos;
public ReadDB(byte[] contents)
{
this.contents = contents;
pos = 0;
}
public string ReadHDR(out int end)
{
int size = ReadInt();
string res = Encoding.ASCII.GetString(contents, pos, 4);
pos += 4;
end = pos + size - 8;
return res;
}
public int ReadInt()
{
int value =
(contents[pos + 3] +
(contents[pos + 2] << 8) +
(contents[pos + 1] << 16) +
(contents[pos + 0] << 24));
pos += 4;
return value;
}
public uint ReadUInt()
{
uint value =
((uint)contents[pos + 3] +
((uint)contents[pos + 2] << 8) +
((uint)contents[pos + 1] << 16) +
((uint)contents[pos + 0] << 24));
pos += 4;
return value;
}
}
internal class DBHDR : IDisposable
{
private long lenOffs;
private MemoryStream stream;
public DBHDR(MemoryStream stream, string name)
{
this.stream = stream;
lenOffs = stream.Position;
Write(0);
Write(name);
}
public void Dispose()
{
long fin = stream.Position;
stream.Position = lenOffs;
Write((int)(fin - lenOffs));
stream.Position = fin;
}
public void Write(int value)
{
byte[] temp = new byte[4];
temp[3] = (byte)(value & 0xff);
temp[2] = (byte)((value >> 8) & 0xff);
temp[1] = (byte)((value >> 16) & 0xff);
temp[0] = (byte)((value >> 24) & 0xff);
Write(temp);
}
public void Write(uint value)
{
byte[] temp = new byte[4];
temp[3] = (byte)(value & 0xff);
temp[2] = (byte)((value >> 8) & 0xff);
temp[1] = (byte)((value >> 16) & 0xff);
temp[0] = (byte)((value >> 24) & 0xff);
Write(temp);
}
public void Write(string value)
{
Write(Encoding.UTF8.GetBytes(value));
}
public void Write(byte[] value)
{
stream.Write(value, 0, value.Length);
}
public DBHDR HDR(string name)
{
return new DBHDR(stream, name);
}
}
[Serializable]
public class CTDBResponseEntry
{
[XmlAttribute]
public string id { get; set; }
[XmlAttribute]
public string crc32 { get; set; }
[XmlAttribute]
public int confidence { get; set; }
[XmlAttribute]
public int npar { get; set; }
[XmlAttribute]
public int stride { get; set; }
[XmlAttribute]
public string hasparity { get; set; }
[XmlAttribute]
public string parity { get; set; }
[XmlAttribute]
public string toc { get; set; }
}
[Serializable]
public class CTDBResponseMetaTrack
{
[XmlAttribute]
public string name { get; set; }
[XmlAttribute]
public string artist { get; set; }
[XmlAttribute]
public string extra { get; set; }
}
[Serializable]
public class CTDBResponseMetaLabel
{
[XmlAttribute]
public string name { get; set; }
[XmlAttribute]
public string catno { get; set; }
}
[Serializable]
public class CTDBResponseMeta
{
[XmlAttribute]
public string source { get; set; }
[XmlAttribute]
public string id { get; set; }
[XmlAttribute]
public string artist { get; set; }
[XmlAttribute]
public string album { get; set; }
[XmlAttribute]
public string year { get; set; }
[XmlAttribute]
public string genre { get; set; }
[XmlAttribute]
public string extra { get; set; }
[XmlAttribute]
public string country { get; set; }
[XmlAttribute]
public string releasedate { get; set; }
[XmlAttribute]
public string discnumber { get; set; }
[XmlAttribute]
public string disccount { get; set; }
[XmlAttribute]
public string discname { get; set; }
[XmlAttribute]
public string coverarturl { get; set; }
[XmlAttribute]
public string infourl { get; set; }
[XmlAttribute]
public string barcode { get; set; }
[XmlElement]
public CTDBResponseMetaTrack[] track;
[XmlElement]
public CTDBResponseMetaLabel[] label;
}
[Serializable]
[XmlRoot(ElementName="ctdb", Namespace="http://db.cuetools.net/ns/mmd-1.0#")]
public class CTDBResponse
{
[XmlElement]
public CTDBResponseEntry[] entry;
[XmlElement]
public CTDBResponseMeta[] musicbrainz;
}
public enum CTDBMetadataSearch
{
None = 0,
Fast = 1,
Default = 2,
Extensive = 3
}
}

59
CUETools.CTDB/DBEntry.cs Normal file
View File

@@ -0,0 +1,59 @@
using System.Net;
using CUETools.AccurateRip;
using CUETools.CDImage;
namespace CUETools.CTDB
{
public class DBEntry
{
public byte[] parity;
public int pos;
public int len;
public int conf;
public int npar;
public int stride;
public int offset;
public uint crc;
public bool hasErrors;
public bool canRecover;
public CDRepairFix repair;
public HttpStatusCode httpStatus;
public string id;
public CDImageLayout toc;
public string hasParity;
public DBEntry(byte[] parity, int pos, int len, int conf, int npar, int stride, uint crc, string id, CDImageLayout toc, string hasParity)
{
this.parity = parity;
this.id = id;
this.pos = pos;
this.len = len;
this.conf = conf;
this.crc = crc;
this.npar = npar;
this.stride = stride;
this.toc = toc;
this.hasParity = hasParity;
}
public string Status
{
get
{
if (!hasErrors)
{
return string.Format("verified OK, confidence {0}", conf);
}
if (canRecover)
{
return string.Format("differs in {1} samples, confidence {0}", conf, repair.CorrectableErrors);
}
if (httpStatus == HttpStatusCode.OK)
{
return "could not be verified";
}
return "could not be verified: " + httpStatus.ToString();
}
}
}
}

63
CUETools.CTDB/DBHDR.cs Normal file
View File

@@ -0,0 +1,63 @@
using System;
using System.IO;
using System.Text;
namespace CUETools.CTDB
{
class DBHDR : IDisposable
{
private long lenOffs;
private MemoryStream stream;
public DBHDR(MemoryStream stream, string name)
{
this.stream = stream;
lenOffs = stream.Position;
Write(0);
Write(name);
}
public void Dispose()
{
long fin = stream.Position;
stream.Position = lenOffs;
Write((int)(fin - lenOffs));
stream.Position = fin;
}
public void Write(int value)
{
byte[] temp = new byte[4];
temp[3] = (byte)(value & 0xff);
temp[2] = (byte)((value >> 8) & 0xff);
temp[1] = (byte)((value >> 16) & 0xff);
temp[0] = (byte)((value >> 24) & 0xff);
Write(temp);
}
public void Write(uint value)
{
byte[] temp = new byte[4];
temp[3] = (byte)(value & 0xff);
temp[2] = (byte)((value >> 8) & 0xff);
temp[1] = (byte)((value >> 16) & 0xff);
temp[0] = (byte)((value >> 24) & 0xff);
Write(temp);
}
public void Write(string value)
{
Write(Encoding.UTF8.GetBytes(value));
}
public void Write(byte[] value)
{
stream.Write(value, 0, value.Length);
}
public DBHDR HDR(string name)
{
return new DBHDR(stream, name);
}
}
}

47
CUETools.CTDB/ReadDB.cs Normal file
View File

@@ -0,0 +1,47 @@
using System.Text;
namespace CUETools.CTDB
{
class ReadDB
{
private byte[] contents;
public int pos;
public ReadDB(byte[] contents)
{
this.contents = contents;
this.pos = 0;
}
public string ReadHDR(out int end)
{
int size = this.ReadInt();
string res = Encoding.ASCII.GetString(contents, pos, 4);
this.pos += 4;
end = pos + size - 8;
return res;
}
public int ReadInt()
{
int value =
(this.contents[this.pos + 3] +
(this.contents[this.pos + 2] << 8) +
(this.contents[this.pos + 1] << 16) +
(this.contents[this.pos + 0] << 24));
this.pos += 4;
return value;
}
public uint ReadUInt()
{
uint value =
((uint)this.contents[this.pos + 3] +
((uint)this.contents[this.pos + 2] << 8) +
((uint)this.contents[this.pos + 1] << 16) +
((uint)this.contents[this.pos + 0] << 24));
this.pos += 4;
return value;
}
}
}