diff --git a/MatterControlLib/DataStorage/ApplicationDataStorage.cs b/MatterControlLib/DataStorage/ApplicationDataStorage.cs index 285b99157..04b0fd4e9 100644 --- a/MatterControlLib/DataStorage/ApplicationDataStorage.cs +++ b/MatterControlLib/DataStorage/ApplicationDataStorage.cs @@ -28,19 +28,25 @@ either expressed or implied, of the FreeBSD Project. */ using System; +using System.Diagnostics.CodeAnalysis; using System.IO; namespace MatterHackers.MatterControl.DataStorage { + [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Private getters used to enforce presence of directories")] public class ApplicationDataStorage { - public bool FirstRun = false; + // Required by Android + public bool FirstRun { get; set; } = false; - //Describes the location for storing all local application data + // Describes the location for storing all local application data private static ApplicationDataStorage globalInstance; - private const string applicationDataFolderName = "MatterControl"; - private const string datastoreName = "MatterControl.db"; + private const string ApplicationDataFolderName = "MatterControl"; + + private const string DatastoreName = "MatterControl.db"; + + private string _applicationPath; public static ApplicationDataStorage Instance { @@ -50,11 +56,11 @@ namespace MatterHackers.MatterControl.DataStorage { globalInstance = new ApplicationDataStorage(); } + return globalInstance; } } - private string _applicationPath; public string ApplicationPath { get @@ -68,12 +74,18 @@ namespace MatterHackers.MatterControl.DataStorage } } - private static string _applicationUserDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), applicationDataFolderName); + private static string _applicationUserDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ApplicationDataFolderName); + private static string _applicationLibraryDataPath => Path.Combine(_applicationUserDataPath, "Library"); + private static string _libraryAssetPath => Path.Combine(_applicationLibraryDataPath, "Assets"); + private static string _platingDirectory => Path.Combine(_applicationLibraryDataPath, "Plating"); + private static string _applicationTempDataPath => Path.Combine(_applicationUserDataPath, "data", "temp"); + private static string _gcodeOutputPath => Path.Combine(_applicationTempDataPath, "gcode"); + private static string _cacheDirectory => Path.Combine(_applicationTempDataPath, "cache"); private static string _webCacheDirectory => Path.Combine(_applicationTempDataPath, "WebCache"); @@ -99,20 +111,20 @@ namespace MatterHackers.MatterControl.DataStorage public string CustomLibraryFoldersPath => Path.Combine(_applicationUserDataPath, "LibraryFolders.conf"); /// - /// Returns the path to the sqlite database + /// Gets the path to the Sqlite database /// - /// - public string DatastorePath => Path.Combine(EnsurePath(_applicationUserDataPath), datastoreName); + /// The path toe Sqlite database + public string DatastorePath => Path.Combine(EnsurePath(_applicationUserDataPath), DatastoreName); /// - /// Returns the public storage folder (ex. download folder on Android) + /// Gets or sets the public storage folder (ex. download folder on Android) /// public string PublicDataStoragePath { get; set; } /// /// Invokes CreateDirectory on all paths, creating if missing, before returning /// - /// + /// Returns the path to the given directory private static string EnsurePath(string fullPath) { Directory.CreateDirectory(fullPath); @@ -123,6 +135,7 @@ namespace MatterHackers.MatterControl.DataStorage /// Overrides the AppData location. Used by tests to set a non-standard AppData location /// /// The new AppData path. + /// The Sqlite generator with platform specific bindings internal void OverrideAppDataLocation(string path, Func sqliteBuilder) { Console.WriteLine(" Overriding ApplicationUserDataPath: " + path); diff --git a/MatterControlLib/DataStorage/Datastore.cs b/MatterControlLib/DataStorage/Datastore.cs index b5c89202a..a23bcc116 100644 --- a/MatterControlLib/DataStorage/Datastore.cs +++ b/MatterControlLib/DataStorage/Datastore.cs @@ -31,21 +31,20 @@ using System; using System.Collections.Generic; using System.IO; using System.Threading; -using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; namespace MatterHackers.MatterControl.DataStorage { public class Datastore { - bool wasExited = false; public bool ConnectionError = false; + private bool wasExited = false; public ISQLite dbSQLite; private string datastoreLocation = ApplicationDataStorage.Instance.DatastorePath; private static Datastore globalInstance; private ApplicationSession activeSession; - private List dataStoreTables = new List + private readonly List dataStoreTables = new List { typeof(PrintItemCollection), typeof(PrinterSetting), @@ -76,6 +75,7 @@ namespace MatterHackers.MatterControl.DataStorage { globalInstance = new Datastore(); } + return globalInstance; } @@ -85,6 +85,7 @@ namespace MatterHackers.MatterControl.DataStorage globalInstance = value; } } + public void Exit() { if (wasExited) @@ -94,10 +95,10 @@ namespace MatterHackers.MatterControl.DataStorage wasExited = true; - if (this.activeSession != null) + if (activeSession != null) { - this.activeSession.SessionEnd = DateTime.Now; - this.activeSession.Commit(); + activeSession.SessionEnd = DateTime.Now; + activeSession.Commit(); } // lets wait a bit to make sure the commit has resolved. @@ -122,7 +123,7 @@ namespace MatterHackers.MatterControl.DataStorage } } - //Run initial checks and operations on sqlite datastore + // Run initial checks and operations on sqlite datastore public void Initialize(ISQLite dbSQLite) { this.dbSQLite = dbSQLite; @@ -148,7 +149,7 @@ namespace MatterHackers.MatterControl.DataStorage return Convert.ToInt32(result); } - //Begins new application session record + // Begins new application session record private void StartSession() { activeSession = new ApplicationSession();