mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Storage - Keep up to 5 backups of the database
Layouts - Prevent LEDs from going outside the layout bounds
This commit is contained in:
1 parent
033e94bc58
commit
bab566a2b9
6 files changed
+97
-24
No files matched your search
@@ -28,12 +28,7 @@ namespace Artemis.Core
|
||||
/// The full path to the Artemis data folder
|
||||
/// </summary>
|
||||
public static readonly string DataFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Artemis\\";
|
||||
|
||||
/// <summary>
|
||||
/// The connection string used to connect to the database
|
||||
/// </summary>
|
||||
public static readonly string ConnectionString = $"FileName={DataFolder}\\database.db";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The plugin info used by core components of Artemis
|
||||
/// </summary>
|
||||
|
||||
@@ -102,6 +102,26 @@ namespace Artemis.Core
|
||||
foreach (LedId led in ledsToRemove)
|
||||
device.RemoveLed(led);
|
||||
}
|
||||
|
||||
List<Led> deviceLeds = device.ToList();
|
||||
foreach (Led led in deviceLeds)
|
||||
{
|
||||
float x = led.Location.X;
|
||||
float y = led.Location.Y;
|
||||
|
||||
// Try to move the LED if it falls outside the boundaries of the layout
|
||||
if (led.Location.X + led.Size.Width > device.Size.Width)
|
||||
x -= led.Location.X + led.Size.Width - device.Size.Width;
|
||||
|
||||
if (led.Location.Y + led.Size.Height > device.Size.Height)
|
||||
y -= led.Location.Y + led.Size.Height - device.Size.Height;
|
||||
|
||||
// If not possible because it's too large we'll have to drop it to avoid rendering issues
|
||||
if (x < 0 || y < 0)
|
||||
device.RemoveLed(led.Id);
|
||||
else
|
||||
led.Location = new Point(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
internal void ApplyDevice(ArtemisDevice artemisDevice)
|
||||
|
||||
@@ -50,24 +50,7 @@ namespace Artemis.Core.Ninject
|
||||
.Configure(c => c.When(HasAccessToProtectedService).InSingletonScope());
|
||||
});
|
||||
|
||||
Kernel.Bind<LiteRepository>().ToMethod(t =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return new LiteRepository(Constants.ConnectionString);
|
||||
}
|
||||
catch (LiteException e)
|
||||
{
|
||||
// I don't like this way of error reporting, now I need to use reflection if I want a meaningful error code
|
||||
if (e.ErrorCode != LiteException.INVALID_DATABASE)
|
||||
throw new ArtemisCoreException($"LiteDB threw error code {e.ErrorCode}. See inner exception for more details", e);
|
||||
|
||||
// If the DB is invalid it's probably LiteDB v4 (TODO: we'll have to do something better later)
|
||||
File.Delete($"{Constants.DataFolder}\\database.db");
|
||||
return new LiteRepository(Constants.ConnectionString);
|
||||
}
|
||||
}).InSingletonScope();
|
||||
|
||||
Kernel.Bind<LiteRepository>().ToMethod(_ => StorageManager.CreateRepository(Constants.DataFolder)).InSingletonScope();
|
||||
Kernel.Bind<StorageMigrationService>().ToSelf().InSingletonScope();
|
||||
|
||||
// Bind all migrations as singletons
|
||||
|
||||
Reference in new issue
Block a user