mirror of
https://github.com/claunia/apprepodbmgr.git
synced 2025-12-16 19:24:42 +00:00
Refactor: Separate engine code from GUI.
This commit is contained in:
20
osrepodbmgr.Core/ChangeLog
Normal file
20
osrepodbmgr.Core/ChangeLog
Normal file
@@ -0,0 +1,20 @@
|
||||
2017-05-10 Natalia Portillo <claunia@claunia.com>
|
||||
|
||||
* Core.cs:
|
||||
* DBOps.cs:
|
||||
* SQLite.cs:
|
||||
* DBCore.cs:
|
||||
* Schema.cs:
|
||||
* DicCore.cs:
|
||||
* Context.cs:
|
||||
* Settings.cs:
|
||||
* Checksum.cs:
|
||||
* DetectOS.cs:
|
||||
* PlatformID.cs:
|
||||
* PluginBase.cs:
|
||||
* packages.config:
|
||||
* DetectImageFormat.cs:
|
||||
* osrepodbmgr.Core.csproj:
|
||||
* Properties/AssemblyInfo.cs:
|
||||
Refactor: Separate engine code from GUI.
|
||||
|
||||
529
osrepodbmgr.Core/Checksum.cs
Normal file
529
osrepodbmgr.Core/Checksum.cs
Normal file
@@ -0,0 +1,529 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Checksum.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Core methods.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Methods to checksum data.
|
||||
//
|
||||
// --[ 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/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2016 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using DiscImageChef.Checksums;
|
||||
using Schemas;
|
||||
|
||||
namespace osrepodbmgr.Core
|
||||
{
|
||||
class Checksum
|
||||
{
|
||||
Adler32Context adler32ctx;
|
||||
CRC16Context crc16ctx;
|
||||
CRC32Context crc32ctx;
|
||||
CRC64Context crc64ctx;
|
||||
MD5Context md5ctx;
|
||||
RIPEMD160Context ripemd160ctx;
|
||||
SHA1Context sha1ctx;
|
||||
SHA256Context sha256ctx;
|
||||
SHA384Context sha384ctx;
|
||||
SHA512Context sha512ctx;
|
||||
SpamSumContext ssctx;
|
||||
|
||||
Thread adlerThread;
|
||||
Thread crc16Thread;
|
||||
Thread crc32Thread;
|
||||
Thread crc64Thread;
|
||||
Thread md5Thread;
|
||||
Thread ripemd160Thread;
|
||||
Thread sha1Thread;
|
||||
Thread sha256Thread;
|
||||
Thread sha384Thread;
|
||||
Thread sha512Thread;
|
||||
Thread spamsumThread;
|
||||
|
||||
adlerPacket adlerPkt;
|
||||
crc16Packet crc16Pkt;
|
||||
crc32Packet crc32Pkt;
|
||||
crc64Packet crc64Pkt;
|
||||
md5Packet md5Pkt;
|
||||
ripemd160Packet ripemd160Pkt;
|
||||
sha1Packet sha1Pkt;
|
||||
sha256Packet sha256Pkt;
|
||||
sha384Packet sha384Pkt;
|
||||
sha512Packet sha512Pkt;
|
||||
spamsumPacket spamsumPkt;
|
||||
|
||||
internal Checksum()
|
||||
{
|
||||
adler32ctx = new Adler32Context();
|
||||
crc16ctx = new CRC16Context();
|
||||
crc32ctx = new CRC32Context();
|
||||
crc64ctx = new CRC64Context();
|
||||
md5ctx = new MD5Context();
|
||||
ripemd160ctx = new RIPEMD160Context();
|
||||
sha1ctx = new SHA1Context();
|
||||
sha256ctx = new SHA256Context();
|
||||
sha384ctx = new SHA384Context();
|
||||
sha512ctx = new SHA512Context();
|
||||
ssctx = new SpamSumContext();
|
||||
|
||||
adlerThread = new Thread(updateAdler);
|
||||
crc16Thread = new Thread(updateCRC16);
|
||||
crc32Thread = new Thread(updateCRC32);
|
||||
crc64Thread = new Thread(updateCRC64);
|
||||
md5Thread = new Thread(updateMD5);
|
||||
ripemd160Thread = new Thread(updateRIPEMD160);
|
||||
sha1Thread = new Thread(updateSHA1);
|
||||
sha256Thread = new Thread(updateSHA256);
|
||||
sha384Thread = new Thread(updateSHA384);
|
||||
sha512Thread = new Thread(updateSHA512);
|
||||
spamsumThread = new Thread(updateSpamSum);
|
||||
|
||||
adlerPkt = new adlerPacket();
|
||||
crc16Pkt = new crc16Packet();
|
||||
crc32Pkt = new crc32Packet();
|
||||
crc64Pkt = new crc64Packet();
|
||||
md5Pkt = new md5Packet();
|
||||
ripemd160Pkt = new ripemd160Packet();
|
||||
sha1Pkt = new sha1Packet();
|
||||
sha256Pkt = new sha256Packet();
|
||||
sha384Pkt = new sha384Packet();
|
||||
sha512Pkt = new sha512Packet();
|
||||
spamsumPkt = new spamsumPacket();
|
||||
|
||||
adler32ctx.Init();
|
||||
adlerPkt.context = adler32ctx;
|
||||
crc16ctx.Init();
|
||||
crc16Pkt.context = crc16ctx;
|
||||
crc32ctx.Init();
|
||||
crc32Pkt.context = crc32ctx;
|
||||
crc64ctx.Init();
|
||||
crc64Pkt.context = crc64ctx;
|
||||
md5ctx.Init();
|
||||
md5Pkt.context = md5ctx;
|
||||
ripemd160ctx.Init();
|
||||
ripemd160Pkt.context = ripemd160ctx;
|
||||
sha1ctx.Init();
|
||||
sha1Pkt.context = sha1ctx;
|
||||
sha256ctx.Init();
|
||||
sha256Pkt.context = sha256ctx;
|
||||
sha384ctx.Init();
|
||||
sha384Pkt.context = sha384ctx;
|
||||
sha512ctx.Init();
|
||||
sha512Pkt.context = sha512ctx;
|
||||
ssctx.Init();
|
||||
spamsumPkt.context = ssctx;
|
||||
}
|
||||
|
||||
internal void Update(byte[] data)
|
||||
{
|
||||
adlerPkt.data = data;
|
||||
adlerThread.Start(adlerPkt);
|
||||
crc16Pkt.data = data;
|
||||
crc16Thread.Start(crc16Pkt);
|
||||
crc32Pkt.data = data;
|
||||
crc32Thread.Start(crc32Pkt);
|
||||
crc64Pkt.data = data;
|
||||
crc64Thread.Start(crc64Pkt);
|
||||
md5Pkt.data = data;
|
||||
md5Thread.Start(md5Pkt);
|
||||
ripemd160Pkt.data = data;
|
||||
ripemd160Thread.Start(ripemd160Pkt);
|
||||
sha1Pkt.data = data;
|
||||
sha1Thread.Start(sha1Pkt);
|
||||
sha256Pkt.data = data;
|
||||
sha256Thread.Start(sha256Pkt);
|
||||
sha384Pkt.data = data;
|
||||
sha384Thread.Start(sha384Pkt);
|
||||
sha512Pkt.data = data;
|
||||
sha512Thread.Start(sha512Pkt);
|
||||
spamsumPkt.data = data;
|
||||
spamsumThread.Start(spamsumPkt);
|
||||
|
||||
while(adlerThread.IsAlive || crc16Thread.IsAlive ||
|
||||
crc32Thread.IsAlive || crc64Thread.IsAlive ||
|
||||
md5Thread.IsAlive || ripemd160Thread.IsAlive ||
|
||||
sha1Thread.IsAlive || sha256Thread.IsAlive ||
|
||||
sha384Thread.IsAlive || sha512Thread.IsAlive ||
|
||||
spamsumThread.IsAlive)
|
||||
{
|
||||
}
|
||||
|
||||
adlerThread = new Thread(updateAdler);
|
||||
crc16Thread = new Thread(updateCRC16);
|
||||
crc32Thread = new Thread(updateCRC32);
|
||||
crc64Thread = new Thread(updateCRC64);
|
||||
md5Thread = new Thread(updateMD5);
|
||||
ripemd160Thread = new Thread(updateRIPEMD160);
|
||||
sha1Thread = new Thread(updateSHA1);
|
||||
sha256Thread = new Thread(updateSHA256);
|
||||
sha384Thread = new Thread(updateSHA384);
|
||||
sha512Thread = new Thread(updateSHA512);
|
||||
spamsumThread = new Thread(updateSpamSum);
|
||||
}
|
||||
|
||||
internal List<ChecksumType> End()
|
||||
{
|
||||
List<ChecksumType> chks = new List<ChecksumType>();
|
||||
|
||||
ChecksumType chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.adler32;
|
||||
chk.Value = adler32ctx.End();
|
||||
chks.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.crc16;
|
||||
chk.Value = crc16ctx.End();
|
||||
chks.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.crc32;
|
||||
chk.Value = crc32ctx.End();
|
||||
chks.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.crc64;
|
||||
chk.Value = crc64ctx.End();
|
||||
chks.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.md5;
|
||||
chk.Value = md5ctx.End();
|
||||
chks.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.ripemd160;
|
||||
chk.Value = ripemd160ctx.End();
|
||||
chks.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.sha1;
|
||||
chk.Value = sha1ctx.End();
|
||||
chks.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.sha256;
|
||||
chk.Value = sha256ctx.End();
|
||||
chks.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.sha384;
|
||||
chk.Value = sha384ctx.End();
|
||||
chks.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.sha512;
|
||||
chk.Value = sha512ctx.End();
|
||||
chks.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.spamsum;
|
||||
chk.Value = ssctx.End();
|
||||
chks.Add(chk);
|
||||
|
||||
return chks;
|
||||
}
|
||||
|
||||
internal static List<ChecksumType> GetChecksums(byte[] data)
|
||||
{
|
||||
Adler32Context adler32ctxData = new Adler32Context();
|
||||
CRC16Context crc16ctxData = new CRC16Context();
|
||||
CRC32Context crc32ctxData = new CRC32Context();
|
||||
CRC64Context crc64ctxData = new CRC64Context();
|
||||
MD5Context md5ctxData = new MD5Context();
|
||||
RIPEMD160Context ripemd160ctxData = new RIPEMD160Context();
|
||||
SHA1Context sha1ctxData = new SHA1Context();
|
||||
SHA256Context sha256ctxData = new SHA256Context();
|
||||
SHA384Context sha384ctxData = new SHA384Context();
|
||||
SHA512Context sha512ctxData = new SHA512Context();
|
||||
SpamSumContext ssctxData = new SpamSumContext();
|
||||
|
||||
Thread adlerThreadData = new Thread(updateAdler);
|
||||
Thread crc16ThreadData = new Thread(updateCRC16);
|
||||
Thread crc32ThreadData = new Thread(updateCRC32);
|
||||
Thread crc64ThreadData = new Thread(updateCRC64);
|
||||
Thread md5ThreadData = new Thread(updateMD5);
|
||||
Thread ripemd160ThreadData = new Thread(updateRIPEMD160);
|
||||
Thread sha1ThreadData = new Thread(updateSHA1);
|
||||
Thread sha256ThreadData = new Thread(updateSHA256);
|
||||
Thread sha384ThreadData = new Thread(updateSHA384);
|
||||
Thread sha512ThreadData = new Thread(updateSHA512);
|
||||
Thread spamsumThreadData = new Thread(updateSpamSum);
|
||||
|
||||
adlerPacket adlerPktData = new adlerPacket();
|
||||
crc16Packet crc16PktData = new crc16Packet();
|
||||
crc32Packet crc32PktData = new crc32Packet();
|
||||
crc64Packet crc64PktData = new crc64Packet();
|
||||
md5Packet md5PktData = new md5Packet();
|
||||
ripemd160Packet ripemd160PktData = new ripemd160Packet();
|
||||
sha1Packet sha1PktData = new sha1Packet();
|
||||
sha256Packet sha256PktData = new sha256Packet();
|
||||
sha384Packet sha384PktData = new sha384Packet();
|
||||
sha512Packet sha512PktData = new sha512Packet();
|
||||
spamsumPacket spamsumPktData = new spamsumPacket();
|
||||
|
||||
adler32ctxData.Init();
|
||||
adlerPktData.context = adler32ctxData;
|
||||
crc16ctxData.Init();
|
||||
crc16PktData.context = crc16ctxData;
|
||||
crc32ctxData.Init();
|
||||
crc32PktData.context = crc32ctxData;
|
||||
crc64ctxData.Init();
|
||||
crc64PktData.context = crc64ctxData;
|
||||
md5ctxData.Init();
|
||||
md5PktData.context = md5ctxData;
|
||||
ripemd160ctxData.Init();
|
||||
ripemd160PktData.context = ripemd160ctxData;
|
||||
sha1ctxData.Init();
|
||||
sha1PktData.context = sha1ctxData;
|
||||
sha256ctxData.Init();
|
||||
sha256PktData.context = sha256ctxData;
|
||||
sha384ctxData.Init();
|
||||
sha384PktData.context = sha384ctxData;
|
||||
sha512ctxData.Init();
|
||||
sha512PktData.context = sha512ctxData;
|
||||
ssctxData.Init();
|
||||
spamsumPktData.context = ssctxData;
|
||||
|
||||
adlerPktData.data = data;
|
||||
adlerThreadData.Start(adlerPktData);
|
||||
crc16PktData.data = data;
|
||||
crc16ThreadData.Start(crc16PktData);
|
||||
crc32PktData.data = data;
|
||||
crc32ThreadData.Start(crc32PktData);
|
||||
crc64PktData.data = data;
|
||||
crc64ThreadData.Start(crc64PktData);
|
||||
md5PktData.data = data;
|
||||
md5ThreadData.Start(md5PktData);
|
||||
ripemd160PktData.data = data;
|
||||
ripemd160ThreadData.Start(ripemd160PktData);
|
||||
sha1PktData.data = data;
|
||||
sha1ThreadData.Start(sha1PktData);
|
||||
sha256PktData.data = data;
|
||||
sha256ThreadData.Start(sha256PktData);
|
||||
sha384PktData.data = data;
|
||||
sha384ThreadData.Start(sha384PktData);
|
||||
sha512PktData.data = data;
|
||||
sha512ThreadData.Start(sha512PktData);
|
||||
spamsumPktData.data = data;
|
||||
spamsumThreadData.Start(spamsumPktData);
|
||||
|
||||
while(adlerThreadData.IsAlive || crc16ThreadData.IsAlive ||
|
||||
crc32ThreadData.IsAlive || crc64ThreadData.IsAlive ||
|
||||
md5ThreadData.IsAlive || ripemd160ThreadData.IsAlive ||
|
||||
sha1ThreadData.IsAlive || sha256ThreadData.IsAlive ||
|
||||
sha384ThreadData.IsAlive || sha512ThreadData.IsAlive ||
|
||||
spamsumThreadData.IsAlive)
|
||||
{
|
||||
}
|
||||
|
||||
List<ChecksumType> dataChecksums = new List<ChecksumType>();
|
||||
ChecksumType chk;
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.adler32;
|
||||
chk.Value = adler32ctxData.End();
|
||||
dataChecksums.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.crc16;
|
||||
chk.Value = crc16ctxData.End();
|
||||
dataChecksums.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.crc32;
|
||||
chk.Value = crc32ctxData.End();
|
||||
dataChecksums.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.crc64;
|
||||
chk.Value = crc64ctxData.End();
|
||||
dataChecksums.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.md5;
|
||||
chk.Value = md5ctxData.End();
|
||||
dataChecksums.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.ripemd160;
|
||||
chk.Value = ripemd160ctxData.End();
|
||||
dataChecksums.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.sha1;
|
||||
chk.Value = sha1ctxData.End();
|
||||
dataChecksums.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.sha256;
|
||||
chk.Value = sha256ctxData.End();
|
||||
dataChecksums.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.sha384;
|
||||
chk.Value = sha384ctxData.End();
|
||||
dataChecksums.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.sha512;
|
||||
chk.Value = sha512ctxData.End();
|
||||
dataChecksums.Add(chk);
|
||||
|
||||
chk = new ChecksumType();
|
||||
chk.type = ChecksumTypeType.spamsum;
|
||||
chk.Value = ssctxData.End();
|
||||
dataChecksums.Add(chk);
|
||||
|
||||
return dataChecksums;
|
||||
}
|
||||
|
||||
#region Threading helpers
|
||||
|
||||
struct adlerPacket
|
||||
{
|
||||
public Adler32Context context;
|
||||
public byte[] data;
|
||||
}
|
||||
|
||||
struct crc16Packet
|
||||
{
|
||||
public CRC16Context context;
|
||||
public byte[] data;
|
||||
}
|
||||
|
||||
struct crc32Packet
|
||||
{
|
||||
public CRC32Context context;
|
||||
public byte[] data;
|
||||
}
|
||||
|
||||
struct crc64Packet
|
||||
{
|
||||
public CRC64Context context;
|
||||
public byte[] data;
|
||||
}
|
||||
|
||||
struct md5Packet
|
||||
{
|
||||
public MD5Context context;
|
||||
public byte[] data;
|
||||
}
|
||||
|
||||
struct ripemd160Packet
|
||||
{
|
||||
public RIPEMD160Context context;
|
||||
public byte[] data;
|
||||
}
|
||||
|
||||
struct sha1Packet
|
||||
{
|
||||
public SHA1Context context;
|
||||
public byte[] data;
|
||||
}
|
||||
|
||||
struct sha256Packet
|
||||
{
|
||||
public SHA256Context context;
|
||||
public byte[] data;
|
||||
}
|
||||
|
||||
struct sha384Packet
|
||||
{
|
||||
public SHA384Context context;
|
||||
public byte[] data;
|
||||
}
|
||||
|
||||
struct sha512Packet
|
||||
{
|
||||
public SHA512Context context;
|
||||
public byte[] data;
|
||||
}
|
||||
|
||||
struct spamsumPacket
|
||||
{
|
||||
public SpamSumContext context;
|
||||
public byte[] data;
|
||||
}
|
||||
|
||||
static void updateAdler(object packet)
|
||||
{
|
||||
((adlerPacket)packet).context.Update(((adlerPacket)packet).data);
|
||||
}
|
||||
|
||||
static void updateCRC16(object packet)
|
||||
{
|
||||
((crc16Packet)packet).context.Update(((crc16Packet)packet).data);
|
||||
}
|
||||
|
||||
static void updateCRC32(object packet)
|
||||
{
|
||||
((crc32Packet)packet).context.Update(((crc32Packet)packet).data);
|
||||
}
|
||||
|
||||
static void updateCRC64(object packet)
|
||||
{
|
||||
((crc64Packet)packet).context.Update(((crc64Packet)packet).data);
|
||||
}
|
||||
|
||||
static void updateMD5(object packet)
|
||||
{
|
||||
((md5Packet)packet).context.Update(((md5Packet)packet).data);
|
||||
}
|
||||
|
||||
static void updateRIPEMD160(object packet)
|
||||
{
|
||||
((ripemd160Packet)packet).context.Update(((ripemd160Packet)packet).data);
|
||||
}
|
||||
|
||||
static void updateSHA1(object packet)
|
||||
{
|
||||
((sha1Packet)packet).context.Update(((sha1Packet)packet).data);
|
||||
}
|
||||
|
||||
static void updateSHA256(object packet)
|
||||
{
|
||||
((sha256Packet)packet).context.Update(((sha256Packet)packet).data);
|
||||
}
|
||||
|
||||
static void updateSHA384(object packet)
|
||||
{
|
||||
((sha384Packet)packet).context.Update(((sha384Packet)packet).data);
|
||||
}
|
||||
|
||||
static void updateSHA512(object packet)
|
||||
{
|
||||
((sha512Packet)packet).context.Update(((sha512Packet)packet).data);
|
||||
}
|
||||
|
||||
static void updateSpamSum(object packet)
|
||||
{
|
||||
((spamsumPacket)packet).context.Update(((spamsumPacket)packet).data);
|
||||
}
|
||||
|
||||
#endregion Threading helpers
|
||||
}
|
||||
}
|
||||
|
||||
83
osrepodbmgr.Core/Context.cs
Normal file
83
osrepodbmgr.Core/Context.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo claunia@claunia.com
|
||||
//
|
||||
// Copyright (c) 2017, © Claunia.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the [ORGANIZATION] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using Schemas;
|
||||
|
||||
namespace osrepodbmgr.Core
|
||||
{
|
||||
public static class Context
|
||||
{
|
||||
public static List<string> files;
|
||||
public static Dictionary<string, DBFile> hashes;
|
||||
public static string path;
|
||||
public static DBEntry dbInfo;
|
||||
public static bool unarUsable;
|
||||
public static string tmpFolder;
|
||||
public static long noFilesInArchive;
|
||||
public static string archiveFormat;
|
||||
public static Process unarProcess;
|
||||
public static bool copyArchive;
|
||||
public static string selectedFile;
|
||||
public static OpticalDiscType workingDisc;
|
||||
public static BlockMediaType workingDisk;
|
||||
public static CICMMetadataType metadata;
|
||||
|
||||
public delegate void UnarChangeStatusDelegate();
|
||||
public static event UnarChangeStatusDelegate UnarChangeStatus;
|
||||
|
||||
public static void CheckUnar()
|
||||
{
|
||||
Core.Finished += CheckUnarFinished;
|
||||
Core.Failed += CheckUnarFailed;
|
||||
|
||||
Thread thdCheckUnar = new Thread(Core.CheckUnar);
|
||||
thdCheckUnar.Start();
|
||||
}
|
||||
|
||||
static void CheckUnarFinished()
|
||||
{
|
||||
unarUsable = true;
|
||||
if(UnarChangeStatus != null)
|
||||
UnarChangeStatus();
|
||||
Core.Finished -= CheckUnarFinished;
|
||||
Core.Failed -= CheckUnarFailed;
|
||||
}
|
||||
|
||||
static void CheckUnarFailed(string text)
|
||||
{
|
||||
unarUsable = false;
|
||||
if(UnarChangeStatus != null)
|
||||
UnarChangeStatus();
|
||||
Core.Finished -= CheckUnarFinished;
|
||||
Core.Failed -= CheckUnarFailed;
|
||||
}
|
||||
}
|
||||
}
|
||||
1360
osrepodbmgr.Core/Core.cs
Normal file
1360
osrepodbmgr.Core/Core.cs
Normal file
File diff suppressed because it is too large
Load Diff
49
osrepodbmgr.Core/DBCore.cs
Normal file
49
osrepodbmgr.Core/DBCore.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo claunia@claunia.com
|
||||
//
|
||||
// Copyright (c) 2017, © Claunia.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the [ORGANIZATION] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
using System.Data;
|
||||
|
||||
namespace osrepodbmgr.Core
|
||||
{
|
||||
public abstract class DBCore
|
||||
{
|
||||
public abstract bool OpenDB(string database, string server, string user, string password);
|
||||
|
||||
public abstract void CloseDB();
|
||||
|
||||
public abstract bool CreateDB(string database, string server, string user, string password);
|
||||
|
||||
public DBOps DBOps;
|
||||
|
||||
public abstract IDbDataAdapter GetNewDataAdapter();
|
||||
|
||||
public abstract long LastInsertRowId
|
||||
{
|
||||
get;
|
||||
}
|
||||
}
|
||||
}
|
||||
404
osrepodbmgr.Core/DBOps.cs
Normal file
404
osrepodbmgr.Core/DBOps.cs
Normal file
@@ -0,0 +1,404 @@
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo claunia@claunia.com
|
||||
//
|
||||
// Copyright (c) 2017, © Claunia.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the [ORGANIZATION] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
|
||||
namespace osrepodbmgr.Core
|
||||
{
|
||||
public struct DBEntry
|
||||
{
|
||||
public long id;
|
||||
public string developer;
|
||||
public string product;
|
||||
public string version;
|
||||
public string languages;
|
||||
public string architecture;
|
||||
public string machine;
|
||||
public string format;
|
||||
public string description;
|
||||
public bool oem;
|
||||
public bool upgrade;
|
||||
public bool update;
|
||||
public bool source;
|
||||
public bool files;
|
||||
public bool netinstall;
|
||||
public byte[] xml;
|
||||
public byte[] json;
|
||||
}
|
||||
|
||||
public struct DBFile
|
||||
{
|
||||
public ulong Id;
|
||||
public string Path;
|
||||
public string Sha256;
|
||||
public long Length;
|
||||
public DateTime CreationTimeUtc;
|
||||
public DateTime LastAccessTimeUtc;
|
||||
public DateTime LastWriteTimeUtc;
|
||||
public FileAttributes Attributes;
|
||||
}
|
||||
|
||||
public class DBOps
|
||||
{
|
||||
readonly IDbConnection dbCon;
|
||||
readonly DBCore dbCore;
|
||||
|
||||
public DBOps(IDbConnection connection, DBCore core)
|
||||
{
|
||||
dbCon = connection;
|
||||
dbCore = core;
|
||||
}
|
||||
|
||||
public bool GetAllOSes(out List<DBEntry> entries)
|
||||
{
|
||||
entries = new List<DBEntry>();
|
||||
|
||||
const string sql = "SELECT * from oses";
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbcmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbcmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
DataTable dataTable = dataSet.Tables[0];
|
||||
|
||||
foreach(DataRow dRow in dataTable.Rows)
|
||||
{
|
||||
DBEntry fEntry = new DBEntry();
|
||||
fEntry.id = long.Parse(dRow["id"].ToString());
|
||||
fEntry.developer = dRow["developer"].ToString();
|
||||
fEntry.product = dRow["product"].ToString();
|
||||
fEntry.version = dRow["version"].ToString();
|
||||
fEntry.languages = dRow["languages"].ToString();
|
||||
fEntry.architecture = dRow["architecture"].ToString();
|
||||
fEntry.machine = dRow["machine"].ToString();
|
||||
fEntry.format = dRow["format"].ToString();
|
||||
fEntry.description = dRow["description"].ToString();
|
||||
fEntry.oem = bool.Parse(dRow["oem"].ToString());
|
||||
fEntry.upgrade = bool.Parse(dRow["upgrade"].ToString());
|
||||
fEntry.update = bool.Parse(dRow["update"].ToString());
|
||||
fEntry.source = bool.Parse(dRow["source"].ToString());
|
||||
fEntry.files = bool.Parse(dRow["files"].ToString());
|
||||
fEntry.netinstall = bool.Parse(dRow["netinstall"].ToString());
|
||||
|
||||
if(dRow["xml"] != DBNull.Value)
|
||||
fEntry.xml = (byte[])dRow["xml"];
|
||||
if(dRow["json"] != DBNull.Value)
|
||||
fEntry.json = (byte[])dRow["json"];
|
||||
entries.Add(fEntry);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetOSCommand(DBEntry entry)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param3 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param4 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param5 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param6 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param7 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param8 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param9 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param10 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param11 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param12 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param13 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param14 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param15 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param16 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@developer";
|
||||
param2.ParameterName = "@product";
|
||||
param3.ParameterName = "@version";
|
||||
param4.ParameterName = "@languages";
|
||||
param5.ParameterName = "@architecture";
|
||||
param6.ParameterName = "@machine";
|
||||
param7.ParameterName = "@format";
|
||||
param8.ParameterName = "@description";
|
||||
param9.ParameterName = "@oem";
|
||||
param10.ParameterName = "@upgrade";
|
||||
param11.ParameterName = "@update";
|
||||
param12.ParameterName = "@source";
|
||||
param13.ParameterName = "@files";
|
||||
param14.ParameterName = "@netinstall";
|
||||
param15.ParameterName = "@xml";
|
||||
param16.ParameterName = "@json";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
param2.DbType = DbType.String;
|
||||
param3.DbType = DbType.String;
|
||||
param4.DbType = DbType.String;
|
||||
param5.DbType = DbType.String;
|
||||
param7.DbType = DbType.String;
|
||||
param8.DbType = DbType.String;
|
||||
param9.DbType = DbType.Boolean;
|
||||
param10.DbType = DbType.Boolean;
|
||||
param11.DbType = DbType.Boolean;
|
||||
param12.DbType = DbType.Boolean;
|
||||
param13.DbType = DbType.Boolean;
|
||||
param14.DbType = DbType.Boolean;
|
||||
param15.DbType = DbType.Object;
|
||||
param16.DbType = DbType.Object;
|
||||
|
||||
param1.Value = entry.developer;
|
||||
param2.Value = entry.product;
|
||||
param3.Value = entry.version;
|
||||
param4.Value = entry.languages;
|
||||
param5.Value = entry.architecture;
|
||||
param6.Value = entry.machine;
|
||||
param7.Value = entry.format;
|
||||
param8.Value = entry.description;
|
||||
param9.Value = entry.oem;
|
||||
param10.Value = entry.upgrade;
|
||||
param11.Value = entry.update;
|
||||
param12.Value = entry.source;
|
||||
param13.Value = entry.files;
|
||||
param14.Value = entry.netinstall;
|
||||
param15.Value = entry.xml;
|
||||
param16.Value = entry.json;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
dbcmd.Parameters.Add(param3);
|
||||
dbcmd.Parameters.Add(param4);
|
||||
dbcmd.Parameters.Add(param5);
|
||||
dbcmd.Parameters.Add(param6);
|
||||
dbcmd.Parameters.Add(param7);
|
||||
dbcmd.Parameters.Add(param8);
|
||||
dbcmd.Parameters.Add(param9);
|
||||
dbcmd.Parameters.Add(param10);
|
||||
dbcmd.Parameters.Add(param11);
|
||||
dbcmd.Parameters.Add(param12);
|
||||
dbcmd.Parameters.Add(param13);
|
||||
dbcmd.Parameters.Add(param14);
|
||||
dbcmd.Parameters.Add(param15);
|
||||
dbcmd.Parameters.Add(param16);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
public bool AddOS(DBEntry entry, out long id)
|
||||
{
|
||||
IDbCommand dbcmd = GetOSCommand(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string sql = "INSERT INTO oses (developer, product, version, languages, architecture, machine, format, description, oem, upgrade, `update`, source, files, netinstall, xml, json)" +
|
||||
" VALUES (@developer, @product, @version, @languages, @architecture, @machine, @format, @description, @oem, @upgrade, @update, @source, @files, @netinstall, @xml, @json)";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
id = dbCore.LastInsertRowId;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AddFile(string hash)
|
||||
{
|
||||
//Console.WriteLine("Adding {0}", hash);
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@hash";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
|
||||
param1.Value = hash;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string sql = "INSERT INTO files (sha256) VALUES (@hash)";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ExistsFile(string hash)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@hash";
|
||||
param1.DbType = DbType.String;
|
||||
param1.Value = hash;
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.CommandText = "SELECT * FROM files WHERE sha256 = @hash";
|
||||
DataSet dataSet = new DataSet();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dataAdapter.SelectCommand = dbcmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
DataTable dataTable = dataSet.Tables[0];
|
||||
|
||||
foreach(DataRow dRow in dataTable.Rows)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
IDbCommand GetFileCommand(DBFile person)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param3 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param4 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param5 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param6 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param7 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@path";
|
||||
param2.ParameterName = "@sha256";
|
||||
param3.ParameterName = "@length";
|
||||
param4.ParameterName = "@creation";
|
||||
param5.ParameterName = "@access";
|
||||
param6.ParameterName = "@modification";
|
||||
param7.ParameterName = "@attributes";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
param2.DbType = DbType.String;
|
||||
param3.DbType = DbType.String;
|
||||
param4.DbType = DbType.String;
|
||||
param5.DbType = DbType.String;
|
||||
param6.DbType = DbType.String;
|
||||
param7.DbType = DbType.Int32;
|
||||
|
||||
param1.Value = person.Path;
|
||||
param2.Value = person.Sha256;
|
||||
param3.Value = person.Length;
|
||||
param4.Value = person.CreationTimeUtc.ToString("yyyy-MM-dd HH:mm");
|
||||
param5.Value = person.LastAccessTimeUtc.ToString("yyyy-MM-dd HH:mm");
|
||||
param6.Value = person.LastWriteTimeUtc.ToString("yyyy-MM-dd HH:mm");
|
||||
param7.Value = (int)person.Attributes;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
dbcmd.Parameters.Add(param3);
|
||||
dbcmd.Parameters.Add(param4);
|
||||
dbcmd.Parameters.Add(param5);
|
||||
dbcmd.Parameters.Add(param6);
|
||||
dbcmd.Parameters.Add(param7);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
public bool AddFileToOS(DBFile file, long os)
|
||||
{
|
||||
IDbCommand dbcmd = GetFileCommand(file);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = string.Format("INSERT INTO `os_{0}` (`path`, `sha256`, `length`, `creation`, `access`, `modification`, `attributes`)" +
|
||||
" VALUES (@path, @sha256, @length, @creation, @access, @modification, @attributes)", os);
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public bool CreateTableForOS(long id)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = string.Format("DROP TABLE IF EXISTS `os_{0}`;\n\n" +
|
||||
"CREATE TABLE IF NOT EXISTS `os_{0}` (\n" +
|
||||
" `id` INTEGER PRIMARY KEY AUTOINCREMENT,\n" +
|
||||
" `path` VARCHAR(8192) NOT NULL,\n" +
|
||||
" `sha256` VARCHAR(64) NOT NULL,\n\n" +
|
||||
" `length` BIGINT NOT NULL,\n" +
|
||||
" `creation` DATETIME NULL,\n" +
|
||||
" `access` DATETIME NULL,\n" +
|
||||
" `modification` DATETIME NULL,\n" +
|
||||
" `attributes` INTEGER NULL);\n\n" +
|
||||
"CREATE UNIQUE INDEX `os_{0}_id_UNIQUE` ON `os_{0}` (`id` ASC);\n\n" +
|
||||
"CREATE INDEX `os_{0}_path_idx` ON `os_{0}` (`path` ASC);", id);
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ExistsFileInOS(string hash, long osId)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@hash";
|
||||
param1.DbType = DbType.String;
|
||||
param1.Value = hash;
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.CommandText = string.Format("SELECT * FROM `os_{0}` WHERE sha256 = @hash", osId);
|
||||
DataSet dataSet = new DataSet();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dataAdapter.SelectCommand = dbcmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
DataTable dataTable = dataSet.Tables[0];
|
||||
|
||||
foreach(DataRow dRow in dataTable.Rows)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
109
osrepodbmgr.Core/DetectImageFormat.cs
Normal file
109
osrepodbmgr.Core/DetectImageFormat.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : DetectImageFormat.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Main program loop.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Detects disc image format.
|
||||
//
|
||||
// --[ 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/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2016 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
using System;
|
||||
using DiscImageChef.Filters;
|
||||
using DiscImageChef.ImagePlugins;
|
||||
|
||||
namespace osrepodbmgr.Core
|
||||
{
|
||||
public static class ImageFormat
|
||||
{
|
||||
public static ImagePlugin Detect(Filter imageFilter)
|
||||
{
|
||||
try
|
||||
{
|
||||
ImagePlugin _imageFormat;
|
||||
PluginBase plugins = new PluginBase();
|
||||
plugins.RegisterAllPlugins();
|
||||
|
||||
_imageFormat = null;
|
||||
|
||||
// Check all but RAW plugin
|
||||
foreach(ImagePlugin _imageplugin in plugins.ImagePluginsList.Values)
|
||||
{
|
||||
if(_imageplugin.PluginUUID != new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_imageplugin.IdentifyImage(imageFilter))
|
||||
{
|
||||
_imageFormat = _imageplugin;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||
catch
|
||||
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check only RAW plugin
|
||||
if(_imageFormat == null)
|
||||
{
|
||||
foreach(ImagePlugin _imageplugin in plugins.ImagePluginsList.Values)
|
||||
{
|
||||
if(_imageplugin.PluginUUID == new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_imageplugin.IdentifyImage(imageFilter))
|
||||
{
|
||||
_imageFormat = _imageplugin;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||
catch
|
||||
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Still not recognized
|
||||
if(_imageFormat == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _imageFormat;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
217
osrepodbmgr.Core/DetectOS.cs
Normal file
217
osrepodbmgr.Core/DetectOS.cs
Normal file
@@ -0,0 +1,217 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : DetectOS.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Interop services.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Detects underlying operating system.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2016 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DiscImageChef.Interop
|
||||
{
|
||||
public static class DetectOS
|
||||
{
|
||||
/// <summary>
|
||||
/// POSIX uname structure, size from OSX, big enough to handle extra fields
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
struct utsname
|
||||
{
|
||||
/// <summary>
|
||||
/// System name
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||
public string sysname;
|
||||
/// <summary>
|
||||
/// Node name
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||
public string nodename;
|
||||
/// <summary>
|
||||
/// Release level
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||
public string release;
|
||||
/// <summary>
|
||||
/// Version level
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||
public string version;
|
||||
/// <summary>
|
||||
/// Hardware level
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||
public string machine;
|
||||
}
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
static extern int uname(out utsname name);
|
||||
|
||||
[DllImport("libc", SetLastError = true, EntryPoint = "sysctlbyname", CharSet = CharSet.Ansi)]
|
||||
static extern int OSX_sysctlbyname(string name, IntPtr oldp, IntPtr oldlenp, IntPtr newp, uint newlen);
|
||||
|
||||
public static PlatformID GetRealPlatformID()
|
||||
{
|
||||
if((int)Environment.OSVersion.Platform < 4 ||
|
||||
(int)Environment.OSVersion.Platform == 5)
|
||||
{
|
||||
return (PlatformID)((int)Environment.OSVersion.Platform);
|
||||
}
|
||||
|
||||
utsname unixname;
|
||||
int error = uname(out unixname);
|
||||
if(error != 0)
|
||||
throw new Exception(string.Format("Unhandled exception calling uname: {0}", Marshal.GetLastWin32Error()));
|
||||
|
||||
switch(unixname.sysname)
|
||||
{
|
||||
// TODO: Differentiate Linux, Android, Tizen
|
||||
case "Linux":
|
||||
{
|
||||
#if __ANDROID__
|
||||
return PlatformID.Android;
|
||||
#else
|
||||
return PlatformID.Linux;
|
||||
#endif
|
||||
}
|
||||
case "Darwin":
|
||||
{
|
||||
int osx_error;
|
||||
|
||||
IntPtr pLen = Marshal.AllocHGlobal(sizeof(int));
|
||||
osx_error = OSX_sysctlbyname("hw.machine", IntPtr.Zero, pLen, IntPtr.Zero, 0);
|
||||
if(osx_error != 0)
|
||||
{
|
||||
Marshal.FreeHGlobal(pLen);
|
||||
|
||||
throw new Exception(string.Format("Unhandled exception calling uname: {0}", Marshal.GetLastWin32Error()));
|
||||
}
|
||||
|
||||
int length = Marshal.ReadInt32(pLen);
|
||||
IntPtr pStr = Marshal.AllocHGlobal(length);
|
||||
osx_error = OSX_sysctlbyname("hw.machine", pStr, pLen, IntPtr.Zero, 0);
|
||||
if(osx_error != 0)
|
||||
{
|
||||
Marshal.FreeHGlobal(pStr);
|
||||
Marshal.FreeHGlobal(pLen);
|
||||
|
||||
throw new Exception(string.Format("Unhandled exception calling uname: {0}", Marshal.GetLastWin32Error()));
|
||||
}
|
||||
|
||||
string machine = Marshal.PtrToStringAnsi(pStr);
|
||||
|
||||
Marshal.FreeHGlobal(pStr);
|
||||
Marshal.FreeHGlobal(pLen);
|
||||
|
||||
if(machine.StartsWith("iPad", StringComparison.Ordinal) ||
|
||||
machine.StartsWith("iPod", StringComparison.Ordinal) ||
|
||||
machine.StartsWith("iPhone", StringComparison.Ordinal))
|
||||
return PlatformID.iOS;
|
||||
|
||||
return PlatformID.MacOSX;
|
||||
}
|
||||
case "GNU":
|
||||
return PlatformID.Hurd;
|
||||
case "FreeBSD":
|
||||
case "GNU/kFreeBSD":
|
||||
return PlatformID.FreeBSD;
|
||||
case "DragonFly":
|
||||
return PlatformID.DragonFly;
|
||||
case "Haiku":
|
||||
return PlatformID.Haiku;
|
||||
case "HP-UX":
|
||||
return PlatformID.HPUX;
|
||||
case "AIX":
|
||||
return PlatformID.AIX;
|
||||
case "OS400":
|
||||
return PlatformID.OS400;
|
||||
case "IRIX":
|
||||
case "IRIX64":
|
||||
return PlatformID.IRIX;
|
||||
case "Minix":
|
||||
return PlatformID.Minix;
|
||||
case "NetBSD":
|
||||
return PlatformID.NetBSD;
|
||||
case "NONSTOP_KERNEL":
|
||||
return PlatformID.NonStop;
|
||||
case "OpenBSD":
|
||||
return PlatformID.OpenBSD;
|
||||
case "QNX":
|
||||
return PlatformID.QNX;
|
||||
case "SINIX-Y":
|
||||
return PlatformID.SINIX;
|
||||
case "SunOS":
|
||||
return PlatformID.Solaris;
|
||||
case "OSF1":
|
||||
return PlatformID.Tru64;
|
||||
case "ULTRIX":
|
||||
return PlatformID.Ultrix;
|
||||
case "SCO_SV":
|
||||
return PlatformID.OpenServer;
|
||||
case "UnixWare":
|
||||
return PlatformID.UnixWare;
|
||||
case "Interix":
|
||||
case "UWIN-W7":
|
||||
return PlatformID.Win32NT;
|
||||
default:
|
||||
{
|
||||
if(unixname.sysname.StartsWith("CYGWIN_NT", StringComparison.Ordinal) ||
|
||||
unixname.sysname.StartsWith("MINGW32_NT", StringComparison.Ordinal) ||
|
||||
unixname.sysname.StartsWith("MSYS_NT", StringComparison.Ordinal) ||
|
||||
unixname.sysname.StartsWith("UWIN", StringComparison.Ordinal))
|
||||
return PlatformID.Win32NT;
|
||||
|
||||
return PlatformID.Unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the underlying runtime runs in 64-bit mode
|
||||
/// </summary>
|
||||
public static bool Is64Bit()
|
||||
{
|
||||
return IntPtr.Size == 8;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the underlying runtime runs in 32-bit mode
|
||||
/// </summary>
|
||||
public static bool Is32Bit()
|
||||
{
|
||||
return IntPtr.Size == 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
989
osrepodbmgr.Core/DicCore.cs
Normal file
989
osrepodbmgr.Core/DicCore.cs
Normal file
@@ -0,0 +1,989 @@
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo claunia@claunia.com
|
||||
//
|
||||
// Copyright (c) 2017, © Claunia.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the [ORGANIZATION] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.Decoders.PCMCIA;
|
||||
using DiscImageChef.Filesystems;
|
||||
using DiscImageChef.Filters;
|
||||
using DiscImageChef.ImagePlugins;
|
||||
using DiscImageChef.PartPlugins;
|
||||
using Schemas;
|
||||
|
||||
namespace osrepodbmgr.Core
|
||||
{
|
||||
public static partial class Core
|
||||
{
|
||||
public static void AddMedia()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(Context.selectedFile))
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("There is no file set");
|
||||
return;
|
||||
}
|
||||
|
||||
string filesPath;
|
||||
|
||||
if(!string.IsNullOrEmpty(Context.tmpFolder) && Directory.Exists(Context.tmpFolder))
|
||||
filesPath = Context.tmpFolder;
|
||||
else
|
||||
filesPath = Context.path;
|
||||
|
||||
string selectedFile = Path.Combine(filesPath, Context.selectedFile);
|
||||
|
||||
if(!File.Exists(selectedFile))
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("Selected file does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
CICMMetadataType sidecar = new CICMMetadataType();
|
||||
PluginBase plugins = new PluginBase();
|
||||
plugins.RegisterAllPlugins();
|
||||
ImagePlugin _imageFormat;
|
||||
|
||||
long maxProgress = 4;
|
||||
long currentProgress = 0;
|
||||
|
||||
FiltersList filtersList = new FiltersList();
|
||||
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, "Detecting image filter", 1, maxProgress);
|
||||
|
||||
Filter inputFilter = filtersList.GetFilter(selectedFile);
|
||||
|
||||
|
||||
if(inputFilter == null)
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("Cannot open specified file.");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, "Detecting image format", 2, maxProgress);
|
||||
_imageFormat = ImageFormat.Detect(inputFilter);
|
||||
|
||||
if(_imageFormat == null)
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("Image format not identified, not proceeding with analysis.");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if(!_imageFormat.OpenImage(inputFilter))
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("Unable to open image format\n" +
|
||||
"No error given");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed(string.Format("Unable to open image format\n" +
|
||||
"Error: {0}", ex.Message));
|
||||
return;
|
||||
}
|
||||
|
||||
FileInfo fi = new FileInfo(selectedFile);
|
||||
FileStream fs = new FileStream(selectedFile, FileMode.Open, FileAccess.Read);
|
||||
|
||||
Checksum imgChkWorker = new Checksum();
|
||||
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, "Hashing image file", 3, maxProgress);
|
||||
|
||||
byte[] data;
|
||||
long position = 0;
|
||||
while(position < (fi.Length - 524288))
|
||||
{
|
||||
data = new byte[524288];
|
||||
fs.Read(data, 0, 524288);
|
||||
|
||||
if(UpdateProgress2 != null)
|
||||
UpdateProgress2(null, string.Format("{0} of {1} bytes", position, fi.Length), position, fi.Length);
|
||||
|
||||
imgChkWorker.Update(data);
|
||||
|
||||
position += 524288;
|
||||
}
|
||||
|
||||
data = new byte[fi.Length - position];
|
||||
fs.Read(data, 0, (int)(fi.Length - position));
|
||||
|
||||
if(UpdateProgress2 != null)
|
||||
UpdateProgress2(null, string.Format("{0} of {1} bytes", position, fi.Length), position, fi.Length);
|
||||
|
||||
imgChkWorker.Update(data);
|
||||
|
||||
fs.Close();
|
||||
|
||||
List<ChecksumType> imgChecksums = imgChkWorker.End();
|
||||
|
||||
if(UpdateProgress2 != null)
|
||||
UpdateProgress2(null, null, 0, 0);
|
||||
|
||||
switch(_imageFormat.ImageInfo.xmlMediaType)
|
||||
{
|
||||
case XmlMediaType.OpticalDisc:
|
||||
{
|
||||
maxProgress = 4 + _imageFormat.ImageInfo.readableMediaTags.Count + _imageFormat.GetTracks().Count;
|
||||
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, "Hashing image file", 3, maxProgress);
|
||||
|
||||
sidecar.OpticalDisc = new OpticalDiscType[1];
|
||||
sidecar.OpticalDisc[0] = new OpticalDiscType();
|
||||
sidecar.OpticalDisc[0].Checksums = imgChecksums.ToArray();
|
||||
sidecar.OpticalDisc[0].Image = new ImageType();
|
||||
sidecar.OpticalDisc[0].Image.format = _imageFormat.GetImageFormat();
|
||||
sidecar.OpticalDisc[0].Image.offset = 0;
|
||||
sidecar.OpticalDisc[0].Image.offsetSpecified = true;
|
||||
sidecar.OpticalDisc[0].Image.Value = Path.GetFileName(selectedFile);
|
||||
sidecar.OpticalDisc[0].Size = fi.Length;
|
||||
sidecar.OpticalDisc[0].Sequence = new SequenceType();
|
||||
if(_imageFormat.GetMediaSequence() != 0 && _imageFormat.GetLastDiskSequence() != 0)
|
||||
{
|
||||
sidecar.OpticalDisc[0].Sequence.MediaSequence = _imageFormat.GetMediaSequence();
|
||||
sidecar.OpticalDisc[0].Sequence.TotalMedia = _imageFormat.GetMediaSequence();
|
||||
}
|
||||
else
|
||||
{
|
||||
sidecar.OpticalDisc[0].Sequence.MediaSequence = 1;
|
||||
sidecar.OpticalDisc[0].Sequence.TotalMedia = 1;
|
||||
}
|
||||
sidecar.OpticalDisc[0].Sequence.MediaTitle = _imageFormat.GetImageName();
|
||||
|
||||
MediaType dskType = _imageFormat.ImageInfo.mediaType;
|
||||
|
||||
currentProgress = 3;
|
||||
|
||||
foreach(MediaTagType tagType in _imageFormat.ImageInfo.readableMediaTags)
|
||||
{
|
||||
currentProgress++;
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, string.Format("Hashing file containing {0}", tagType), currentProgress, maxProgress);
|
||||
|
||||
switch(tagType)
|
||||
{
|
||||
case MediaTagType.CD_ATIP:
|
||||
sidecar.OpticalDisc[0].ATIP = new DumpType();
|
||||
sidecar.OpticalDisc[0].ATIP.Checksums = Checksum.GetChecksums(_imageFormat.ReadDiskTag(MediaTagType.CD_ATIP)).ToArray();
|
||||
sidecar.OpticalDisc[0].ATIP.Size = _imageFormat.ReadDiskTag(MediaTagType.CD_ATIP).Length;
|
||||
DiscImageChef.Decoders.CD.ATIP.CDATIP? atip = DiscImageChef.Decoders.CD.ATIP.Decode(_imageFormat.ReadDiskTag(MediaTagType.CD_ATIP));
|
||||
if(atip.HasValue)
|
||||
{
|
||||
if(atip.Value.DDCD)
|
||||
dskType = atip.Value.DiscType ? MediaType.DDCDRW : MediaType.DDCDR;
|
||||
else
|
||||
dskType = atip.Value.DiscType ? MediaType.CDRW : MediaType.CDR;
|
||||
}
|
||||
break;
|
||||
case MediaTagType.DVD_BCA:
|
||||
sidecar.OpticalDisc[0].BCA = new DumpType();
|
||||
sidecar.OpticalDisc[0].BCA.Checksums = Checksum.GetChecksums(_imageFormat.ReadDiskTag(MediaTagType.DVD_BCA)).ToArray();
|
||||
sidecar.OpticalDisc[0].BCA.Size = _imageFormat.ReadDiskTag(MediaTagType.DVD_BCA).Length;
|
||||
break;
|
||||
case MediaTagType.BD_BCA:
|
||||
sidecar.OpticalDisc[0].BCA = new DumpType();
|
||||
sidecar.OpticalDisc[0].BCA.Checksums = Checksum.GetChecksums(_imageFormat.ReadDiskTag(MediaTagType.BD_BCA)).ToArray();
|
||||
sidecar.OpticalDisc[0].BCA.Size = _imageFormat.ReadDiskTag(MediaTagType.BD_BCA).Length;
|
||||
break;
|
||||
case MediaTagType.DVD_CMI:
|
||||
sidecar.OpticalDisc[0].CMI = new DumpType();
|
||||
DiscImageChef.Decoders.DVD.CSS_CPRM.LeadInCopyright? cmi = DiscImageChef.Decoders.DVD.CSS_CPRM.DecodeLeadInCopyright(_imageFormat.ReadDiskTag(MediaTagType.DVD_CMI));
|
||||
if(cmi.HasValue)
|
||||
{
|
||||
switch(cmi.Value.CopyrightType)
|
||||
{
|
||||
case DiscImageChef.Decoders.DVD.CopyrightType.AACS:
|
||||
sidecar.OpticalDisc[0].CopyProtection = "AACS";
|
||||
break;
|
||||
case DiscImageChef.Decoders.DVD.CopyrightType.CSS:
|
||||
sidecar.OpticalDisc[0].CopyProtection = "CSS";
|
||||
break;
|
||||
case DiscImageChef.Decoders.DVD.CopyrightType.CPRM:
|
||||
sidecar.OpticalDisc[0].CopyProtection = "CPRM";
|
||||
break;
|
||||
}
|
||||
}
|
||||
sidecar.OpticalDisc[0].CMI.Checksums = Checksum.GetChecksums(_imageFormat.ReadDiskTag(MediaTagType.DVD_CMI)).ToArray();
|
||||
sidecar.OpticalDisc[0].CMI.Size = _imageFormat.ReadDiskTag(MediaTagType.DVD_CMI).Length;
|
||||
break;
|
||||
case MediaTagType.DVD_DMI:
|
||||
sidecar.OpticalDisc[0].DMI = new DumpType();
|
||||
sidecar.OpticalDisc[0].DMI.Checksums = Checksum.GetChecksums(_imageFormat.ReadDiskTag(MediaTagType.DVD_DMI)).ToArray();
|
||||
sidecar.OpticalDisc[0].DMI.Size = _imageFormat.ReadDiskTag(MediaTagType.DVD_DMI).Length;
|
||||
if(DiscImageChef.Decoders.Xbox.DMI.IsXbox(_imageFormat.ReadDiskTag(MediaTagType.DVD_DMI)))
|
||||
{
|
||||
dskType = MediaType.XGD;
|
||||
sidecar.OpticalDisc[0].Dimensions = new DimensionsType();
|
||||
sidecar.OpticalDisc[0].Dimensions.Diameter = 120;
|
||||
}
|
||||
else if(DiscImageChef.Decoders.Xbox.DMI.IsXbox360(_imageFormat.ReadDiskTag(MediaTagType.DVD_DMI)))
|
||||
{
|
||||
dskType = MediaType.XGD2;
|
||||
sidecar.OpticalDisc[0].Dimensions = new DimensionsType();
|
||||
sidecar.OpticalDisc[0].Dimensions.Diameter = 120;
|
||||
}
|
||||
break;
|
||||
case MediaTagType.DVD_PFI:
|
||||
sidecar.OpticalDisc[0].PFI = new DumpType();
|
||||
sidecar.OpticalDisc[0].PFI.Checksums = Checksum.GetChecksums(_imageFormat.ReadDiskTag(MediaTagType.DVD_PFI)).ToArray();
|
||||
sidecar.OpticalDisc[0].PFI.Size = _imageFormat.ReadDiskTag(MediaTagType.DVD_PFI).Length;
|
||||
DiscImageChef.Decoders.DVD.PFI.PhysicalFormatInformation? pfi = DiscImageChef.Decoders.DVD.PFI.Decode(_imageFormat.ReadDiskTag(MediaTagType.DVD_PFI));
|
||||
if(pfi.HasValue)
|
||||
{
|
||||
if(dskType != MediaType.XGD &&
|
||||
dskType != MediaType.XGD2 &&
|
||||
dskType != MediaType.XGD3)
|
||||
{
|
||||
switch(pfi.Value.DiskCategory)
|
||||
{
|
||||
case DiscImageChef.Decoders.DVD.DiskCategory.DVDPR:
|
||||
dskType = MediaType.DVDPR;
|
||||
break;
|
||||
case DiscImageChef.Decoders.DVD.DiskCategory.DVDPRDL:
|
||||
dskType = MediaType.DVDPRDL;
|
||||
break;
|
||||
case DiscImageChef.Decoders.DVD.DiskCategory.DVDPRW:
|
||||
dskType = MediaType.DVDPRW;
|
||||
break;
|
||||
case DiscImageChef.Decoders.DVD.DiskCategory.DVDPRWDL:
|
||||
dskType = MediaType.DVDPRWDL;
|
||||
break;
|
||||
case DiscImageChef.Decoders.DVD.DiskCategory.DVDR:
|
||||
dskType = MediaType.DVDR;
|
||||
break;
|
||||
case DiscImageChef.Decoders.DVD.DiskCategory.DVDRAM:
|
||||
dskType = MediaType.DVDRAM;
|
||||
break;
|
||||
case DiscImageChef.Decoders.DVD.DiskCategory.DVDROM:
|
||||
dskType = MediaType.DVDROM;
|
||||
break;
|
||||
case DiscImageChef.Decoders.DVD.DiskCategory.DVDRW:
|
||||
dskType = MediaType.DVDRW;
|
||||
break;
|
||||
case DiscImageChef.Decoders.DVD.DiskCategory.HDDVDR:
|
||||
dskType = MediaType.HDDVDR;
|
||||
break;
|
||||
case DiscImageChef.Decoders.DVD.DiskCategory.HDDVDRAM:
|
||||
dskType = MediaType.HDDVDRAM;
|
||||
break;
|
||||
case DiscImageChef.Decoders.DVD.DiskCategory.HDDVDROM:
|
||||
dskType = MediaType.HDDVDROM;
|
||||
break;
|
||||
case DiscImageChef.Decoders.DVD.DiskCategory.HDDVDRW:
|
||||
dskType = MediaType.HDDVDRW;
|
||||
break;
|
||||
case DiscImageChef.Decoders.DVD.DiskCategory.Nintendo:
|
||||
dskType = MediaType.GOD;
|
||||
break;
|
||||
case DiscImageChef.Decoders.DVD.DiskCategory.UMD:
|
||||
dskType = MediaType.UMD;
|
||||
break;
|
||||
}
|
||||
|
||||
if(dskType == MediaType.DVDR && pfi.Value.PartVersion == 6)
|
||||
dskType = MediaType.DVDRDL;
|
||||
if(dskType == MediaType.DVDRW && pfi.Value.PartVersion == 3)
|
||||
dskType = MediaType.DVDRWDL;
|
||||
if(dskType == MediaType.GOD && pfi.Value.DiscSize == DiscImageChef.Decoders.DVD.DVDSize.OneTwenty)
|
||||
dskType = MediaType.WOD;
|
||||
|
||||
sidecar.OpticalDisc[0].Dimensions = new DimensionsType();
|
||||
if(dskType == MediaType.UMD)
|
||||
sidecar.OpticalDisc[0].Dimensions.Diameter = 60;
|
||||
else if(pfi.Value.DiscSize == DiscImageChef.Decoders.DVD.DVDSize.Eighty)
|
||||
sidecar.OpticalDisc[0].Dimensions.Diameter = 80;
|
||||
else if(pfi.Value.DiscSize == DiscImageChef.Decoders.DVD.DVDSize.OneTwenty)
|
||||
sidecar.OpticalDisc[0].Dimensions.Diameter = 120;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MediaTagType.CD_PMA:
|
||||
sidecar.OpticalDisc[0].PMA = new DumpType();
|
||||
sidecar.OpticalDisc[0].PMA.Checksums = Checksum.GetChecksums(_imageFormat.ReadDiskTag(MediaTagType.CD_PMA)).ToArray();
|
||||
sidecar.OpticalDisc[0].PMA.Size = _imageFormat.ReadDiskTag(MediaTagType.CD_PMA).Length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
List<Session> sessions = _imageFormat.GetSessions();
|
||||
sidecar.OpticalDisc[0].Sessions = sessions != null ? sessions.Count : 1;
|
||||
}
|
||||
catch
|
||||
{
|
||||
sidecar.OpticalDisc[0].Sessions = 1;
|
||||
}
|
||||
|
||||
List<Track> tracks = _imageFormat.GetTracks();
|
||||
List<Schemas.TrackType> trksLst = null;
|
||||
if(tracks != null)
|
||||
{
|
||||
sidecar.OpticalDisc[0].Tracks = new int[1];
|
||||
sidecar.OpticalDisc[0].Tracks[0] = tracks.Count;
|
||||
trksLst = new List<Schemas.TrackType>();
|
||||
}
|
||||
|
||||
foreach(Track trk in tracks)
|
||||
{
|
||||
currentProgress++;
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, string.Format("Hashing track {0}", trk.TrackSequence), currentProgress, maxProgress);
|
||||
|
||||
Schemas.TrackType xmlTrk = new Schemas.TrackType();
|
||||
switch(trk.TrackType)
|
||||
{
|
||||
case DiscImageChef.ImagePlugins.TrackType.Audio:
|
||||
xmlTrk.TrackType1 = TrackTypeTrackType.audio;
|
||||
break;
|
||||
case DiscImageChef.ImagePlugins.TrackType.CDMode2Form2:
|
||||
xmlTrk.TrackType1 = TrackTypeTrackType.m2f2;
|
||||
break;
|
||||
case DiscImageChef.ImagePlugins.TrackType.CDMode2Formless:
|
||||
xmlTrk.TrackType1 = TrackTypeTrackType.mode2;
|
||||
break;
|
||||
case DiscImageChef.ImagePlugins.TrackType.CDMode2Form1:
|
||||
xmlTrk.TrackType1 = TrackTypeTrackType.m2f1;
|
||||
break;
|
||||
case DiscImageChef.ImagePlugins.TrackType.CDMode1:
|
||||
xmlTrk.TrackType1 = TrackTypeTrackType.mode1;
|
||||
break;
|
||||
case DiscImageChef.ImagePlugins.TrackType.Data:
|
||||
switch(sidecar.OpticalDisc[0].DiscType)
|
||||
{
|
||||
case "BD":
|
||||
xmlTrk.TrackType1 = TrackTypeTrackType.bluray;
|
||||
break;
|
||||
case "DDCD":
|
||||
xmlTrk.TrackType1 = TrackTypeTrackType.ddcd;
|
||||
break;
|
||||
case "DVD":
|
||||
xmlTrk.TrackType1 = TrackTypeTrackType.dvd;
|
||||
break;
|
||||
case "HD DVD":
|
||||
xmlTrk.TrackType1 = TrackTypeTrackType.hddvd;
|
||||
break;
|
||||
default:
|
||||
xmlTrk.TrackType1 = TrackTypeTrackType.mode1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
xmlTrk.Sequence = new TrackSequenceType();
|
||||
xmlTrk.Sequence.Session = trk.TrackSession;
|
||||
xmlTrk.Sequence.TrackNumber = (int)trk.TrackSequence;
|
||||
xmlTrk.StartSector = (long)trk.TrackStartSector;
|
||||
xmlTrk.EndSector = (long)trk.TrackEndSector;
|
||||
|
||||
if(trk.Indexes != null && trk.Indexes.ContainsKey(0))
|
||||
{
|
||||
ulong idx0;
|
||||
if(trk.Indexes.TryGetValue(0, out idx0))
|
||||
xmlTrk.StartSector = (long)idx0;
|
||||
}
|
||||
|
||||
if(sidecar.OpticalDisc[0].DiscType == "CD" ||
|
||||
sidecar.OpticalDisc[0].DiscType == "GD")
|
||||
{
|
||||
xmlTrk.StartMSF = LbaToMsf(xmlTrk.StartSector);
|
||||
xmlTrk.EndMSF = LbaToMsf(xmlTrk.EndSector);
|
||||
}
|
||||
else if(sidecar.OpticalDisc[0].DiscType == "DDCD")
|
||||
{
|
||||
xmlTrk.StartMSF = DdcdLbaToMsf(xmlTrk.StartSector);
|
||||
xmlTrk.EndMSF = DdcdLbaToMsf(xmlTrk.EndSector);
|
||||
}
|
||||
|
||||
xmlTrk.Image = new ImageType();
|
||||
xmlTrk.Image.Value = Path.GetFileName(trk.TrackFile);
|
||||
if(trk.TrackFileOffset > 0)
|
||||
{
|
||||
xmlTrk.Image.offset = (long)trk.TrackFileOffset;
|
||||
xmlTrk.Image.offsetSpecified = true;
|
||||
}
|
||||
|
||||
xmlTrk.Image.format = trk.TrackFileType;
|
||||
xmlTrk.Size = (xmlTrk.EndSector - xmlTrk.StartSector + 1) * trk.TrackRawBytesPerSector;
|
||||
xmlTrk.BytesPerSector = trk.TrackBytesPerSector;
|
||||
|
||||
uint sectorsToRead = 512;
|
||||
|
||||
Checksum trkChkWorker = new Checksum();
|
||||
|
||||
ulong sectors = (ulong)(xmlTrk.EndSector - xmlTrk.StartSector + 1);
|
||||
ulong doneSectors = 0;
|
||||
|
||||
while(doneSectors < sectors)
|
||||
{
|
||||
byte[] sector;
|
||||
|
||||
if((sectors - doneSectors) >= sectorsToRead)
|
||||
{
|
||||
sector = _imageFormat.ReadSectorsLong(doneSectors, sectorsToRead, (uint)xmlTrk.Sequence.TrackNumber);
|
||||
if(UpdateProgress2 != null)
|
||||
UpdateProgress2(null, string.Format("Sector {0} of {1}", doneSectors, sectors), (long)doneSectors, (long)sectors);
|
||||
doneSectors += sectorsToRead;
|
||||
}
|
||||
else
|
||||
{
|
||||
sector = _imageFormat.ReadSectorsLong(doneSectors, (uint)(sectors - doneSectors), (uint)xmlTrk.Sequence.TrackNumber);
|
||||
if(UpdateProgress2 != null)
|
||||
UpdateProgress2(null, string.Format("Sector {0} of {1}", doneSectors, sectors), (long)doneSectors, (long)sectors);
|
||||
doneSectors += (sectors - doneSectors);
|
||||
}
|
||||
|
||||
trkChkWorker.Update(sector);
|
||||
}
|
||||
|
||||
List<ChecksumType> trkChecksums = trkChkWorker.End();
|
||||
|
||||
xmlTrk.Checksums = trkChecksums.ToArray();
|
||||
|
||||
if(UpdateProgress2 != null)
|
||||
UpdateProgress2(null, null, 0, 0);
|
||||
|
||||
if(trk.TrackSubchannelType != TrackSubchannelType.None)
|
||||
{
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, string.Format("Hashing subchannel of track {0}", trk.TrackSequence), currentProgress, maxProgress);
|
||||
|
||||
xmlTrk.SubChannel = new SubChannelType();
|
||||
xmlTrk.SubChannel.Image = new ImageType();
|
||||
switch(trk.TrackSubchannelType)
|
||||
{
|
||||
case TrackSubchannelType.Packed:
|
||||
case TrackSubchannelType.PackedInterleaved:
|
||||
xmlTrk.SubChannel.Image.format = "rw";
|
||||
break;
|
||||
case TrackSubchannelType.Raw:
|
||||
case TrackSubchannelType.RawInterleaved:
|
||||
xmlTrk.SubChannel.Image.format = "rw_raw";
|
||||
break;
|
||||
case TrackSubchannelType.Q16:
|
||||
case TrackSubchannelType.Q16Interleaved:
|
||||
xmlTrk.SubChannel.Image.format = "q16";
|
||||
break;
|
||||
}
|
||||
|
||||
if(trk.TrackFileOffset > 0)
|
||||
{
|
||||
xmlTrk.SubChannel.Image.offset = (long)trk.TrackSubchannelOffset;
|
||||
xmlTrk.SubChannel.Image.offsetSpecified = true;
|
||||
}
|
||||
xmlTrk.SubChannel.Image.Value = trk.TrackSubchannelFile;
|
||||
|
||||
// TODO: Packed subchannel has different size?
|
||||
xmlTrk.SubChannel.Size = (xmlTrk.EndSector - xmlTrk.StartSector + 1) * 96;
|
||||
|
||||
Checksum subChkWorker = new Checksum();
|
||||
|
||||
sectors = (ulong)(xmlTrk.EndSector - xmlTrk.StartSector + 1);
|
||||
doneSectors = 0;
|
||||
|
||||
while(doneSectors < sectors)
|
||||
{
|
||||
byte[] sector;
|
||||
|
||||
if((sectors - doneSectors) >= sectorsToRead)
|
||||
{
|
||||
sector = _imageFormat.ReadSectorsTag(doneSectors, sectorsToRead, (uint)xmlTrk.Sequence.TrackNumber, SectorTagType.CDSectorSubchannel);
|
||||
if(UpdateProgress2 != null)
|
||||
UpdateProgress2(null, string.Format("Sector {0} of {1}", doneSectors, sectors), position, fi.Length);
|
||||
doneSectors += sectorsToRead;
|
||||
}
|
||||
else
|
||||
{
|
||||
sector = _imageFormat.ReadSectorsTag(doneSectors, (uint)(sectors - doneSectors), (uint)xmlTrk.Sequence.TrackNumber, SectorTagType.CDSectorSubchannel);
|
||||
if(UpdateProgress2 != null)
|
||||
UpdateProgress2(null, string.Format("Sector {0} of {1}", doneSectors, sectors), position, fi.Length);
|
||||
doneSectors += (sectors - doneSectors);
|
||||
}
|
||||
|
||||
subChkWorker.Update(sector);
|
||||
}
|
||||
|
||||
List<ChecksumType> subChecksums = subChkWorker.End();
|
||||
|
||||
xmlTrk.SubChannel.Checksums = subChecksums.ToArray();
|
||||
|
||||
if(UpdateProgress2 != null)
|
||||
UpdateProgress2(null, null, 0, 0);
|
||||
}
|
||||
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, "Checking filesystems", maxProgress - 1, maxProgress);
|
||||
|
||||
List<Partition> partitions = new List<Partition>();
|
||||
|
||||
foreach(PartPlugin _partplugin in plugins.PartPluginsList.Values)
|
||||
{
|
||||
List<Partition> _partitions;
|
||||
|
||||
if(_partplugin.GetInformation(_imageFormat, out _partitions))
|
||||
partitions.AddRange(_partitions);
|
||||
}
|
||||
|
||||
xmlTrk.FileSystemInformation = new PartitionType[1];
|
||||
if(partitions.Count > 0)
|
||||
{
|
||||
xmlTrk.FileSystemInformation = new PartitionType[partitions.Count];
|
||||
for(int i = 0; i < partitions.Count; i++)
|
||||
{
|
||||
xmlTrk.FileSystemInformation[i] = new PartitionType();
|
||||
xmlTrk.FileSystemInformation[i].Description = partitions[i].PartitionDescription;
|
||||
xmlTrk.FileSystemInformation[i].EndSector = (int)(partitions[i].PartitionStartSector + partitions[i].PartitionSectors - 1);
|
||||
xmlTrk.FileSystemInformation[i].Name = partitions[i].PartitionName;
|
||||
xmlTrk.FileSystemInformation[i].Sequence = (int)partitions[i].PartitionSequence;
|
||||
xmlTrk.FileSystemInformation[i].StartSector = (int)partitions[i].PartitionStartSector;
|
||||
xmlTrk.FileSystemInformation[i].Type = partitions[i].PartitionType;
|
||||
|
||||
List<FileSystemType> lstFs = new List<FileSystemType>();
|
||||
|
||||
foreach(Filesystem _plugin in plugins.PluginsList.Values)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_plugin.Identify(_imageFormat, partitions[i].PartitionStartSector, partitions[i].PartitionStartSector + partitions[i].PartitionSectors - 1))
|
||||
{
|
||||
string foo;
|
||||
_plugin.GetInformation(_imageFormat, partitions[i].PartitionStartSector, partitions[i].PartitionStartSector + partitions[i].PartitionSectors - 1, out foo);
|
||||
lstFs.Add(_plugin.XmlFSType);
|
||||
|
||||
if(_plugin.XmlFSType.Type == "Opera")
|
||||
dskType = MediaType.ThreeDO;
|
||||
if(_plugin.XmlFSType.Type == "PC Engine filesystem")
|
||||
dskType = MediaType.SuperCDROM2;
|
||||
if(_plugin.XmlFSType.Type == "Nintendo Wii filesystem")
|
||||
dskType = MediaType.WOD;
|
||||
if(_plugin.XmlFSType.Type == "Nintendo Gamecube filesystem")
|
||||
dskType = MediaType.GOD;
|
||||
}
|
||||
}
|
||||
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||
catch
|
||||
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||
{
|
||||
//DicConsole.DebugWriteLine("Create-sidecar command", "Plugin {0} crashed", _plugin.Name);
|
||||
}
|
||||
}
|
||||
|
||||
if(lstFs.Count > 0)
|
||||
xmlTrk.FileSystemInformation[i].FileSystems = lstFs.ToArray();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlTrk.FileSystemInformation[0] = new PartitionType();
|
||||
xmlTrk.FileSystemInformation[0].EndSector = (int)xmlTrk.EndSector;
|
||||
xmlTrk.FileSystemInformation[0].StartSector = (int)xmlTrk.StartSector;
|
||||
|
||||
List<FileSystemType> lstFs = new List<FileSystemType>();
|
||||
|
||||
foreach(Filesystem _plugin in plugins.PluginsList.Values)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_plugin.Identify(_imageFormat, (ulong)xmlTrk.StartSector, (ulong)xmlTrk.EndSector))
|
||||
{
|
||||
string foo;
|
||||
_plugin.GetInformation(_imageFormat, (ulong)xmlTrk.StartSector, (ulong)xmlTrk.EndSector, out foo);
|
||||
lstFs.Add(_plugin.XmlFSType);
|
||||
|
||||
if(_plugin.XmlFSType.Type == "Opera")
|
||||
dskType = MediaType.ThreeDO;
|
||||
if(_plugin.XmlFSType.Type == "PC Engine filesystem")
|
||||
dskType = MediaType.SuperCDROM2;
|
||||
if(_plugin.XmlFSType.Type == "Nintendo Wii filesystem")
|
||||
dskType = MediaType.WOD;
|
||||
if(_plugin.XmlFSType.Type == "Nintendo Gamecube filesystem")
|
||||
dskType = MediaType.GOD;
|
||||
}
|
||||
}
|
||||
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||
catch
|
||||
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||
{
|
||||
//DicConsole.DebugWriteLine("Create-sidecar command", "Plugin {0} crashed", _plugin.Name);
|
||||
}
|
||||
}
|
||||
|
||||
if(lstFs.Count > 0)
|
||||
xmlTrk.FileSystemInformation[0].FileSystems = lstFs.ToArray();
|
||||
}
|
||||
|
||||
trksLst.Add(xmlTrk);
|
||||
}
|
||||
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, "Finishing", maxProgress, maxProgress);
|
||||
|
||||
if(trksLst != null)
|
||||
sidecar.OpticalDisc[0].Track = trksLst.ToArray();
|
||||
|
||||
string dscType, dscSubType;
|
||||
DiscImageChef.Metadata.MediaType.MediaTypeToString(dskType, out dscType, out dscSubType);
|
||||
sidecar.OpticalDisc[0].DiscType = dscType;
|
||||
sidecar.OpticalDisc[0].DiscSubType = dscSubType;
|
||||
|
||||
if(!string.IsNullOrEmpty(_imageFormat.ImageInfo.driveManufacturer) ||
|
||||
!string.IsNullOrEmpty(_imageFormat.ImageInfo.driveModel) ||
|
||||
!string.IsNullOrEmpty(_imageFormat.ImageInfo.driveFirmwareRevision) ||
|
||||
!string.IsNullOrEmpty(_imageFormat.ImageInfo.driveSerialNumber))
|
||||
{
|
||||
sidecar.OpticalDisc[0].DumpHardwareArray = new DumpHardwareType[1];
|
||||
sidecar.OpticalDisc[0].DumpHardwareArray[0].Extents = new ExtentType[0];
|
||||
sidecar.OpticalDisc[0].DumpHardwareArray[0].Extents[0].Start = 0;
|
||||
sidecar.OpticalDisc[0].DumpHardwareArray[0].Extents[0].End = (int)_imageFormat.ImageInfo.sectors;
|
||||
sidecar.OpticalDisc[0].DumpHardwareArray[0].Manufacturer = _imageFormat.ImageInfo.driveManufacturer;
|
||||
sidecar.OpticalDisc[0].DumpHardwareArray[0].Model = _imageFormat.ImageInfo.driveModel;
|
||||
sidecar.OpticalDisc[0].DumpHardwareArray[0].Firmware = _imageFormat.ImageInfo.driveFirmwareRevision;
|
||||
sidecar.OpticalDisc[0].DumpHardwareArray[0].Serial = _imageFormat.ImageInfo.driveSerialNumber;
|
||||
sidecar.OpticalDisc[0].DumpHardwareArray[0].Software = new SoftwareType();
|
||||
sidecar.OpticalDisc[0].DumpHardwareArray[0].Software.Name = _imageFormat.GetImageApplication();
|
||||
sidecar.OpticalDisc[0].DumpHardwareArray[0].Software.Version = _imageFormat.GetImageApplicationVersion();
|
||||
}
|
||||
|
||||
Context.workingDisc = sidecar.OpticalDisc[0];
|
||||
if(Finished != null)
|
||||
Finished();
|
||||
return;
|
||||
}
|
||||
case XmlMediaType.BlockMedia:
|
||||
{
|
||||
maxProgress = 3 + _imageFormat.ImageInfo.readableMediaTags.Count;
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, "Hashing image file", 3, maxProgress);
|
||||
|
||||
sidecar.BlockMedia = new BlockMediaType[1];
|
||||
sidecar.BlockMedia[0] = new BlockMediaType();
|
||||
sidecar.BlockMedia[0].Checksums = imgChecksums.ToArray();
|
||||
sidecar.BlockMedia[0].Image = new ImageType();
|
||||
sidecar.BlockMedia[0].Image.format = _imageFormat.GetImageFormat();
|
||||
sidecar.BlockMedia[0].Image.offset = 0;
|
||||
sidecar.BlockMedia[0].Image.offsetSpecified = true;
|
||||
sidecar.BlockMedia[0].Image.Value = Path.GetFileName(selectedFile);
|
||||
sidecar.BlockMedia[0].Size = fi.Length;
|
||||
sidecar.BlockMedia[0].Sequence = new SequenceType();
|
||||
if(_imageFormat.GetMediaSequence() != 0 && _imageFormat.GetLastDiskSequence() != 0)
|
||||
{
|
||||
sidecar.BlockMedia[0].Sequence.MediaSequence = _imageFormat.GetMediaSequence();
|
||||
sidecar.BlockMedia[0].Sequence.TotalMedia = _imageFormat.GetMediaSequence();
|
||||
}
|
||||
else
|
||||
{
|
||||
sidecar.BlockMedia[0].Sequence.MediaSequence = 1;
|
||||
sidecar.BlockMedia[0].Sequence.TotalMedia = 1;
|
||||
}
|
||||
sidecar.BlockMedia[0].Sequence.MediaTitle = _imageFormat.GetImageName();
|
||||
|
||||
currentProgress = 3;
|
||||
|
||||
foreach(MediaTagType tagType in _imageFormat.ImageInfo.readableMediaTags)
|
||||
{
|
||||
currentProgress++;
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, string.Format("Hashing file containing {0}", tagType), currentProgress, maxProgress);
|
||||
|
||||
switch(tagType)
|
||||
{
|
||||
case MediaTagType.ATAPI_IDENTIFY:
|
||||
sidecar.BlockMedia[0].ATA = new ATAType();
|
||||
sidecar.BlockMedia[0].ATA.Identify = new DumpType();
|
||||
sidecar.BlockMedia[0].ATA.Identify.Checksums = Checksum.GetChecksums(_imageFormat.ReadDiskTag(MediaTagType.ATAPI_IDENTIFY)).ToArray();
|
||||
sidecar.BlockMedia[0].ATA.Identify.Size = _imageFormat.ReadDiskTag(MediaTagType.ATAPI_IDENTIFY).Length;
|
||||
break;
|
||||
case MediaTagType.ATA_IDENTIFY:
|
||||
sidecar.BlockMedia[0].ATA = new ATAType();
|
||||
sidecar.BlockMedia[0].ATA.Identify = new DumpType();
|
||||
sidecar.BlockMedia[0].ATA.Identify.Checksums = Checksum.GetChecksums(_imageFormat.ReadDiskTag(MediaTagType.ATA_IDENTIFY)).ToArray();
|
||||
sidecar.BlockMedia[0].ATA.Identify.Size = _imageFormat.ReadDiskTag(MediaTagType.ATA_IDENTIFY).Length;
|
||||
break;
|
||||
case MediaTagType.PCMCIA_CIS:
|
||||
byte[] cis = _imageFormat.ReadDiskTag(MediaTagType.PCMCIA_CIS);
|
||||
sidecar.BlockMedia[0].PCMCIA = new PCMCIAType();
|
||||
sidecar.BlockMedia[0].PCMCIA.CIS = new DumpType();
|
||||
sidecar.BlockMedia[0].PCMCIA.CIS.Checksums = Checksum.GetChecksums(cis).ToArray();
|
||||
sidecar.BlockMedia[0].PCMCIA.CIS.Size = cis.Length;
|
||||
DiscImageChef.Decoders.PCMCIA.Tuple[] tuples = CIS.GetTuples(cis);
|
||||
if(tuples != null)
|
||||
{
|
||||
foreach(DiscImageChef.Decoders.PCMCIA.Tuple tuple in tuples)
|
||||
{
|
||||
if(tuple.Code == TupleCodes.CISTPL_MANFID)
|
||||
{
|
||||
ManufacturerIdentificationTuple manfid = CIS.DecodeManufacturerIdentificationTuple(tuple);
|
||||
|
||||
if(manfid != null)
|
||||
{
|
||||
sidecar.BlockMedia[0].PCMCIA.ManufacturerCode = manfid.ManufacturerID;
|
||||
sidecar.BlockMedia[0].PCMCIA.CardCode = manfid.CardID;
|
||||
sidecar.BlockMedia[0].PCMCIA.ManufacturerCodeSpecified = true;
|
||||
sidecar.BlockMedia[0].PCMCIA.CardCodeSpecified = true;
|
||||
}
|
||||
}
|
||||
else if(tuple.Code == TupleCodes.CISTPL_VERS_1)
|
||||
{
|
||||
Level1VersionTuple vers = CIS.DecodeLevel1VersionTuple(tuple);
|
||||
|
||||
if(vers != null)
|
||||
{
|
||||
sidecar.BlockMedia[0].PCMCIA.Manufacturer = vers.Manufacturer;
|
||||
sidecar.BlockMedia[0].PCMCIA.ProductName = vers.Product;
|
||||
sidecar.BlockMedia[0].PCMCIA.Compliance = string.Format("{0}.{1}", vers.MajorVersion, vers.MinorVersion);
|
||||
sidecar.BlockMedia[0].PCMCIA.AdditionalInformation = vers.AdditionalInformation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MediaTagType.SCSI_INQUIRY:
|
||||
sidecar.BlockMedia[0].SCSI = new SCSIType();
|
||||
sidecar.BlockMedia[0].SCSI.Inquiry = new DumpType();
|
||||
sidecar.BlockMedia[0].SCSI.Inquiry.Checksums = Checksum.GetChecksums(_imageFormat.ReadDiskTag(MediaTagType.SCSI_INQUIRY)).ToArray();
|
||||
sidecar.BlockMedia[0].SCSI.Inquiry.Size = _imageFormat.ReadDiskTag(MediaTagType.SCSI_INQUIRY).Length;
|
||||
break;
|
||||
case MediaTagType.SD_CID:
|
||||
if(sidecar.BlockMedia[0].SecureDigital == null)
|
||||
sidecar.BlockMedia[0].SecureDigital = new SecureDigitalType();
|
||||
sidecar.BlockMedia[0].SecureDigital.CID = new DumpType();
|
||||
sidecar.BlockMedia[0].SecureDigital.CID.Checksums = Checksum.GetChecksums(_imageFormat.ReadDiskTag(MediaTagType.SD_CID)).ToArray();
|
||||
sidecar.BlockMedia[0].SecureDigital.CID.Size = _imageFormat.ReadDiskTag(MediaTagType.SD_CID).Length;
|
||||
break;
|
||||
case MediaTagType.SD_CSD:
|
||||
if(sidecar.BlockMedia[0].SecureDigital == null)
|
||||
sidecar.BlockMedia[0].SecureDigital = new SecureDigitalType();
|
||||
sidecar.BlockMedia[0].SecureDigital.CSD = new DumpType();
|
||||
sidecar.BlockMedia[0].SecureDigital.CSD.Checksums = Checksum.GetChecksums(_imageFormat.ReadDiskTag(MediaTagType.SD_CSD)).ToArray();
|
||||
sidecar.BlockMedia[0].SecureDigital.CSD.Size = _imageFormat.ReadDiskTag(MediaTagType.SD_CSD).Length;
|
||||
break;
|
||||
case MediaTagType.SD_ExtendedCSD:
|
||||
if(sidecar.BlockMedia[0].SecureDigital == null)
|
||||
sidecar.BlockMedia[0].SecureDigital = new SecureDigitalType();
|
||||
sidecar.BlockMedia[0].SecureDigital.ExtendedCSD = new DumpType();
|
||||
sidecar.BlockMedia[0].SecureDigital.ExtendedCSD.Checksums = Checksum.GetChecksums(_imageFormat.ReadDiskTag(MediaTagType.SD_ExtendedCSD)).ToArray();
|
||||
sidecar.BlockMedia[0].SecureDigital.ExtendedCSD.Size = _imageFormat.ReadDiskTag(MediaTagType.SD_ExtendedCSD).Length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string dskType, dskSubType;
|
||||
DiscImageChef.Metadata.MediaType.MediaTypeToString(_imageFormat.ImageInfo.mediaType, out dskType, out dskSubType);
|
||||
sidecar.BlockMedia[0].DiskType = dskType;
|
||||
sidecar.BlockMedia[0].DiskSubType = dskSubType;
|
||||
|
||||
sidecar.BlockMedia[0].Dimensions = DiscImageChef.Metadata.Dimensions.DimensionsFromMediaType(_imageFormat.ImageInfo.mediaType);
|
||||
|
||||
sidecar.BlockMedia[0].LogicalBlocks = (long)_imageFormat.GetSectors();
|
||||
sidecar.BlockMedia[0].LogicalBlockSize = (int)_imageFormat.GetSectorSize();
|
||||
// TODO: Detect it
|
||||
sidecar.BlockMedia[0].PhysicalBlockSize = (int)_imageFormat.GetSectorSize();
|
||||
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, "Checking filesystems", maxProgress - 1, maxProgress);
|
||||
|
||||
List<Partition> partitions = new List<Partition>();
|
||||
|
||||
foreach(PartPlugin _partplugin in plugins.PartPluginsList.Values)
|
||||
{
|
||||
List<Partition> _partitions;
|
||||
|
||||
if(_partplugin.GetInformation(_imageFormat, out _partitions))
|
||||
{
|
||||
partitions = _partitions;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sidecar.BlockMedia[0].FileSystemInformation = new PartitionType[1];
|
||||
if(partitions.Count > 0)
|
||||
{
|
||||
sidecar.BlockMedia[0].FileSystemInformation = new PartitionType[partitions.Count];
|
||||
for(int i = 0; i < partitions.Count; i++)
|
||||
{
|
||||
sidecar.BlockMedia[0].FileSystemInformation[i] = new PartitionType();
|
||||
sidecar.BlockMedia[0].FileSystemInformation[i].Description = partitions[i].PartitionDescription;
|
||||
sidecar.BlockMedia[0].FileSystemInformation[i].EndSector = (int)(partitions[i].PartitionStartSector + partitions[i].PartitionSectors - 1);
|
||||
sidecar.BlockMedia[0].FileSystemInformation[i].Name = partitions[i].PartitionName;
|
||||
sidecar.BlockMedia[0].FileSystemInformation[i].Sequence = (int)partitions[i].PartitionSequence;
|
||||
sidecar.BlockMedia[0].FileSystemInformation[i].StartSector = (int)partitions[i].PartitionStartSector;
|
||||
sidecar.BlockMedia[0].FileSystemInformation[i].Type = partitions[i].PartitionType;
|
||||
|
||||
List<FileSystemType> lstFs = new List<FileSystemType>();
|
||||
|
||||
foreach(Filesystem _plugin in plugins.PluginsList.Values)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_plugin.Identify(_imageFormat, partitions[i].PartitionStartSector, partitions[i].PartitionStartSector + partitions[i].PartitionSectors - 1))
|
||||
{
|
||||
string foo;
|
||||
_plugin.GetInformation(_imageFormat, partitions[i].PartitionStartSector, partitions[i].PartitionStartSector + partitions[i].PartitionSectors - 1, out foo);
|
||||
lstFs.Add(_plugin.XmlFSType);
|
||||
}
|
||||
}
|
||||
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||
catch
|
||||
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||
{
|
||||
//DicConsole.DebugWriteLine("Create-sidecar command", "Plugin {0} crashed", _plugin.Name);
|
||||
}
|
||||
}
|
||||
|
||||
if(lstFs.Count > 0)
|
||||
sidecar.BlockMedia[0].FileSystemInformation[i].FileSystems = lstFs.ToArray();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sidecar.BlockMedia[0].FileSystemInformation[0] = new PartitionType();
|
||||
sidecar.BlockMedia[0].FileSystemInformation[0].StartSector = 0;
|
||||
sidecar.BlockMedia[0].FileSystemInformation[0].EndSector = (int)(_imageFormat.GetSectors() - 1);
|
||||
|
||||
List<FileSystemType> lstFs = new List<FileSystemType>();
|
||||
|
||||
foreach(Filesystem _plugin in plugins.PluginsList.Values)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_plugin.Identify(_imageFormat, 0, _imageFormat.GetSectors() - 1))
|
||||
{
|
||||
string foo;
|
||||
_plugin.GetInformation(_imageFormat, 0, _imageFormat.GetSectors() - 1, out foo);
|
||||
lstFs.Add(_plugin.XmlFSType);
|
||||
}
|
||||
}
|
||||
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||
catch
|
||||
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||
{
|
||||
//DicConsole.DebugWriteLine("Create-sidecar command", "Plugin {0} crashed", _plugin.Name);
|
||||
}
|
||||
}
|
||||
|
||||
if(lstFs.Count > 0)
|
||||
sidecar.BlockMedia[0].FileSystemInformation[0].FileSystems = lstFs.ToArray();
|
||||
}
|
||||
|
||||
// TODO: Implement support for getting CHS
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, "Finishing", maxProgress, maxProgress);
|
||||
Context.workingDisk = sidecar.BlockMedia[0];
|
||||
if(Finished != null)
|
||||
Finished();
|
||||
return;
|
||||
}
|
||||
case XmlMediaType.LinearMedia:
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("Linear media not yet supported.");
|
||||
return;
|
||||
}
|
||||
case XmlMediaType.AudioMedia:
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("Audio media not yet supported.");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(Failed != null)
|
||||
Failed("Should've not arrived here.");
|
||||
return;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed(string.Format("Error reading file: {0}\n{1}", ex.Message, ex.StackTrace));
|
||||
}
|
||||
}
|
||||
|
||||
static string LbaToMsf(long lba)
|
||||
{
|
||||
long m, s, f;
|
||||
if(lba >= -150)
|
||||
{
|
||||
m = (lba + 150) / (75 * 60);
|
||||
lba -= m * (75 * 60);
|
||||
s = (lba + 150) / 75;
|
||||
lba -= s * 75;
|
||||
f = lba + 150;
|
||||
}
|
||||
else
|
||||
{
|
||||
m = (lba + 450150) / (75 * 60);
|
||||
lba -= m * (75 * 60);
|
||||
s = (lba + 450150) / 75;
|
||||
lba -= s * 75;
|
||||
f = lba + 450150;
|
||||
}
|
||||
|
||||
return string.Format("{0}:{1:D2}:{2:D2}", m, s, f);
|
||||
}
|
||||
|
||||
static string DdcdLbaToMsf(long lba)
|
||||
{
|
||||
long h, m, s, f;
|
||||
if(lba >= -150)
|
||||
{
|
||||
h = (lba + 150) / (75 * 60 * 60);
|
||||
lba -= h * (75 * 60 * 60);
|
||||
m = (lba + 150) / (75 * 60);
|
||||
lba -= m * (75 * 60);
|
||||
s = (lba + 150) / 75;
|
||||
lba -= s * 75;
|
||||
f = lba + 150;
|
||||
}
|
||||
else
|
||||
{
|
||||
h = (lba + 450150 * 2) / (75 * 60 * 60);
|
||||
lba -= h * (75 * 60 * 60);
|
||||
m = (lba + 450150 * 2) / (75 * 60);
|
||||
lba -= m * (75 * 60);
|
||||
s = (lba + 450150 * 2) / 75;
|
||||
lba -= s * 75;
|
||||
f = lba + 450150 * 2;
|
||||
}
|
||||
|
||||
return string.Format("{3}:{0:D2}:{1:D2}:{2:D2}", m, s, f, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
189
osrepodbmgr.Core/PlatformID.cs
Normal file
189
osrepodbmgr.Core/PlatformID.cs
Normal file
@@ -0,0 +1,189 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : PlatformID.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Interop services.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains an enhanced PlatformID enumeration.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2016 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
namespace DiscImageChef.Interop
|
||||
{
|
||||
public enum PlatformID
|
||||
{
|
||||
/// <summary>
|
||||
/// Win32s
|
||||
/// </summary>
|
||||
Win32S = 0,
|
||||
/// <summary>
|
||||
/// Win32 (Windows 9x)
|
||||
/// </summary>
|
||||
Win32Windows = 1,
|
||||
/// <summary>
|
||||
/// Windows NT
|
||||
/// </summary>
|
||||
Win32NT = 2,
|
||||
/// <summary>
|
||||
/// Windows Mobile
|
||||
/// </summary>
|
||||
WinCE = 3,
|
||||
/// <summary>
|
||||
/// UNIX (do not use, too generic)
|
||||
/// </summary>
|
||||
Unix = 4,
|
||||
/// <summary>
|
||||
/// Xbox 360
|
||||
/// </summary>
|
||||
Xbox = 5,
|
||||
/// <summary>
|
||||
/// OS X
|
||||
/// </summary>
|
||||
MacOSX = 6,
|
||||
/// <summary>
|
||||
/// iOS is not OS X
|
||||
/// </summary>
|
||||
iOS = 7,
|
||||
/// <summary>
|
||||
/// Linux
|
||||
/// </summary>
|
||||
Linux = 8,
|
||||
/// <summary>
|
||||
/// Sun Solaris
|
||||
/// </summary>
|
||||
Solaris = 9,
|
||||
/// <summary>
|
||||
/// NetBSD
|
||||
/// </summary>
|
||||
NetBSD = 10,
|
||||
/// <summary>
|
||||
/// OpenBSD
|
||||
/// </summary>
|
||||
OpenBSD = 11,
|
||||
/// <summary>
|
||||
/// FreeBSD
|
||||
/// </summary>
|
||||
FreeBSD = 12,
|
||||
/// <summary>
|
||||
/// DragonFly BSD
|
||||
/// </summary>
|
||||
DragonFly = 13,
|
||||
/// <summary>
|
||||
/// Nintendo Wii
|
||||
/// </summary>
|
||||
Wii = 14,
|
||||
/// <summary>
|
||||
/// Nintendo Wii U
|
||||
/// </summary>
|
||||
WiiU = 15,
|
||||
/// <summary>
|
||||
/// Sony PlayStation 3
|
||||
/// </summary>
|
||||
PlayStation3 = 16,
|
||||
/// <summary>
|
||||
/// Sony Playstation 4
|
||||
/// </summary>
|
||||
PlayStation4 = 17,
|
||||
/// <summary>
|
||||
/// Google Android
|
||||
/// </summary>
|
||||
Android = 18,
|
||||
/// <summary>
|
||||
/// Samsung Tizen
|
||||
/// </summary>
|
||||
Tizen = 19,
|
||||
/// <summary>
|
||||
/// Windows Phone
|
||||
/// </summary>
|
||||
WindowsPhone = 20,
|
||||
/// <summary>
|
||||
/// GNU/Hurd
|
||||
/// </summary>
|
||||
Hurd = 21,
|
||||
/// <summary>
|
||||
/// Haiku
|
||||
/// </summary>
|
||||
Haiku = 22,
|
||||
/// <summary>
|
||||
/// HP-UX
|
||||
/// </summary>
|
||||
HPUX = 23,
|
||||
/// <summary>
|
||||
/// AIX
|
||||
/// </summary>
|
||||
AIX = 24,
|
||||
/// <summary>
|
||||
/// OS/400
|
||||
/// </summary>
|
||||
OS400 = 25,
|
||||
/// <summary>
|
||||
/// IRIX
|
||||
/// </summary>
|
||||
IRIX = 26,
|
||||
/// <summary>
|
||||
/// Minix
|
||||
/// </summary>
|
||||
Minix = 27,
|
||||
/// <summary>
|
||||
/// NonStop
|
||||
/// </summary>
|
||||
NonStop = 28,
|
||||
/// <summary>
|
||||
/// QNX
|
||||
/// </summary>
|
||||
QNX = 29,
|
||||
/// <summary>
|
||||
/// SINIX
|
||||
/// </summary>
|
||||
SINIX = 30,
|
||||
/// <summary>
|
||||
/// Tru64 UNIX
|
||||
/// </summary>
|
||||
Tru64 = 31,
|
||||
/// <summary>
|
||||
/// Ultrix
|
||||
/// </summary>
|
||||
Ultrix = 32,
|
||||
/// <summary>
|
||||
/// SCO OpenServer / SCO UNIX
|
||||
/// </summary>
|
||||
OpenServer = 33,
|
||||
/// <summary>
|
||||
/// SCO UnixWare
|
||||
/// </summary>
|
||||
UnixWare = 34,
|
||||
/// <summary>
|
||||
/// IBM z/OS
|
||||
/// </summary>
|
||||
zOS = 35,
|
||||
Unknown = -1
|
||||
}
|
||||
}
|
||||
137
osrepodbmgr.Core/PluginBase.cs
Normal file
137
osrepodbmgr.Core/PluginBase.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Plugins.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Plugins
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Base methods for plugins.
|
||||
//
|
||||
// --[ 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/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2016 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using DiscImageChef.Filesystems;
|
||||
using DiscImageChef.ImagePlugins;
|
||||
using DiscImageChef.PartPlugins;
|
||||
|
||||
namespace osrepodbmgr.Core
|
||||
{
|
||||
public class PluginBase
|
||||
{
|
||||
public SortedDictionary<string, Filesystem> PluginsList;
|
||||
public SortedDictionary<string, PartPlugin> PartPluginsList;
|
||||
public SortedDictionary<string, ImagePlugin> ImagePluginsList;
|
||||
|
||||
public PluginBase()
|
||||
{
|
||||
PluginsList = new SortedDictionary<string, Filesystem>();
|
||||
PartPluginsList = new SortedDictionary<string, PartPlugin>();
|
||||
ImagePluginsList = new SortedDictionary<string, ImagePlugin>();
|
||||
}
|
||||
|
||||
public void RegisterAllPlugins()
|
||||
{
|
||||
Assembly assembly;
|
||||
|
||||
assembly = Assembly.GetAssembly(typeof(ImagePlugin));
|
||||
|
||||
foreach(Type type in assembly.GetTypes())
|
||||
{
|
||||
try
|
||||
{
|
||||
if(type.IsSubclassOf(typeof(ImagePlugin)))
|
||||
{
|
||||
ImagePlugin plugin = (ImagePlugin)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
|
||||
RegisterImagePlugin(plugin);
|
||||
}
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
Console.WriteLine("Exception {0}", exception);
|
||||
}
|
||||
}
|
||||
|
||||
assembly = Assembly.GetAssembly(typeof(PartPlugin));
|
||||
|
||||
foreach(Type type in assembly.GetTypes())
|
||||
{
|
||||
try
|
||||
{
|
||||
if(type.IsSubclassOf(typeof(PartPlugin)))
|
||||
{
|
||||
PartPlugin plugin = (PartPlugin)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
|
||||
RegisterPartPlugin(plugin);
|
||||
}
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
Console.WriteLine("Exception {0}", exception);
|
||||
}
|
||||
}
|
||||
|
||||
assembly = Assembly.GetAssembly(typeof(Filesystem));
|
||||
|
||||
foreach(Type type in assembly.GetTypes())
|
||||
{
|
||||
try
|
||||
{
|
||||
if(type.IsSubclassOf(typeof(Filesystem)))
|
||||
{
|
||||
Filesystem plugin = (Filesystem)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
|
||||
RegisterPlugin(plugin);
|
||||
}
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
Console.WriteLine("Exception {0}", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterImagePlugin(ImagePlugin plugin)
|
||||
{
|
||||
if(!ImagePluginsList.ContainsKey(plugin.Name.ToLower()))
|
||||
{
|
||||
ImagePluginsList.Add(plugin.Name.ToLower(), plugin);
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterPlugin(Filesystem plugin)
|
||||
{
|
||||
if(!PluginsList.ContainsKey(plugin.Name.ToLower()))
|
||||
{
|
||||
PluginsList.Add(plugin.Name.ToLower(), plugin);
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterPartPlugin(PartPlugin partplugin)
|
||||
{
|
||||
if(!PartPluginsList.ContainsKey(partplugin.Name.ToLower()))
|
||||
{
|
||||
PartPluginsList.Add(partplugin.Name.ToLower(), partplugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
53
osrepodbmgr.Core/Properties/AssemblyInfo.cs
Normal file
53
osrepodbmgr.Core/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo claunia@claunia.com
|
||||
//
|
||||
// Copyright (c) 2017, © Claunia.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the [ORGANIZATION] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("osrepodbmgr.Core")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Claunia.com")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("© Claunia.com")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
143
osrepodbmgr.Core/SQLite.cs
Normal file
143
osrepodbmgr.Core/SQLite.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo claunia@claunia.com
|
||||
//
|
||||
// Copyright (c) 2017, © Claunia.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the [ORGANIZATION] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SQLite;
|
||||
|
||||
namespace osrepodbmgr.Core
|
||||
{
|
||||
public class SQLite : DBCore
|
||||
{
|
||||
SQLiteConnection dbCon;
|
||||
|
||||
#region implemented abstract members of DBCore
|
||||
|
||||
public override bool OpenDB(string database, string server, string user, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
string dataSrc = string.Format("URI=file:{0}", database);
|
||||
dbCon = new SQLiteConnection(dataSrc);
|
||||
dbCon.Open();
|
||||
string sql;
|
||||
|
||||
sql = "SELECT * FROM osrepodbmgr";
|
||||
|
||||
SQLiteCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = sql;
|
||||
SQLiteDataAdapter dAdapter = new SQLiteDataAdapter();
|
||||
dAdapter.SelectCommand = dbcmd;
|
||||
DataSet dSet = new DataSet();
|
||||
dAdapter.Fill(dSet);
|
||||
DataTable dTable = dSet.Tables[0];
|
||||
|
||||
if(dTable.Rows.Count != 1)
|
||||
return false;
|
||||
|
||||
if((long)dTable.Rows[0]["version"] != 1)
|
||||
{
|
||||
dbCon = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
DBOps = new DBOps(dbCon, this);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(SQLiteException ex)
|
||||
{
|
||||
Console.WriteLine("Error opening DB.");
|
||||
Console.WriteLine(ex.Message);
|
||||
dbCon = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void CloseDB()
|
||||
{
|
||||
if(dbCon != null)
|
||||
dbCon.Close();
|
||||
|
||||
DBOps = null;
|
||||
}
|
||||
|
||||
public override bool CreateDB(string database, string server, string user, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
string dataSrc = string.Format("URI=file:{0}", database);
|
||||
dbCon = new SQLiteConnection(dataSrc);
|
||||
dbCon.Open();
|
||||
SQLiteCommand dbCmd = dbCon.CreateCommand();
|
||||
string sql;
|
||||
|
||||
Console.WriteLine("Creating osrepodbmgr table");
|
||||
|
||||
sql = "CREATE TABLE osrepodbmgr ( version INTEGER, name TEXT )";
|
||||
dbCmd.CommandText = sql;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
sql = "INSERT INTO osrepodbmgr ( version, name ) VALUES ( '1', 'Canary Islands Computer Museum' )";
|
||||
dbCmd.CommandText = sql;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating oses table");
|
||||
dbCmd.CommandText = Schema.OSesTableSql;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating files table");
|
||||
dbCmd.CommandText = Schema.FilesTableSql;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
dbCmd.Dispose();
|
||||
dbCon = null;
|
||||
return true;
|
||||
}
|
||||
catch(SQLiteException ex)
|
||||
{
|
||||
Console.WriteLine("Error opening DB.");
|
||||
Console.WriteLine(ex.Message);
|
||||
dbCon = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override IDbDataAdapter GetNewDataAdapter()
|
||||
{
|
||||
return new SQLiteDataAdapter();
|
||||
}
|
||||
|
||||
public override long LastInsertRowId
|
||||
{
|
||||
get { return dbCon.LastInsertRowId; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
74
osrepodbmgr.Core/Schema.cs
Normal file
74
osrepodbmgr.Core/Schema.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo claunia@claunia.com
|
||||
//
|
||||
// Copyright (c) 2017, © Claunia.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the [ORGANIZATION] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
namespace osrepodbmgr.Core
|
||||
{
|
||||
public static class Schema
|
||||
{
|
||||
public const string FilesTableSql = "-- -----------------------------------------------------\n" +
|
||||
"-- Table `files`\n" +
|
||||
"-- -----------------------------------------------------\n" +
|
||||
"DROP TABLE IF EXISTS `files` ;\n\n" +
|
||||
"CREATE TABLE IF NOT EXISTS `files` (\n" +
|
||||
" `id` INTEGER PRIMARY KEY AUTOINCREMENT,\n" +
|
||||
" `sha256` VARCHAR(64) NOT NULL);\n\n" +
|
||||
"CREATE UNIQUE INDEX `files_id_UNIQUE` ON `files` (`id` ASC);\n\n" +
|
||||
"CREATE UNIQUE INDEX `files_sha256_UNIQUE` ON `files` (`sha256` ASC);";
|
||||
|
||||
public const string OSesTableSql = "-- -----------------------------------------------------\n" +
|
||||
"-- Table `oses`\n" +
|
||||
"-- -----------------------------------------------------\n" +
|
||||
"DROP TABLE IF EXISTS `oses` ;\n\n" +
|
||||
"CREATE TABLE IF NOT EXISTS `oses` (\n" +
|
||||
" `id` INTEGER PRIMARY KEY AUTOINCREMENT,\n" +
|
||||
" `developer` VARCHAR(45) NOT NULL,\n" +
|
||||
" `product` VARCHAR(45) NOT NULL,\n" +
|
||||
" `version` VARCHAR(45) NULL,\n" +
|
||||
" `languages` VARCHAR(45) NULL,\n" +
|
||||
" `architecture` VARCHAR(45) NULL,\n" +
|
||||
" `machine` VARCHAR(45) NULL,\n" +
|
||||
" `format` VARCHAR(45) NULL,\n" +
|
||||
" `description` VARCHAR(45) NULL,\n" +
|
||||
" `oem` BOOLEAN NULL,\n" +
|
||||
" `upgrade` BOOLEAN NULL,\n" +
|
||||
" `update` BOOLEAN NULL,\n" +
|
||||
" `source` BOOLEAN NULL,\n" +
|
||||
" `files` BOOLEAN NULL,\n" +
|
||||
" `netinstall` BOOLEAN NULL,\n" +
|
||||
" `xml` BLOB NULL,\n" +
|
||||
" `json` BLOB NULL);\n\n" +
|
||||
"CREATE UNIQUE INDEX `oses_id_UNIQUE` ON `oses` (`id` ASC);\n\n" +
|
||||
"CREATE INDEX `oses_developer_idx` ON `oses` (`developer` ASC);\n\n" +
|
||||
"CREATE INDEX `oses_product_idx` ON `oses` (`product` ASC);\n\n" +
|
||||
"CREATE INDEX `oses_version_idx` ON `oses` (`version` ASC);\n\n" +
|
||||
"CREATE INDEX `oses_architecture_idx` ON `oses` (`architecture` ASC);\n\n" +
|
||||
"CREATE INDEX `oses_format_idx` ON `oses` (`format` ASC);\n\n" +
|
||||
"CREATE INDEX `oses_machine_idx` ON `oses` (`machine` ASC);\n\n" +
|
||||
"CREATE INDEX `oses_description_idx` ON `oses` (`description` ASC);";
|
||||
}
|
||||
}
|
||||
|
||||
240
osrepodbmgr.Core/Settings.cs
Normal file
240
osrepodbmgr.Core/Settings.cs
Normal file
@@ -0,0 +1,240 @@
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo claunia@claunia.com
|
||||
//
|
||||
// Copyright (c) 2017, © Canary Islands Computer Museum
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the [ORGANIZATION] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml.Serialization;
|
||||
using Claunia.PropertyList;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace osrepodbmgr.Core
|
||||
{
|
||||
public class SetSettings
|
||||
{
|
||||
public string TemporaryFolder;
|
||||
public string DatabasePath;
|
||||
public string RepositoryPath;
|
||||
public string UnArchiverPath;
|
||||
}
|
||||
|
||||
public static class Settings
|
||||
{
|
||||
public static SetSettings Current;
|
||||
|
||||
public static void LoadSettings()
|
||||
{
|
||||
Current = new SetSettings();
|
||||
DiscImageChef.Interop.PlatformID ptID = DiscImageChef.Interop.DetectOS.GetRealPlatformID();
|
||||
|
||||
try
|
||||
{
|
||||
switch(ptID)
|
||||
{
|
||||
case DiscImageChef.Interop.PlatformID.MacOSX:
|
||||
case DiscImageChef.Interop.PlatformID.iOS:
|
||||
{
|
||||
string preferencesPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library", "Preferences");
|
||||
string preferencesFilePath = Path.Combine(preferencesPath, "com.claunia.museum.osrepodbmgr.plist");
|
||||
|
||||
if(!File.Exists(preferencesFilePath))
|
||||
{
|
||||
SetDefaultSettings();
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
NSDictionary parsedPreferences = (NSDictionary)BinaryPropertyListParser.Parse(new FileInfo(preferencesFilePath));
|
||||
if(parsedPreferences != null)
|
||||
{
|
||||
NSObject obj;
|
||||
|
||||
if(parsedPreferences.TryGetValue("TemporaryFolder", out obj))
|
||||
{
|
||||
Current.TemporaryFolder = ((NSString)obj).ToString();
|
||||
}
|
||||
else
|
||||
Current.TemporaryFolder = Path.GetTempPath();
|
||||
|
||||
if(parsedPreferences.TryGetValue("DatabasePath", out obj))
|
||||
{
|
||||
Current.DatabasePath = ((NSString)obj).ToString();
|
||||
}
|
||||
else
|
||||
Current.DatabasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "osrepodbmgr.db");
|
||||
|
||||
if(parsedPreferences.TryGetValue("RepositoryPath", out obj))
|
||||
{
|
||||
Current.RepositoryPath = ((NSString)obj).ToString();
|
||||
}
|
||||
else
|
||||
Current.RepositoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "osrepo");
|
||||
|
||||
if(parsedPreferences.TryGetValue("UnArchiverPath", out obj))
|
||||
{
|
||||
Current.UnArchiverPath = ((NSString)obj).ToString();
|
||||
}
|
||||
else
|
||||
Current.UnArchiverPath = null;
|
||||
|
||||
}
|
||||
else {
|
||||
SetDefaultSettings();
|
||||
SaveSettings();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DiscImageChef.Interop.PlatformID.Win32NT:
|
||||
case DiscImageChef.Interop.PlatformID.Win32S:
|
||||
case DiscImageChef.Interop.PlatformID.Win32Windows:
|
||||
case DiscImageChef.Interop.PlatformID.WinCE:
|
||||
case DiscImageChef.Interop.PlatformID.WindowsPhone:
|
||||
{
|
||||
RegistryKey parentKey = Registry.CurrentUser.OpenSubKey("SOFTWARE").OpenSubKey("Canary Islands Computer Museum");
|
||||
if(parentKey == null)
|
||||
{
|
||||
SetDefaultSettings();
|
||||
SaveSettings();
|
||||
return;
|
||||
}
|
||||
|
||||
RegistryKey key = parentKey.OpenSubKey("OSRepoDBMgr");
|
||||
if(key == null)
|
||||
{
|
||||
SetDefaultSettings();
|
||||
SaveSettings();
|
||||
return;
|
||||
}
|
||||
|
||||
Current.TemporaryFolder = (string)key.GetValue("TemporaryFolder");
|
||||
Current.DatabasePath = (string)key.GetValue("DatabasePath");
|
||||
Current.RepositoryPath = (string)key.GetValue("RepositoryPath");
|
||||
Current.UnArchiverPath = (string)key.GetValue("UnArchiverPath");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
string configPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config");
|
||||
string settingsPath = Path.Combine(configPath, "OSRepoDBMgr.xml");
|
||||
|
||||
if(!Directory.Exists(configPath))
|
||||
{
|
||||
SetDefaultSettings();
|
||||
SaveSettings();
|
||||
return;
|
||||
}
|
||||
|
||||
XmlSerializer xs = new XmlSerializer(Current.GetType());
|
||||
StreamReader sr = new StreamReader(settingsPath);
|
||||
Current = (SetSettings)xs.Deserialize(sr);
|
||||
sr.Close();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
SetDefaultSettings();
|
||||
SaveSettings();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
DiscImageChef.Interop.PlatformID ptID = DiscImageChef.Interop.DetectOS.GetRealPlatformID();
|
||||
|
||||
switch(ptID)
|
||||
{
|
||||
case DiscImageChef.Interop.PlatformID.MacOSX:
|
||||
case DiscImageChef.Interop.PlatformID.iOS:
|
||||
{
|
||||
NSDictionary root = new NSDictionary();
|
||||
root.Add("TemporaryFolder", Current.TemporaryFolder);
|
||||
root.Add("DatabasePath", Current.DatabasePath);
|
||||
root.Add("RepositoryPath", Current.RepositoryPath);
|
||||
root.Add("UnArchiverPath", Current.UnArchiverPath);
|
||||
|
||||
string preferencesPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library", "Preferences");
|
||||
string preferencesFilePath = Path.Combine(preferencesPath, "com.claunia.museum.osrepodbmgr.plist");
|
||||
|
||||
FileStream fs = new FileStream(preferencesFilePath, FileMode.Create);
|
||||
BinaryPropertyListWriter.Write(fs, root);
|
||||
fs.Close();
|
||||
}
|
||||
break;
|
||||
case DiscImageChef.Interop.PlatformID.Win32NT:
|
||||
case DiscImageChef.Interop.PlatformID.Win32S:
|
||||
case DiscImageChef.Interop.PlatformID.Win32Windows:
|
||||
case DiscImageChef.Interop.PlatformID.WinCE:
|
||||
case DiscImageChef.Interop.PlatformID.WindowsPhone:
|
||||
{
|
||||
RegistryKey parentKey = Registry.CurrentUser.OpenSubKey("SOFTWARE").CreateSubKey("Canary Islands Computer Museum");
|
||||
RegistryKey key = parentKey.CreateSubKey("OSRepoDBMgr");
|
||||
|
||||
key.SetValue("TemporaryFolder", Current.TemporaryFolder);
|
||||
key.SetValue("DatabasePath", Current.DatabasePath);
|
||||
key.SetValue("RepositoryPath", Current.RepositoryPath);
|
||||
key.SetValue("UnArchiverPath", Current.UnArchiverPath);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
string configPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config");
|
||||
string settingsPath = Path.Combine(configPath, "OSRepoDBMgr.xml");
|
||||
|
||||
if(!Directory.Exists(configPath))
|
||||
Directory.CreateDirectory(configPath);
|
||||
|
||||
FileStream fs = new FileStream(settingsPath, FileMode.Create);
|
||||
XmlSerializer xs = new XmlSerializer(Current.GetType());
|
||||
xs.Serialize(fs, Current);
|
||||
fs.Close();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||
catch
|
||||
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||
{
|
||||
if(System.Diagnostics.Debugger.IsAttached)
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetDefaultSettings()
|
||||
{
|
||||
Current = new SetSettings();
|
||||
Current.TemporaryFolder = Path.GetTempPath();
|
||||
Current.DatabasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "osrepodbmgr.db");
|
||||
Current.RepositoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "osrepo");
|
||||
Current.UnArchiverPath = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
101
osrepodbmgr.Core/osrepodbmgr.Core.csproj
Normal file
101
osrepodbmgr.Core/osrepodbmgr.Core.csproj
Normal file
@@ -0,0 +1,101 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{076D5C4D-9601-4164-B979-0DABACB56BB8}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>osrepodbmgr.Core</RootNamespace>
|
||||
<AssemblyName>osrepodbmgr.Core</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DotNetZip">
|
||||
<HintPath>..\packages\DotNetZip.1.10.1\lib\net20\DotNetZip.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="plist-cil">
|
||||
<HintPath>..\packages\plist-cil.1.15.0\lib\net40\plist-cil.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.SQLite">
|
||||
<HintPath>..\packages\System.Data.SQLite.Core.1.0.105.0\lib\net45\System.Data.SQLite.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Data" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Checksum.cs" />
|
||||
<Compile Include="Core.cs" />
|
||||
<Compile Include="DBCore.cs" />
|
||||
<Compile Include="DBOps.cs" />
|
||||
<Compile Include="DetectImageFormat.cs" />
|
||||
<Compile Include="DetectOS.cs" />
|
||||
<Compile Include="DicCore.cs" />
|
||||
<Compile Include="PlatformID.cs" />
|
||||
<Compile Include="PluginBase.cs" />
|
||||
<Compile Include="Schema.cs" />
|
||||
<Compile Include="Settings.cs" />
|
||||
<Compile Include="SQLite.cs" />
|
||||
<Compile Include="Context.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DiscImageChef\DiscImageChef.Checksums\DiscImageChef.Checksums.csproj">
|
||||
<Project>{CC48B324-A532-4A45-87A6-6F91F7141E8D}</Project>
|
||||
<Name>DiscImageChef.Checksums</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\DiscImageChef\DiscImageChef.CommonTypes\DiscImageChef.CommonTypes.csproj">
|
||||
<Project>{F2B84194-26EB-4227-B1C5-6602517E85AE}</Project>
|
||||
<Name>DiscImageChef.CommonTypes</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\DiscImageChef\DiscImageChef.Decoders\DiscImageChef.Decoders.csproj">
|
||||
<Project>{0BEB3088-B634-4289-AE17-CDF2D25D00D5}</Project>
|
||||
<Name>DiscImageChef.Decoders</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\DiscImageChef\DiscImageChef.DiscImages\DiscImageChef.DiscImages.csproj">
|
||||
<Project>{74032CBC-339B-42F3-AF6F-E96C261F3E6A}</Project>
|
||||
<Name>DiscImageChef.DiscImages</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\DiscImageChef\DiscImageChef.Filesystems\DiscImageChef.Filesystems.csproj">
|
||||
<Project>{D7016DF2-5A5E-4524-B40D-BA2D59576688}</Project>
|
||||
<Name>DiscImageChef.Filesystems</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\DiscImageChef\DiscImageChef.Filters\DiscImageChef.Filters.csproj">
|
||||
<Project>{D571B8EF-903D-4353-BDD5-B834F9F029EF}</Project>
|
||||
<Name>DiscImageChef.Filters</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\DiscImageChef\DiscImageChef.Metadata\DiscImageChef.Metadata.csproj">
|
||||
<Project>{9F213318-5CB8-4066-A757-074489C9F818}</Project>
|
||||
<Name>DiscImageChef.Metadata</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\DiscImageChef\DiscImageChef.Partitions\DiscImageChef.Partitions.csproj">
|
||||
<Project>{DA7AB65D-B5BA-4003-8893-A51BB071BA2F}</Project>
|
||||
<Name>DiscImageChef.Partitions</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\System.Data.SQLite.Core.1.0.105.0\build\net45\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.105.0\build\net45\System.Data.SQLite.Core.targets')" />
|
||||
</Project>
|
||||
7
osrepodbmgr.Core/packages.config
Normal file
7
osrepodbmgr.Core/packages.config
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="DotNetZip" version="1.10.1" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net45" />
|
||||
<package id="plist-cil" version="1.15.0" targetFramework="net45" />
|
||||
<package id="System.Data.SQLite.Core" version="1.0.105.0" targetFramework="net45" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user