initial include of an avalonia version of EDBGS

This commit is contained in:
2024-11-07 10:49:01 +01:00
parent 6cbe54ff73
commit 8370ee26a4
64 changed files with 8453 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.ComponentModel;
namespace EliteBGS.Util;
public class AppConfig {
private static readonly string default_journal_location = "%UserProfile%\\Saved Games\\Frontier Developments\\Elite Dangerous";
private string journal_location = default_journal_location;
private string colour = "Amber";
private string theme = "Dark";
public static string DefaultJournalLocation => default_journal_location;
public string LastUsedDiscordTemplate { get; set; }
public string JournalLocation {
get {
if (journal_location == null) {
return DefaultJournalLocation;
}
return journal_location;
}
set {
journal_location = value;
}
}
public string Theme {
get {
return theme;
}
set {
if (string.IsNullOrEmpty(value)) {
theme = "Dark";
} else {
theme = value;
}
}
}
public string Colour {
get {
return colour;
}
set {
if (string.IsNullOrEmpty(value)) {
colour = "Blue";
} else {
colour = value;
}
}
}
/// <summary>
/// Whether we ignore influence support scenarios form parsing.
/// </summary>
public bool IgnoreInfluenceSupport { get; set; } = false;
/// <summary>
/// Whether we ignore market buy entries during parsing.
/// </summary>
public bool IgnoreMarketBuy { get; set; } = false;
/// <summary>
/// Whether to ignore fleet carrier stuff when parsing.
/// </summary>
public bool IgnoreFleetCarrier { get; set; } = true;
/// <summary>
/// List of Webhooks configured
/// </summary>
public List<DiscordWebhook> Webhooks { get; set; } = new List<DiscordWebhook>();
[JsonIgnore]
public string FullTheme {
get { return Theme + "." + Colour; }
}
}

View File

@@ -0,0 +1,58 @@
using System;
using System.Text;
using System.IO;
using Newtonsoft.Json;
using System.ComponentModel;
namespace EliteBGS.Util {
public class Config {
private string config_folder = null;
private string config_file = null;
private AppConfig global_config = new AppConfig();
public Config() {
DetermineConfigFolder();
}
public string ConfigPath => config_folder;
public AppConfig Global => global_config;
private void DetermineConfigFolder() {
string folder = Environment.ExpandEnvironmentVariables("%appdata%\\EliteBGS");
if (!Directory.Exists(folder)) {
Directory.CreateDirectory(folder);
}
config_folder = folder;
config_file = Path.Combine(config_folder, "config.json");
}
public void SaveGlobal() {
var serializer = JsonSerializer.CreateDefault();
using (FileStream filestream = File.OpenWrite(config_file)) {
filestream.SetLength(0);
filestream.Flush();
using (StreamWriter file = new StreamWriter(filestream, Encoding.UTF8)) {
var stream = new JsonTextWriter(file);
stream.Formatting = Formatting.Indented;
serializer.Serialize(stream, global_config);
}
}
}
public void LoadGlobal() {
var serializer = JsonSerializer.CreateDefault();
using (var file = new StreamReader(File.OpenRead(config_file), Encoding.UTF8)) {
var stream = new JsonTextReader(file);
var app = serializer.Deserialize<AppConfig>(stream);
if (app != null) {
this.global_config = app;
}
}
}
}
}

View File

@@ -0,0 +1,13 @@
namespace EliteBGS.Util;
public class DiscordWebhook {
/// <summary>
/// Webhook URL
/// </summary>
public string Webhook { get; set; } = string.Empty;
/// <summary>
/// Human readable name for easier identification
/// </summary>
public string Name { get; set; } = string.Empty;
}