Use correct path for database.

This commit is contained in:
2019-01-01 05:43:32 +00:00
parent 5ea28edfbf
commit a95a1f71e0
9 changed files with 351 additions and 362 deletions

View File

@@ -56,7 +56,6 @@
<e p="Settings.StyleCop" t="Include" /> <e p="Settings.StyleCop" t="Include" />
<e p="StyleCop.Cache" t="Include" /> <e p="StyleCop.Cache" t="Include" />
<e p="bin" t="ExcludeRecursive" /> <e p="bin" t="ExcludeRecursive" />
<e p="discimagechef.db" t="Include" />
<e p="obj" t="ExcludeRecursive"> <e p="obj" t="ExcludeRecursive">
<e p="Debug" t="Include"> <e p="Debug" t="Include">
<e p="net461" t="Include"> <e p="net461" t="Include">
@@ -1147,7 +1146,6 @@
<e p="DiscImageChef.EntityFramework.csproj" t="IncludeRecursive" /> <e p="DiscImageChef.EntityFramework.csproj" t="IncludeRecursive" />
<e p="Program.cs" t="Include" /> <e p="Program.cs" t="Include" />
<e p="bin" t="ExcludeRecursive" /> <e p="bin" t="ExcludeRecursive" />
<e p="discimagechef.db" t="Include" />
<e p="obj" t="ExcludeRecursive"> <e p="obj" t="ExcludeRecursive">
<e p="Debug" t="Include"> <e p="Debug" t="Include">
<e p="netcoreapp2.1" t="Include"> <e p="netcoreapp2.1" t="Include">

View File

@@ -60,13 +60,13 @@ namespace DiscImageChef.Core
/// </summary> /// </summary>
static bool submitStatsLock; static bool submitStatsLock;
static DicContext ctx = new DicContext();
/// <summary> /// <summary>
/// Loads saved statistics from disk /// Loads saved statistics from disk
/// </summary> /// </summary>
public static void LoadStats() public static void LoadStats()
{ {
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
if(File.Exists(Path.Combine(Settings.Settings.StatsPath, "Statistics.xml"))) if(File.Exists(Path.Combine(Settings.Settings.StatsPath, "Statistics.xml")))
try try
{ {
@@ -431,10 +431,12 @@ namespace DiscImageChef.Core
Version = DetectOS.GetVersion(), Version = DetectOS.GetVersion(),
Count = 1 Count = 1
}); });
ctx.Versions.Add(new Version ctx.Versions.Add(new Version
{ {
Value = CommonTypes.Interop.Version.GetVersion(), Synchronized = false, Count = 1 Value = CommonTypes.Interop.Version.GetVersion(), Synchronized = false, Count = 1
}); });
ctx.SaveChanges();
} }
/// <summary> /// <summary>
@@ -442,6 +444,7 @@ namespace DiscImageChef.Core
/// </summary> /// </summary>
public static void SaveStats() public static void SaveStats()
{ {
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
ctx.SaveChanges(); ctx.SaveChanges();
if(Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.ShareStats) SubmitStats(); if(Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.ShareStats) SubmitStats();
} }
@@ -453,7 +456,8 @@ namespace DiscImageChef.Core
{ {
Thread submitThread = new Thread(() => Thread submitThread = new Thread(() =>
{ {
lock(ctx) DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
if(ctx.Commands.Any(c => !c.Synchronized) || ctx.Filesystems.Any(c => !c.Synchronized) || if(ctx.Commands.Any(c => !c.Synchronized) || ctx.Filesystems.Any(c => !c.Synchronized) ||
ctx.Filters.Any(c => !c.Synchronized) || ctx.MediaFormats.Any(c => !c.Synchronized) || ctx.Filters.Any(c => !c.Synchronized) || ctx.MediaFormats.Any(c => !c.Synchronized) ||
ctx.Partitions.Any(c => !c.Synchronized) || ctx.Medias.Any(c => !c.Synchronized) || ctx.Partitions.Any(c => !c.Synchronized) || ctx.Medias.Any(c => !c.Synchronized) ||
@@ -465,8 +469,7 @@ namespace DiscImageChef.Core
if(ctx.Commands.Any(c => !c.Synchronized)) if(ctx.Commands.Any(c => !c.Synchronized))
{ {
dto.Commands = new List<NameValueStats>(); dto.Commands = new List<NameValueStats>();
foreach(string nvs in foreach(string nvs in ctx.Commands.Where(c => !c.Synchronized).Select(c => c.Name).Distinct())
ctx.Commands.Where(c => !c.Synchronized).Select(c => c.Name).Distinct())
dto.Commands.Add(new NameValueStats dto.Commands.Add(new NameValueStats
{ {
name = nvs, name = nvs,
@@ -478,8 +481,8 @@ namespace DiscImageChef.Core
if(ctx.Filesystems.Any(c => !c.Synchronized)) if(ctx.Filesystems.Any(c => !c.Synchronized))
{ {
dto.Filesystems = new List<NameValueStats>(); dto.Filesystems = new List<NameValueStats>();
foreach(string nvs in foreach(string nvs in ctx.Filesystems.Where(c => !c.Synchronized).Select(c => c.Name).Distinct()
ctx.Filesystems.Where(c => !c.Synchronized).Select(c => c.Name).Distinct()) )
dto.Filesystems.Add(new NameValueStats dto.Filesystems.Add(new NameValueStats
{ {
name = nvs, name = nvs,
@@ -491,21 +494,18 @@ namespace DiscImageChef.Core
if(ctx.Filters.Any(c => !c.Synchronized)) if(ctx.Filters.Any(c => !c.Synchronized))
{ {
dto.Filters = new List<NameValueStats>(); dto.Filters = new List<NameValueStats>();
foreach(string nvs in ctx.Filters.Where(c => !c.Synchronized).Select(c => c.Name).Distinct() foreach(string nvs in ctx.Filters.Where(c => !c.Synchronized).Select(c => c.Name).Distinct())
)
dto.Filters.Add(new NameValueStats dto.Filters.Add(new NameValueStats
{ {
name = nvs, name = nvs,
Value = ctx.Filters.LongCount(c => !c.Synchronized && Value = ctx.Filters.LongCount(c => !c.Synchronized && c.Name == nvs)
c.Name == nvs)
}); });
} }
if(ctx.MediaFormats.Any(c => !c.Synchronized)) if(ctx.MediaFormats.Any(c => !c.Synchronized))
{ {
dto.MediaFormats = new List<NameValueStats>(); dto.MediaFormats = new List<NameValueStats>();
foreach(string nvs in foreach(string nvs in ctx.Commands.Where(c => !c.Synchronized).Select(c => c.Name).Distinct())
ctx.Commands.Where(c => !c.Synchronized).Select(c => c.Name).Distinct())
dto.MediaFormats.Add(new NameValueStats dto.MediaFormats.Add(new NameValueStats
{ {
name = nvs, name = nvs,
@@ -517,8 +517,7 @@ namespace DiscImageChef.Core
if(ctx.Partitions.Any(c => !c.Synchronized)) if(ctx.Partitions.Any(c => !c.Synchronized))
{ {
dto.Partitions = new List<NameValueStats>(); dto.Partitions = new List<NameValueStats>();
foreach(string nvs in foreach(string nvs in ctx.Partitions.Where(c => !c.Synchronized).Select(c => c.Name).Distinct())
ctx.Partitions.Where(c => !c.Synchronized).Select(c => c.Name).Distinct())
dto.Partitions.Add(new NameValueStats dto.Partitions.Add(new NameValueStats
{ {
name = nvs, name = nvs,
@@ -530,8 +529,7 @@ namespace DiscImageChef.Core
if(ctx.Versions.Any(c => !c.Synchronized)) if(ctx.Versions.Any(c => !c.Synchronized))
{ {
dto.Versions = new List<NameValueStats>(); dto.Versions = new List<NameValueStats>();
foreach(string nvs in foreach(string nvs in ctx.Versions.Where(c => !c.Synchronized).Select(c => c.Value).Distinct())
ctx.Versions.Where(c => !c.Synchronized).Select(c => c.Value).Distinct())
dto.Versions.Add(new NameValueStats dto.Versions.Add(new NameValueStats
{ {
name = nvs, name = nvs,
@@ -543,8 +541,7 @@ namespace DiscImageChef.Core
if(ctx.Medias.Any(c => !c.Synchronized)) if(ctx.Medias.Any(c => !c.Synchronized))
{ {
dto.Medias = new List<MediaStats>(); dto.Medias = new List<MediaStats>();
foreach(string media in ctx.Medias.Where(c => !c.Synchronized).Select(c => c.Type) foreach(string media in ctx.Medias.Where(c => !c.Synchronized).Select(c => c.Type).Distinct())
.Distinct())
{ {
if(ctx.Medias.Any(c => !c.Synchronized && c.Type == media && c.Real)) if(ctx.Medias.Any(c => !c.Synchronized && c.Type == media && c.Real))
dto.Medias.Add(new MediaStats dto.Medias.Add(new MediaStats
@@ -582,8 +579,8 @@ namespace DiscImageChef.Core
if(ctx.OperatingSystems.Any(c => !c.Synchronized)) if(ctx.OperatingSystems.Any(c => !c.Synchronized))
{ {
dto.OperatingSystems = new List<OsStats>(); dto.OperatingSystems = new List<OsStats>();
foreach(string osName in ctx.OperatingSystems.Where(c => !c.Synchronized) foreach(string osName in ctx.OperatingSystems.Where(c => !c.Synchronized).Select(c => c.Name)
.Select(c => c.Name).Distinct()) .Distinct())
{ {
foreach(string osVersion in foreach(string osVersion in
ctx.OperatingSystems.Where(c => !c.Synchronized && c.Name == osName) ctx.OperatingSystems.Where(c => !c.Synchronized && c.Name == osName)
@@ -618,12 +615,10 @@ namespace DiscImageChef.Core
jsonSw.Write(JsonConvert.SerializeObject(dto, Formatting.Indented, jsonSw.Write(JsonConvert.SerializeObject(dto, Formatting.Indented,
new JsonSerializerSettings new JsonSerializerSettings
{ {
NullValueHandling = NullValueHandling = NullValueHandling.Ignore
NullValueHandling.Ignore
})); }));
jsonStream.Seek(0, SeekOrigin.Begin); jsonStream.Seek(0, SeekOrigin.Begin);
WebRequest request = WebRequest request = WebRequest.Create("http://discimagechef.claunia.com/api/uploadstatsv2");
WebRequest.Create("http://discimagechef.claunia.com/api/uploadstatsv2");
((HttpWebRequest)request).UserAgent = ((HttpWebRequest)request).UserAgent =
$"DiscImageChef {typeof(Version).Assembly.GetName().Version}"; $"DiscImageChef {typeof(Version).Assembly.GetName().Version}";
request.Method = "POST"; request.Method = "POST";
@@ -646,23 +641,19 @@ namespace DiscImageChef.Core
jsonStream.Close(); jsonStream.Close();
if(ctx.Commands.Any(c => !c.Synchronized)) if(ctx.Commands.Any(c => !c.Synchronized))
foreach(string nvs in ctx foreach(string nvs in ctx.Commands.Where(c => !c.Synchronized).Select(c => c.Name)
.Commands.Where(c => !c.Synchronized).Select(c => c.Name)
.Distinct()) .Distinct())
{ {
Command existing = Command existing = ctx.Commands.FirstOrDefault(c => c.Synchronized && c.Name == nvs) ??
ctx.Commands.FirstOrDefault(c => c.Synchronized && c.Name == nvs) ??
new Command {Name = nvs, Synchronized = true}; new Command {Name = nvs, Synchronized = true};
existing.Count += existing.Count += (ulong)ctx.Commands.LongCount(c => !c.Synchronized && c.Name == nvs);
(ulong)ctx.Commands.LongCount(c => !c.Synchronized && c.Name == nvs);
ctx.Commands.Update(existing); ctx.Commands.Update(existing);
ctx.Commands.RemoveRange(ctx.Commands.Where(c => !c.Synchronized && c.Name == nvs)); ctx.Commands.RemoveRange(ctx.Commands.Where(c => !c.Synchronized && c.Name == nvs));
} }
if(ctx.Filesystems.Any(c => !c.Synchronized)) if(ctx.Filesystems.Any(c => !c.Synchronized))
foreach(string nvs in ctx foreach(string nvs in ctx.Filesystems.Where(c => !c.Synchronized).Select(c => c.Name)
.Filesystems.Where(c => !c.Synchronized).Select(c => c.Name)
.Distinct()) .Distinct())
{ {
Filesystem existing = Filesystem existing =
@@ -677,23 +668,19 @@ namespace DiscImageChef.Core
} }
if(ctx.Filters.Any(c => !c.Synchronized)) if(ctx.Filters.Any(c => !c.Synchronized))
foreach(string nvs in ctx foreach(string nvs in ctx.Filters.Where(c => !c.Synchronized).Select(c => c.Name).Distinct()
.Filters.Where(c => !c.Synchronized).Select(c => c.Name) )
.Distinct())
{ {
Filter existing = Filter existing = ctx.Filters.FirstOrDefault(c => c.Synchronized && c.Name == nvs) ??
ctx.Filters.FirstOrDefault(c => c.Synchronized && c.Name == nvs) ??
new Filter {Name = nvs, Synchronized = true}; new Filter {Name = nvs, Synchronized = true};
existing.Count += existing.Count += (ulong)ctx.Filters.LongCount(c => !c.Synchronized && c.Name == nvs);
(ulong)ctx.Filters.LongCount(c => !c.Synchronized && c.Name == nvs);
ctx.Filters.Update(existing); ctx.Filters.Update(existing);
ctx.Filters.RemoveRange(ctx.Filters.Where(c => !c.Synchronized && c.Name == nvs)); ctx.Filters.RemoveRange(ctx.Filters.Where(c => !c.Synchronized && c.Name == nvs));
} }
if(ctx.MediaFormats.Any(c => !c.Synchronized)) if(ctx.MediaFormats.Any(c => !c.Synchronized))
foreach(string nvs in ctx foreach(string nvs in ctx.MediaFormats.Where(c => !c.Synchronized).Select(c => c.Name)
.MediaFormats.Where(c => !c.Synchronized).Select(c => c.Name)
.Distinct()) .Distinct())
{ {
MediaFormat existing = MediaFormat existing =
@@ -708,8 +695,7 @@ namespace DiscImageChef.Core
} }
if(ctx.Partitions.Any(c => !c.Synchronized)) if(ctx.Partitions.Any(c => !c.Synchronized))
foreach(string nvs in ctx foreach(string nvs in ctx.Partitions.Where(c => !c.Synchronized).Select(c => c.Name)
.Partitions.Where(c => !c.Synchronized).Select(c => c.Name)
.Distinct()) .Distinct())
{ {
Partition existing = Partition existing =
@@ -719,24 +705,19 @@ namespace DiscImageChef.Core
existing.Count += existing.Count +=
(ulong)ctx.Partitions.LongCount(c => !c.Synchronized && c.Name == nvs); (ulong)ctx.Partitions.LongCount(c => !c.Synchronized && c.Name == nvs);
ctx.Partitions.Update(existing); ctx.Partitions.Update(existing);
ctx.Partitions.RemoveRange(ctx.Partitions.Where(c => !c.Synchronized && ctx.Partitions.RemoveRange(ctx.Partitions.Where(c => !c.Synchronized && c.Name == nvs));
c.Name == nvs));
} }
if(ctx.Versions.Any(c => !c.Synchronized)) if(ctx.Versions.Any(c => !c.Synchronized))
foreach(string nvs in ctx foreach(string nvs in ctx.Versions.Where(c => !c.Synchronized).Select(c => c.Value)
.Versions.Where(c => !c.Synchronized).Select(c => c.Value)
.Distinct()) .Distinct())
{ {
Version existing = Version existing = ctx.Versions.FirstOrDefault(c => c.Synchronized && c.Value == nvs) ??
ctx.Versions.FirstOrDefault(c => c.Synchronized && c.Value == nvs) ??
new Version {Value = nvs, Synchronized = true}; new Version {Value = nvs, Synchronized = true};
existing.Count += existing.Count += (ulong)ctx.Versions.LongCount(c => !c.Synchronized && c.Value == nvs);
(ulong)ctx.Versions.LongCount(c => !c.Synchronized && c.Value == nvs);
ctx.Versions.Update(existing); ctx.Versions.Update(existing);
ctx.Versions.RemoveRange(ctx.Versions.Where(c => !c.Synchronized && ctx.Versions.RemoveRange(ctx.Versions.Where(c => !c.Synchronized && c.Value == nvs));
c.Value == nvs));
} }
if(ctx.Medias.Any(c => !c.Synchronized)) if(ctx.Medias.Any(c => !c.Synchronized))
@@ -746,36 +727,28 @@ namespace DiscImageChef.Core
if(ctx.Medias.Any(c => !c.Synchronized && c.Type == media && c.Real)) if(ctx.Medias.Any(c => !c.Synchronized && c.Type == media && c.Real))
{ {
Database.Models.Media existing = Database.Models.Media existing =
ctx.Medias.FirstOrDefault(c => c.Synchronized && c.Type == media && ctx.Medias.FirstOrDefault(c => c.Synchronized && c.Type == media && c.Real) ??
c.Real) ?? new Database.Models.Media new Database.Models.Media {Synchronized = true, Type = media, Real = true};
{
Synchronized = true, Type = media, Real = true
};
existing.Count += existing.Count +=
(ulong)ctx.Medias.LongCount(c => !c.Synchronized && c.Type == media && (ulong)ctx.Medias.LongCount(c => !c.Synchronized && c.Type == media && c.Real);
c.Real);
ctx.Medias.Update(existing); ctx.Medias.Update(existing);
ctx.Medias.RemoveRange(ctx.Medias.Where(c => !c.Synchronized && ctx.Medias.RemoveRange(ctx.Medias.Where(c => !c.Synchronized && c.Type == media &&
c.Type == media && c.Real)); c.Real));
} }
if(!ctx.Medias.Any(c => !c.Synchronized && c.Type == media && !c.Real)) continue; if(!ctx.Medias.Any(c => !c.Synchronized && c.Type == media && !c.Real)) continue;
{ {
Database.Models.Media existing = Database.Models.Media existing =
ctx.Medias.FirstOrDefault(c => c.Synchronized && c.Type == media && ctx.Medias.FirstOrDefault(c => c.Synchronized && c.Type == media && !c.Real) ??
!c.Real) ?? new Database.Models.Media new Database.Models.Media {Synchronized = true, Type = media, Real = false};
{
Synchronized = true, Type = media, Real = false
};
existing.Count += existing.Count +=
(ulong)ctx.Medias.LongCount(c => !c.Synchronized && c.Type == media && (ulong)ctx.Medias.LongCount(c => !c.Synchronized && c.Type == media && !c.Real);
!c.Real);
ctx.Medias.Update(existing); ctx.Medias.Update(existing);
ctx.Medias.RemoveRange(ctx.Medias.Where(c => !c.Synchronized && ctx.Medias.RemoveRange(ctx.Medias.Where(c => !c.Synchronized && c.Type == media &&
c.Type == media && !c.Real)); !c.Real));
} }
} }
@@ -796,24 +769,18 @@ namespace DiscImageChef.Core
.Select(c => c.Version).Distinct()) .Select(c => c.Version).Distinct())
{ {
OperatingSystem existing = OperatingSystem existing =
ctx.OperatingSystems.FirstOrDefault(c => c.Synchronized && ctx.OperatingSystems.FirstOrDefault(c => c.Synchronized && c.Name == osName &&
c.Name == osName && c.Version ==
c.Version == osVersion) ?? osVersion) ??
new OperatingSystem new OperatingSystem {Synchronized = true, Version = osVersion, Name = osName};
{
Synchronized = true, Version = osVersion, Name = osName
};
existing.Count += existing.Count +=
(ulong)ctx.OperatingSystems.LongCount(c => !c.Synchronized && (ulong)ctx.OperatingSystems.LongCount(c => !c.Synchronized &&
c.Name == osName && c.Name == osName &&
c.Version == osVersion); c.Version == osVersion);
ctx.OperatingSystems.Update(existing); ctx.OperatingSystems.Update(existing);
ctx.OperatingSystems.RemoveRange(ctx.OperatingSystems.Where(c => ctx.OperatingSystems.RemoveRange(ctx.OperatingSystems.Where(c => !c.Synchronized &&
!c c.Name == osName &&
.Synchronized &&
c.Name ==
osName &&
c.Version == c.Version ==
osVersion)); osVersion));
} }
@@ -911,7 +878,9 @@ namespace DiscImageChef.Core
if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.DeviceStats) return; if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.DeviceStats) return;
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
ctx.Commands.Add(new Command {Name = command, Synchronized = false, Count = 1}); ctx.Commands.Add(new Command {Name = command, Synchronized = false, Count = 1});
ctx.SaveChanges();
} }
/// <summary> /// <summary>
@@ -924,7 +893,9 @@ namespace DiscImageChef.Core
if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.FilesystemStats) return; if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.FilesystemStats) return;
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
ctx.Filesystems.Add(new Filesystem {Name = filesystem, Synchronized = false, Count = 1}); ctx.Filesystems.Add(new Filesystem {Name = filesystem, Synchronized = false, Count = 1});
ctx.SaveChanges();
} }
/// <summary> /// <summary>
@@ -937,7 +908,9 @@ namespace DiscImageChef.Core
if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.PartitionStats) return; if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.PartitionStats) return;
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
ctx.Partitions.Add(new Partition {Name = partition, Synchronized = false, Count = 1}); ctx.Partitions.Add(new Partition {Name = partition, Synchronized = false, Count = 1});
ctx.SaveChanges();
} }
/// <summary> /// <summary>
@@ -950,7 +923,9 @@ namespace DiscImageChef.Core
if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.FilterStats) return; if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.FilterStats) return;
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
ctx.Filters.Add(new Filter {Name = filter, Synchronized = false, Count = 1}); ctx.Filters.Add(new Filter {Name = filter, Synchronized = false, Count = 1});
ctx.SaveChanges();
} }
/// <summary> /// <summary>
@@ -963,7 +938,9 @@ namespace DiscImageChef.Core
if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.MediaImageStats) return; if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.MediaImageStats) return;
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
ctx.MediaFormats.Add(new MediaFormat {Name = format, Synchronized = false, Count = 1}); ctx.MediaFormats.Add(new MediaFormat {Name = format, Synchronized = false, Count = 1});
ctx.SaveChanges();
} }
/// <summary> /// <summary>
@@ -979,6 +956,7 @@ namespace DiscImageChef.Core
else if(dev.IsFireWire) deviceBus = "FireWire"; else if(dev.IsFireWire) deviceBus = "FireWire";
else deviceBus = dev.Type.ToString(); else deviceBus = dev.Type.ToString();
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
ctx.SeenDevices.Add(new DeviceStat ctx.SeenDevices.Add(new DeviceStat
{ {
Bus = deviceBus, Bus = deviceBus,
@@ -987,6 +965,7 @@ namespace DiscImageChef.Core
Revision = dev.Revision, Revision = dev.Revision,
Synchronized = false Synchronized = false
}); });
ctx.SaveChanges();
} }
/// <summary> /// <summary>
@@ -998,10 +977,12 @@ namespace DiscImageChef.Core
{ {
if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.MediaStats) return; if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.MediaStats) return;
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
ctx.Medias.Add(new Database.Models.Media ctx.Medias.Add(new Database.Models.Media
{ {
Real = real, Synchronized = false, Type = type.ToString(), Count = 1 Real = real, Synchronized = false, Type = type.ToString(), Count = 1
}); });
ctx.SaveChanges();
} }
} }
} }

View File

@@ -37,8 +37,7 @@ namespace DiscImageChef.Database
{ {
public sealed class DicContext : DbContext public sealed class DicContext : DbContext
{ {
// Note: If table does not appear check that last migration has been REALLY added to the project public DicContext(DbContextOptions options) : base(options)
public DicContext()
{ {
Database.Migrate(); Database.Migrate();
} }
@@ -57,10 +56,13 @@ namespace DiscImageChef.Database
public DbSet<UsbVendor> UsbVendors { get; set; } public DbSet<UsbVendor> UsbVendors { get; set; }
public DbSet<UsbProduct> UsbProducts { get; set; } public DbSet<UsbProduct> UsbProducts { get; set; }
public DbSet<CdOffset> CdOffsets { get; set; } public DbSet<CdOffset> CdOffsets { get; set; }
// Note: If table does not appear check that last migration has been REALLY added to the project
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) public static DicContext Create(string dbPath)
{ {
optionsBuilder.UseSqlite("Data Source=discimagechef.db"); DbContextOptionsBuilder optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseSqlite($"Data Source={dbPath}");
return new DicContext(optionsBuilder.Options);
} }
} }
} }

View File

@@ -41,13 +41,11 @@ namespace DiscImageChef.Gui.Dialogs
{ {
public class dlgStatistics : Dialog public class dlgStatistics : Dialog
{ {
DicContext ctx;
public dlgStatistics() public dlgStatistics()
{ {
XamlReader.Load(this); XamlReader.Load(this);
ctx = new DicContext(); DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
if(ctx.Commands.Any()) if(ctx.Commands.Any())
{ {

View File

@@ -597,7 +597,7 @@ namespace DiscImageChef.Gui.Forms
protected void OnMenuStatistics(object sender, EventArgs e) protected void OnMenuStatistics(object sender, EventArgs e)
{ {
DicContext ctx = new DicContext(); DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
if(!ctx.Commands.Any() && !ctx.Filesystems.Any() && !ctx.Filters.Any() && !ctx.MediaFormats.Any() && if(!ctx.Commands.Any() && !ctx.Filesystems.Any() && !ctx.Filters.Any() && !ctx.MediaFormats.Any() &&
!ctx.Medias.Any() && !ctx.Partitions.Any() && !ctx.SeenDevices.Any()) !ctx.Medias.Any() && !ctx.Partitions.Any() && !ctx.SeenDevices.Any())

View File

@@ -155,6 +155,8 @@ namespace DiscImageChef.Settings
/// </summary> /// </summary>
public static string StatsPath { get; private set; } public static string StatsPath { get; private set; }
public static string DbPath { get; private set; }
/// <summary> /// <summary>
/// Loads settings /// Loads settings
/// </summary> /// </summary>
@@ -163,6 +165,7 @@ namespace DiscImageChef.Settings
Current = new DicSettings(); Current = new DicSettings();
PlatformID ptId = DetectOS.GetRealPlatformID(); PlatformID ptId = DetectOS.GetRealPlatformID();
string homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); string homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
DbPath = "discimagechef.db";
try try
{ {
@@ -180,6 +183,8 @@ namespace DiscImageChef.Settings
string dicPath = Path.Combine(appSupportPath, "DiscImageChef"); string dicPath = Path.Combine(appSupportPath, "DiscImageChef");
if(!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath); if(!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath);
DbPath = Path.Combine(dicPath, DbPath);
ReportsPath = Path.Combine(dicPath, "Reports"); ReportsPath = Path.Combine(dicPath, "Reports");
if(!Directory.Exists(ReportsPath)) Directory.CreateDirectory(ReportsPath); if(!Directory.Exists(ReportsPath)) Directory.CreateDirectory(ReportsPath);
@@ -202,6 +207,8 @@ namespace DiscImageChef.Settings
string dicPath = Path.Combine(appSupportPath, "DiscImageChef"); string dicPath = Path.Combine(appSupportPath, "DiscImageChef");
if(!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath); if(!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath);
DbPath = Path.Combine(dicPath, DbPath);
ReportsPath = Path.Combine(dicPath, "Reports"); ReportsPath = Path.Combine(dicPath, "Reports");
if(!Directory.Exists(ReportsPath)) Directory.CreateDirectory(ReportsPath); if(!Directory.Exists(ReportsPath)) Directory.CreateDirectory(ReportsPath);
@@ -227,6 +234,8 @@ namespace DiscImageChef.Settings
if(!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath); if(!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath);
DbPath = Path.Combine(dicPath, DbPath);
ReportsPath = Path.Combine(dicPath, "Reports"); ReportsPath = Path.Combine(dicPath, "Reports");
if(!Directory.Exists(ReportsPath)) Directory.CreateDirectory(ReportsPath); if(!Directory.Exists(ReportsPath)) Directory.CreateDirectory(ReportsPath);

View File

@@ -924,7 +924,7 @@ namespace DiscImageChef.Commands
Core.Statistics.AddCommand("device-report"); Core.Statistics.AddCommand("device-report");
using(DicContext ctx = new DicContext()) using(DicContext ctx = DicContext.Create(Settings.Settings.DbPath))
{ {
ctx.Reports.Add(new Report(report)); ctx.Reports.Add(new Report(report));
ctx.SaveChanges(); ctx.SaveChanges();

View File

@@ -41,7 +41,7 @@ namespace DiscImageChef.Commands
{ {
internal static void ShowStats() internal static void ShowStats()
{ {
DicContext ctx = new DicContext(); DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
if(!ctx.Commands.Any() && !ctx.Filesystems.Any() && !ctx.Filters.Any() && !ctx.MediaFormats.Any() && if(!ctx.Commands.Any() && !ctx.Filesystems.Any() && !ctx.Filters.Any() && !ctx.MediaFormats.Any() &&
!ctx.Medias.Any() && !ctx.Partitions.Any() && !ctx.SeenDevices.Any()) !ctx.Medias.Any() && !ctx.Partitions.Any() && !ctx.SeenDevices.Any())

View File

@@ -55,11 +55,12 @@ namespace DiscImageChef
DicConsole.WriteEvent += System.Console.Write; DicConsole.WriteEvent += System.Console.Write;
DicConsole.ErrorWriteLineEvent += System.Console.Error.WriteLine; DicConsole.ErrorWriteLineEvent += System.Console.Error.WriteLine;
DicContext ctx = new DicContext(); Settings.Settings.LoadSettings();
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
ctx.Database.Migrate(); ctx.Database.Migrate();
ctx.SaveChanges(); ctx.SaveChanges();
Settings.Settings.LoadSettings();
if((args.Length < 1 || args[0].ToLowerInvariant() != "gui") && if((args.Length < 1 || args[0].ToLowerInvariant() != "gui") &&
Settings.Settings.Current.GdprCompliance < DicSettings.GdprLevel) Configure.DoConfigure(true); Settings.Settings.Current.GdprCompliance < DicSettings.GdprLevel) Configure.DoConfigure(true);
Statistics.LoadStats(); Statistics.LoadStats();