General refactor and code cleanup.

This commit is contained in:
2017-12-30 00:32:21 +00:00
parent d47d64a86a
commit f5805acde1
42 changed files with 10532 additions and 11118 deletions

View File

@@ -25,6 +25,7 @@
// 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 enum AlgoEnum
@@ -34,4 +35,4 @@ namespace osrepodbmgr.Core
LZMA,
LZip
}
}
}

View File

@@ -29,6 +29,7 @@
// ----------------------------------------------------------------------------
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
using System.Collections.Generic;
using System.Threading;
using DiscImageChef.Checksums;
@@ -39,78 +40,78 @@ 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;
Thread adlerThread;
Crc16Context crc16ctx;
crc16Packet crc16Pkt;
Thread crc16Thread;
Crc32Context crc32ctx;
crc32Packet crc32Pkt;
Thread crc32Thread;
Crc64Context crc64ctx;
crc64Packet crc64Pkt;
Thread crc64Thread;
Md5Context md5ctx;
md5Packet md5Pkt;
Thread md5Thread;
Ripemd160Context ripemd160ctx;
ripemd160Packet ripemd160Pkt;
Thread ripemd160Thread;
Sha1Context sha1ctx;
sha1Packet sha1Pkt;
Thread sha1Thread;
Sha256Context sha256ctx;
sha256Packet sha256Pkt;
Thread sha256Thread;
Sha384Context sha384ctx;
sha384Packet sha384Pkt;
Thread sha384Thread;
Sha512Context sha512ctx;
sha512Packet sha512Pkt;
Thread sha512Thread;
spamsumPacket spamsumPkt;
Thread spamsumThread;
SpamSumContext ssctx;
internal Checksum()
{
adler32ctx = new Adler32Context();
crc16ctx = new Crc16Context();
crc32ctx = new Crc32Context();
crc64ctx = new Crc64Context();
md5ctx = new Md5Context();
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();
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);
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);
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();
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();
sha1Pkt = new sha1Packet();
sha256Pkt = new sha256Packet();
sha384Pkt = new sha384Packet();
sha512Pkt = new sha512Packet();
spamsumPkt = new spamsumPacket();
adler32ctx.Init();
adlerPkt.context = adler32ctx;
@@ -161,85 +162,58 @@ namespace osrepodbmgr.Core
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)
{
}
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);
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);
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();
ChecksumType chk = new ChecksumType {type = ChecksumTypeType.adler32, Value = adler32ctx.End()};
chks.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.crc16;
chk.Value = crc16ctx.End();
chk = new ChecksumType {type = ChecksumTypeType.crc16, Value = crc16ctx.End()};
chks.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.crc32;
chk.Value = crc32ctx.End();
chk = new ChecksumType {type = ChecksumTypeType.crc32, Value = crc32ctx.End()};
chks.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.crc64;
chk.Value = crc64ctx.End();
chk = new ChecksumType {type = ChecksumTypeType.crc64, Value = crc64ctx.End()};
chks.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.md5;
chk.Value = md5ctx.End();
chk = new ChecksumType {type = ChecksumTypeType.md5, Value = md5ctx.End()};
chks.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.ripemd160;
chk.Value = ripemd160ctx.End();
chk = new ChecksumType {type = ChecksumTypeType.ripemd160, Value = ripemd160ctx.End()};
chks.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.sha1;
chk.Value = sha1ctx.End();
chk = new ChecksumType {type = ChecksumTypeType.sha1, Value = sha1ctx.End()};
chks.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.sha256;
chk.Value = sha256ctx.End();
chk = new ChecksumType {type = ChecksumTypeType.sha256, Value = sha256ctx.End()};
chks.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.sha384;
chk.Value = sha384ctx.End();
chk = new ChecksumType {type = ChecksumTypeType.sha384, Value = sha384ctx.End()};
chks.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.sha512;
chk.Value = sha512ctx.End();
chk = new ChecksumType {type = ChecksumTypeType.sha512, Value = sha512ctx.End()};
chks.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.spamsum;
chk.Value = ssctx.End();
chk = new ChecksumType {type = ChecksumTypeType.spamsum, Value = ssctx.End()};
chks.Add(chk);
return chks;
@@ -247,41 +221,41 @@ namespace osrepodbmgr.Core
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();
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();
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 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);
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();
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();
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;
@@ -329,142 +303,114 @@ namespace osrepodbmgr.Core
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)
{
}
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();
ChecksumType chk = new ChecksumType {type = ChecksumTypeType.adler32, Value = adler32ctxData.End()};
dataChecksums.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.crc16;
chk.Value = crc16ctxData.End();
chk = new ChecksumType {type = ChecksumTypeType.crc16, Value = crc16ctxData.End()};
dataChecksums.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.crc32;
chk.Value = crc32ctxData.End();
chk = new ChecksumType {type = ChecksumTypeType.crc32, Value = crc32ctxData.End()};
dataChecksums.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.crc64;
chk.Value = crc64ctxData.End();
chk = new ChecksumType {type = ChecksumTypeType.crc64, Value = crc64ctxData.End()};
dataChecksums.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.md5;
chk.Value = md5ctxData.End();
chk = new ChecksumType {type = ChecksumTypeType.md5, Value = md5ctxData.End()};
dataChecksums.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.ripemd160;
chk.Value = ripemd160ctxData.End();
chk = new ChecksumType {type = ChecksumTypeType.ripemd160, Value = ripemd160ctxData.End()};
dataChecksums.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.sha1;
chk.Value = sha1ctxData.End();
chk = new ChecksumType {type = ChecksumTypeType.sha1, Value = sha1ctxData.End()};
dataChecksums.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.sha256;
chk.Value = sha256ctxData.End();
chk = new ChecksumType {type = ChecksumTypeType.sha256, Value = sha256ctxData.End()};
dataChecksums.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.sha384;
chk.Value = sha384ctxData.End();
chk = new ChecksumType {type = ChecksumTypeType.sha384, Value = sha384ctxData.End()};
dataChecksums.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.sha512;
chk.Value = sha512ctxData.End();
chk = new ChecksumType {type = ChecksumTypeType.sha512, Value = sha512ctxData.End()};
dataChecksums.Add(chk);
chk = new ChecksumType();
chk.type = ChecksumTypeType.spamsum;
chk.Value = ssctxData.End();
chk = new ChecksumType {type = ChecksumTypeType.spamsum, Value = ssctxData.End()};
dataChecksums.Add(chk);
return dataChecksums;
}
#region Threading helpers
struct adlerPacket
{
public Adler32Context context;
public byte[] data;
public byte[] data;
}
struct crc16Packet
{
public Crc16Context context;
public byte[] data;
public byte[] data;
}
struct crc32Packet
{
public Crc32Context context;
public byte[] data;
public byte[] data;
}
struct crc64Packet
{
public Crc64Context context;
public byte[] data;
public byte[] data;
}
struct md5Packet
{
public Md5Context context;
public byte[] data;
public byte[] data;
}
struct ripemd160Packet
{
public Ripemd160Context context;
public byte[] data;
public byte[] data;
}
struct sha1Packet
{
public Sha1Context context;
public byte[] data;
public byte[] data;
}
struct sha256Packet
{
public Sha256Context context;
public byte[] data;
public byte[] data;
}
struct sha384Packet
{
public Sha384Context context;
public byte[] data;
public byte[] data;
}
struct sha512Packet
{
public Sha512Context context;
public byte[] data;
public byte[] data;
}
struct spamsumPacket
{
public SpamSumContext context;
public byte[] data;
public byte[] data;
}
static void updateAdler(object packet)
@@ -521,8 +467,6 @@ namespace osrepodbmgr.Core
{
((spamsumPacket)packet).context.Update(((spamsumPacket)packet).data);
}
#endregion Threading helpers
}
}
}

View File

@@ -1,4 +1,4 @@
//
//
// Author:
// Natalia Portillo claunia@claunia.com
//
@@ -25,6 +25,7 @@
// 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.Collections.Generic;
using System.Diagnostics;
using System.Threading;
@@ -34,36 +35,36 @@ namespace osrepodbmgr.Core
{
public static class Context
{
public static List<string> files;
public static List<string> folders;
public static List<string> symlinks;
public static Dictionary<string, DBOSFile> hashes;
public static Dictionary<string, DBFolder> foldersDict;
public static Dictionary<string, string> symlinksDict;
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 unzipWithUnAr;
public static string selectedFile;
public static OpticalDiscType workingDisc;
public static BlockMediaType workingDisk;
public static CICMMetadataType metadata;
public static bool userExtracting;
public static bool usableDotNetZip;
public static string clamdVersion;
public static bool virusTotalEnabled;
public delegate void UnarChangeStatusDelegate();
public static event UnarChangeStatusDelegate UnarChangeStatus;
public static List<string> Files;
public static List<string> Folders;
public static List<string> Symlinks;
public static Dictionary<string, DbOsFile> Hashes;
public static Dictionary<string, DbFolder> FoldersDict;
public static Dictionary<string, string> SymlinksDict;
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 UnzipWithUnAr;
public static string SelectedFile;
public static OpticalDiscType WorkingDisc;
public static BlockMediaType WorkingDisk;
public static CICMMetadataType Metadata;
public static bool UserExtracting;
public static bool UsableDotNetZip;
public static string ClamdVersion;
public static bool VirusTotalEnabled;
public static event UnarChangeStatusDelegate UnarChangeStatus;
public static void CheckUnar()
{
Workers.FinishedWithText += CheckUnarFinished;
Workers.Failed += CheckUnarFailed;
Workers.Failed += CheckUnarFailed;
Thread thdCheckUnar = new Thread(Workers.CheckUnar);
thdCheckUnar.Start();
@@ -71,20 +72,18 @@ namespace osrepodbmgr.Core
static void CheckUnarFinished(string text)
{
unarUsable = true;
if(UnarChangeStatus != null)
UnarChangeStatus();
UnarUsable = true;
UnarChangeStatus?.Invoke();
Workers.FinishedWithText -= CheckUnarFinished;
Workers.Failed -= CheckUnarFailed;
Workers.Failed -= CheckUnarFailed;
}
static void CheckUnarFailed(string text)
{
unarUsable = false;
if(UnarChangeStatus != null)
UnarChangeStatus();
UnarUsable = false;
UnarChangeStatus?.Invoke();
Workers.FinishedWithText -= CheckUnarFinished;
Workers.Failed -= CheckUnarFailed;
Workers.Failed -= CheckUnarFailed;
}
}
}
}

View File

@@ -25,25 +25,23 @@
// 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 class DbCore
{
public abstract bool OpenDB(string database, string server, string user, string password);
public DbOps DbOps;
public abstract void CloseDB();
public abstract long LastInsertRowId { get; }
public abstract bool CreateDB(string database, string server, string user, string password);
public abstract bool OpenDb(string database, string server, string user, string password);
public DBOps DBOps;
public abstract void CloseDb();
public abstract bool CreateDb(string database, string server, string user, string password);
public abstract IDbDataAdapter GetNewDataAdapter();
public abstract long LastInsertRowId
{
get;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -29,7 +29,9 @@
// ----------------------------------------------------------------------------
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
using System;
using System.Linq;
using DiscImageChef.DiscImages;
using DiscImageChef.Filters;
@@ -41,68 +43,47 @@ namespace osrepodbmgr.Core
{
try
{
IMediaImage _imageFormat;
PluginBase plugins = new PluginBase();
_imageFormat = null;
IMediaImage imageFormat = null;
// Check all but RAW plugin
foreach(IMediaImage _imageplugin in plugins.ImagePluginsList.Values)
{
if(_imageplugin.Id != new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
foreach(IMediaImage imageplugin in
plugins.ImagePluginsList.Values.Where(p => p.Id != new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
)
try
{
try
{
if(_imageplugin.Identify(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
{
}
if(!imageplugin.Identify(imageFilter)) continue;
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(IMediaImage _imageplugin in plugins.ImagePluginsList.Values)
if(imageFormat != null) return imageFormat;
foreach(IMediaImage imageplugin in
plugins.ImagePluginsList.Values.Where(p => p.Id == new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
)
try
{
if(_imageplugin.Id == new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
{
try
{
if(_imageplugin.Identify(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
{
}
}
if(!imageplugin.Identify(imageFilter)) continue;
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;
return imageFormat;
}
catch { return null; }
}
}
}
}

View File

@@ -35,6 +35,7 @@
// ----------------------------------------------------------------------------
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
using System;
using System.Runtime.InteropServices;
@@ -42,39 +43,6 @@ 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);
@@ -83,122 +51,93 @@ namespace DiscImageChef.Interop
public static PlatformID GetRealPlatformID()
{
if((int)Environment.OSVersion.Platform < 4 ||
(int)Environment.OSVersion.Platform == 5)
{
return (PlatformID)((int)Environment.OSVersion.Platform);
}
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()));
int error = uname(out utsname unixname);
if(error != 0) throw new Exception($"Unhandled exception calling uname: {Marshal.GetLastWin32Error()}");
switch(unixname.sysname)
{
// TODO: Differentiate Linux, Android, Tizen
case "Linux":
{
#if __ANDROID__
{
#if __ANDROID__
return PlatformID.Android;
#else
return PlatformID.Linux;
#endif
}
#else
return PlatformID.Linux;
#endif
}
case "Darwin":
{
IntPtr pLen = Marshal.AllocHGlobal(sizeof(int));
int osx_error = OSX_sysctlbyname("hw.machine", IntPtr.Zero, pLen, IntPtr.Zero, 0);
if(osx_error != 0)
{
int osx_error;
Marshal.FreeHGlobal(pLen);
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);
throw new Exception($"Unhandled exception calling uname: {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);
if(machine.StartsWith("iPad", StringComparison.Ordinal) ||
machine.StartsWith("iPod", StringComparison.Ordinal) ||
machine.StartsWith("iPhone", StringComparison.Ordinal))
return PlatformID.iOS;
return PlatformID.MacOSX;
throw new Exception($"Unhandled exception calling uname: {Marshal.GetLastWin32Error()}");
}
case "GNU":
return PlatformID.Hurd;
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 "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 "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;
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;
{
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;
}
return PlatformID.Unknown;
}
}
}
/// <summary>
/// Checks if the underlying runtime runs in 64-bit mode
/// Checks if the underlying runtime runs in 64-bit mode
/// </summary>
public static bool Is64Bit()
{
@@ -206,11 +145,44 @@ namespace DiscImageChef.Interop
}
/// <summary>
/// Checks if the underlying runtime runs in 32-bit mode
/// Checks if the underlying runtime runs in 32-bit mode
/// </summary>
public static bool Is32Bit()
{
return IntPtr.Size == 4;
}
/// <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;
}
}
}

View File

@@ -1,96 +1,89 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace osrepodbmgr.Core
{
public static class IO
{
public static List<string> EnumerateFiles(string path, string searchPattern, SearchOption searchOption, bool followLinks = true, bool symlinks = true)
public static List<string> EnumerateFiles(string path, string searchPattern,
SearchOption searchOption,
bool followLinks = true, bool symlinks = true)
{
if (followLinks)
return new List<string>(Directory.EnumerateFiles(path, searchPattern, searchOption));
if(followLinks) return new List<string>(Directory.EnumerateFiles(path, searchPattern, searchOption));
List<string> files = new List<string>();
List<string> files = new List<string>();
List<string> directories = new List<string>();
foreach (string file in Directory.EnumerateFiles(path, searchPattern))
foreach(string file in Directory.EnumerateFiles(path, searchPattern))
{
FileInfo fi = new FileInfo(file);
if (fi.Attributes.HasFlag(FileAttributes.ReparsePoint) && symlinks)
files.Add(file);
else if (!fi.Attributes.HasFlag(FileAttributes.ReparsePoint))
if(fi.Attributes.HasFlag(FileAttributes.ReparsePoint) && symlinks) files.Add(file);
else if(!fi.Attributes.HasFlag(FileAttributes.ReparsePoint))
files.Add(file);
}
if (searchOption == SearchOption.AllDirectories)
if(searchOption != SearchOption.AllDirectories) return files;
foreach(string directory in Directory.EnumerateDirectories(path, searchPattern))
{
foreach (string directory in Directory.EnumerateDirectories(path, searchPattern))
{
DirectoryInfo di = new DirectoryInfo(directory);
if (!di.Attributes.HasFlag(FileAttributes.ReparsePoint))
files.AddRange(EnumerateFiles(directory, searchPattern, searchOption, followLinks, symlinks));
}
DirectoryInfo di = new DirectoryInfo(directory);
if(!di.Attributes.HasFlag(FileAttributes.ReparsePoint))
files.AddRange(EnumerateFiles(directory, searchPattern, searchOption, followLinks, symlinks));
}
return files;
}
public static List<string> EnumerateDirectories(string path, string searchPattern, SearchOption searchOption, bool followLinks = true, bool symlinks = true)
public static List<string> EnumerateDirectories(string path, string searchPattern,
SearchOption searchOption,
bool followLinks = true, bool symlinks = true)
{
if (followLinks)
return new List<string>(Directory.EnumerateDirectories(path, searchPattern, searchOption));
if(followLinks) return new List<string>(Directory.EnumerateDirectories(path, searchPattern, searchOption));
List<string> directories = new List<string>();
if (searchOption == SearchOption.AllDirectories)
{
foreach (string directory in Directory.EnumerateDirectories(path, searchPattern))
{
DirectoryInfo di = new DirectoryInfo(directory);
if (!di.Attributes.HasFlag(FileAttributes.ReparsePoint))
directories.Add(directory);
}
if(searchOption != SearchOption.AllDirectories) return directories;
List<string> newDirectories = new List<string>();
directories.AddRange(from directory in Directory.EnumerateDirectories(path, searchPattern)
let di = new DirectoryInfo(directory)
where !di.Attributes.HasFlag(FileAttributes.ReparsePoint)
select directory);
foreach (string directory in directories)
newDirectories.AddRange(EnumerateDirectories(directory, searchPattern, searchOption, followLinks, symlinks));
List<string> newDirectories = new List<string>();
directories.AddRange(newDirectories);
}
foreach(string directory in directories)
newDirectories.AddRange(EnumerateDirectories(directory, searchPattern, searchOption, followLinks,
symlinks));
directories.AddRange(newDirectories);
return directories;
}
public static List<string> EnumerateSymlinks(string path, string searchPattern, SearchOption searchOption)
{
List<string> links = new List<string>();
List<string> directories = new List<string>();
foreach (string file in Directory.EnumerateFiles(path, searchPattern))
List<string> links = (from file in Directory.EnumerateFiles(path, searchPattern)
let fi = new FileInfo(file)
where fi.Attributes.HasFlag(FileAttributes.ReparsePoint)
select file).ToList();
if(searchOption != SearchOption.AllDirectories) return links;
foreach(string directory in Directory.EnumerateDirectories(path, searchPattern))
{
FileInfo fi = new FileInfo(file);
if (fi.Attributes.HasFlag(FileAttributes.ReparsePoint))
links.Add(file);
DirectoryInfo di = new DirectoryInfo(directory);
if(!di.Attributes.HasFlag(FileAttributes.ReparsePoint)) directories.Add(directory);
else //if (!links.Contains(directory))
links.Add(directory);
}
if (searchOption == SearchOption.AllDirectories)
{
foreach (string directory in Directory.EnumerateDirectories(path, searchPattern))
{
DirectoryInfo di = new DirectoryInfo(directory);
if (!di.Attributes.HasFlag(FileAttributes.ReparsePoint))
directories.Add(directory);
else //if (!links.Contains(directory))
links.Add(directory);
}
foreach (string directory in directories)
links.AddRange(EnumerateSymlinks(directory, searchPattern, searchOption));
}
foreach(string directory in directories)
links.AddRange(EnumerateSymlinks(directory, searchPattern, searchOption));
return links;
}
}
}
}

View File

@@ -41,149 +41,149 @@ namespace DiscImageChef.Interop
public enum PlatformID
{
/// <summary>
/// Win32s
/// Win32s
/// </summary>
Win32S = 0,
/// <summary>
/// Win32 (Windows 9x)
/// Win32 (Windows 9x)
/// </summary>
Win32Windows = 1,
/// <summary>
/// Windows NT
/// Windows NT
/// </summary>
Win32NT = 2,
/// <summary>
/// Windows Mobile
/// Windows Mobile
/// </summary>
WinCE = 3,
/// <summary>
/// UNIX (do not use, too generic)
/// UNIX (do not use, too generic)
/// </summary>
Unix = 4,
/// <summary>
/// Xbox 360
/// Xbox 360
/// </summary>
Xbox = 5,
/// <summary>
/// OS X
/// OS X
/// </summary>
MacOSX = 6,
/// <summary>
/// iOS is not OS X
/// iOS is not OS X
/// </summary>
iOS = 7,
/// <summary>
/// Linux
/// Linux
/// </summary>
Linux = 8,
/// <summary>
/// Sun Solaris
/// Sun Solaris
/// </summary>
Solaris = 9,
/// <summary>
/// NetBSD
/// NetBSD
/// </summary>
NetBSD = 10,
/// <summary>
/// OpenBSD
/// OpenBSD
/// </summary>
OpenBSD = 11,
/// <summary>
/// FreeBSD
/// FreeBSD
/// </summary>
FreeBSD = 12,
/// <summary>
/// DragonFly BSD
/// DragonFly BSD
/// </summary>
DragonFly = 13,
/// <summary>
/// Nintendo Wii
/// Nintendo Wii
/// </summary>
Wii = 14,
/// <summary>
/// Nintendo Wii U
/// Nintendo Wii U
/// </summary>
WiiU = 15,
/// <summary>
/// Sony PlayStation 3
/// Sony PlayStation 3
/// </summary>
PlayStation3 = 16,
/// <summary>
/// Sony Playstation 4
/// Sony Playstation 4
/// </summary>
PlayStation4 = 17,
/// <summary>
/// Google Android
/// Google Android
/// </summary>
Android = 18,
/// <summary>
/// Samsung Tizen
/// Samsung Tizen
/// </summary>
Tizen = 19,
/// <summary>
/// Windows Phone
/// Windows Phone
/// </summary>
WindowsPhone = 20,
/// <summary>
/// GNU/Hurd
/// GNU/Hurd
/// </summary>
Hurd = 21,
/// <summary>
/// Haiku
/// Haiku
/// </summary>
Haiku = 22,
/// <summary>
/// HP-UX
/// HP-UX
/// </summary>
HPUX = 23,
/// <summary>
/// AIX
/// AIX
/// </summary>
AIX = 24,
/// <summary>
/// OS/400
/// OS/400
/// </summary>
OS400 = 25,
/// <summary>
/// IRIX
/// IRIX
/// </summary>
IRIX = 26,
/// <summary>
/// Minix
/// Minix
/// </summary>
Minix = 27,
/// <summary>
/// NonStop
/// NonStop
/// </summary>
NonStop = 28,
/// <summary>
/// QNX
/// QNX
/// </summary>
QNX = 29,
/// <summary>
/// SINIX
/// SINIX
/// </summary>
SINIX = 30,
/// <summary>
/// Tru64 UNIX
/// Tru64 UNIX
/// </summary>
Tru64 = 31,
/// <summary>
/// Ultrix
/// Ultrix
/// </summary>
Ultrix = 32,
/// <summary>
/// SCO OpenServer / SCO UNIX
/// SCO OpenServer / SCO UNIX
/// </summary>
OpenServer = 33,
/// <summary>
/// SCO UnixWare
/// SCO UnixWare
/// </summary>
UnixWare = 34,
/// <summary>
/// IBM z/OS
/// IBM z/OS
/// </summary>
zOS = 35,
zOS = 35,
Unknown = -1
}
}

View File

@@ -25,39 +25,36 @@
// 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
public class SQLite : DbCore
{
SQLiteConnection dbCon;
#region implemented abstract members of DBCore
public override bool OpenDB(string database, string server, string user, string password)
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);
string dataSrc = $"URI=file:{database}";
dbCon = new SQLiteConnection(dataSrc);
dbCon.Open();
string sql;
sql = "SELECT * FROM osrepodbmgr";
const string SQL = "SELECT * FROM osrepodbmgr";
SQLiteCommand dbcmd = dbCon.CreateCommand();
dbcmd.CommandText = sql;
SQLiteDataAdapter dAdapter = new SQLiteDataAdapter();
dAdapter.SelectCommand = dbcmd;
DataSet dSet = new DataSet();
SQLiteCommand dbcmd = dbCon.CreateCommand();
dbcmd.CommandText = SQL;
SQLiteDataAdapter dAdapter = new SQLiteDataAdapter {SelectCommand = dbcmd};
DataSet dSet = new DataSet();
dAdapter.Fill(dSet);
DataTable dTable = dSet.Tables[0];
if(dTable.Rows.Count != 1)
return false;
if(dTable.Rows.Count != 1) return false;
if((long)dTable.Rows[0]["version"] != 1)
{
@@ -65,7 +62,7 @@ namespace osrepodbmgr.Core
return false;
}
DBOps = new DBOps(dbCon, this);
DbOps = new DbOps(dbCon, this);
return true;
}
@@ -78,45 +75,44 @@ namespace osrepodbmgr.Core
}
}
public override void CloseDB()
public override void CloseDb()
{
if(dbCon != null)
dbCon.Close();
dbCon?.Close();
DBOps = null;
DbOps = null;
}
public override bool CreateDB(string database, string server, string user, string password)
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);
string dataSrc = $"URI=file:{database}";
dbCon = new SQLiteConnection(dataSrc);
dbCon.Open();
SQLiteCommand dbCmd = dbCon.CreateCommand();
string sql;
#if DEBUG
#if DEBUG
Console.WriteLine("Creating osrepodbmgr table");
#endif
#endif
sql = "CREATE TABLE osrepodbmgr ( version INTEGER, name TEXT )";
string 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' )";
sql =
"INSERT INTO osrepodbmgr ( version, name ) VALUES ( '1', 'Canary Islands Computer Museum' )";
dbCmd.CommandText = sql;
dbCmd.ExecuteNonQuery();
#if DEBUG
#if DEBUG
Console.WriteLine("Creating oses table");
#endif
#endif
dbCmd.CommandText = Schema.OSesTableSql;
dbCmd.ExecuteNonQuery();
#if DEBUG
#if DEBUG
Console.WriteLine("Creating files table");
#endif
#endif
dbCmd.CommandText = Schema.FilesTableSql;
dbCmd.ExecuteNonQuery();
@@ -138,12 +134,7 @@ namespace osrepodbmgr.Core
return new SQLiteDataAdapter();
}
public override long LastInsertRowId
{
get { return dbCon.LastInsertRowId; }
}
public override long LastInsertRowId => dbCon.LastInsertRowId;
#endregion
}
}
}

View File

@@ -1,4 +1,4 @@
//
//
// Author:
// Natalia Portillo claunia@claunia.com
//
@@ -25,61 +25,61 @@
// 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" +
" `crack` BOOLEAN NOT NULL,\n" +
" `hasvirus` BOOLEAN NULL,\n" +
" `clamtime` DATETIME NULL,\n" +
" `vtotaltime` DATETIME NULL,\n" +
" `virus` VARCHAR(128) NULL,\n" +
" `length` BIGINT 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);\n\n" +
"CREATE INDEX `files_hasvirus_idx` ON `files` (`hasvirus` ASC);\n\n" +
"CREATE INDEX `files_virus_idx` ON `files` (`virus` ASC);\n\n" +
"CREATE INDEX `files_length_idx` ON `files` (`length` ASC);";
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" +
" `crack` BOOLEAN NOT NULL,\n" +
" `hasvirus` BOOLEAN NULL,\n" +
" `clamtime` DATETIME NULL,\n" +
" `vtotaltime` DATETIME NULL,\n" +
" `virus` VARCHAR(128) NULL,\n" +
" `length` BIGINT 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);\n\n" +
"CREATE INDEX `files_hasvirus_idx` ON `files` (`hasvirus` ASC);\n\n" +
"CREATE INDEX `files_virus_idx` ON `files` (`virus` ASC);\n\n" +
"CREATE INDEX `files_length_idx` ON `files` (`length` 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" +
" `mdid` CHAR(40) NOT NULL,\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 NOT NULL,\n" +
" `upgrade` BOOLEAN NOT NULL,\n" +
" `update` BOOLEAN NOT NULL,\n" +
" `source` BOOLEAN NOT NULL,\n" +
" `files` BOOLEAN NOT NULL,\n" +
" `netinstall` BOOLEAN NOT NULL,\n" +
" `xml` BLOB NULL,\n" +
" `json` BLOB NULL);\n\n" +
"CREATE UNIQUE INDEX `oses_id_UNIQUE` ON `oses` (`id` ASC);\n\n" +
"CREATE UNIQUE INDEX `oses_mdid_UNIQUE` ON `oses` (`mdid` 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);";
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" +
" `mdid` CHAR(40) NOT NULL,\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 NOT NULL,\n" +
" `upgrade` BOOLEAN NOT NULL,\n" +
" `update` BOOLEAN NOT NULL,\n" +
" `source` BOOLEAN NOT NULL,\n" +
" `files` BOOLEAN NOT NULL,\n" +
" `netinstall` BOOLEAN NOT NULL,\n" +
" `xml` BLOB NULL,\n" +
" `json` BLOB NULL);\n\n" +
"CREATE UNIQUE INDEX `oses_id_UNIQUE` ON `oses` (`id` ASC);\n\n" +
"CREATE UNIQUE INDEX `oses_mdid_UNIQUE` ON `oses` (`mdid` 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);";
}
}
}

View File

@@ -25,28 +25,32 @@
// 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.Diagnostics;
using System.IO;
using System.Xml.Serialization;
using Claunia.PropertyList;
using DiscImageChef.Interop;
using Microsoft.Win32;
using PlatformID = DiscImageChef.Interop.PlatformID;
namespace osrepodbmgr.Core
{
public class SetSettings
{
public string TemporaryFolder;
public string DatabasePath;
public string RepositoryPath;
public string UnArchiverPath;
public string ClamdHost;
public bool ClamdIsLocal;
public ushort ClamdPort;
public AlgoEnum CompressionAlgorithm;
public bool UseAntivirus;
public bool UseClamd;
public string ClamdHost;
public ushort ClamdPort;
public bool ClamdIsLocal;
public bool UseVirusTotal;
public string VirusTotalKey;
public string DatabasePath;
public string RepositoryPath;
public string TemporaryFolder;
public string UnArchiverPath;
public bool UseAntivirus;
public bool UseClamd;
public bool UseVirusTotal;
public string VirusTotalKey;
}
public static class Settings
@@ -55,192 +59,163 @@ namespace osrepodbmgr.Core
public static void LoadSettings()
{
Current = new SetSettings();
DiscImageChef.Interop.PlatformID ptID = DiscImageChef.Interop.DetectOS.GetRealPlatformID();
Current = new SetSettings();
PlatformID ptId = DetectOS.GetRealPlatformID();
FileStream prefsFs = null;
FileStream prefsFs = null;
StreamReader prefsSr = null;
try
{
switch(ptID)
switch(ptId)
{
case DiscImageChef.Interop.PlatformID.MacOSX:
case DiscImageChef.Interop.PlatformID.iOS:
case PlatformID.MacOSX:
case 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))
{
string preferencesPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library", "Preferences");
string preferencesFilePath = Path.Combine(preferencesPath, "com.claunia.museum.osrepodbmgr.plist");
SetDefaultSettings();
SaveSettings();
}
if(!File.Exists(preferencesFilePath))
prefsFs = new FileStream(preferencesFilePath, FileMode.Open);
NSDictionary parsedPreferences = (NSDictionary)BinaryPropertyListParser.Parse(prefsFs);
if(parsedPreferences != null)
{
Current.TemporaryFolder = parsedPreferences.TryGetValue("TemporaryFolder", out NSObject obj)
? ((NSString)obj).ToString()
: Path.GetTempPath();
Current.DatabasePath = parsedPreferences.TryGetValue("DatabasePath", out obj)
? ((NSString)obj).ToString()
: Path
.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"osrepodbmgr.db");
Current.RepositoryPath = parsedPreferences.TryGetValue("RepositoryPath", out obj)
? ((NSString)obj).ToString()
: Path
.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"osrepo");
Current.UnArchiverPath = parsedPreferences.TryGetValue("UnArchiverPath", out obj)
? ((NSString)obj).ToString()
: null;
if(parsedPreferences.TryGetValue("CompressionAlgorithm", out obj))
{
SetDefaultSettings();
SaveSettings();
}
prefsFs = new FileStream(preferencesFilePath, FileMode.Open);
NSDictionary parsedPreferences = (NSDictionary)BinaryPropertyListParser.Parse(prefsFs);
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;
if(parsedPreferences.TryGetValue("CompressionAlgorithm", out obj))
{
if(!Enum.TryParse(((NSString)obj).ToString(), true, out Current.CompressionAlgorithm))
Current.CompressionAlgorithm = AlgoEnum.GZip;
}
else
if(!Enum.TryParse(((NSString)obj).ToString(), true, out Current.CompressionAlgorithm))
Current.CompressionAlgorithm = AlgoEnum.GZip;
if(parsedPreferences.TryGetValue("UseAntivirus", out obj))
{
Current.UseAntivirus = ((NSNumber)obj).ToBool();
}
else
Current.UseAntivirus = false;
if(parsedPreferences.TryGetValue("UseClamd", out obj))
{
Current.UseClamd = ((NSNumber)obj).ToBool();
}
else
Current.UseClamd = false;
if(parsedPreferences.TryGetValue("ClamdHost", out obj))
{
Current.ClamdHost = ((NSString)obj).ToString();
}
else
Current.ClamdHost = null;
if(parsedPreferences.TryGetValue("ClamdPort", out obj))
{
Current.ClamdPort = (ushort)((NSNumber)obj).ToLong();
}
else
Current.ClamdPort = 3310;
if(parsedPreferences.TryGetValue("ClamdIsLocal", out obj))
{
Current.ClamdIsLocal = ((NSNumber)obj).ToBool();
}
else
Current.ClamdIsLocal = false;
if(parsedPreferences.TryGetValue("UseVirusTotal", out obj))
{
Current.ClamdIsLocal = ((NSNumber)obj).ToBool();
}
else
Current.ClamdIsLocal = false;
if(parsedPreferences.TryGetValue("VirusTotalKey", out obj))
{
Current.ClamdHost = ((NSString)obj).ToString();
}
else
Current.ClamdHost = null;
prefsFs.Close();
}
else {
prefsFs.Close();
else Current.CompressionAlgorithm = AlgoEnum.GZip;
SetDefaultSettings();
SaveSettings();
}
Current.UseAntivirus = parsedPreferences.TryGetValue("UseAntivirus", out obj) &&
((NSNumber)obj).ToBool();
Current.UseClamd = parsedPreferences.TryGetValue("UseClamd", out obj) &&
((NSNumber)obj).ToBool();
Current.ClamdHost = parsedPreferences.TryGetValue("ClamdHost", out obj)
? ((NSString)obj).ToString()
: null;
if(parsedPreferences.TryGetValue("ClamdPort", out obj))
Current.ClamdPort = (ushort)((NSNumber)obj).ToLong();
else Current.ClamdPort = 3310;
Current.ClamdIsLocal = parsedPreferences.TryGetValue("ClamdIsLocal", out obj) &&
((NSNumber)obj).ToBool();
Current.ClamdIsLocal = parsedPreferences.TryGetValue("UseVirusTotal", out obj) &&
((NSNumber)obj).ToBool();
Current.ClamdHost = parsedPreferences.TryGetValue("VirusTotalKey", out obj)
? ((NSString)obj).ToString()
: null;
prefsFs.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:
else
{
RegistryKey parentKey = Registry.CurrentUser.OpenSubKey("SOFTWARE").OpenSubKey("Canary Islands Computer Museum");
if(parentKey == null)
{
SetDefaultSettings();
SaveSettings();
return;
}
prefsFs.Close();
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");
if(!Enum.TryParse((string)key.GetValue("CompressionAlgorithm"), true, out Current.CompressionAlgorithm))
Current.CompressionAlgorithm = AlgoEnum.GZip;
Current.UseAntivirus = (bool)key.GetValue("UseAntivirus");
Current.UseClamd = (bool)key.GetValue("UseClamd");
Current.ClamdHost = (string)key.GetValue("ClamdHost");
Current.ClamdPort = (ushort)key.GetValue("ClamdPort");
Current.ClamdIsLocal = (bool)key.GetValue("ClamdIsLocal");
Current.UseVirusTotal = (bool)key.GetValue("UseVirusTotal");
Current.VirusTotalKey = (string)key.GetValue("VirusTotalKey");
SetDefaultSettings();
SaveSettings();
}
}
break;
case PlatformID.Win32NT:
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.WinCE:
case 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");
if(!Enum.TryParse((string)key.GetValue("CompressionAlgorithm"), true,
out Current.CompressionAlgorithm))
Current.CompressionAlgorithm = AlgoEnum.GZip;
Current.UseAntivirus = (bool)key.GetValue("UseAntivirus");
Current.UseClamd = (bool)key.GetValue("UseClamd");
Current.ClamdHost = (string)key.GetValue("ClamdHost");
Current.ClamdPort = (ushort)key.GetValue("ClamdPort");
Current.ClamdIsLocal = (bool)key.GetValue("ClamdIsLocal");
Current.UseVirusTotal = (bool)key.GetValue("UseVirusTotal");
Current.VirusTotalKey = (string)key.GetValue("VirusTotalKey");
}
break;
default:
{
string configPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config");
string settingsPath =
Path.Combine(configPath, "OSRepoDBMgr.xml");
if(!Directory.Exists(configPath))
{
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());
prefsSr = new StreamReader(settingsPath);
Current = (SetSettings)xs.Deserialize(prefsSr);
prefsSr.Close();
SetDefaultSettings();
SaveSettings();
return;
}
XmlSerializer xs = new XmlSerializer(Current.GetType());
prefsSr = new StreamReader(settingsPath);
Current = (SetSettings)xs.Deserialize(prefsSr);
prefsSr.Close();
}
break;
}
}
catch
{
if(prefsFs != null)
prefsFs.Close();
if(prefsSr != null)
prefsSr.Close();
prefsFs?.Close();
prefsSr?.Close();
SetDefaultSettings();
SaveSettings();
@@ -251,100 +226,113 @@ namespace osrepodbmgr.Core
{
try
{
DiscImageChef.Interop.PlatformID ptID = DiscImageChef.Interop.DetectOS.GetRealPlatformID();
PlatformID ptId = DetectOS.GetRealPlatformID();
switch(ptID)
switch(ptId)
{
case DiscImageChef.Interop.PlatformID.MacOSX:
case DiscImageChef.Interop.PlatformID.iOS:
case PlatformID.MacOSX:
case PlatformID.iOS:
{
NSDictionary root = new NSDictionary
{
NSDictionary root = new NSDictionary();
root.Add("TemporaryFolder", Current.TemporaryFolder);
root.Add("DatabasePath", Current.DatabasePath);
root.Add("RepositoryPath", Current.RepositoryPath);
root.Add("UnArchiverPath", Current.UnArchiverPath);
root.Add("CompressionAlgorithm", Current.CompressionAlgorithm.ToString());
root.Add("UseAntivirus", Current.UseAntivirus);
root.Add("UseClamd", Current.UseClamd);
root.Add("ClamdHost", Current.ClamdHost);
root.Add("ClamdPort", Current.ClamdPort);
root.Add("ClamdIsLocal", Current.ClamdIsLocal);
root.Add("UseVirusTotal", Current.UseVirusTotal);
root.Add("VirusTotalKey", Current.VirusTotalKey);
{"TemporaryFolder", Current.TemporaryFolder},
{"DatabasePath", Current.DatabasePath},
{"RepositoryPath", Current.RepositoryPath},
{"UnArchiverPath", Current.UnArchiverPath},
{"CompressionAlgorithm", Current.CompressionAlgorithm.ToString()},
{"UseAntivirus", Current.UseAntivirus},
{"UseClamd", Current.UseClamd},
{"ClamdHost", Current.ClamdHost},
{"ClamdPort", Current.ClamdPort},
{"ClamdIsLocal", Current.ClamdIsLocal},
{"UseVirusTotal", Current.UseVirusTotal},
{"VirusTotalKey", Current.VirusTotalKey}
};
string preferencesPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library", "Preferences");
string preferencesFilePath = Path.Combine(preferencesPath, "com.claunia.museum.osrepodbmgr.plist");
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();
}
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", true).CreateSubKey("Canary Islands Computer Museum");
RegistryKey key = parentKey.CreateSubKey("OSRepoDBMgr");
case PlatformID.Win32NT:
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.WinCE:
case PlatformID.WindowsPhone:
{
RegistryKey parentKey = Registry
.CurrentUser.OpenSubKey("SOFTWARE", true)
?.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);
if(Current.UnArchiverPath != null)
key.SetValue("UnArchiverPath", Current.UnArchiverPath);
key.SetValue("CompressionAlgorithm", Current.CompressionAlgorithm);
key.SetValue("UseAntivirus", Current.UseAntivirus);
key.SetValue("UseClamd", Current.UseClamd);
key.SetValue("ClamdHost", Current.ClamdHost);
key.SetValue("ClamdPort", Current.ClamdPort);
key.SetValue("ClamdIsLocal", Current.ClamdIsLocal);
if(key != null)
{
key.SetValue("TemporaryFolder", Current.TemporaryFolder);
key.SetValue("DatabasePath", Current.DatabasePath);
key.SetValue("RepositoryPath", Current.RepositoryPath);
if(Current.UnArchiverPath != null) key.SetValue("UnArchiverPath", Current.UnArchiverPath);
key.SetValue("CompressionAlgorithm",
Current.CompressionAlgorithm);
key.SetValue("UseAntivirus", Current.UseAntivirus);
key.SetValue("UseClamd", Current.UseClamd);
key.SetValue("ClamdHost", Current.ClamdHost);
key.SetValue("ClamdPort", Current.ClamdPort);
key.SetValue("ClamdIsLocal", Current.ClamdIsLocal);
key.SetValue("UseVirusTotal", Current.UseVirusTotal);
key.SetValue("VirusTotalKey", Current.VirusTotalKey);
}
}
break;
default:
{
string configPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config");
string settingsPath = Path.Combine(configPath, "OSRepoDBMgr.xml");
{
string configPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config");
string settingsPath =
Path.Combine(configPath, "OSRepoDBMgr.xml");
if(!Directory.Exists(configPath))
Directory.CreateDirectory(configPath);
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();
}
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
#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
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
{
if(System.Diagnostics.Debugger.IsAttached)
throw;
if(Debugger.IsAttached) throw;
}
}
public static void SetDefaultSettings()
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;
Current.CompressionAlgorithm = AlgoEnum.GZip;
Current.UseAntivirus = false;
Current.UseClamd = false;
Current.ClamdHost = null;
Current.ClamdPort = 3310;
Current.ClamdIsLocal = false;
Current.UseVirusTotal = false;
Current.VirusTotalKey = null;
Current = new SetSettings
{
TemporaryFolder = Path.GetTempPath(),
DatabasePath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "osrepodbmgr.db"),
RepositoryPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "osrepo"),
UnArchiverPath = null,
CompressionAlgorithm = AlgoEnum.GZip,
UseAntivirus = false,
UseClamd = false,
ClamdHost = null,
ClamdPort = 3310,
ClamdIsLocal = false,
UseVirusTotal = false,
VirusTotalKey = null
};
}
}
}
}

View File

@@ -7,7 +7,7 @@ namespace osrepodbmgr.Core
public static class Symlinks
{
[DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
internal static extern int readlink(string path, IntPtr buf, int bufsize);
static extern int readlink(string path, IntPtr buf, int bufsize);
public static string ReadLink(string path)
{
@@ -15,8 +15,7 @@ namespace osrepodbmgr.Core
int ret = readlink(path, buf, 16384);
if(ret < 0)
return null;
if(ret < 0) return null;
byte[] target = new byte[ret];
Marshal.Copy(buf, target, 0, ret);
@@ -25,7 +24,7 @@ namespace osrepodbmgr.Core
}
[DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
internal static extern int symlink(string target, string path);
static extern int symlink(string target, string path);
public static int Symlink(string target, string path)
{

View File

@@ -25,11 +25,15 @@
// 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 System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using nClam;
using SharpCompress.Compressors;
using SharpCompress.Compressors.BZip2;
using SharpCompress.Compressors.Deflate;
using SharpCompress.Compressors.LZMA;
@@ -44,7 +48,7 @@ namespace osrepodbmgr.Core
{
if(!Settings.Current.UseClamd || !Settings.Current.UseAntivirus)
{
Context.clamdVersion = null;
Context.ClamdVersion = null;
return;
}
@@ -57,62 +61,51 @@ namespace osrepodbmgr.Core
{
try
{
clam = new ClamClient(Settings.Current.ClamdHost, Settings.Current.ClamdPort);
Context.clamdVersion = await clam.GetVersionAsync();
}
catch(System.Net.Sockets.SocketException)
{
clam = new ClamClient(Settings.Current.ClamdHost, Settings.Current.ClamdPort);
Context.ClamdVersion = await clam.GetVersionAsync();
}
catch(SocketException) { }
}).Wait();
}
public static void ClamScanFileFromRepo(DBFile file)
public static void ClamScanFileFromRepo(DbFile file)
{
try
{
if(Context.clamdVersion == null)
if(Context.ClamdVersion == null)
{
if(Failed != null)
Failed("clamd is not usable");
Failed?.Invoke("clamd is not usable");
return;
}
if(clam == null)
{
if(Failed != null)
Failed("clamd is not initalized");
}
if(clam == null) Failed?.Invoke("clamd is not initalized");
string repoPath;
string repoPath;
AlgoEnum algorithm;
if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".gz")))
file.Sha256[3].ToString(), file.Sha256[4].ToString(), file.Sha256 + ".gz")))
{
repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".gz");
file.Sha256[3].ToString(), file.Sha256[4].ToString(), file.Sha256 + ".gz");
algorithm = AlgoEnum.GZip;
}
else if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".bz2")))
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".bz2")))
{
repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".bz2");
file.Sha256[3].ToString(), file.Sha256[4].ToString(), file.Sha256 + ".bz2");
algorithm = AlgoEnum.BZip2;
}
else if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lzma")))
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lzma")))
{
repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
@@ -121,34 +114,30 @@ namespace osrepodbmgr.Core
algorithm = AlgoEnum.LZMA;
}
else if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lz")))
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lz")))
{
repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lz");
file.Sha256[3].ToString(), file.Sha256[4].ToString(), file.Sha256 + ".lz");
algorithm = AlgoEnum.LZip;
}
else
{
if(Failed != null)
Failed(string.Format("Cannot find file with hash {0} in the repository", file.Sha256));
Failed?.Invoke($"Cannot find file with hash {file.Sha256} in the repository");
return;
}
ClamScanResult result = null;
Stream zStream = null;
ClamScanResult result = null;
Stream zStream = null;
if(Settings.Current.ClamdIsLocal)
{
// clamd supports gzip and bzip2 but not lzma
if(algorithm == AlgoEnum.LZMA || algorithm == AlgoEnum.LZip)
{
string tmpFile = Path.Combine(Settings.Current.TemporaryFolder, Path.GetTempFileName());
FileStream outFs = new FileStream(tmpFile, FileMode.Create, FileAccess.Write);
FileStream inFs = new FileStream(repoPath, FileMode.Open, FileAccess.Read);
string tmpFile = Path.Combine(Settings.Current.TemporaryFolder, Path.GetTempFileName());
FileStream outFs = new FileStream(tmpFile, FileMode.Create, FileAccess.Write);
FileStream inFs = new FileStream(repoPath, FileMode.Open, FileAccess.Read);
if(algorithm == AlgoEnum.LZMA)
{
@@ -157,58 +146,52 @@ namespace osrepodbmgr.Core
inFs.Seek(8, SeekOrigin.Current);
zStream = new LzmaStream(properties, inFs, inFs.Length - 13, file.Length);
}
else
zStream = new LZipStream(inFs, SharpCompress.Compressors.CompressionMode.Decompress);
else zStream = new LZipStream(inFs, CompressionMode.Decompress);
if(UpdateProgress != null)
UpdateProgress("Uncompressing file...", null, 0, 0);
UpdateProgress?.Invoke("Uncompressing file...", null, 0, 0);
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
#endif
zStream.CopyTo(outFs);
zStream.Close();
outFs.Close();
#if DEBUG
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.ClamScanFileFromRepo({0}): Uncompressing took {1} seconds", file, stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.ClamScanFileFromRepo({0}): Uncompressing took {1} seconds", file,
stopwatch.Elapsed.TotalSeconds);
#endif
if(UpdateProgress != null)
UpdateProgress("Requesting local scan to clamd server...", null, 0, 0);
UpdateProgress?.Invoke("Requesting local scan to clamd server...", null, 0, 0);
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
Task.Run(async () =>
{
result = await clam.ScanFileOnServerMultithreadedAsync(tmpFile);
}).Wait();
#if DEBUG
#endif
Task.Run(async () => { result = await clam.ScanFileOnServerMultithreadedAsync(tmpFile); })
.Wait();
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.ClamScanFileFromRepo({0}): Clamd took {1} seconds to scan", file, stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.ClamScanFileFromRepo({0}): Clamd took {1} seconds to scan", file,
stopwatch.Elapsed.TotalSeconds);
#endif
File.Delete(tmpFile);
}
else
{
if(UpdateProgress != null)
UpdateProgress("Requesting local scan to clamd server...", null, 0, 0);
UpdateProgress?.Invoke("Requesting local scan to clamd server...", null, 0, 0);
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
Task.Run(async () =>
{
result = await clam.ScanFileOnServerMultithreadedAsync(repoPath);
}).Wait();
#if DEBUG
#endif
Task.Run(async () => { result = await clam.ScanFileOnServerMultithreadedAsync(repoPath); })
.Wait();
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.ClamScanFileFromRepo({0}): Clamd took {1} seconds to scan", file, stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.ClamScanFileFromRepo({0}): Clamd took {1} seconds to scan", file,
stopwatch.Elapsed.TotalSeconds);
#endif
}
}
else
{
FileStream inFs = new FileStream(repoPath, FileMode.Open, FileAccess.Read);
@@ -216,10 +199,10 @@ namespace osrepodbmgr.Core
switch(algorithm)
{
case AlgoEnum.GZip:
zStream = new GZipStream(inFs, SharpCompress.Compressors.CompressionMode.Decompress);
zStream = new GZipStream(inFs, CompressionMode.Decompress);
break;
case AlgoEnum.BZip2:
zStream = new BZip2Stream(inFs, SharpCompress.Compressors.CompressionMode.Decompress);
zStream = new BZip2Stream(inFs, CompressionMode.Decompress);
break;
case AlgoEnum.LZMA:
byte[] properties = new byte[5];
@@ -228,97 +211,85 @@ namespace osrepodbmgr.Core
zStream = new LzmaStream(properties, inFs, inFs.Length - 13, file.Length);
break;
case AlgoEnum.LZip:
zStream = new LZipStream(inFs, SharpCompress.Compressors.CompressionMode.Decompress);
zStream = new LZipStream(inFs, CompressionMode.Decompress);
break;
}
if(UpdateProgress != null)
UpdateProgress("Uploading file to clamd server...", null, 0, 0);
UpdateProgress?.Invoke("Uploading file to clamd server...", null, 0, 0);
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
Task.Run(async () =>
{
result = await clam.SendAndScanFileAsync(zStream);
}).Wait();
#if DEBUG
#endif
Task.Run(async () => { result = await clam.SendAndScanFileAsync(zStream); }).Wait();
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.ClamScanFileFromRepo({0}): Clamd took {1} seconds to scan", file, stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.ClamScanFileFromRepo({0}): Clamd took {1} seconds to scan", file,
stopwatch.Elapsed.TotalSeconds);
#endif
zStream.Close();
}
if(result.InfectedFiles != null && result.InfectedFiles.Count > 0)
{
file.HasVirus = true;
file.Virus = result.InfectedFiles[0].VirusName;
file.Virus = result.InfectedFiles[0].VirusName;
}
else if(file.HasVirus == null)
{
// If no scan has been done, mark as false.
// If a positive has already existed don't overwrite it.
file.HasVirus = false;
file.Virus = null;
file.Virus = null;
}
file.ClamTime = DateTime.UtcNow;
dbCore.DBOps.UpdateFile(file);
dbCore.DbOps.UpdateFile(file);
if(ScanFinished != null)
ScanFinished(file);
return;
ScanFinished?.Invoke(file);
}
catch(System.Threading.ThreadAbortException)
{ }
catch(ThreadAbortException) { }
catch(Exception ex)
{
if(Failed != null)
Failed(string.Format("Exception {0} when calling clamd", ex.Message));
#if DEBUG
Failed?.Invoke($"Exception {ex.Message} when calling clamd");
#if DEBUG
Console.WriteLine("Exception {0}\n{1}", ex.Message, ex.InnerException);
#endif
#endif
}
}
public static void ClamScanAllFiles()
{
if(UpdateProgress2 != null)
UpdateProgress2("Asking database for files", null, 0, 0);
UpdateProgress2?.Invoke("Asking database for files", null, 0, 0);
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
List<DBFile> files;
#endif
if(!dbCore.DBOps.GetNotAvFiles(out files))
{
if(Failed != null)
Failed("Could not get files from database.");
}
#if DEBUG
if(!dbCore.DbOps.GetNotAvFiles(out List<DbFile> files))
Failed?.Invoke("Could not get files from database.");
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.ClamScanAllFiles(): Took {0} seconds to get files from database", stopwatch.Elapsed.TotalSeconds);
Console.WriteLine("Core.ClamScanAllFiles(): Took {0} seconds to get files from database",
stopwatch.Elapsed.TotalSeconds);
stopwatch.Restart();
#endif
#endif
int counter = 0;
foreach(DBFile file in files)
foreach(DbFile file in files)
{
if(UpdateProgress2 != null)
UpdateProgress2(string.Format("Scanning file {0} of {1}", counter, files.Count), null, counter, files.Count);
UpdateProgress2?.Invoke($"Scanning file {counter} of {files.Count}", null, counter, files.Count);
ClamScanFileFromRepo(file);
counter++;
}
#if DEBUG
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.ClamScanAllFiles(): Took {0} seconds scan all pending files", stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.ClamScanAllFiles(): Took {0} seconds scan all pending files",
stopwatch.Elapsed.TotalSeconds);
#endif
if(Finished != null)
Finished();
Finished?.Invoke();
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -25,11 +25,12 @@
// 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 partial class Workers
{
// Sets a 128Kbyte buffer
const long bufferSize = 131072;
const long BUFFER_SIZE = 131072;
}
}
}

View File

@@ -25,6 +25,7 @@
// 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;
@@ -39,56 +40,54 @@ namespace osrepodbmgr.Core
{
try
{
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
List<DBEntry> oses;
dbCore.DBOps.GetAllOSes(out oses);
#if DEBUG
#endif
dbCore.DbOps.GetAllOSes(out List<DbEntry> oses);
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.GetAllOSes(): Took {0} seconds to get OSes from database", stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.GetAllOSes(): Took {0} seconds to get OSes from database",
stopwatch.Elapsed.TotalSeconds);
#endif
if(AddOS != null)
{
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
#endif
int counter = 0;
// TODO: Check file name and existence
foreach(DBEntry os in oses)
foreach(DbEntry os in oses)
{
if(UpdateProgress != null)
UpdateProgress("Populating OSes table", string.Format("{0} {1}", os.developer, os.product), counter, oses.Count);
string destination = Path.Combine(Settings.Current.RepositoryPath, os.mdid[0].ToString(),
os.mdid[1].ToString(), os.mdid[2].ToString(), os.mdid[3].ToString(),
os.mdid[4].ToString(), os.mdid) + ".zip";
UpdateProgress?.Invoke("Populating OSes table", $"{os.Developer} {os.Product}", counter,
oses.Count);
string destination = Path.Combine(Settings.Current.RepositoryPath, os.Mdid[0].ToString(),
os.Mdid[1].ToString(), os.Mdid[2].ToString(),
os.Mdid[3].ToString(), os.Mdid[4].ToString(), os.Mdid) +
".zip";
if(AddOS != null)
AddOS(os);
AddOS?.Invoke(os);
counter++;
}
#if DEBUG
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.GetAllOSes(): Took {0} seconds to add OSes to the GUI", stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.GetAllOSes(): Took {0} seconds to add OSes to the GUI",
stopwatch.Elapsed.TotalSeconds);
#endif
}
if(Finished != null)
Finished();
Finished?.Invoke();
}
catch(ThreadAbortException)
{ }
catch(ThreadAbortException) { }
catch(Exception ex)
{
if(Debugger.IsAttached)
throw;
if(Failed != null)
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
#if DEBUG
if(Debugger.IsAttached) throw;
Failed?.Invoke($"Exception {ex.Message}\n{ex.InnerException}");
#if DEBUG
Console.WriteLine("Exception {0}\n{1}", ex.Message, ex.InnerException);
#endif
#endif
}
}
@@ -97,14 +96,14 @@ namespace osrepodbmgr.Core
try
{
long counter = 0;
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
Dictionary<string, DBOSFile> knownFiles = new Dictionary<string, DBOSFile>();
#endif
Dictionary<string, DbOsFile> knownFiles = new Dictionary<string, DbOsFile>();
bool unknownFile = false;
foreach(KeyValuePair<string, DBOSFile> kvp in Context.hashes)
foreach(KeyValuePair<string, DbOsFile> kvp in Context.Hashes)
{
// Empty file with size zero
if(kvp.Value.Sha256 == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
@@ -114,66 +113,61 @@ namespace osrepodbmgr.Core
continue;
}
if(UpdateProgress != null)
UpdateProgress(null, "Checking files in database", counter, Context.hashes.Count);
UpdateProgress?.Invoke(null, "Checking files in database", counter, Context.Hashes.Count);
if(AddFileForOS != null)
AddFileForOS(kvp.Key, kvp.Value.Sha256, dbCore.DBOps.ExistsFile(kvp.Value.Sha256), kvp.Value.Crack);
AddFileForOS?.Invoke(kvp.Key, kvp.Value.Sha256, dbCore.DbOps.ExistsFile(kvp.Value.Sha256),
kvp.Value.Crack);
if(dbCore.DBOps.ExistsFile(kvp.Value.Sha256))
if(dbCore.DbOps.ExistsFile(kvp.Value.Sha256))
{
counter++;
knownFiles.Add(kvp.Key, kvp.Value);
}
else
unknownFile = true;
else unknownFile = true;
}
#if DEBUG
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.CheckDbForFiles(): Took {0} seconds to checks for file knowledge in the DB", stopwatch.Elapsed.TotalSeconds);
Console.WriteLine("Core.CheckDbForFiles(): Took {0} seconds to checks for file knowledge in the DB",
stopwatch.Elapsed.TotalSeconds);
stopwatch.Restart();
#endif
#endif
if(knownFiles.Count == 0 || unknownFile)
{
if(Finished != null)
Finished();
Finished?.Invoke();
return;
}
if(UpdateProgress != null)
UpdateProgress(null, "Retrieving OSes from database", counter, Context.hashes.Count);
List<DBEntry> oses;
dbCore.DBOps.GetAllOSes(out oses);
#if DEBUG
UpdateProgress?.Invoke(null, "Retrieving OSes from database", counter, Context.Hashes.Count);
dbCore.DbOps.GetAllOSes(out List<DbEntry> oses);
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.CheckDbForFiles(): Took {0} seconds get all OSes from DB", stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.CheckDbForFiles(): Took {0} seconds get all OSes from DB",
stopwatch.Elapsed.TotalSeconds);
#endif
if(oses != null && oses.Count > 0)
{
DBEntry[] osesArray = new DBEntry[oses.Count];
DbEntry[] osesArray = new DbEntry[oses.Count];
oses.CopyTo(osesArray);
long osCounter = 0;
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
#endif
foreach(DBEntry os in osesArray)
foreach(DbEntry os in osesArray)
{
if(UpdateProgress != null)
UpdateProgress(null, string.Format("Check OS id {0}", os.id), osCounter, osesArray.Length);
UpdateProgress?.Invoke(null, $"Check OS id {os.Id}", osCounter, osesArray.Length);
counter = 0;
foreach(KeyValuePair<string, DBOSFile> kvp in knownFiles)
foreach(KeyValuePair<string, DbOsFile> kvp in knownFiles)
{
if(UpdateProgress2 != null)
UpdateProgress2(null, string.Format("Checking for file {0}", kvp.Value.Path), counter, knownFiles.Count);
UpdateProgress2?.Invoke(null, $"Checking for file {kvp.Value.Path}", counter,
knownFiles.Count);
if(!dbCore.DBOps.ExistsFileInOS(kvp.Value.Sha256, os.id))
if(!dbCore.DbOps.ExistsFileInOs(kvp.Value.Sha256, os.Id))
{
if (oses.Contains(os))
oses.Remove(os);
if(oses.Contains(os)) oses.Remove(os);
// If one file is missing, the rest don't matter
break;
@@ -182,43 +176,37 @@ namespace osrepodbmgr.Core
counter++;
}
if(oses.Count == 0)
break; // No OSes left
if(oses.Count == 0) break; // No OSes left
}
#if DEBUG
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.CheckDbForFiles(): Took {0} seconds correlate all files with all known OSes", stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.CheckDbForFiles(): Took {0} seconds correlate all files with all known OSes",
stopwatch.Elapsed.TotalSeconds);
#endif
}
if(AddOS != null)
{
// TODO: Check file name and existence
foreach(DBEntry os in oses)
foreach(DbEntry os in oses)
{
string destination = Path.Combine(Settings.Current.RepositoryPath, os.mdid[0].ToString(),
os.mdid[1].ToString(), os.mdid[2].ToString(), os.mdid[3].ToString(),
os.mdid[4].ToString(), os.mdid) + ".zip";
string destination = Path.Combine(Settings.Current.RepositoryPath, os.Mdid[0].ToString(),
os.Mdid[1].ToString(), os.Mdid[2].ToString(),
os.Mdid[3].ToString(), os.Mdid[4].ToString(), os.Mdid) +
".zip";
if(AddOS != null)
AddOS(os);
AddOS?.Invoke(os);
}
}
if(Finished != null)
Finished();
Finished?.Invoke();
}
catch(ThreadAbortException)
{ }
catch(ThreadAbortException) { }
catch(Exception ex)
{
if(Debugger.IsAttached)
throw;
if(Failed != null)
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
#if DEBUG
if(Debugger.IsAttached) throw;
Failed?.Invoke($"Exception {ex.Message}\n{ex.InnerException}");
#if DEBUG
Console.WriteLine("Exception {0}\n{1}", ex.Message, ex.InnerException);
#endif
#endif
}
}
@@ -227,106 +215,106 @@ namespace osrepodbmgr.Core
try
{
long counter = 0;
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
foreach(KeyValuePair<string, DBOSFile> kvp in Context.hashes)
#endif
foreach(KeyValuePair<string, DbOsFile> kvp in Context.Hashes)
{
if(UpdateProgress != null)
UpdateProgress(null, "Adding files to database", counter, Context.hashes.Count);
UpdateProgress?.Invoke(null, "Adding files to database", counter, Context.Hashes.Count);
if(!dbCore.DBOps.ExistsFile(kvp.Value.Sha256))
if(!dbCore.DbOps.ExistsFile(kvp.Value.Sha256))
{
DBFile file = new DBFile
DbFile file = new DbFile
{
Sha256 = kvp.Value.Sha256, ClamTime = null, Crack = kvp.Value.Crack,
Length = kvp.Value.Length, Virus = null, HasVirus = null, VirusTotalTime = null
Sha256 = kvp.Value.Sha256,
ClamTime = null,
Crack = kvp.Value.Crack,
Length = kvp.Value.Length,
Virus = null,
HasVirus = null,
VirusTotalTime = null
};
dbCore.DBOps.AddFile(file);
dbCore.DbOps.AddFile(file);
if(AddFile != null)
AddFile(file);
AddFile?.Invoke(file);
}
counter++;
}
#if DEBUG
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.AddFilesToDb(): Took {0} seconds to add all files to the database", stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.AddFilesToDb(): Took {0} seconds to add all files to the database",
stopwatch.Elapsed.TotalSeconds);
#endif
if(UpdateProgress != null)
UpdateProgress(null, "Adding OS information", counter, Context.hashes.Count);
dbCore.DBOps.AddOS(Context.dbInfo, out Context.dbInfo.id);
if(UpdateProgress != null)
UpdateProgress(null, "Creating OS table", counter, Context.hashes.Count);
dbCore.DBOps.CreateTableForOS(Context.dbInfo.id);
UpdateProgress?.Invoke(null, "Adding OS information", counter, Context.Hashes.Count);
dbCore.DbOps.AddOs(Context.DbInfo, out Context.DbInfo.Id);
UpdateProgress?.Invoke(null, "Creating OS table", counter, Context.Hashes.Count);
dbCore.DbOps.CreateTableForOs(Context.DbInfo.Id);
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
#endif
counter = 0;
foreach(KeyValuePair<string, DBOSFile> kvp in Context.hashes)
foreach(KeyValuePair<string, DbOsFile> kvp in Context.Hashes)
{
if(UpdateProgress != null)
UpdateProgress(null, "Adding files to OS in database", counter, Context.hashes.Count);
UpdateProgress?.Invoke(null, "Adding files to OS in database", counter, Context.Hashes.Count);
dbCore.DBOps.AddFileToOS(kvp.Value, Context.dbInfo.id);
dbCore.DbOps.AddFileToOs(kvp.Value, Context.DbInfo.Id);
counter++;
}
#if DEBUG
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.AddFilesToDb(): Took {0} seconds to add all files to the OS in the database", stopwatch.Elapsed.TotalSeconds);
Console.WriteLine("Core.AddFilesToDb(): Took {0} seconds to add all files to the OS in the database",
stopwatch.Elapsed.TotalSeconds);
stopwatch.Restart();
#endif
#endif
counter = 0;
foreach(KeyValuePair<string, DBFolder> kvp in Context.foldersDict)
foreach(KeyValuePair<string, DbFolder> kvp in Context.FoldersDict)
{
if(UpdateProgress != null)
UpdateProgress(null, "Adding folders to OS in database", counter, Context.foldersDict.Count);
UpdateProgress?.Invoke(null, "Adding folders to OS in database", counter,
Context.FoldersDict.Count);
dbCore.DBOps.AddFolderToOS(kvp.Value, Context.dbInfo.id);
dbCore.DbOps.AddFolderToOs(kvp.Value, Context.DbInfo.Id);
counter++;
}
#if DEBUG
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.AddFilesToDb(): Took {0} seconds to add all folders to the database", stopwatch.Elapsed.TotalSeconds);
Console.WriteLine("Core.AddFilesToDb(): Took {0} seconds to add all folders to the database",
stopwatch.Elapsed.TotalSeconds);
stopwatch.Restart();
#endif
#endif
counter = 0;
if(Context.symlinksDict.Count > 0)
dbCore.DBOps.CreateSymlinkTableForOS(Context.dbInfo.id);
foreach(KeyValuePair<string, string> kvp in Context.symlinksDict)
{
if(UpdateProgress != null)
UpdateProgress(null, "Adding symbolic links to OS in database", counter, Context.symlinksDict.Count);
if(Context.SymlinksDict.Count > 0) dbCore.DbOps.CreateSymlinkTableForOs(Context.DbInfo.Id);
dbCore.DBOps.AddSymlinkToOS(kvp.Key, kvp.Value, Context.dbInfo.id);
foreach(KeyValuePair<string, string> kvp in Context.SymlinksDict)
{
UpdateProgress?.Invoke(null, "Adding symbolic links to OS in database", counter,
Context.SymlinksDict.Count);
dbCore.DbOps.AddSymlinkToOs(kvp.Key, kvp.Value, Context.DbInfo.Id);
counter++;
}
#if DEBUG
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.AddFilesToDb(): Took {0} seconds to add all symbolic links to the database", stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.AddFilesToDb(): Took {0} seconds to add all symbolic links to the database",
stopwatch.Elapsed.TotalSeconds);
#endif
if(Finished != null)
Finished();
Finished?.Invoke();
}
catch(ThreadAbortException)
{ }
catch(ThreadAbortException) { }
catch(Exception ex)
{
if(Debugger.IsAttached)
throw;
if(Failed != null)
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
#if DEBUG
if(Debugger.IsAttached) throw;
Failed?.Invoke($"Exception {ex.Message}\n{ex.InnerException}");
#if DEBUG
Console.WriteLine("Exception {0}\n{1}", ex.Message, ex.InnerException);
#endif
#endif
}
}
@@ -339,123 +327,107 @@ namespace osrepodbmgr.Core
{
if(string.IsNullOrEmpty(Settings.Current.DatabasePath))
{
if(Failed != null)
Failed("No database file specified");
Failed?.Invoke("No database file specified");
return;
}
dbCore = new SQLite();
if(File.Exists(Settings.Current.DatabasePath))
{
if(!dbCore.OpenDB(Settings.Current.DatabasePath, null, null, null))
if(!dbCore.OpenDb(Settings.Current.DatabasePath, null, null, null))
{
if(Failed != null)
Failed("Could not open database, correct file selected?");
Failed?.Invoke("Could not open database, correct file selected?");
dbCore = null;
return;
}
}
else
{
if(!dbCore.CreateDB(Settings.Current.DatabasePath, null, null, null))
if(!dbCore.CreateDb(Settings.Current.DatabasePath, null, null, null))
{
if(Failed != null)
Failed("Could not create database, correct file selected?");
Failed?.Invoke("Could not create database, correct file selected?");
dbCore = null;
return;
}
if(!dbCore.OpenDB(Settings.Current.DatabasePath, null, null, null))
if(!dbCore.OpenDb(Settings.Current.DatabasePath, null, null, null))
{
if(Failed != null)
Failed("Could not open database, correct file selected?");
Failed?.Invoke("Could not open database, correct file selected?");
dbCore = null;
return;
}
}
if(Finished != null)
Finished();
Finished?.Invoke();
}
catch(ThreadAbortException)
{ }
catch(ThreadAbortException) { }
catch(Exception ex)
{
if(Debugger.IsAttached)
throw;
if(Failed != null)
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
#if DEBUG
if(Debugger.IsAttached) throw;
Failed?.Invoke($"Exception {ex.Message}\n{ex.InnerException}");
#if DEBUG
Console.WriteLine("Exception {0}\n{1}", ex.Message, ex.InnerException);
#endif
#endif
}
}
public static void CloseDB()
{
if(dbCore != null)
dbCore.CloseDB();
dbCore?.CloseDb();
}
public static void RemoveOS(long id, string mdid)
{
if(id == 0 || string.IsNullOrWhiteSpace(mdid))
return;
if(id == 0 || string.IsNullOrWhiteSpace(mdid)) return;
string destination = Path.Combine(Settings.Current.RepositoryPath, mdid[0].ToString(),
mdid[1].ToString(), mdid[2].ToString(), mdid[3].ToString(),
mdid[4].ToString(), mdid) + ".zip";
string destination = Path.Combine(Settings.Current.RepositoryPath, mdid[0].ToString(), mdid[1].ToString(),
mdid[2].ToString(), mdid[3].ToString(), mdid[4].ToString(),
mdid) + ".zip";
if(File.Exists(destination))
File.Delete(destination);
if(File.Exists(destination)) File.Delete(destination);
dbCore.DBOps.RemoveOS(id);
dbCore.DbOps.RemoveOs(id);
}
public static void GetFilesFromDb()
{
try
{
ulong count = dbCore.DBOps.GetFilesCount();
const ulong page = 2500;
ulong offset = 0;
ulong count = dbCore.DbOps.GetFilesCount();
const ulong PAGE = 2500;
ulong offset = 0;
List<DBFile> files;
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
while(dbCore.DBOps.GetFiles(out files, offset, page))
#endif
while(dbCore.DbOps.GetFiles(out List<DbFile> files, offset, PAGE))
{
if(files.Count == 0)
break;
if(files.Count == 0) break;
if(UpdateProgress != null)
UpdateProgress(null, string.Format("Loaded file {0} of {1}", offset, count), (long)offset, (long)count);
UpdateProgress?.Invoke(null, $"Loaded file {offset} of {count}", (long)offset, (long)count);
if(AddFiles != null)
AddFiles?.Invoke(files);
AddFiles(files);
offset += page;
offset += PAGE;
}
#if DEBUG
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.GetFilesFromDb(): Took {0} seconds to get all files from the database", stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.GetFilesFromDb(): Took {0} seconds to get all files from the database",
stopwatch.Elapsed.TotalSeconds);
#endif
if(Finished != null)
Finished();
Finished?.Invoke();
}
catch(ThreadAbortException)
{ }
catch(ThreadAbortException) { }
catch(Exception ex)
{
if(Debugger.IsAttached)
throw;
if(Failed != null)
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
#if DEBUG
if(Debugger.IsAttached) throw;
Failed?.Invoke($"Exception {ex.Message}\n{ex.InnerException}");
#if DEBUG
Console.WriteLine("Exception {0}\n{1}", ex.Message, ex.InnerException);
#endif
#endif
}
}
@@ -463,28 +435,25 @@ namespace osrepodbmgr.Core
{
try
{
dbCore.DBOps.ToggleCrack(hash, crack);
dbCore.DbOps.ToggleCrack(hash, crack);
if(Finished != null)
Finished();
Finished?.Invoke();
}
catch(ThreadAbortException)
{ }
catch(ThreadAbortException) { }
catch(Exception ex)
{
if(Debugger.IsAttached)
throw;
if(Failed != null)
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
#if DEBUG
if(Debugger.IsAttached) throw;
Failed?.Invoke($"Exception {ex.Message}\n{ex.InnerException}");
#if DEBUG
Console.WriteLine("Exception {0}\n{1}", ex.Message, ex.InnerException);
#endif
#endif
}
}
public static DBFile GetDBFile(string hash)
public static DbFile GetDBFile(string hash)
{
return dbCore.DBOps.GetFile(hash);
return dbCore.DbOps.GetFile(hash);
}
}
}
}

View File

@@ -25,32 +25,42 @@
// 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.Collections.Generic;
namespace osrepodbmgr.Core
{
public static partial class Workers
{
public delegate void UpdateProgressDelegate(string text, string inner, long current, long maximum);
public delegate void UpdateProgress2Delegate(string text, string inner, long current, long maximum);
public delegate void FailedDelegate(string text);
public delegate void FinishedWithoutErrorDelegate();
public delegate void FinishedWithTextDelegate(string text);
public delegate void AddFileForOSDelegate(string filename, string hash, bool known, bool isCrack);
public delegate void AddOSDelegate(DBEntry os);
public delegate void AddFileDelegate(DBFile file);
public delegate void AddFilesDelegate(List<DBFile> file);
public delegate void ScanFinishedDelegate(DBFile file);
public delegate void AddFileDelegate(DbFile file);
public static event UpdateProgressDelegate UpdateProgress;
public static event UpdateProgress2Delegate UpdateProgress2;
public static event FailedDelegate Failed;
public delegate void AddFileForOSDelegate(string filename, string hash, bool known, bool isCrack);
public delegate void AddFilesDelegate(List<DbFile> file);
public delegate void AddOSDelegate(DbEntry os);
public delegate void FailedDelegate(string text);
public delegate void FinishedWithoutErrorDelegate();
public delegate void FinishedWithTextDelegate(string text);
public delegate void ScanFinishedDelegate(DbFile file);
public delegate void UpdateProgress2Delegate(string text, string inner, long current, long maximum);
public delegate void UpdateProgressDelegate(string text, string inner, long current, long maximum);
public static event UpdateProgressDelegate UpdateProgress;
public static event UpdateProgress2Delegate UpdateProgress2;
public static event FailedDelegate Failed;
public static event FinishedWithoutErrorDelegate Finished;
public static event FinishedWithTextDelegate FinishedWithText;
public static event AddFileForOSDelegate AddFileForOS;
public static event AddOSDelegate AddOS;
public static event AddFileDelegate AddFile;
public static event AddFilesDelegate AddFiles;
public static event ScanFinishedDelegate ScanFinished;
public static event FinishedWithTextDelegate FinishedWithText;
public static event AddFileForOSDelegate AddFileForOS;
public static event AddOSDelegate AddOS;
public static event AddFileDelegate AddFile;
public static event AddFilesDelegate AddFiles;
public static event ScanFinishedDelegate ScanFinished;
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -25,6 +25,7 @@
// 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.Diagnostics;
using System.IO;
@@ -34,55 +35,48 @@ namespace osrepodbmgr.Core
{
public static partial class Workers
{
static DBCore dbCore;
static DbCore dbCore;
static int zipCounter;
static int zipCounter;
static string zipCurrentEntryName;
#if DEBUG
#if DEBUG
static Stopwatch stopwatch = new Stopwatch();
#endif
#endif
static string stringify(byte[] hash)
static string Stringify(byte[] hash)
{
StringBuilder hashOutput = new StringBuilder();
for(int i = 0; i < hash.Length; i++)
{
hashOutput.Append(hash[i].ToString("x2"));
}
foreach(byte h in hash) hashOutput.Append(h.ToString("x2"));
return hashOutput.ToString();
}
public static void CheckUnar()
{
if(string.IsNullOrWhiteSpace(Settings.Current.UnArchiverPath))
{
if(Failed != null)
Failed("unar path is not set.");
Failed?.Invoke("unar path is not set.");
return;
}
string unarFolder = Path.GetDirectoryName(Settings.Current.UnArchiverPath);
string extension = Path.GetExtension(Settings.Current.UnArchiverPath);
string unarFolder = Path.GetDirectoryName(Settings.Current.UnArchiverPath);
string extension = Path.GetExtension(Settings.Current.UnArchiverPath);
string unarfilename = Path.GetFileNameWithoutExtension(Settings.Current.UnArchiverPath);
string lsarfilename = unarfilename.Replace("unar", "lsar");
string unarPath = Path.Combine(unarFolder, unarfilename + extension);
string lsarPath = Path.Combine(unarFolder, lsarfilename + extension);
string unarPath = Path.Combine(unarFolder, unarfilename + extension);
string lsarPath = Path.Combine(unarFolder, lsarfilename + extension);
if(!File.Exists(unarPath))
{
if(Failed != null)
Failed(string.Format("Cannot find unar executable at {0}.", unarPath));
Failed?.Invoke($"Cannot find unar executable at {unarPath}.");
return;
}
if(!File.Exists(lsarPath))
{
if(Failed != null)
Failed("Cannot find unar executable.");
Failed?.Invoke("Cannot find unar executable.");
return;
}
@@ -90,65 +84,75 @@ namespace osrepodbmgr.Core
try
{
Process unarProcess = new Process();
unarProcess.StartInfo.FileName = unarPath;
unarProcess.StartInfo.CreateNoWindow = true;
unarProcess.StartInfo.RedirectStandardOutput = true;
unarProcess.StartInfo.UseShellExecute = false;
Process unarProcess = new Process
{
StartInfo =
{
FileName = unarPath,
CreateNoWindow = true,
RedirectStandardOutput = true,
UseShellExecute = false
}
};
unarProcess.Start();
unarProcess.WaitForExit();
unarOut = unarProcess.StandardOutput.ReadToEnd();
}
catch
{
if(Failed != null)
Failed("Cannot run unar.");
Failed?.Invoke("Cannot run unar.");
return;
}
try
{
Process lsarProcess = new Process();
lsarProcess.StartInfo.FileName = lsarPath;
lsarProcess.StartInfo.CreateNoWindow = true;
lsarProcess.StartInfo.RedirectStandardOutput = true;
lsarProcess.StartInfo.UseShellExecute = false;
Process lsarProcess = new Process
{
StartInfo =
{
FileName = lsarPath,
CreateNoWindow = true,
RedirectStandardOutput = true,
UseShellExecute = false
}
};
lsarProcess.Start();
lsarProcess.WaitForExit();
lsarOut = lsarProcess.StandardOutput.ReadToEnd();
}
catch
{
if(Failed != null)
Failed("Cannot run lsar.");
Failed?.Invoke("Cannot run lsar.");
return;
}
if(!unarOut.StartsWith("unar ", StringComparison.CurrentCulture))
{
if(Failed != null)
Failed("Not the correct unar executable");
Failed?.Invoke("Not the correct unar executable");
return;
}
if(!lsarOut.StartsWith("lsar ", StringComparison.CurrentCulture))
{
if(Failed != null)
Failed("Not the correct unar executable");
Failed?.Invoke("Not the correct unar executable");
return;
}
Process versionProcess = new Process();
versionProcess.StartInfo.FileName = unarPath;
versionProcess.StartInfo.CreateNoWindow = true;
versionProcess.StartInfo.RedirectStandardOutput = true;
versionProcess.StartInfo.UseShellExecute = false;
versionProcess.StartInfo.Arguments = "-v";
Process versionProcess = new Process
{
StartInfo =
{
FileName = unarPath,
CreateNoWindow = true,
RedirectStandardOutput = true,
UseShellExecute = false,
Arguments = "-v"
}
};
versionProcess.Start();
versionProcess.WaitForExit();
if(FinishedWithText != null)
FinishedWithText(versionProcess.StandardOutput.ReadToEnd().TrimEnd(new char[] { '\n' }));
FinishedWithText?.Invoke(versionProcess.StandardOutput.ReadToEnd().TrimEnd('\n'));
}
}
}
}

View File

@@ -25,16 +25,19 @@
// 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 System.Threading;
using System.Threading.Tasks;
using SharpCompress.Compressors;
using SharpCompress.Compressors.BZip2;
using SharpCompress.Compressors.Deflate;
using SharpCompress.Compressors.LZMA;
using VirusTotalNET;
using VirusTotalNET.Objects;
using VirusTotalNET.ResponseCodes;
using VirusTotalNET.Results;
namespace osrepodbmgr.Core
@@ -52,14 +55,14 @@ namespace osrepodbmgr.Core
{
Task.Run(async () =>
{
vt = new VirusTotal(key);
report = await vt.GetFileReportAsync("b82758fc5f737a58078d3c60e2798a70d895443a86aa39adf52dec70e98c2bed");
vt = new VirusTotal(key);
report =
await vt.GetFileReportAsync("b82758fc5f737a58078d3c60e2798a70d895443a86aa39adf52dec70e98c2bed");
}).Wait();
}
catch(Exception ex)
{
if(Failed != null)
Failed(ex.InnerException.Message);
Failed?.Invoke(ex.InnerException?.Message);
return false;
}
@@ -68,117 +71,99 @@ namespace osrepodbmgr.Core
public static bool InitVirusTotal(string key)
{
VirusTotal vt = null;
VirusTotal vt = null;
FileReport report = null;
try
{
Task.Run(async () =>
{
vt = new VirusTotal(key);
report = await vt.GetFileReportAsync("b82758fc5f737a58078d3c60e2798a70d895443a86aa39adf52dec70e98c2bed");
vt = new VirusTotal(key);
report =
await vt.GetFileReportAsync("b82758fc5f737a58078d3c60e2798a70d895443a86aa39adf52dec70e98c2bed");
}).Wait();
}
catch(Exception ex)
{
if(Failed != null)
Failed(ex.InnerException.Message);
Failed?.Invoke(ex.InnerException?.Message);
return false;
}
if(report != null && report.MD5 == "0bf60adb1435639a42b490e7e80d25c7")
{
vTotal = vt;
Context.virusTotalEnabled = true;
return true;
}
return false;
if(report == null || report.MD5 != "0bf60adb1435639a42b490e7e80d25c7") return false;
vTotal = vt;
Context.VirusTotalEnabled = true;
return true;
}
public static void VirusTotalFileFromRepo(DBFile file)
public static void VirusTotalFileFromRepo(DbFile file)
{
try
{
if(!Context.virusTotalEnabled)
if(!Context.VirusTotalEnabled)
{
if(Failed != null)
Failed("VirusTotal is not usable");
Failed?.Invoke("VirusTotal is not usable");
return;
}
if(vTotal == null)
{
if(Failed != null)
Failed("VirusTotal is not initalized");
}
if(vTotal == null) Failed?.Invoke("VirusTotal is not initalized");
FileReport fResult = null;
if(UpdateProgress != null)
UpdateProgress("Requesting existing report to VirusTotal", null, 0, 0);
UpdateProgress?.Invoke("Requesting existing report to VirusTotal", null, 0, 0);
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
Task.Run(async () =>
{
fResult = await vTotal.GetFileReportAsync(file.Sha256);
}).Wait();
#if DEBUG
#endif
Task.Run(async () => { fResult = await vTotal.GetFileReportAsync(file.Sha256); }).Wait();
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.VirusTotalFileFromRepo({0}): VirusTotal took {1} seconds to answer for SHA256 request", file, stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.VirusTotalFileFromRepo({0}): VirusTotal took {1} seconds to answer for SHA256 request",
file, stopwatch.Elapsed.TotalSeconds);
#endif
if(fResult.ResponseCode == VirusTotalNET.ResponseCodes.FileReportResponseCode.NotPresent)
if(fResult.ResponseCode == FileReportResponseCode.NotPresent)
{
if(Failed != null)
Failed(fResult.VerboseMsg);
Failed?.Invoke(fResult.VerboseMsg);
return;
}
if(fResult.ResponseCode != VirusTotalNET.ResponseCodes.FileReportResponseCode.Queued)
if(fResult.ResponseCode != FileReportResponseCode.Queued)
{
if(fResult.ResponseCode == VirusTotalNET.ResponseCodes.FileReportResponseCode.Present)
{
if(fResult.ResponseCode == FileReportResponseCode.Present)
if(fResult.Positives > 0)
{
file.HasVirus = true;
if(fResult.Scans != null)
{
foreach(KeyValuePair<string, ScanEngine> engine in fResult.Scans)
{
if(engine.Value.Detected)
{
file.Virus = engine.Value.Result;
file.VirusTotalTime = engine.Value.Update;
dbCore.DBOps.UpdateFile(file);
if(!engine.Value.Detected) continue;
if(ScanFinished != null)
ScanFinished(file);
file.Virus = engine.Value.Result;
file.VirusTotalTime = engine.Value.Update;
dbCore.DbOps.UpdateFile(file);
return;
}
ScanFinished?.Invoke(file);
return;
}
}
}
else
{
// If no scan has been done, mark as false.
// If a positive has already existed don't overwrite it.
file.HasVirus = false;
file.Virus = null;
file.HasVirus = false;
file.Virus = null;
file.VirusTotalTime = DateTime.UtcNow;
dbCore.DBOps.UpdateFile(file);
dbCore.DbOps.UpdateFile(file);
if(ScanFinished != null)
ScanFinished(file);
ScanFinished?.Invoke(file);
return;
}
}
string repoPath;
string repoPath;
AlgoEnum algorithm;
if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
@@ -193,9 +178,9 @@ namespace osrepodbmgr.Core
algorithm = AlgoEnum.GZip;
}
else if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".bz2")))
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".bz2")))
{
repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
@@ -204,9 +189,9 @@ namespace osrepodbmgr.Core
algorithm = AlgoEnum.BZip2;
}
else if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lzma")))
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lzma")))
{
repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
@@ -215,9 +200,9 @@ namespace osrepodbmgr.Core
algorithm = AlgoEnum.LZMA;
}
else if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lz")))
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lz")))
{
repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
@@ -227,24 +212,22 @@ namespace osrepodbmgr.Core
}
else
{
if(Failed != null)
Failed(string.Format("Cannot find file with hash {0} in the repository", file.Sha256));
Failed?.Invoke($"Cannot find file with hash {file.Sha256} in the repository");
return;
}
if(UpdateProgress != null)
UpdateProgress("Uncompressing file...", null, 0, 0);
UpdateProgress?.Invoke("Uncompressing file...", null, 0, 0);
FileStream inFs = new FileStream(repoPath, FileMode.Open, FileAccess.Read);
Stream zStream = null;
FileStream inFs = new FileStream(repoPath, FileMode.Open, FileAccess.Read);
Stream zStream = null;
switch(algorithm)
{
case AlgoEnum.GZip:
zStream = new GZipStream(inFs, SharpCompress.Compressors.CompressionMode.Decompress);
zStream = new GZipStream(inFs, CompressionMode.Decompress);
break;
case AlgoEnum.BZip2:
zStream = new BZip2Stream(inFs, SharpCompress.Compressors.CompressionMode.Decompress);
zStream = new BZip2Stream(inFs, CompressionMode.Decompress);
break;
case AlgoEnum.LZMA:
byte[] properties = new byte[5];
@@ -253,53 +236,49 @@ namespace osrepodbmgr.Core
zStream = new LzmaStream(properties, inFs, inFs.Length - 13, file.Length);
break;
case AlgoEnum.LZip:
zStream = new LZipStream(inFs, SharpCompress.Compressors.CompressionMode.Decompress);
zStream = new LZipStream(inFs, CompressionMode.Decompress);
break;
}
ScanResult sResult = null;
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
#endif
// Cannot use zStream directly, VirusTotal.NET requests the size *sigh*
string tmpFile = Path.Combine(Settings.Current.TemporaryFolder, Path.GetTempFileName());
FileStream outFs = new FileStream(tmpFile, FileMode.Create, FileAccess.ReadWrite);
zStream.CopyTo(outFs);
zStream.Close();
string tmpFile = Path.Combine(Settings.Current.TemporaryFolder, Path.GetTempFileName());
FileStream outFs = new FileStream(tmpFile, FileMode.Create, FileAccess.ReadWrite);
zStream?.CopyTo(outFs);
zStream?.Close();
outFs.Seek(0, SeekOrigin.Begin);
#if DEBUG
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.VirusTotalFileFromRepo({0}): Uncompressing took {1} seconds", file, stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.VirusTotalFileFromRepo({0}): Uncompressing took {1} seconds", file,
stopwatch.Elapsed.TotalSeconds);
#endif
if(UpdateProgress != null)
UpdateProgress("Uploading file to VirusTotal...", null, 0, 0);
UpdateProgress?.Invoke("Uploading file to VirusTotal...", null, 0, 0);
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
#endif
Task.Run(async () =>
{
sResult = await vTotal.ScanFileAsync(outFs, file.Sha256); // Keep filename private, sorry!
}).Wait();
#if DEBUG
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.VirusTotalFileFromRepo({0}): Upload to VirusTotal took {1} seconds", file, stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.VirusTotalFileFromRepo({0}): Upload to VirusTotal took {1} seconds", file,
stopwatch.Elapsed.TotalSeconds);
#endif
outFs.Close();
File.Delete(tmpFile);
if(sResult == null || sResult.ResponseCode == VirusTotalNET.ResponseCodes.ScanFileResponseCode.Error)
if(sResult == null || sResult.ResponseCode == ScanFileResponseCode.Error)
{
if(sResult == null)
{
if(Failed != null)
Failed("Cannot send file to VirusTotal");
}
else
Failed(sResult.VerboseMsg);
if(sResult == null) Failed?.Invoke("Cannot send file to VirusTotal");
else Failed(sResult.VerboseMsg);
return;
}
@@ -307,92 +286,77 @@ namespace osrepodbmgr.Core
// Seems that we are faster than them, getting a lot of "not queued" responses...
Thread.Sleep(2500);
Task.Run(async () =>
{
fResult = await vTotal.GetFileReportAsync(file.Sha256);
}).Wait();
Task.Run(async () => { fResult = await vTotal.GetFileReportAsync(file.Sha256); }).Wait();
}
if(UpdateProgress != null)
UpdateProgress("Waiting for VirusTotal analysis...", null, 0, 0);
UpdateProgress?.Invoke("Waiting for VirusTotal analysis...", null, 0, 0);
#if DEBUG
#if DEBUG
stopwatch.Restart();
#endif
#endif
int counter = 0;
while(fResult.ResponseCode == VirusTotalNET.ResponseCodes.FileReportResponseCode.Queued)
while(fResult.ResponseCode == FileReportResponseCode.Queued)
{
// Timeout...
if(counter == 10)
break;
if(counter == 10) break;
// Wait 15 seconds so we fall in the 4 requests/minute
Thread.Sleep(15000);
Task.Run(async () =>
{
fResult = await vTotal.GetFileReportAsync(file.Sha256);
}).Wait();
Task.Run(async () => { fResult = await vTotal.GetFileReportAsync(file.Sha256); }).Wait();
counter++;
}
#if DEBUG
#if DEBUG
stopwatch.Stop();
Console.WriteLine("Core.VirusTotalFileFromRepo({0}): VirusTotal took {1} seconds to do the analysis", file, stopwatch.Elapsed.TotalSeconds);
#endif
Console.WriteLine("Core.VirusTotalFileFromRepo({0}): VirusTotal took {1} seconds to do the analysis",
file, stopwatch.Elapsed.TotalSeconds);
#endif
if(fResult.ResponseCode != VirusTotalNET.ResponseCodes.FileReportResponseCode.Present)
if(fResult.ResponseCode != FileReportResponseCode.Present)
{
if(Failed != null)
Failed(fResult.VerboseMsg);
Failed?.Invoke(fResult.VerboseMsg);
return;
}
if(fResult.Positives > 0)
{
file.HasVirus = true;
if(fResult.Scans != null)
if(fResult.Scans == null) return;
foreach(KeyValuePair<string, ScanEngine> engine in fResult.Scans)
{
foreach(KeyValuePair<string, ScanEngine> engine in fResult.Scans)
{
if(engine.Value.Detected)
{
file.Virus = engine.Value.Result;
file.VirusTotalTime = engine.Value.Update;
dbCore.DBOps.UpdateFile(file);
if(!engine.Value.Detected) continue;
if(ScanFinished != null)
ScanFinished(file);
file.Virus = engine.Value.Result;
file.VirusTotalTime = engine.Value.Update;
dbCore.DbOps.UpdateFile(file);
return;
}
}
ScanFinished?.Invoke(file);
return;
}
}
else
{
// If no scan has been done, mark as false.
// If a positive has already existed don't overwrite it.
file.HasVirus = false;
file.Virus = null;
file.HasVirus = false;
file.Virus = null;
file.VirusTotalTime = DateTime.UtcNow;
dbCore.DBOps.UpdateFile(file);
dbCore.DbOps.UpdateFile(file);
if(ScanFinished != null)
ScanFinished(file);
return;
ScanFinished?.Invoke(file);
}
}
catch(Exception ex)
{
if(Failed != null)
Failed(string.Format("Exception {0} when calling VirusTotal", ex.InnerException.Message));
#if DEBUG
Failed?.Invoke($"Exception {ex.InnerException.Message} when calling VirusTotal");
#if DEBUG
Console.WriteLine("Exception {0}\n{1}", ex.Message, ex.InnerException);
#endif
#endif
}
}
}
}
}

View File

@@ -44,9 +44,9 @@ namespace osrepodbmgr.Eto.Desktop
if(Settings.Current.UseClamd)
Workers.InitClamd();
if(Settings.Current.UseVirusTotal)
Context.virusTotalEnabled = Workers.InitVirusTotal(Settings.Current.VirusTotalKey);
Context.VirusTotalEnabled = Workers.InitVirusTotal(Settings.Current.VirusTotalKey);
}
Context.usableDotNetZip = !Platform.Detect.IsMac && !Platform.Detect.IsIos;
Context.UsableDotNetZip = !Platform.Detect.IsMac && !Platform.Detect.IsIos;
new Application(Platform.Detect).Run(new frmMain());
}

View File

@@ -44,9 +44,9 @@ namespace osrepodbmgr.Eto.XamMac2
if(Settings.Current.UseClamd)
Workers.InitClamd();
if(Settings.Current.UseVirusTotal)
Context.virusTotalEnabled = Workers.InitVirusTotal(Settings.Current.VirusTotalKey);
Context.VirusTotalEnabled = Workers.InitVirusTotal(Settings.Current.VirusTotalKey);
}
Context.usableDotNetZip = false;
Context.UsableDotNetZip = false;
new Application(Platforms.XamMac2).Run(new frmMain());
}
}

View File

@@ -25,6 +25,7 @@
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
using osrepodbmgr.Core;
using Schemas;
@@ -32,32 +33,109 @@ namespace osrepodbmgr.Eto
{
class DBEntryForEto
{
DBEntry _item;
public DBEntryForEto(DBEntry item)
DbEntry _item;
public DBEntryForEto(DbEntry item)
{
_item = item;
}
public long id { get { return _item.id; } set { } }
public string developer { get { return _item.developer; } set { } }
public string product { get { return _item.product; } set { } }
public string version { get { return _item.version; } set { } }
public string languages { get { return _item.languages; } set { } }
public string architecture { get { return _item.architecture; } set { } }
public string machine { get { return _item.machine; } set { } }
public string format { get { return _item.format; } set { } }
public string description { get { return _item.description; } set { } }
public bool oem { get { return _item.oem; } set { } }
public bool upgrade { get { return _item.upgrade; } set { } }
public bool update { get { return _item.update; } set { } }
public bool source { get { return _item.source; } set { } }
public bool files { get { return _item.files; } set { } }
public bool netinstall { get { return _item.netinstall; } set { } }
public byte[] xml { get { return _item.xml; } set { } }
public byte[] json { get { return _item.json; } set { } }
public string mdid { get { return _item.mdid; } set { } }
public long id
{
get { return _item.Id; }
set { }
}
public string developer
{
get { return _item.Developer; }
set { }
}
public string product
{
get { return _item.Product; }
set { }
}
public string version
{
get { return _item.Version; }
set { }
}
public string languages
{
get { return _item.Languages; }
set { }
}
public string architecture
{
get { return _item.Architecture; }
set { }
}
public string machine
{
get { return _item.Machine; }
set { }
}
public string format
{
get { return _item.Format; }
set { }
}
public string description
{
get { return _item.Description; }
set { }
}
public bool oem
{
get { return _item.Oem; }
set { }
}
public bool upgrade
{
get { return _item.Upgrade; }
set { }
}
public bool update
{
get { return _item.Update; }
set { }
}
public bool source
{
get { return _item.Source; }
set { }
}
public bool files
{
get { return _item.Files; }
set { }
}
public bool netinstall
{
get { return _item.Netinstall; }
set { }
}
public byte[] xml
{
get { return _item.Xml; }
set { }
}
public byte[] json
{
get { return _item.Json; }
set { }
}
public string mdid
{
get { return _item.Mdid; }
set { }
}
public DBEntry original { get { return _item; } set { } }
public DbEntry original
{
get { return _item; }
set { }
}
}
class StringEntry
@@ -67,19 +145,19 @@ namespace osrepodbmgr.Eto
class BarcodeEntry
{
public string code { get; set; }
public string code { get; set; }
public BarcodeTypeType type { get; set; }
}
class DiscEntry
{
public string path { get; set; }
public string path { get; set; }
public OpticalDiscType disc { get; set; }
}
class DiskEntry
{
public string path { get; set; }
public string path { get; set; }
public BlockMediaType disk { get; set; }
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -25,6 +25,7 @@
// 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 Eto.Forms;
using Eto.Serialization.Xaml;
@@ -35,101 +36,67 @@ namespace osrepodbmgr.Eto
public class dlgFilesystem : Dialog
{
public FileSystemType Metadata;
public bool Modified;
#region XAML UI elements
#pragma warning disable 0649
TextBox txtType;
TextBox txtFiles;
CheckBox chkBootable;
CheckBox chkDirty;
NumericUpDown spClusterSize;
TextBox txtClusters;
TextBox txtFreeClusters;
CheckBox chkCreationDate;
DateTimePicker cldCreationDate;
CheckBox chkModificationDate;
DateTimePicker cldModificationDate;
CheckBox chkEffectiveDate;
DateTimePicker cldEffectiveDate;
CheckBox chkExpirationDate;
DateTimePicker cldExpirationDate;
CheckBox chkBackupDate;
DateTimePicker cldBackupDate;
TextBox txtLabel;
TextBox txtSerial;
TextBox txtSysId;
TextBox txtVolId;
TextBox txtPubId;
TextBox txtDataId;
TextBox txtAppId;
#pragma warning restore 0649
#endregion XAML UI elements
public bool Modified;
public dlgFilesystem()
{
XamlReader.Load(this);
Modified = false;
}
public void FillFields()
{
if(Metadata == null)
return;
if(Metadata == null) return;
if(Metadata.Type != null)
txtType.Text = Metadata.Type;
if(Metadata.Type != null) txtType.Text = Metadata.Type;
if(Metadata.CreationDateSpecified)
{
chkCreationDate.Checked = true;
cldCreationDate.Enabled = true;
cldCreationDate.Value = Metadata.CreationDate;
cldCreationDate.Value = Metadata.CreationDate;
}
if(Metadata.ModificationDateSpecified)
{
chkModificationDate.Checked = true;
cldModificationDate.Enabled = true;
cldModificationDate.Value = Metadata.ModificationDate;
cldModificationDate.Value = Metadata.ModificationDate;
}
if(Metadata.BackupDateSpecified)
{
chkBackupDate.Checked = true;
cldBackupDate.Enabled = true;
cldBackupDate.Value = Metadata.BackupDate;
cldBackupDate.Value = Metadata.BackupDate;
}
spClusterSize.Value = Metadata.ClusterSize;
txtClusters.Text = Metadata.Clusters.ToString();
if(Metadata.FilesSpecified)
txtFiles.Text = Metadata.Files.ToString();
chkBootable.Checked = Metadata.Bootable;
if(Metadata.VolumeSerial != null)
txtSerial.Text = Metadata.VolumeSerial;
if(Metadata.VolumeName != null)
txtLabel.Text = Metadata.VolumeName;
if(Metadata.FreeClustersSpecified)
txtFreeClusters.Text = Metadata.FreeClusters.ToString();
chkDirty.Checked = Metadata.Dirty;
spClusterSize.Value = Metadata.ClusterSize;
txtClusters.Text = Metadata.Clusters.ToString();
if(Metadata.FilesSpecified) txtFiles.Text = Metadata.Files.ToString();
chkBootable.Checked = Metadata.Bootable;
if(Metadata.VolumeSerial != null) txtSerial.Text = Metadata.VolumeSerial;
if(Metadata.VolumeName != null) txtLabel.Text = Metadata.VolumeName;
if(Metadata.FreeClustersSpecified) txtFreeClusters.Text = Metadata.FreeClusters.ToString();
chkDirty.Checked = Metadata.Dirty;
if(Metadata.ExpirationDateSpecified)
{
chkExpirationDate.Checked = true;
cldExpirationDate.Enabled = true;
cldExpirationDate.Value = Metadata.ExpirationDate;
cldExpirationDate.Value = Metadata.ExpirationDate;
}
if(Metadata.EffectiveDateSpecified)
{
chkEffectiveDate.Checked = true;
cldEffectiveDate.Enabled = true;
cldEffectiveDate.Value = Metadata.EffectiveDate;
cldEffectiveDate.Value = Metadata.EffectiveDate;
}
if(Metadata.SystemIdentifier != null)
txtSysId.Text = Metadata.SystemIdentifier;
if(Metadata.VolumeSetIdentifier != null)
txtVolId.Text = Metadata.VolumeSetIdentifier;
if(Metadata.PublisherIdentifier != null)
txtPubId.Text = Metadata.PublisherIdentifier;
if(Metadata.DataPreparerIdentifier != null)
txtDataId.Text = Metadata.DataPreparerIdentifier;
if(Metadata.ApplicationIdentifier != null)
txtAppId.Text = Metadata.ApplicationIdentifier;
if(Metadata.SystemIdentifier != null) txtSysId.Text = Metadata.SystemIdentifier;
if(Metadata.VolumeSetIdentifier != null) txtVolId.Text = Metadata.VolumeSetIdentifier;
if(Metadata.PublisherIdentifier != null) txtPubId.Text = Metadata.PublisherIdentifier;
if(Metadata.DataPreparerIdentifier != null) txtDataId.Text = Metadata.DataPreparerIdentifier;
if(Metadata.ApplicationIdentifier != null) txtAppId.Text = Metadata.ApplicationIdentifier;
}
protected void OnChkCreationDateToggled(object sender, EventArgs e)
@@ -165,19 +132,15 @@ namespace osrepodbmgr.Eto
protected void OnBtnSaveClicked(object sender, EventArgs e)
{
long temp;
if(string.IsNullOrWhiteSpace(txtType.Text))
MessageBox.Show("Filesystem type cannot be empty", MessageBoxType.Error);
if(spClusterSize.Value < 1)
MessageBox.Show("Clusters must be bigger than 0 bytes", MessageBoxType.Error);
if(spClusterSize.Value < 1) MessageBox.Show("Clusters must be bigger than 0 bytes", MessageBoxType.Error);
if(!long.TryParse(txtClusters.Text, out temp))
if(!long.TryParse(txtClusters.Text, out long temp))
MessageBox.Show("Clusters must be a number", MessageBoxType.Error);
if(temp < 1)
MessageBox.Show("Filesystem must have more than 0 clusters", MessageBoxType.Error);
if(temp < 1) MessageBox.Show("Filesystem must have more than 0 clusters", MessageBoxType.Error);
if(!string.IsNullOrWhiteSpace(txtFiles.Text) && !long.TryParse(txtFiles.Text, out temp))
MessageBox.Show("Files must be a number, or empty for unknown", MessageBoxType.Error);
@@ -191,64 +154,92 @@ namespace osrepodbmgr.Eto
if(!string.IsNullOrWhiteSpace(txtFreeClusters.Text) && temp < 0)
MessageBox.Show("Free clusters must be positive", MessageBoxType.Error);
Metadata = new FileSystemType();
Metadata.Type = txtType.Text;
Metadata = new FileSystemType {Type = txtType.Text};
if(chkCreationDate.Checked.Value)
{
Metadata.CreationDateSpecified = true;
Metadata.CreationDate = cldCreationDate.Value.Value;
Metadata.CreationDate = cldCreationDate.Value.Value;
}
if(chkModificationDate.Checked.Value)
{
Metadata.ModificationDateSpecified = true;
Metadata.ModificationDate = cldModificationDate.Value.Value;
Metadata.ModificationDate = cldModificationDate.Value.Value;
}
if(chkBackupDate.Checked.Value)
{
Metadata.BackupDateSpecified = true;
Metadata.BackupDate = cldBackupDate.Value.Value;
Metadata.BackupDate = cldBackupDate.Value.Value;
}
Metadata.ClusterSize = (int)spClusterSize.Value;
Metadata.Clusters = long.Parse(txtClusters.Text);
Metadata.Clusters = long.Parse(txtClusters.Text);
if(!string.IsNullOrWhiteSpace(txtFiles.Text))
{
Metadata.FilesSpecified = true;
Metadata.Files = long.Parse(txtFiles.Text);
Metadata.Files = long.Parse(txtFiles.Text);
}
Metadata.Bootable = chkBootable.Checked.Value;
if(!string.IsNullOrWhiteSpace(txtSerial.Text))
Metadata.VolumeSerial = txtSerial.Text;
if(!string.IsNullOrWhiteSpace(txtLabel.Text))
Metadata.VolumeName = txtLabel.Text;
Metadata.Bootable = chkBootable.Checked.Value;
if(!string.IsNullOrWhiteSpace(txtSerial.Text)) Metadata.VolumeSerial = txtSerial.Text;
if(!string.IsNullOrWhiteSpace(txtLabel.Text)) Metadata.VolumeName = txtLabel.Text;
if(!string.IsNullOrWhiteSpace(txtFreeClusters.Text))
{
Metadata.FreeClustersSpecified = true;
Metadata.FreeClusters = long.Parse(txtFreeClusters.Text);
Metadata.FreeClusters = long.Parse(txtFreeClusters.Text);
}
Metadata.Dirty = chkDirty.Checked.Value;
if(chkExpirationDate.Checked.Value)
{
Metadata.ExpirationDateSpecified = true;
Metadata.ExpirationDate = cldExpirationDate.Value.Value;
Metadata.ExpirationDate = cldExpirationDate.Value.Value;
}
if(chkEffectiveDate.Checked.Value)
{
Metadata.EffectiveDateSpecified = true;
Metadata.EffectiveDate = cldEffectiveDate.Value.Value;
Metadata.EffectiveDate = cldEffectiveDate.Value.Value;
}
if(!string.IsNullOrWhiteSpace(txtSysId.Text))
Metadata.SystemIdentifier = txtSysId.Text;
if(!string.IsNullOrWhiteSpace(txtVolId.Text))
Metadata.VolumeSetIdentifier = txtVolId.Text;
if(!string.IsNullOrWhiteSpace(txtPubId.Text))
Metadata.PublisherIdentifier = txtPubId.Text;
if(!string.IsNullOrWhiteSpace(txtDataId.Text))
Metadata.DataPreparerIdentifier = txtDataId.Text;
if(!string.IsNullOrWhiteSpace(txtAppId.Text))
Metadata.ApplicationIdentifier = txtAppId.Text;
if(!string.IsNullOrWhiteSpace(txtSysId.Text)) Metadata.SystemIdentifier = txtSysId.Text;
if(!string.IsNullOrWhiteSpace(txtVolId.Text)) Metadata.VolumeSetIdentifier = txtVolId.Text;
if(!string.IsNullOrWhiteSpace(txtPubId.Text)) Metadata.PublisherIdentifier = txtPubId.Text;
if(!string.IsNullOrWhiteSpace(txtDataId.Text)) Metadata.DataPreparerIdentifier = txtDataId.Text;
if(!string.IsNullOrWhiteSpace(txtAppId.Text)) Metadata.ApplicationIdentifier = txtAppId.Text;
Modified = true;
Close();
}
#region XAML UI elements
#pragma warning disable 0649
TextBox txtType;
TextBox txtFiles;
CheckBox chkBootable;
CheckBox chkDirty;
NumericUpDown spClusterSize;
TextBox txtClusters;
TextBox txtFreeClusters;
CheckBox chkCreationDate;
DateTimePicker cldCreationDate;
CheckBox chkModificationDate;
DateTimePicker cldModificationDate;
CheckBox chkEffectiveDate;
DateTimePicker cldEffectiveDate;
CheckBox chkExpirationDate;
DateTimePicker cldExpirationDate;
CheckBox chkBackupDate;
DateTimePicker cldBackupDate;
TextBox txtLabel;
TextBox txtSerial;
TextBox txtSysId;
TextBox txtVolId;
TextBox txtPubId;
TextBox txtDataId;
TextBox txtAppId;
#pragma warning restore 0649
#endregion XAML UI elements
}
}

View File

@@ -25,6 +25,7 @@
// 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 Eto.Forms;
using Eto.Serialization.Xaml;
@@ -34,133 +35,128 @@ namespace osrepodbmgr.Eto
public class dlgHelp : Dialog
{
#region XAML UI elements
#pragma warning disable 0649
#pragma warning disable 0649
TextArea txtHelp;
#pragma warning restore 0649
#pragma warning restore 0649
#endregion XAML UI elements
public dlgHelp()
{
XamlReader.Load(this);
txtHelp.Text = "This is the naming scheme and folder organization conventions for the Operating System Repository.\n\n" +
"The basic layout is as follows:\n\n" +
txtHelp.Text =
"This is the naming scheme and folder organization conventions for the Operating System Repository.\n\n" +
"The basic layout is as follows:\n\n" +
"<Developer>/<Product>/<Version>/<Language>/<Architecture>/oem/for <Machine>/<[format]_update/upgrade/files/source/netinstall/description>.zip\n" +
"All fields should contain only 7-bit ASCII.\n\n" +
"<Developer>\n" +
"-----------\n" +
"This is the main developer of the operating system or associated software. e.g. Microsoft\n\n" +
"<Product>\n" +
"---------\n" +
"This is the name of the operating system or associated software. e.g. Windows NT\n\n" +
"<Version>\n" +
"---------\n" +
"This is the version of the operating system or associated software. e.g. 6.00.6000.16386\n" +
"Service pack and release markers should be appended. e.g. 6.10.7601.16385 (RTM)\n" +
"Build can be specified by appending \"build\". e.g. 10.2.7 build 6S80\n" +
"And combined. e.g. 10.5 build 9A581 (Server)\n" +
"Version with same version number but different build date should have it appended. Date format should be YYYYmm[dd]. e.g. 10 201009\n\n" +
"<Language>\n" +
"----------\n" +
"This specifies the language localization and translation:\n" +
"xxx: Language variation, e.g. German = deu\n" +
"xxx_yy: Country specific language variation. e.g. Swiss German = deu_ch\n" +
"multi: The only known variation of the product that contains more than a language\n" +
"xxx,xxx,xxx and xxx_yy,xxx_yy,xxx_yy: The variation contains more than a single language\n" +
"Where xxx is the ISO-639-2/T language code and yy is the ISO-3166-1 alpha-2 country code.\n" +
"https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes\n" +
"https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2\n" +
"If the product has ever been only released in one language variation, being it English (like CP/M) or multilanguage " +
"(like Mac OS X and Linux), this field should be omitted.\n\n" +
"<Architecture>\n" +
"--------------\n" +
"The processor architecture the product is compiled for.\n" +
"Omitted if it has only ever been compiled for a single one, contains all supported ones in same files, " +
"or it is source code containing support for several of them.\n" +
"Exact one depends on the product (that is, the one that the product uses to identify itself, should be used). Examples:\n" +
"* x86, i86, i386, i486, i586, i686, ia32: Intel Architecture 32 aka 8086 aka iAPX86\n" +
"* x64, amd64, x86_64: AMD64 aka x86_64 aka EM64T\n" +
"* ia64: Intel Architecture 64 aka Itanium\n" +
"* sparc: SPARC\n" +
"* sun4u, sun4m, sun1, sun2, sun3: Specific Sun architectures that specify not only the processor architecture but the whole system one.\n" +
"* 68k, ppc, fat: For products that run under Mac OS indicate they require a Macintosh, a Power Macintosh, or can run on both, respectively.\n" +
"* rpi, rpi2, beaglebone, bananapi: Specific whole systems that share a processor architecture but require a completely different variant.\n\n" +
"oem\n" +
"---\n" +
"Present if the variant is OEM. Omitted otherwise.\n\n" +
"for <Machine>\n" +
"-------------\n" +
"Present if the variant requires a specific computer to run.\n" +
"Useful for computer restoration variants.\n" +
"e.g. for Power Mac 5200\n" +
"e.g. for Tandy 1000\n\n" +
"<[format]/update/upgrade/files/source/netinstall/description>.zip\n" +
"-----------------------------------------------------------------\n" +
"This is the file containing the product itself.\n" +
"It should be compressed using ZIP with certain parameters (see below).\n" +
"Several of them can be combined separated with underscores.\n" +
"Naming as following:\n" +
"* [format]: If the variation is encoded in a disk image format that's neither a simple dump of sectors (.iso/.dsk/.xdf) " +
"or a BinCue/BinToc (.bin+.cue/.bin+.toc) format should be substituted to a descriptive name for the format. e.g.: [Nero], [CloneCD]\n" +
"* update: Should be used when the product requires and updates a previous point release or build to the new one. " +
"Product version should be the updated, not the required, one. e.g.: 1.3 updates to 1.3.1 or 2.0 updates to 2.5\n" +
"* upgrade: Should be used when the product requires and updates a previous version to the new one. Product version should be the updated, " +
"not the required, one. e.g.: 2.0 updates to 3.0 or MS-DOS updates to Windows 95.\n" +
"* files: Should be used when the contents of the product disks are dumped as is (copied from the media) or it contains already installed " +
"files.\n" +
"* source: Should be used when it contains the source code for the product.\n" +
"* netinstall: Similar to files except that the files are designed to be put in a network share for remote installation of the product.\n" +
"* description: Free form description or product part number if it is known.\n\n" +
"Compression\n" +
"-----------\n" +
"The product should be compressed using ZIP with Deflate algorithm and UTF-8 headers. Zip64 extensions may be used. " +
"UNIX extensions MUST be used for products that require them (e.g. it contains softlinks).\n" +
"In the doubt, use Info-ZIP with following parameters:\n" +
"zip -9ry -dd archive.zip .\n" +
"If the product requires Acorn, BeOS or OS/2 extended attributes it should be compressed using the corresponding Info-ZIP version under " +
"that operating system so the required extension is used.\n" +
"DO NOT recompress archives in an operating system which zip product doesn't support all already present headers.\n" +
"DO NOT use TorrentZip. It discards all headers as well as date stamps.\n" +
"DO NOT use Mac OS headers. For conserving FinderInfo and Resource Fork see below.\n\n" +
"FinderInfo and Resource Fork\n" +
"----------------------------\n" +
"FinderInfo and Resource Fork should be stored as Mac OS X AppleDouble format: file and ._file\n" +
"This format is understand by all Mac OS X versions under any filesystem or a CIFS/SMB network share.\n" +
"Also mkisofs recognizes it and is able to create an HFS partition with them correctly set.\n" +
"Other formats should be converted to this one.\n\n" +
"Metadata\n" +
"--------\n" +
"Each archive should be accompanied with a JSON metadata file using the CICM Metadata format. " +
"Name for metadata sidecar should be same as the archive changing the extension to .json.\n" +
"If the archive can be modified (doesn't contain ZIP headers you would lose) the metadata should be put inside the archive as a file " +
"named metadata.json.\n\n" +
"Recovery\n" +
"--------\n" +
"Disks fail, bit rot happens, so every archive as well as the metadata file should have a PAR2 recovery set created.\n" +
"Example command line (with 5% redundancy):\n" +
"par2 c -r5 archive.par2 archive.zip archive.json\n\n" +
"Result\n" +
"------\n" +
"In the end you get something like this:\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.json\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.vol000+01.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.vol001+02.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.vol003+04.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.vol007+08.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.vol015+16.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.vol031+32.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.vol063+37.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.zip\n" +
"QNX/QNX/20090229/source.json\n" +
"QNX/QNX/20090229/source.par2\n" +
"QNX/QNX/20090229/source.vol000+01.par2\n" +
"QNX/QNX/20090229/source.vol001+02.par2\n" +
"QNX/QNX/20090229/source.vol003+04.par2\n" +
"QNX/QNX/20090229/source.vol007+08.par2\n" +
"QNX/QNX/20090229/source.vol015+16.par2\n" +
"QNX/QNX/20090229/source.vol031+32.par2\n" +
"QNX/QNX/20090229/source.vol063+37.par2\n" +
"All fields should contain only 7-bit ASCII.\n\n" +
"<Developer>\n" + "-----------\n" +
"This is the main developer of the operating system or associated software. e.g. Microsoft\n\n" +
"<Product>\n" +
"---------\n" +
"This is the name of the operating system or associated software. e.g. Windows NT\n\n" +
"<Version>\n" +
"---------\n" +
"This is the version of the operating system or associated software. e.g. 6.00.6000.16386\n" +
"Service pack and release markers should be appended. e.g. 6.10.7601.16385 (RTM)\n" +
"Build can be specified by appending \"build\". e.g. 10.2.7 build 6S80\n" +
"And combined. e.g. 10.5 build 9A581 (Server)\n" +
"Version with same version number but different build date should have it appended. Date format should be YYYYmm[dd]. e.g. 10 201009\n\n" +
"<Language>\n" +
"----------\n" + "This specifies the language localization and translation:\n" +
"xxx: Language variation, e.g. German = deu\n" +
"xxx_yy: Country specific language variation. e.g. Swiss German = deu_ch\n" +
"multi: The only known variation of the product that contains more than a language\n" +
"xxx,xxx,xxx and xxx_yy,xxx_yy,xxx_yy: The variation contains more than a single language\n" +
"Where xxx is the ISO-639-2/T language code and yy is the ISO-3166-1 alpha-2 country code.\n" +
"https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes\n" +
"https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2\n" +
"If the product has ever been only released in one language variation, being it English (like CP/M) or multilanguage " +
"(like Mac OS X and Linux), this field should be omitted.\n\n" +
"<Architecture>\n" +
"--------------\n" +
"The processor architecture the product is compiled for.\n" +
"Omitted if it has only ever been compiled for a single one, contains all supported ones in same files, " +
"or it is source code containing support for several of them.\n" +
"Exact one depends on the product (that is, the one that the product uses to identify itself, should be used). Examples:\n" +
"* x86, i86, i386, i486, i586, i686, ia32: Intel Architecture 32 aka 8086 aka iAPX86\n" +
"* x64, amd64, x86_64: AMD64 aka x86_64 aka EM64T\n" +
"* ia64: Intel Architecture 64 aka Itanium\n" +
"* sparc: SPARC\n" +
"* sun4u, sun4m, sun1, sun2, sun3: Specific Sun architectures that specify not only the processor architecture but the whole system one.\n" +
"* 68k, ppc, fat: For products that run under Mac OS indicate they require a Macintosh, a Power Macintosh, or can run on both, respectively.\n" +
"* rpi, rpi2, beaglebone, bananapi: Specific whole systems that share a processor architecture but require a completely different variant.\n\n" +
"oem\n" +
"---\n" +
"Present if the variant is OEM. Omitted otherwise.\n\n" + "for <Machine>\n" +
"-------------\n" +
"Present if the variant requires a specific computer to run.\n" +
"Useful for computer restoration variants.\n" +
"e.g. for Power Mac 5200\n" +
"e.g. for Tandy 1000\n\n" +
"<[format]/update/upgrade/files/source/netinstall/description>.zip\n" +
"-----------------------------------------------------------------\n" +
"This is the file containing the product itself.\n" +
"It should be compressed using ZIP with certain parameters (see below).\n" +
"Several of them can be combined separated with underscores.\n" +
"Naming as following:\n" +
"* [format]: If the variation is encoded in a disk image format that's neither a simple dump of sectors (.iso/.dsk/.xdf) " +
"or a BinCue/BinToc (.bin+.cue/.bin+.toc) format should be substituted to a descriptive name for the format. e.g.: [Nero], [CloneCD]\n" +
"* update: Should be used when the product requires and updates a previous point release or build to the new one. " +
"Product version should be the updated, not the required, one. e.g.: 1.3 updates to 1.3.1 or 2.0 updates to 2.5\n" +
"* upgrade: Should be used when the product requires and updates a previous version to the new one. Product version should be the updated, " +
"not the required, one. e.g.: 2.0 updates to 3.0 or MS-DOS updates to Windows 95.\n" +
"* files: Should be used when the contents of the product disks are dumped as is (copied from the media) or it contains already installed " +
"files.\n" +
"* source: Should be used when it contains the source code for the product.\n" +
"* netinstall: Similar to files except that the files are designed to be put in a network share for remote installation of the product.\n" +
"* description: Free form description or product part number if it is known.\n\n" +
"Compression\n" +
"-----------\n" +
"The product should be compressed using ZIP with Deflate algorithm and UTF-8 headers. Zip64 extensions may be used. " +
"UNIX extensions MUST be used for products that require them (e.g. it contains softlinks).\n" +
"In the doubt, use Info-ZIP with following parameters:\n" +
"zip -9ry -dd archive.zip .\n" +
"If the product requires Acorn, BeOS or OS/2 extended attributes it should be compressed using the corresponding Info-ZIP version under " +
"that operating system so the required extension is used.\n" +
"DO NOT recompress archives in an operating system which zip product doesn't support all already present headers.\n" +
"DO NOT use TorrentZip. It discards all headers as well as date stamps.\n" +
"DO NOT use Mac OS headers. For conserving FinderInfo and Resource Fork see below.\n\n" +
"FinderInfo and Resource Fork\n" +
"----------------------------\n" +
"FinderInfo and Resource Fork should be stored as Mac OS X AppleDouble format: file and ._file\n" +
"This format is understand by all Mac OS X versions under any filesystem or a CIFS/SMB network share.\n" +
"Also mkisofs recognizes it and is able to create an HFS partition with them correctly set.\n" +
"Other formats should be converted to this one.\n\n" +
"Metadata\n" + "--------\n" +
"Each archive should be accompanied with a JSON metadata file using the CICM Metadata format. " +
"Name for metadata sidecar should be same as the archive changing the extension to .json.\n" +
"If the archive can be modified (doesn't contain ZIP headers you would lose) the metadata should be put inside the archive as a file " +
"named metadata.json.\n\n" +
"Recovery\n" + "--------\n" +
"Disks fail, bit rot happens, so every archive as well as the metadata file should have a PAR2 recovery set created.\n" +
"Example command line (with 5% redundancy):\n" +
"par2 c -r5 archive.par2 archive.zip archive.json\n\n" +
"Result\n" + "------\n" +
"In the end you get something like this:\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.json\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.vol000+01.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.vol001+02.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.vol003+04.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.vol007+08.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.vol015+16.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.vol031+32.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.vol063+37.par2\n" +
"Apple/Mac OS/9.1/eng/for iMac (Early 2001) v1.1/archive.zip\n" +
"QNX/QNX/20090229/source.json\n" +
"QNX/QNX/20090229/source.par2\n" +
"QNX/QNX/20090229/source.vol000+01.par2\n" +
"QNX/QNX/20090229/source.vol001+02.par2\n" +
"QNX/QNX/20090229/source.vol003+04.par2\n" +
"QNX/QNX/20090229/source.vol007+08.par2\n" +
"QNX/QNX/20090229/source.vol015+16.par2\n" +
"QNX/QNX/20090229/source.vol031+32.par2\n" +
"QNX/QNX/20090229/source.vol063+37.par2\n" +
"QNX/QNX/20090229/source.zip";
}
@@ -169,4 +165,4 @@ namespace osrepodbmgr.Eto
Close();
}
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -25,6 +25,7 @@
// 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.Threading;
@@ -36,66 +37,40 @@ namespace osrepodbmgr.Eto
{
public class dlgSettings : Dialog
{
#region XAML UI elements
#pragma warning disable 0649
TextBox txtTmp;
TextBox txtUnar;
TextBox txtDatabase;
TextBox txtRepository;
Label lblUnarVersion;
EnumDropDown<AlgoEnum> cmbCompAlg;
StackLayout StackLayoutForAlgoEnum;
GroupBox frmClamd;
CheckBox chkAntivirus;
CheckBox chkClamd;
TextBox txtClamdHost;
NumericUpDown spClamdPort;
Button btnClamdTest;
Label lblClamdVersion;
CheckBox chkClamdIsLocal;
GroupBox frmVirusTotal;
CheckBox chkVirusTotal;
TextBox txtVirusTotal;
Button btnVirusTotal;
Label lblVirusTotal;
#pragma warning restore 0649
#endregion XAML UI elements
string oldUnarPath;
public dlgSettings()
{
XamlReader.Load(this);
txtTmp.Text = Settings.Current.TemporaryFolder;
txtUnar.Text = Settings.Current.UnArchiverPath;
txtDatabase.Text = Settings.Current.DatabasePath;
txtTmp.Text = Settings.Current.TemporaryFolder;
txtUnar.Text = Settings.Current.UnArchiverPath;
txtDatabase.Text = Settings.Current.DatabasePath;
txtRepository.Text = Settings.Current.RepositoryPath;
if(!string.IsNullOrWhiteSpace(txtUnar.Text))
CheckUnar();
if(!string.IsNullOrWhiteSpace(txtUnar.Text)) CheckUnar();
cmbCompAlg = new EnumDropDown<AlgoEnum>();
StackLayoutForAlgoEnum.Items.Add(new StackLayoutItem(cmbCompAlg, HorizontalAlignment.Stretch, true));
cmbCompAlg.SelectedValue = Settings.Current.CompressionAlgorithm;
spClamdPort.Value = 3310;
chkAntivirus.Checked = Core.Settings.Current.UseAntivirus;
frmClamd.Visible = chkAntivirus.Checked.Value;
if(Core.Settings.Current.UseAntivirus && Core.Settings.Current.UseClamd)
spClamdPort.Value = 3310;
chkAntivirus.Checked = Settings.Current.UseAntivirus;
frmClamd.Visible = chkAntivirus.Checked.Value;
if(Settings.Current.UseAntivirus && Settings.Current.UseClamd)
{
chkClamd.Checked = Core.Settings.Current.UseClamd;
txtClamdHost.Text = Core.Settings.Current.ClamdHost;
spClamdPort.Value = Core.Settings.Current.ClamdPort;
chkClamdIsLocal.Checked = Core.Settings.Current.ClamdIsLocal;
}
if(Core.Settings.Current.UseAntivirus && Core.Settings.Current.UseVirusTotal)
{
chkVirusTotal.Checked = true;
chkVirusTotal.Enabled = true;
txtVirusTotal.Enabled = true;
txtVirusTotal.Text = Core.Settings.Current.VirusTotalKey;
btnVirusTotal.Enabled = true;
chkClamd.Checked = Settings.Current.UseClamd;
txtClamdHost.Text = Settings.Current.ClamdHost;
spClamdPort.Value = Settings.Current.ClamdPort;
chkClamdIsLocal.Checked = Settings.Current.ClamdIsLocal;
}
if(!Settings.Current.UseAntivirus || !Settings.Current.UseVirusTotal) return;
chkVirusTotal.Checked = true;
chkVirusTotal.Enabled = true;
txtVirusTotal.Enabled = true;
txtVirusTotal.Text = Settings.Current.VirusTotalKey;
btnVirusTotal.Enabled = true;
}
protected void OnBtnCancelClicked(object sender, EventArgs e)
@@ -106,139 +81,127 @@ namespace osrepodbmgr.Eto
protected void OnBtnApplyClicked(object sender, EventArgs e)
{
// TODO: Check sanity
Settings.Current.TemporaryFolder = txtTmp.Text;
Settings.Current.UnArchiverPath = txtUnar.Text;
Settings.Current.DatabasePath = txtDatabase.Text;
Settings.Current.RepositoryPath = txtRepository.Text;
Settings.Current.TemporaryFolder = txtTmp.Text;
Settings.Current.UnArchiverPath = txtUnar.Text;
Settings.Current.DatabasePath = txtDatabase.Text;
Settings.Current.RepositoryPath = txtRepository.Text;
Settings.Current.CompressionAlgorithm = cmbCompAlg.SelectedValue;
if(!chkClamd.Checked.Value || !chkAntivirus.Checked.Value)
{
Core.Settings.Current.UseClamd = false;
Core.Settings.Current.ClamdHost = null;
Core.Settings.Current.ClamdPort = 3310;
Core.Settings.Current.ClamdIsLocal = false;
Settings.Current.UseClamd = false;
Settings.Current.ClamdHost = null;
Settings.Current.ClamdPort = 3310;
Settings.Current.ClamdIsLocal = false;
}
if(chkVirusTotal.Checked.Value && chkAntivirus.Checked.Value)
{
Core.Settings.Current.UseVirusTotal = true;
Core.Settings.Current.VirusTotalKey = txtVirusTotal.Text;
Core.Workers.InitVirusTotal(Core.Settings.Current.VirusTotalKey);
Settings.Current.UseVirusTotal = true;
Settings.Current.VirusTotalKey = txtVirusTotal.Text;
Workers.InitVirusTotal(Settings.Current.VirusTotalKey);
}
else
{
Core.Settings.Current.UseVirusTotal = false;
Core.Settings.Current.VirusTotalKey = null;
Settings.Current.UseVirusTotal = false;
Settings.Current.VirusTotalKey = null;
}
Settings.SaveSettings();
Workers.CloseDB();
Workers.InitDB();
Context.clamdVersion = null;
Core.Workers.InitClamd();
Context.ClamdVersion = null;
Workers.InitClamd();
Context.CheckUnar();
Close();
}
protected void OnBtnUnarClicked(object sender, EventArgs e)
{
OpenFileDialog dlgFile = new OpenFileDialog();
dlgFile.Title = "Choose UnArchiver executable";
dlgFile.MultiSelect = false;
OpenFileDialog dlgFile = new OpenFileDialog {Title = "Choose UnArchiver executable", MultiSelect = false};
if(!string.IsNullOrWhiteSpace(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)))
dlgFile.Directory = new Uri(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
if(dlgFile.ShowDialog(this) == DialogResult.Ok)
{
txtUnar.Text = dlgFile.FileName;
lblUnarVersion.Visible = false;
CheckUnar();
}
if(dlgFile.ShowDialog(this) != DialogResult.Ok) return;
txtUnar.Text = dlgFile.FileName;
lblUnarVersion.Visible = false;
CheckUnar();
}
protected void OnBtnTmpClicked(object sender, EventArgs e)
{
SelectFolderDialog dlgFolder = new SelectFolderDialog();
dlgFolder.Title = "Choose temporary folder";
dlgFolder.Directory = Path.GetTempPath();
SelectFolderDialog dlgFolder =
new SelectFolderDialog {Title = "Choose temporary folder", Directory = Path.GetTempPath()};
if(dlgFolder.ShowDialog(this) == DialogResult.Ok)
txtTmp.Text = dlgFolder.Directory;
if(dlgFolder.ShowDialog(this) == DialogResult.Ok) txtTmp.Text = dlgFolder.Directory;
}
protected void OnBtnRepositoryClicked(object sender, EventArgs e)
{
SelectFolderDialog dlgFolder = new SelectFolderDialog();
dlgFolder.Title = "Choose repository folder";
dlgFolder.Directory = Path.GetTempPath();
SelectFolderDialog dlgFolder =
new SelectFolderDialog {Title = "Choose repository folder", Directory = Path.GetTempPath()};
if(dlgFolder.ShowDialog(this) == DialogResult.Ok)
txtRepository.Text = dlgFolder.Directory;
if(dlgFolder.ShowDialog(this) == DialogResult.Ok) txtRepository.Text = dlgFolder.Directory;
}
protected void OnBtnDatabaseClicked(object sender, EventArgs e)
{
SaveFileDialog dlgFile = new SaveFileDialog();
dlgFile.Title = "Choose database to open/create";
dlgFile.Directory = new Uri(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
dlgFile.CheckFileExists = false;
dlgFile.FileName = "osrepodbmgr.db";
if(dlgFile.ShowDialog(this) == DialogResult.Ok)
SaveFileDialog dlgFile = new SaveFileDialog
{
if(File.Exists(dlgFile.FileName))
Title = "Choose database to open/create",
Directory = new Uri(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)),
CheckFileExists = false,
FileName = "osrepodbmgr.db"
};
if(dlgFile.ShowDialog(this) != DialogResult.Ok) return;
if(File.Exists(dlgFile.FileName))
{
DbCore dbCore = new SQLite();
bool notDb = false;
try { notDb |= !dbCore.OpenDb(dlgFile.FileName, null, null, null); }
catch { notDb = true; }
if(notDb)
{
DBCore _dbCore = new SQLite();
bool notDb = false;
try
{
notDb |= !_dbCore.OpenDB(dlgFile.FileName, null, null, null);
}
catch
{
notDb = true;
}
if(notDb)
{
MessageBox.Show("Cannot open specified file as a database, please choose another.", MessageBoxType.Error);
return;
}
_dbCore.CloseDB();
}
else
{
DBCore _dbCore = new SQLite();
bool notDb = false;
try
{
notDb |= !_dbCore.CreateDB(dlgFile.FileName, null, null, null);
}
catch
{
notDb = true;
}
if(notDb)
{
MessageBox.Show("Cannot create a database in the specified file as a database.", MessageBoxType.Error);
return;
}
_dbCore.CloseDB();
MessageBox.Show("Cannot open specified file as a database, please choose another.",
MessageBoxType.Error);
return;
}
txtDatabase.Text = dlgFile.FileName;
dbCore.CloseDb();
}
else
{
DbCore dbCore = new SQLite();
bool notDb = false;
try { notDb |= !dbCore.CreateDb(dlgFile.FileName, null, null, null); }
catch { notDb = true; }
if(notDb)
{
MessageBox.Show("Cannot create a database in the specified file as a database.",
MessageBoxType.Error);
return;
}
dbCore.CloseDb();
}
txtDatabase.Text = dlgFile.FileName;
}
void CheckUnar()
{
Workers.FinishedWithText += CheckUnarFinished;
Workers.Failed += CheckUnarFailed;
Workers.Failed += CheckUnarFailed;
oldUnarPath = Settings.Current.UnArchiverPath;
oldUnarPath = Settings.Current.UnArchiverPath;
Settings.Current.UnArchiverPath = txtUnar.Text;
Thread thdCheckUnar = new Thread(Workers.CheckUnar);
Thread thdCheckUnar = new Thread(Workers.CheckUnar);
thdCheckUnar.Start();
}
@@ -247,10 +210,10 @@ namespace osrepodbmgr.Eto
Application.Instance.Invoke(delegate
{
Workers.FinishedWithText -= CheckUnarFinished;
Workers.Failed -= CheckUnarFailed;
Workers.Failed -= CheckUnarFailed;
lblUnarVersion.Text = text;
lblUnarVersion.Visible = true;
lblUnarVersion.Text = text;
lblUnarVersion.Visible = true;
Settings.Current.UnArchiverPath = oldUnarPath;
});
}
@@ -260,12 +223,9 @@ namespace osrepodbmgr.Eto
Application.Instance.Invoke(delegate
{
Workers.FinishedWithText -= CheckUnarFinished;
Workers.Failed -= CheckUnarFailed;
Workers.Failed -= CheckUnarFailed;
if(string.IsNullOrWhiteSpace(oldUnarPath))
txtUnar.Text = "";
else
txtUnar.Text = oldUnarPath;
txtUnar.Text = string.IsNullOrWhiteSpace(oldUnarPath) ? "" : oldUnarPath;
Settings.Current.UnArchiverPath = oldUnarPath;
MessageBox.Show(text, MessageBoxType.Error);
});
@@ -273,15 +233,15 @@ namespace osrepodbmgr.Eto
protected void OnChkAntivirusToggled(object sender, EventArgs e)
{
frmClamd.Visible = chkAntivirus.Checked.Value;
frmClamd.Visible = chkAntivirus.Checked.Value;
frmVirusTotal.Visible = chkAntivirus.Checked.Value;
}
protected void OnChkClamdToggled(object sender, EventArgs e)
{
txtClamdHost.Enabled = chkClamd.Checked.Value;
spClamdPort.Enabled = chkClamd.Checked.Value;
btnClamdTest.Enabled = chkClamd.Checked.Value;
txtClamdHost.Enabled = chkClamd.Checked.Value;
spClamdPort.Enabled = chkClamd.Checked.Value;
btnClamdTest.Enabled = chkClamd.Checked.Value;
lblClamdVersion.Visible = false;
chkClamdIsLocal.Enabled = chkClamd.Checked.Value;
}
@@ -296,27 +256,27 @@ namespace osrepodbmgr.Eto
return;
}
string oldVersion = Context.clamdVersion;
Context.clamdVersion = null;
string oldVersion = Context.ClamdVersion;
Context.ClamdVersion = null;
string oldHost = Core.Settings.Current.ClamdHost;
ushort oldPort = Core.Settings.Current.ClamdPort;
Core.Settings.Current.ClamdHost = txtClamdHost.Text;
Core.Settings.Current.ClamdPort = (ushort)spClamdPort.Value;
string oldHost = Settings.Current.ClamdHost;
ushort oldPort = Settings.Current.ClamdPort;
Settings.Current.ClamdHost = txtClamdHost.Text;
Settings.Current.ClamdPort = (ushort)spClamdPort.Value;
Workers.TestClamd();
Core.Settings.Current.ClamdHost = oldHost;
Core.Settings.Current.ClamdPort = oldPort;
Settings.Current.ClamdHost = oldHost;
Settings.Current.ClamdPort = oldPort;
if(string.IsNullOrEmpty(Context.clamdVersion))
if(string.IsNullOrEmpty(Context.ClamdVersion))
{
MessageBox.Show("Cannot connect to clamd", MessageBoxType.Error);
return;
}
lblClamdVersion.Text = Context.clamdVersion;
Context.clamdVersion = oldVersion;
lblClamdVersion.Text = Context.ClamdVersion;
Context.ClamdVersion = oldVersion;
lblClamdVersion.Visible = true;
}
@@ -330,16 +290,40 @@ namespace osrepodbmgr.Eto
protected void OnBtnVirusTotalClicked(object sender, EventArgs e)
{
Workers.Failed += VirusTotalTestFailed;
if(Workers.TestVirusTotal(txtVirusTotal.Text))
{
lblVirusTotal.Visible = true;
lblVirusTotal.Text = "Working!";
}
if(!Workers.TestVirusTotal(txtVirusTotal.Text)) return;
lblVirusTotal.Visible = true;
lblVirusTotal.Text = "Working!";
}
void VirusTotalTestFailed(string text)
static void VirusTotalTestFailed(string text)
{
MessageBox.Show(text, MessageBoxType.Error);
}
#region XAML UI elements
#pragma warning disable 0649
TextBox txtTmp;
TextBox txtUnar;
TextBox txtDatabase;
TextBox txtRepository;
Label lblUnarVersion;
EnumDropDown<AlgoEnum> cmbCompAlg;
StackLayout StackLayoutForAlgoEnum;
GroupBox frmClamd;
CheckBox chkAntivirus;
CheckBox chkClamd;
TextBox txtClamdHost;
NumericUpDown spClamdPort;
Button btnClamdTest;
Label lblClamdVersion;
CheckBox chkClamdIsLocal;
GroupBox frmVirusTotal;
CheckBox chkVirusTotal;
TextBox txtVirusTotal;
Button btnVirusTotal;
Label lblVirusTotal;
#pragma warning restore 0649
#endregion XAML UI elements
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -25,8 +25,10 @@
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
using Gtk;
using osrepodbmgr.Core;
using Settings = osrepodbmgr.Core.Settings;
namespace osrepodbmgr
{
@@ -34,20 +36,20 @@ namespace osrepodbmgr
{
public static void Main(string[] args)
{
Core.Settings.LoadSettings();
Settings.LoadSettings();
Context.CheckUnar();
Context.usableDotNetZip = true;
if(Core.Settings.Current.UseAntivirus)
Context.UsableDotNetZip = true;
if(Settings.Current.UseAntivirus)
{
if(Core.Settings.Current.UseClamd)
Workers.InitClamd();
if(Core.Settings.Current.UseVirusTotal)
Context.virusTotalEnabled = Workers.InitVirusTotal(Core.Settings.Current.VirusTotalKey);
if(Settings.Current.UseClamd) Workers.InitClamd();
if(Settings.Current.UseVirusTotal)
Context.VirusTotalEnabled = Workers.InitVirusTotal(Settings.Current.VirusTotalKey);
}
Application.Init();
frmMain win = new frmMain();
win.Show();
Application.Run();
}
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -25,6 +25,7 @@
// 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 Gtk;
using Schemas;
@@ -42,63 +43,57 @@ namespace osrepodbmgr
public void FillFields()
{
if(Metadata == null)
return;
if(Metadata == null) return;
if(Metadata.Type != null)
txtType.Text = Metadata.Type;
if(Metadata.Type != null) txtType.Text = Metadata.Type;
if(Metadata.CreationDateSpecified)
{
chkCreationDate.Active = true;
chkCreationDate.Active = true;
cldCreationDate.Sensitive = true;
cldCreationDate.Date = Metadata.CreationDate;
cldCreationDate.Date = Metadata.CreationDate;
}
if(Metadata.ModificationDateSpecified)
{
chkModificationDate.Active = true;
chkModificationDate.Active = true;
cldModificationDate.Sensitive = true;
cldModificationDate.Date = Metadata.ModificationDate;
cldModificationDate.Date = Metadata.ModificationDate;
}
if(Metadata.BackupDateSpecified)
{
chkBackupDate.Active = true;
chkBackupDate.Active = true;
cldBackupDate.Sensitive = true;
cldBackupDate.Date = Metadata.BackupDate;
cldBackupDate.Date = Metadata.BackupDate;
}
spClusterSize.Value = Metadata.ClusterSize;
txtClusters.Text = Metadata.Clusters.ToString();
if(Metadata.FilesSpecified)
txtFiles.Text = Metadata.Files.ToString();
chkBootable.Active = Metadata.Bootable;
if(Metadata.VolumeSerial != null)
txtSerial.Text = Metadata.VolumeSerial;
if(Metadata.VolumeName != null)
txtLabel.Text = Metadata.VolumeName;
if(Metadata.FreeClustersSpecified)
txtFreeClusters.Text = Metadata.FreeClusters.ToString();
chkDirty.Active = Metadata.Dirty;
spClusterSize.Value = Metadata.ClusterSize;
txtClusters.Text = Metadata.Clusters.ToString();
if(Metadata.FilesSpecified) txtFiles.Text = Metadata.Files.ToString();
chkBootable.Active = Metadata.Bootable;
if(Metadata.VolumeSerial != null) txtSerial.Text = Metadata.VolumeSerial;
if(Metadata.VolumeName != null) txtLabel.Text = Metadata.VolumeName;
if(Metadata.FreeClustersSpecified) txtFreeClusters.Text = Metadata.FreeClusters.ToString();
chkDirty.Active = Metadata.Dirty;
if(Metadata.ExpirationDateSpecified)
{
chkExpirationDate.Active = true;
chkExpirationDate.Active = true;
cldExpirationDate.Sensitive = true;
cldExpirationDate.Date = Metadata.ExpirationDate;
cldExpirationDate.Date = Metadata.ExpirationDate;
}
if(Metadata.EffectiveDateSpecified)
{
chkEffectiveDate.Active = true;
chkEffectiveDate.Active = true;
cldEffectiveDate.Sensitive = true;
cldEffectiveDate.Date = Metadata.EffectiveDate;
cldEffectiveDate.Date = Metadata.EffectiveDate;
}
if(Metadata.SystemIdentifier != null)
txtSysId.Text = Metadata.SystemIdentifier;
if(Metadata.VolumeSetIdentifier != null)
txtVolId.Text = Metadata.VolumeSetIdentifier;
if(Metadata.PublisherIdentifier != null)
txtPubId.Text = Metadata.PublisherIdentifier;
if(Metadata.DataPreparerIdentifier != null)
txtDataId.Text = Metadata.DataPreparerIdentifier;
if(Metadata.ApplicationIdentifier != null)
txtAppId.Text = Metadata.ApplicationIdentifier;
if(Metadata.SystemIdentifier != null) txtSysId.Text = Metadata.SystemIdentifier;
if(Metadata.VolumeSetIdentifier != null) txtVolId.Text = Metadata.VolumeSetIdentifier;
if(Metadata.PublisherIdentifier != null) txtPubId.Text = Metadata.PublisherIdentifier;
if(Metadata.DataPreparerIdentifier != null) txtDataId.Text = Metadata.DataPreparerIdentifier;
if(Metadata.ApplicationIdentifier != null) txtAppId.Text = Metadata.ApplicationIdentifier;
}
protected void OnChkCreationDateToggled(object sender, EventArgs e)
@@ -126,9 +121,7 @@ namespace osrepodbmgr
cldBackupDate.Sensitive = chkBackupDate.Active;
}
protected void OnButtonOkClicked(object sender, EventArgs e)
{
}
protected void OnButtonOkClicked(object sender, EventArgs e) { }
protected void OnBtnCancelClicked(object sender, EventArgs e)
{
@@ -138,11 +131,11 @@ namespace osrepodbmgr
protected void OnBtnSaveClicked(object sender, EventArgs e)
{
MessageDialog dlgMsg;
long temp;
if(string.IsNullOrWhiteSpace(txtType.Text))
{
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Filesystem type cannot be empty");
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok,
"Filesystem type cannot be empty");
dlgMsg.Run();
dlgMsg.Destroy();
return;
@@ -150,15 +143,17 @@ namespace osrepodbmgr
if(spClusterSize.ValueAsInt < 1)
{
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Clusters must be bigger than 0 bytes");
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok,
"Clusters must be bigger than 0 bytes");
dlgMsg.Run();
dlgMsg.Destroy();
return;
}
if(!long.TryParse(txtClusters.Text, out temp))
if(!long.TryParse(txtClusters.Text, out long temp))
{
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Clusters must be a number");
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok,
"Clusters must be a number");
dlgMsg.Run();
dlgMsg.Destroy();
return;
@@ -166,7 +161,8 @@ namespace osrepodbmgr
if(temp < 1)
{
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Filesystem must have more than 0 clusters");
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok,
"Filesystem must have more than 0 clusters");
dlgMsg.Run();
dlgMsg.Destroy();
return;
@@ -174,7 +170,8 @@ namespace osrepodbmgr
if(!string.IsNullOrWhiteSpace(txtFiles.Text) && !long.TryParse(txtFiles.Text, out temp))
{
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Files must be a number, or empty for unknown");
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok,
"Files must be a number, or empty for unknown");
dlgMsg.Run();
dlgMsg.Destroy();
return;
@@ -182,7 +179,8 @@ namespace osrepodbmgr
if(!string.IsNullOrWhiteSpace(txtFiles.Text) && temp < 0)
{
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Files must be positive");
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok,
"Files must be positive");
dlgMsg.Run();
dlgMsg.Destroy();
return;
@@ -190,7 +188,8 @@ namespace osrepodbmgr
if(!string.IsNullOrWhiteSpace(txtFreeClusters.Text) && !long.TryParse(txtFreeClusters.Text, out temp))
{
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Free clusters must be a number or empty for unknown");
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok,
"Free clusters must be a number or empty for unknown");
dlgMsg.Run();
dlgMsg.Destroy();
return;
@@ -198,69 +197,69 @@ namespace osrepodbmgr
if(!string.IsNullOrWhiteSpace(txtFreeClusters.Text) && temp < 0)
{
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Free clusters must be positive");
dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok,
"Free clusters must be positive");
dlgMsg.Run();
dlgMsg.Destroy();
return;
}
Metadata = new FileSystemType();
Metadata.Type = txtType.Text;
Metadata = new FileSystemType {Type = txtType.Text};
if(chkCreationDate.Active)
{
Metadata.CreationDateSpecified = true;
Metadata.CreationDate = cldCreationDate.Date;
Metadata.CreationDate = cldCreationDate.Date;
}
if(chkModificationDate.Active)
{
Metadata.ModificationDateSpecified = true;
Metadata.ModificationDate = cldModificationDate.Date;
Metadata.ModificationDate = cldModificationDate.Date;
}
if(chkBackupDate.Active)
{
Metadata.BackupDateSpecified = true;
Metadata.BackupDate = cldBackupDate.Date;
Metadata.BackupDate = cldBackupDate.Date;
}
Metadata.ClusterSize = (int)spClusterSize.Value;
Metadata.Clusters = long.Parse(txtClusters.Text);
Metadata.Clusters = long.Parse(txtClusters.Text);
if(!string.IsNullOrWhiteSpace(txtFiles.Text))
{
Metadata.FilesSpecified = true;
Metadata.Files = long.Parse(txtFiles.Text);
Metadata.Files = long.Parse(txtFiles.Text);
}
Metadata.Bootable = chkBootable.Active;
if(!string.IsNullOrWhiteSpace(txtSerial.Text))
Metadata.VolumeSerial = txtSerial.Text;
if(!string.IsNullOrWhiteSpace(txtLabel.Text))
Metadata.VolumeName = txtLabel.Text;
Metadata.Bootable = chkBootable.Active;
if(!string.IsNullOrWhiteSpace(txtSerial.Text)) Metadata.VolumeSerial = txtSerial.Text;
if(!string.IsNullOrWhiteSpace(txtLabel.Text)) Metadata.VolumeName = txtLabel.Text;
if(!string.IsNullOrWhiteSpace(txtFreeClusters.Text))
{
Metadata.FreeClustersSpecified = true;
Metadata.FreeClusters = long.Parse(txtFreeClusters.Text);
Metadata.FreeClusters = long.Parse(txtFreeClusters.Text);
}
Metadata.Dirty = chkDirty.Active;
if(chkExpirationDate.Active)
{
Metadata.ExpirationDateSpecified = true;
Metadata.ExpirationDate = cldExpirationDate.Date;
Metadata.ExpirationDate = cldExpirationDate.Date;
}
if(chkEffectiveDate.Active)
{
Metadata.EffectiveDateSpecified = true;
Metadata.EffectiveDate = cldEffectiveDate.Date;
Metadata.EffectiveDate = cldEffectiveDate.Date;
}
if(!string.IsNullOrWhiteSpace(txtSysId.Text))
Metadata.SystemIdentifier = txtSysId.Text;
if(!string.IsNullOrWhiteSpace(txtVolId.Text))
Metadata.VolumeSetIdentifier = txtVolId.Text;
if(!string.IsNullOrWhiteSpace(txtPubId.Text))
Metadata.PublisherIdentifier = txtPubId.Text;
if(!string.IsNullOrWhiteSpace(txtDataId.Text))
Metadata.DataPreparerIdentifier = txtDataId.Text;
if(!string.IsNullOrWhiteSpace(txtAppId.Text))
Metadata.ApplicationIdentifier = txtAppId.Text;
if(!string.IsNullOrWhiteSpace(txtSysId.Text)) Metadata.SystemIdentifier = txtSysId.Text;
if(!string.IsNullOrWhiteSpace(txtVolId.Text)) Metadata.VolumeSetIdentifier = txtVolId.Text;
if(!string.IsNullOrWhiteSpace(txtPubId.Text)) Metadata.PublisherIdentifier = txtPubId.Text;
if(!string.IsNullOrWhiteSpace(txtDataId.Text)) Metadata.DataPreparerIdentifier = txtDataId.Text;
if(!string.IsNullOrWhiteSpace(txtAppId.Text)) Metadata.ApplicationIdentifier = txtAppId.Text;
buttonOk.Click();
}
}
}
}

View File

@@ -25,11 +25,13 @@
// 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 Gtk;
namespace osrepodbmgr
{
public partial class dlgHelp : Gtk.Dialog
public partial class dlgHelp : Dialog
{
public dlgHelp()
{
@@ -41,4 +43,4 @@ namespace osrepodbmgr
btnDialog.Click();
}
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -25,6 +25,7 @@
// 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.Threading;
@@ -40,13 +41,12 @@ namespace osrepodbmgr
public dlgSettings()
{
Build();
txtTmp.Text = Core.Settings.Current.TemporaryFolder;
txtUnar.Text = Core.Settings.Current.UnArchiverPath;
txtDatabase.Text = Core.Settings.Current.DatabasePath;
txtTmp.Text = Core.Settings.Current.TemporaryFolder;
txtUnar.Text = Core.Settings.Current.UnArchiverPath;
txtDatabase.Text = Core.Settings.Current.DatabasePath;
txtRepository.Text = Core.Settings.Current.RepositoryPath;
if(!string.IsNullOrWhiteSpace(txtUnar.Text))
CheckUnar();
if(!string.IsNullOrWhiteSpace(txtUnar.Text)) CheckUnar();
CellRendererText textCell = new CellRendererText();
cmbCompAlg.Clear();
@@ -56,45 +56,43 @@ namespace osrepodbmgr
cmbCompAlg.Model = lstCompAlgs;
lstCompAlgs.Clear();
foreach(AlgoEnum type in Enum.GetValues(typeof(AlgoEnum)))
lstCompAlgs.AppendValues(type.ToString());
foreach(AlgoEnum type in Enum.GetValues(typeof(AlgoEnum))) lstCompAlgs.AppendValues(type.ToString());
cmbCompAlg.Active = 0;
TreeIter iter;
cmbCompAlg.Model.GetIterFirst(out iter);
cmbCompAlg.Model.GetIterFirst(out TreeIter iter);
do
{
if((string)cmbCompAlg.Model.GetValue(iter, 0) == Core.Settings.Current.CompressionAlgorithm.ToString())
{
cmbCompAlg.SetActiveIter(iter);
break;
}
if((string)cmbCompAlg.Model.GetValue(iter, 0) !=
Core.Settings.Current.CompressionAlgorithm.ToString()) continue;
cmbCompAlg.SetActiveIter(iter);
break;
}
while(cmbCompAlg.Model.IterNext(ref iter));
spClamdPort.Value = 3310;
spClamdPort.Value = 3310;
chkAntivirus.Active = Core.Settings.Current.UseAntivirus;
frmClamd.Visible = chkAntivirus.Active;
frmClamd.Visible = chkAntivirus.Active;
if(Core.Settings.Current.UseAntivirus && Core.Settings.Current.UseClamd)
{
chkClamd.Active = Core.Settings.Current.UseClamd;
txtClamdHost.Text = Core.Settings.Current.ClamdHost;
spClamdPort.Value = Core.Settings.Current.ClamdPort;
chkClamdIsLocal.Active = Core.Settings.Current.ClamdIsLocal;
chkClamd.Sensitive = true;
chkClamd.Active = Core.Settings.Current.UseClamd;
txtClamdHost.Text = Core.Settings.Current.ClamdHost;
spClamdPort.Value = Core.Settings.Current.ClamdPort;
chkClamdIsLocal.Active = Core.Settings.Current.ClamdIsLocal;
chkClamd.Sensitive = true;
chkClamdIsLocal.Sensitive = true;
txtClamdHost.Sensitive = true;
spClamdPort.Sensitive = true;
btnClamdTest.Sensitive = true;
}
if(Core.Settings.Current.UseAntivirus && Core.Settings.Current.UseVirusTotal)
{
chkVirusTotal.Active = true;
chkVirusTotal.Sensitive = true;
txtVirusTotal.Sensitive = true;
txtVirusTotal.Text = Core.Settings.Current.VirusTotalKey;
btnVirusTotal.Sensitive = true;
txtClamdHost.Sensitive = true;
spClamdPort.Sensitive = true;
btnClamdTest.Sensitive = true;
}
if(!Core.Settings.Current.UseAntivirus || !Core.Settings.Current.UseVirusTotal) return;
chkVirusTotal.Active = true;
chkVirusTotal.Sensitive = true;
txtVirusTotal.Sensitive = true;
txtVirusTotal.Text = Core.Settings.Current.VirusTotalKey;
btnVirusTotal.Sensitive = true;
}
protected void OnBtnCancelClicked(object sender, EventArgs e)
@@ -105,65 +103,65 @@ namespace osrepodbmgr
protected void OnBtnApplyClicked(object sender, EventArgs e)
{
if(chkAntivirus.Active && chkClamd.Active)
{
if(string.IsNullOrEmpty(txtClamdHost.Text))
{
MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "clamd host cannot be empty");
MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok,
"clamd host cannot be empty");
dlgMsg.Run();
dlgMsg.Destroy();
return;
}
}
// TODO: Check sanity
Core.Settings.Current.TemporaryFolder = txtTmp.Text;
Core.Settings.Current.UnArchiverPath = txtUnar.Text;
Core.Settings.Current.DatabasePath = txtDatabase.Text;
Core.Settings.Current.RepositoryPath = txtRepository.Text;
Core.Settings.Current.UseAntivirus = chkAntivirus.Active;
Core.Settings.Current.UseClamd = chkClamd.Active;
Core.Settings.Current.ClamdHost = txtClamdHost.Text;
Core.Settings.Current.ClamdPort = (ushort)spClamdPort.Value;
Core.Settings.Current.ClamdIsLocal = chkClamdIsLocal.Active;
Core.Settings.Current.TemporaryFolder = txtTmp.Text;
Core.Settings.Current.UnArchiverPath = txtUnar.Text;
Core.Settings.Current.DatabasePath = txtDatabase.Text;
Core.Settings.Current.RepositoryPath = txtRepository.Text;
Core.Settings.Current.UseAntivirus = chkAntivirus.Active;
Core.Settings.Current.UseClamd = chkClamd.Active;
Core.Settings.Current.ClamdHost = txtClamdHost.Text;
Core.Settings.Current.ClamdPort = (ushort)spClamdPort.Value;
Core.Settings.Current.ClamdIsLocal = chkClamdIsLocal.Active;
Core.Settings.Current.CompressionAlgorithm = (AlgoEnum)Enum.Parse(typeof(AlgoEnum), cmbCompAlg.ActiveText);
if(!chkClamd.Active || !chkAntivirus.Active)
{
Core.Settings.Current.UseClamd = false;
Core.Settings.Current.ClamdHost = null;
Core.Settings.Current.ClamdPort = 3310;
Core.Settings.Current.UseClamd = false;
Core.Settings.Current.ClamdHost = null;
Core.Settings.Current.ClamdPort = 3310;
Core.Settings.Current.ClamdIsLocal = false;
}
if(chkVirusTotal.Active && chkAntivirus.Active)
{
Core.Settings.Current.UseVirusTotal = true;
Core.Settings.Current.VirusTotalKey = txtVirusTotal.Text;
Core.Workers.InitVirusTotal(Core.Settings.Current.VirusTotalKey);
Workers.InitVirusTotal(Core.Settings.Current.VirusTotalKey);
}
else
{
Core.Settings.Current.UseVirusTotal = false;
Core.Settings.Current.VirusTotalKey = null;
}
Core.Settings.SaveSettings();
Core.Workers.CloseDB();
Core.Workers.InitDB();
Context.clamdVersion = null;
Core.Workers.InitClamd();
Workers.CloseDB();
Workers.InitDB();
Context.ClamdVersion = null;
Workers.InitClamd();
Context.CheckUnar();
btnDialog.Click();
}
protected void OnBtnUnarClicked(object sender, EventArgs e)
{
FileChooserDialog dlgFile = new FileChooserDialog("Choose UnArchiver executable", this, FileChooserAction.Open,
"Cancel", ResponseType.Cancel, "Choose", ResponseType.Accept);
dlgFile.SelectMultiple = false;
FileChooserDialog dlgFile =
new FileChooserDialog("Choose UnArchiver executable", this, FileChooserAction.Open, "Cancel",
ResponseType.Cancel, "Choose", ResponseType.Accept) {SelectMultiple = false};
dlgFile.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
if(dlgFile.Run() == (int)ResponseType.Accept)
{
txtUnar.Text = dlgFile.Filename;
txtUnar.Text = dlgFile.Filename;
lblUnarVersion.Visible = false;
CheckUnar();
}
@@ -173,39 +171,33 @@ namespace osrepodbmgr
protected void OnBtnTmpClicked(object sender, EventArgs e)
{
FileChooserDialog dlgFolder = new FileChooserDialog("Choose temporary folder", this, FileChooserAction.SelectFolder,
"Cancel", ResponseType.Cancel, "Choose", ResponseType.Accept);
dlgFolder.SelectMultiple = false;
FileChooserDialog dlgFolder =
new FileChooserDialog("Choose temporary folder", this, FileChooserAction.SelectFolder, "Cancel",
ResponseType.Cancel, "Choose", ResponseType.Accept) {SelectMultiple = false};
dlgFolder.SetCurrentFolder(System.IO.Path.GetTempPath());
if(dlgFolder.Run() == (int)ResponseType.Accept)
{
txtTmp.Text = dlgFolder.Filename;
}
if(dlgFolder.Run() == (int)ResponseType.Accept) txtTmp.Text = dlgFolder.Filename;
dlgFolder.Destroy();
}
protected void OnBtnRepositoryClicked(object sender, EventArgs e)
{
FileChooserDialog dlgFolder = new FileChooserDialog("Choose repository folder", this, FileChooserAction.SelectFolder,
"Cancel", ResponseType.Cancel, "Choose", ResponseType.Accept);
dlgFolder.SelectMultiple = false;
FileChooserDialog dlgFolder =
new FileChooserDialog("Choose repository folder", this, FileChooserAction.SelectFolder, "Cancel",
ResponseType.Cancel, "Choose", ResponseType.Accept) {SelectMultiple = false};
dlgFolder.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
if(dlgFolder.Run() == (int)ResponseType.Accept)
{
txtRepository.Text = dlgFolder.Filename;
}
if(dlgFolder.Run() == (int)ResponseType.Accept) txtRepository.Text = dlgFolder.Filename;
dlgFolder.Destroy();
}
protected void OnBtnDatabaseClicked(object sender, EventArgs e)
{
FileChooserDialog dlgFile = new FileChooserDialog("Choose database to open/create", this, FileChooserAction.Save,
"Cancel", ResponseType.Cancel, "Choose", ResponseType.Accept);
dlgFile.SelectMultiple = false;
FileChooserDialog dlgFile =
new FileChooserDialog("Choose database to open/create", this, FileChooserAction.Save, "Cancel",
ResponseType.Cancel, "Choose", ResponseType.Accept) {SelectMultiple = false};
dlgFile.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
dlgFile.SetFilename("Core.db");
@@ -213,50 +205,45 @@ namespace osrepodbmgr
{
if(File.Exists(dlgFile.Filename))
{
DBCore _dbCore = new SQLite();
bool notDb = false;
DbCore dbCore = new SQLite();
bool notDb = false;
try
{
notDb |= !_dbCore.OpenDB(dlgFile.Filename, null, null, null);
}
catch
{
notDb = true;
}
try { notDb |= !dbCore.OpenDb(dlgFile.Filename, null, null, null); }
catch { notDb = true; }
if(notDb)
{
MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Cannot open specified file as a database, please choose another.");
MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error,
ButtonsType.Ok,
"Cannot open specified file as a database, please choose another.");
dlgMsg.Run();
dlgMsg.Destroy();
dlgFile.Destroy();
return;
}
_dbCore.CloseDB();
dbCore.CloseDb();
}
else {
DBCore _dbCore = new SQLite();
bool notDb = false;
else
{
DbCore dbCore = new SQLite();
bool notDb = false;
try
{
notDb |= !_dbCore.CreateDB(dlgFile.Filename, null, null, null);
}
catch
{
notDb = true;
}
try { notDb |= !dbCore.CreateDb(dlgFile.Filename, null, null, null); }
catch { notDb = true; }
if(notDb)
{
MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Cannot create a database in the specified file as a database.");
MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error,
ButtonsType.Ok,
"Cannot create a database in the specified file as a database.");
dlgMsg.Run();
dlgMsg.Destroy();
dlgFile.Destroy();
return;
}
_dbCore.CloseDB();
dbCore.CloseDb();
}
txtDatabase.Text = dlgFile.Filename;
@@ -267,12 +254,12 @@ namespace osrepodbmgr
void CheckUnar()
{
Core.Workers.FinishedWithText += CheckUnarFinished;
Core.Workers.Failed += CheckUnarFailed;
Workers.FinishedWithText += CheckUnarFinished;
Workers.Failed += CheckUnarFailed;
oldUnarPath = Core.Settings.Current.UnArchiverPath;
oldUnarPath = Core.Settings.Current.UnArchiverPath;
Core.Settings.Current.UnArchiverPath = txtUnar.Text;
Thread thdCheckUnar = new Thread(Core.Workers.CheckUnar);
Thread thdCheckUnar = new Thread(Workers.CheckUnar);
thdCheckUnar.Start();
}
@@ -280,11 +267,11 @@ namespace osrepodbmgr
{
Application.Invoke(delegate
{
Core.Workers.FinishedWithText -= CheckUnarFinished;
Core.Workers.Failed -= CheckUnarFailed;
Workers.FinishedWithText -= CheckUnarFinished;
Workers.Failed -= CheckUnarFailed;
lblUnarVersion.Text = text;
lblUnarVersion.Visible = true;
lblUnarVersion.Text = text;
lblUnarVersion.Visible = true;
Core.Settings.Current.UnArchiverPath = oldUnarPath;
});
}
@@ -293,15 +280,13 @@ namespace osrepodbmgr
{
Application.Invoke(delegate
{
Core.Workers.FinishedWithText -= CheckUnarFinished;
Core.Workers.Failed -= CheckUnarFailed;
Workers.FinishedWithText -= CheckUnarFinished;
Workers.Failed -= CheckUnarFailed;
if(string.IsNullOrWhiteSpace(oldUnarPath))
txtUnar.Text = "";
else
txtUnar.Text = oldUnarPath;
txtUnar.Text = string.IsNullOrWhiteSpace(oldUnarPath) ? "" : oldUnarPath;
Core.Settings.Current.UnArchiverPath = oldUnarPath;
MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, text);
MessageDialog dlgMsg =
new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, text);
dlgMsg.Run();
dlgMsg.Destroy();
});
@@ -309,16 +294,16 @@ namespace osrepodbmgr
protected void OnChkAntivirusToggled(object sender, EventArgs e)
{
frmClamd.Visible = chkAntivirus.Active;
frmClamd.Visible = chkAntivirus.Active;
frmVirusTotal.Visible = chkAntivirus.Active;
}
protected void OnChkClamdToggled(object sender, EventArgs e)
{
txtClamdHost.Sensitive = chkClamd.Active;
spClamdPort.Sensitive = chkClamd.Active;
btnClamdTest.Sensitive = chkClamd.Active;
lblClamdVersion.Visible = false;
txtClamdHost.Sensitive = chkClamd.Active;
spClamdPort.Sensitive = chkClamd.Active;
btnClamdTest.Sensitive = chkClamd.Active;
lblClamdVersion.Visible = false;
chkClamdIsLocal.Sensitive = chkClamd.Active;
}
@@ -328,17 +313,18 @@ namespace osrepodbmgr
if(string.IsNullOrEmpty(txtClamdHost.Text))
{
MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "clamd host cannot be empty");
MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok,
"clamd host cannot be empty");
dlgMsg.Run();
dlgMsg.Destroy();
return;
}
string oldVersion = Context.clamdVersion;
Context.clamdVersion = null;
string oldVersion = Context.ClamdVersion;
Context.ClamdVersion = null;
string oldHost = Core.Settings.Current.ClamdHost;
ushort oldPort = Core.Settings.Current.ClamdPort;
string oldHost = Core.Settings.Current.ClamdHost;
ushort oldPort = Core.Settings.Current.ClamdPort;
Core.Settings.Current.ClamdHost = txtClamdHost.Text;
Core.Settings.Current.ClamdPort = (ushort)spClamdPort.Value;
@@ -347,16 +333,17 @@ namespace osrepodbmgr
Core.Settings.Current.ClamdHost = oldHost;
Core.Settings.Current.ClamdPort = oldPort;
if(string.IsNullOrEmpty(Context.clamdVersion))
if(string.IsNullOrEmpty(Context.ClamdVersion))
{
MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Cannot connect to clamd");
MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok,
"Cannot connect to clamd");
dlgMsg.Run();
dlgMsg.Destroy();
return;
}
lblClamdVersion.Text = Context.clamdVersion;
Context.clamdVersion = oldVersion;
lblClamdVersion.Text = Context.ClamdVersion;
Context.ClamdVersion = oldVersion;
lblClamdVersion.Visible = true;
}
@@ -364,17 +351,16 @@ namespace osrepodbmgr
{
txtVirusTotal.Sensitive = chkVirusTotal.Active;
btnVirusTotal.Sensitive = chkVirusTotal.Active;
lblVirusTotal.Visible = false;
lblVirusTotal.Visible = false;
}
protected void OnBtnVirusTotalClicked(object sender, EventArgs e)
{
Workers.Failed += VirusTotalTestFailed;
if(Workers.TestVirusTotal(txtVirusTotal.Text))
{
lblVirusTotal.Visible = true;
lblVirusTotal.Text = "Working!";
}
if(!Workers.TestVirusTotal(txtVirusTotal.Text)) return;
lblVirusTotal.Visible = true;
lblVirusTotal.Text = "Working!";
}
void VirusTotalTestFailed(string text)
@@ -384,4 +370,4 @@ namespace osrepodbmgr
dlgMsg.Destroy();
}
}
}
}

File diff suppressed because it is too large Load Diff