Add project files.
This commit is contained in:
52
ModVersionChecker/managers/filesystem/AppStatusManager.cs
Normal file
52
ModVersionChecker/managers/filesystem/AppStatusManager.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.filesystem
|
||||
{
|
||||
|
||||
public class AppStatusManager : IAppStatusManager
|
||||
{
|
||||
private Dictionary<string, AppStatus> _statuses = new Dictionary<string, AppStatus>();
|
||||
|
||||
public AppStatusManager() { }
|
||||
public AppStatus? GetAppStatus(string appId)
|
||||
{
|
||||
if (!_statuses.ContainsKey(appId))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _statuses[appId];
|
||||
}
|
||||
public List<AppStatus> Load()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public void Save(List<AppStatus> appStatuses)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public void UpdateAppStatus(string appId, AppStatus appStatus)
|
||||
{
|
||||
if (_statuses.ContainsKey(appId))
|
||||
{
|
||||
_statuses[appId] = appStatus;
|
||||
} else
|
||||
{
|
||||
_statuses.Add(appId, appStatus);
|
||||
}
|
||||
}
|
||||
public bool DeleteAppStatus(string appId) {
|
||||
return _statuses.Remove(appId);
|
||||
}
|
||||
public void ClearAll()
|
||||
{
|
||||
_statuses.Clear();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
42
ModVersionChecker/managers/filesystem/AppsManager.cs
Normal file
42
ModVersionChecker/managers/filesystem/AppsManager.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ModVersionChecker.managers.filesystem
|
||||
{
|
||||
public class AppsManager
|
||||
{
|
||||
private readonly string FilePath = Path.Combine(AppContext.BaseDirectory, "data", "apps.json");
|
||||
|
||||
public List<AppConfig> Load()
|
||||
{
|
||||
if (!File.Exists(FilePath))
|
||||
return new List<AppConfig>();
|
||||
var json = File.ReadAllText(FilePath);
|
||||
return JsonSerializer.Deserialize<List<AppConfig>>(json) ?? new();
|
||||
}
|
||||
|
||||
public void Save(List<AppConfig> apps)
|
||||
{
|
||||
var options = new JsonSerializerOptions { WriteIndented = true };
|
||||
var json = JsonSerializer.Serialize(apps, options);
|
||||
File.WriteAllText(FilePath, json);
|
||||
}
|
||||
|
||||
public void Upsert(AppConfig app)
|
||||
{
|
||||
var apps = Load();
|
||||
var index = apps.FindIndex(a => a.Id == app.Id);
|
||||
if (index >= 0)
|
||||
{
|
||||
apps[index] = app;
|
||||
}
|
||||
else
|
||||
{
|
||||
apps.Add(app);
|
||||
}
|
||||
Save(apps);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ModVersionChecker.managers.filesystem
|
||||
{
|
||||
public class CheckerTypesDefManager : ICheckerTypesDefManager
|
||||
{
|
||||
private readonly string FilePath = Path.Combine(AppContext.BaseDirectory, "data", "checkerTypesDef.json");
|
||||
|
||||
public List<CheckerTypeDef> Load()
|
||||
{
|
||||
if (!File.Exists(FilePath))
|
||||
return new List<CheckerTypeDef>();
|
||||
var json = File.ReadAllText(FilePath);
|
||||
return JsonSerializer.Deserialize<List<CheckerTypeDef>>(json) ?? new();
|
||||
}
|
||||
|
||||
public void Save(List<CheckerTypeDef> checkerTypesDef)
|
||||
{
|
||||
var options = new JsonSerializerOptions { WriteIndented = true };
|
||||
var json = JsonSerializer.Serialize(checkerTypesDef, options);
|
||||
File.WriteAllText(FilePath, json);
|
||||
}
|
||||
}
|
||||
}
|
40
ModVersionChecker/managers/filesystem/ConfigManager.cs
Normal file
40
ModVersionChecker/managers/filesystem/ConfigManager.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ModVersionChecker.managers.filesystem
|
||||
{
|
||||
public class ConfigManager : IConfigManager
|
||||
{
|
||||
|
||||
private static readonly string _filePath = Path.Combine(AppContext.BaseDirectory, "data", "config.json");
|
||||
private GlobalConfig _config;
|
||||
|
||||
public ConfigManager()
|
||||
{
|
||||
_config = Load();
|
||||
}
|
||||
|
||||
public GlobalConfig Load()
|
||||
{
|
||||
if (!File.Exists(_filePath))
|
||||
return new GlobalConfig();
|
||||
var json = File.ReadAllText(_filePath);
|
||||
return JsonSerializer.Deserialize<GlobalConfig>(json) ?? new GlobalConfig();
|
||||
}
|
||||
|
||||
public GlobalConfig GetConfig()
|
||||
{
|
||||
return _config;
|
||||
}
|
||||
|
||||
public void Save(GlobalConfig config)
|
||||
{
|
||||
var options = new JsonSerializerOptions { WriteIndented = true };
|
||||
var json = JsonSerializer.Serialize(config, options);
|
||||
File.WriteAllText(_filePath, json);
|
||||
}
|
||||
}
|
||||
}
|
22
ModVersionChecker/managers/filesystem/NotifyIconService.cs
Normal file
22
ModVersionChecker/managers/filesystem/NotifyIconService.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.filesystem
|
||||
{
|
||||
public class NotifyIconService : INotifyIconService
|
||||
{
|
||||
private NotifyIcon? _notifyIcon;
|
||||
public void SetNotifyIcon(NotifyIcon icon)
|
||||
{
|
||||
_notifyIcon = icon;
|
||||
}
|
||||
public void ShowBalloonTip(int millis, string title, string message, ToolTipIcon icon)
|
||||
{
|
||||
_notifyIcon?.ShowBalloonTip(millis, title, message, icon);
|
||||
}
|
||||
}
|
||||
}
|
52
ModVersionChecker/managers/filesystem/SourcesDefManager.cs
Normal file
52
ModVersionChecker/managers/filesystem/SourcesDefManager.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ModVersionChecker.managers.filesystem
|
||||
{
|
||||
public class SourcesDefManager
|
||||
{
|
||||
private readonly string _filePath = Path.Combine(AppContext.BaseDirectory, "data", "sourcesDef.json");
|
||||
private List<SourceDef> _sourcesDef = new List<SourceDef>();
|
||||
|
||||
public SourcesDefManager()
|
||||
{
|
||||
_sourcesDef = Load();
|
||||
}
|
||||
|
||||
private List<SourceDef> Load()
|
||||
{
|
||||
if (!File.Exists(_filePath))
|
||||
return new List<SourceDef>();
|
||||
var json = File.ReadAllText(_filePath);
|
||||
return JsonSerializer.Deserialize<List<SourceDef>>(json) ?? new();
|
||||
}
|
||||
|
||||
public List<SourceDef> GetSourcesDef()
|
||||
{
|
||||
return _sourcesDef;
|
||||
}
|
||||
|
||||
public void AddSourceDef(SourceDef sourceDef)
|
||||
{
|
||||
_sourcesDef.Add(sourceDef);
|
||||
Save(_sourcesDef);
|
||||
}
|
||||
|
||||
public void RemoveSourceDef(string id)
|
||||
{
|
||||
_sourcesDef.RemoveAll(s => s.Id == id);
|
||||
Save(_sourcesDef);
|
||||
}
|
||||
|
||||
|
||||
public void Save(List<SourceDef> sourcesDef)
|
||||
{
|
||||
var options = new JsonSerializerOptions { WriteIndented = true };
|
||||
var json = JsonSerializer.Serialize(sourcesDef, options);
|
||||
File.WriteAllText(_filePath, json);
|
||||
}
|
||||
}
|
||||
}
|
23
ModVersionChecker/managers/interfaces/IAppStatusManager.cs
Normal file
23
ModVersionChecker/managers/interfaces/IAppStatusManager.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.interfaces
|
||||
{
|
||||
public interface IAppStatusManager
|
||||
{
|
||||
List<AppStatus> Load();
|
||||
void Save(List<AppStatus> appStatuses);
|
||||
AppStatus? GetAppStatus(string appId);
|
||||
|
||||
void UpdateAppStatus(string appId, AppStatus appStatus);
|
||||
|
||||
bool DeleteAppStatus(string appId);
|
||||
|
||||
void ClearAll();
|
||||
|
||||
}
|
||||
}
|
26
ModVersionChecker/managers/interfaces/IAppsManager.cs
Normal file
26
ModVersionChecker/managers/interfaces/IAppsManager.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.interfaces
|
||||
{
|
||||
public interface IAppsManager
|
||||
{
|
||||
|
||||
List<AppConfig> Load();
|
||||
|
||||
void Save(List<AppConfig> apps);
|
||||
|
||||
public void Insert(AppConfig app);
|
||||
|
||||
public void Update(AppConfig app);
|
||||
|
||||
void Delete(string id);
|
||||
|
||||
void UpdateStatus(AppConfig app, AppStatus status);
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.interfaces
|
||||
{
|
||||
public interface ICheckerTypesDefManager
|
||||
{
|
||||
List<CheckerTypeDef> Load();
|
||||
void Save(List<CheckerTypeDef> checkerTypesDef);
|
||||
}
|
||||
}
|
16
ModVersionChecker/managers/interfaces/IConfigManager.cs
Normal file
16
ModVersionChecker/managers/interfaces/IConfigManager.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.interfaces
|
||||
{
|
||||
public interface IConfigManager
|
||||
{
|
||||
GlobalConfig Load();
|
||||
void Save(GlobalConfig config);
|
||||
GlobalConfig GetConfig();
|
||||
}
|
||||
}
|
17
ModVersionChecker/managers/interfaces/IFlightSimsManager.cs
Normal file
17
ModVersionChecker/managers/interfaces/IFlightSimsManager.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.interfaces
|
||||
{
|
||||
public interface IFlightSimsManager
|
||||
{
|
||||
List<FsModPathConfig> Load();
|
||||
void Save(FsModPathConfig config);
|
||||
|
||||
FsModPathConfig? GetByShortName(string id);
|
||||
}
|
||||
}
|
14
ModVersionChecker/managers/interfaces/INotifyIconService.cs
Normal file
14
ModVersionChecker/managers/interfaces/INotifyIconService.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.interfaces
|
||||
{
|
||||
public interface INotifyIconService
|
||||
{
|
||||
void SetNotifyIcon(NotifyIcon icon);
|
||||
void ShowBalloonTip(int millis, string title, string message, ToolTipIcon icon);
|
||||
}
|
||||
}
|
19
ModVersionChecker/managers/interfaces/ISourcesDefManager.cs
Normal file
19
ModVersionChecker/managers/interfaces/ISourcesDefManager.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.interfaces
|
||||
{
|
||||
public interface ISourcesDefManager
|
||||
{
|
||||
List<SourceDef> List();
|
||||
|
||||
SourceDef? GetById(string id);
|
||||
void AddSourceDef(SourceDef sourceDef);
|
||||
void RemoveSourceDef(string id);
|
||||
void Save(SourceDef sourceDef);
|
||||
}
|
||||
}
|
70
ModVersionChecker/managers/litedb/AppConfigLiteDb.cs
Normal file
70
ModVersionChecker/managers/litedb/AppConfigLiteDb.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using ModVersionChecker.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.litedb
|
||||
{
|
||||
public class AppConfigLiteDb : LiteDb, IAppsManager
|
||||
{
|
||||
private string collection = LiteDb.APPS_COLLECTION;
|
||||
public List<AppConfig> Load()
|
||||
{
|
||||
var col = _db.GetCollection<AppConfig>(collection);
|
||||
return col.FindAll().ToList();
|
||||
}
|
||||
|
||||
public void Insert(AppConfig app)
|
||||
{
|
||||
var now = TimeUtils.GetUnixTimeMillis(null);
|
||||
app.CreatedAt = now;
|
||||
app.UpdatedAt = now;
|
||||
var col = _db.GetCollection<AppConfig>(collection);
|
||||
col.Insert(app);
|
||||
}
|
||||
|
||||
public void Update(AppConfig app)
|
||||
{
|
||||
var now = TimeUtils.GetUnixTimeMillis(null);
|
||||
app.UpdatedAt = now;
|
||||
var col = _db.GetCollection<AppConfig>(collection);
|
||||
col.Update(app);
|
||||
}
|
||||
|
||||
//public void Upsert(AppConfig app)
|
||||
//{
|
||||
// var now = TimeUtils.GetUnixTimeMillis(null);
|
||||
// app.UpdatedAt = now;
|
||||
// var col = _db.GetCollection<AppConfig>(collection);
|
||||
// if (string.IsNullOrEmpty(app.Id))
|
||||
// {
|
||||
// app.CreatedAt = now;
|
||||
// col.Insert(app);
|
||||
// }
|
||||
// col.Update(app);
|
||||
//}
|
||||
|
||||
public void Delete(string id)
|
||||
{
|
||||
var col = _db.GetCollection<AppConfig>(collection);
|
||||
col.Delete(id);
|
||||
}
|
||||
|
||||
public void Save(List<AppConfig> apps)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void UpdateStatus(AppConfig app, AppStatus status)
|
||||
{
|
||||
app.LastCheckedAt = TimeUtils.GetUnixTimeMillis(null);
|
||||
app.Status = status;
|
||||
var col = _db.GetCollection<AppConfig>(collection);
|
||||
col.Update(app);
|
||||
}
|
||||
}
|
||||
}
|
24
ModVersionChecker/managers/litedb/ConfigLiteDb.cs
Normal file
24
ModVersionChecker/managers/litedb/ConfigLiteDb.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
|
||||
namespace ModVersionChecker.managers.litedb
|
||||
{
|
||||
public class ConfigLiteDb : LiteDb, IConfigManager
|
||||
{
|
||||
private string collection = LiteDb.CONFIG_COLLECTION;
|
||||
public GlobalConfig Load()
|
||||
{
|
||||
var col = _db.GetCollection<GlobalConfig>(collection);
|
||||
return col.FindAll().FirstOrDefault() ?? new GlobalConfig();
|
||||
}
|
||||
public void Save(GlobalConfig config)
|
||||
{
|
||||
var col = _db.GetCollection<GlobalConfig>(collection);
|
||||
col.Upsert(config);
|
||||
}
|
||||
public GlobalConfig GetConfig()
|
||||
{
|
||||
return Load();
|
||||
}
|
||||
}
|
||||
}
|
32
ModVersionChecker/managers/litedb/FlightSimsLiteDb.cs
Normal file
32
ModVersionChecker/managers/litedb/FlightSimsLiteDb.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.litedb
|
||||
{
|
||||
internal class FlightSimsLiteDb : LiteDb, IFlightSimsManager
|
||||
{
|
||||
private string collection = FLIGHT_SIMS_COLLECTION;
|
||||
public List<FsModPathConfig> Load()
|
||||
{
|
||||
var col = _db.GetCollection<FsModPathConfig>(collection);
|
||||
return col.FindAll().ToList();
|
||||
}
|
||||
|
||||
public void Save(FsModPathConfig config)
|
||||
{
|
||||
var col = _db.GetCollection<FsModPathConfig>(collection);
|
||||
col.Upsert(config);
|
||||
}
|
||||
|
||||
public FsModPathConfig? GetByShortName(string id)
|
||||
{
|
||||
var col = _db.GetCollection<FsModPathConfig>(collection);
|
||||
return col.FindOne(x => x.ShortName == id);
|
||||
}
|
||||
}
|
||||
}
|
16
ModVersionChecker/managers/litedb/LiteDb.cs
Normal file
16
ModVersionChecker/managers/litedb/LiteDb.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using LiteDB;
|
||||
|
||||
namespace ModVersionChecker.managers.litedb
|
||||
{
|
||||
public class LiteDb
|
||||
{
|
||||
public static string DB_PATH = "ModVersionChecker.db";
|
||||
public static string APPS_COLLECTION = "apps";
|
||||
public static string CHECKER_TYPES_DEF_COLLECTION = "checker_types_def";
|
||||
public static string SOURCES_DEF_COLLECTION = "sources_def";
|
||||
public static string CONFIG_COLLECTION = "config";
|
||||
public static string FLIGHT_SIMS_COLLECTION = "flight_sims";
|
||||
|
||||
protected LiteDatabase _db = LiteDbSingleton.Instance;
|
||||
}
|
||||
}
|
12
ModVersionChecker/managers/litedb/LiteDbSingleton.cs
Normal file
12
ModVersionChecker/managers/litedb/LiteDbSingleton.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using LiteDB;
|
||||
|
||||
public static class LiteDbSingleton
|
||||
{
|
||||
private static readonly LiteDatabase _db = new LiteDatabase(new ConnectionString
|
||||
{
|
||||
Filename = "ModVersionChecker.db",
|
||||
Connection = ConnectionType.Shared
|
||||
});
|
||||
|
||||
public static LiteDatabase Instance => _db;
|
||||
}
|
43
ModVersionChecker/managers/litedb/SourcesLiteDb.cs
Normal file
43
ModVersionChecker/managers/litedb/SourcesLiteDb.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.litedb
|
||||
{
|
||||
public class SourcesLiteDb : LiteDb, ISourcesDefManager
|
||||
{
|
||||
private string collection = SOURCES_DEF_COLLECTION;
|
||||
public List<SourceDef> List()
|
||||
{
|
||||
var col = _db.GetCollection<SourceDef>(collection);
|
||||
return col.FindAll().ToList();
|
||||
}
|
||||
|
||||
public SourceDef? GetById(string id)
|
||||
{
|
||||
var col = _db.GetCollection<SourceDef>(collection);
|
||||
return col.FindOne(x => x.Id == id);
|
||||
}
|
||||
|
||||
public void AddSourceDef(SourceDef sourceDef)
|
||||
{
|
||||
var col = _db.GetCollection<SourceDef>(collection);
|
||||
col.Insert(sourceDef);
|
||||
}
|
||||
public void RemoveSourceDef(string id)
|
||||
{
|
||||
var col = _db.GetCollection<SourceDef>(collection);
|
||||
col.Delete(id);
|
||||
}
|
||||
|
||||
public void Save(SourceDef sourceDef)
|
||||
{
|
||||
var col = _db.GetCollection<SourceDef>(collection);
|
||||
col.Upsert(sourceDef);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user