clean up
This commit is contained in:
56
controller/Config.cs
Normal file
56
controller/Config.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using BeatSaber_Versions.controller.helper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YamlDotNet.Serialization;
|
||||
using YamlDotNet.Serialization.NamingConventions;
|
||||
|
||||
namespace BeatSaber_Versions.controller
|
||||
{
|
||||
internal class Config
|
||||
{
|
||||
public Config()
|
||||
{
|
||||
VersionConfigDict c = new VersionConfigDict();
|
||||
if (!ConfigFile.isConfigFileThere(Storage.ConfigPath))
|
||||
{
|
||||
c = ConfigFile.createEmptyConfig();
|
||||
Storage.Config = c;
|
||||
writeConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
readConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public void readConfig()
|
||||
{
|
||||
var deserializer = new DeserializerBuilder()
|
||||
.WithNamingConvention(UnderscoredNamingConvention.Instance)
|
||||
.Build();
|
||||
|
||||
string yml = File.ReadAllText(Storage.ConfigPath);
|
||||
try
|
||||
{
|
||||
VersionConfigDict tmp = deserializer.Deserialize<VersionConfigDict>(yml);
|
||||
Storage.Config = tmp;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
public void writeConfig()
|
||||
{
|
||||
var serializer = new SerializerBuilder()
|
||||
.WithNamingConvention(CamelCaseNamingConvention.Instance)
|
||||
.Build();
|
||||
var yaml = serializer.Serialize(Storage.Config);
|
||||
File.WriteAllTextAsync(Storage.ConfigPath, yaml);
|
||||
}
|
||||
}
|
||||
}
|
||||
16
controller/Storage.cs
Normal file
16
controller/Storage.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using BeatSaber_Versions.controller.helper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeatSaber_Versions.controller
|
||||
{
|
||||
internal class Storage
|
||||
{
|
||||
internal static readonly string ConfigPath = $@"{AppDomain.CurrentDomain.BaseDirectory}config.yaml";
|
||||
static public VersionConfigDict Config = ConfigFile.createEmptyConfig();
|
||||
static public Config? CC;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeatSaber_Versions.controller
|
||||
{
|
||||
internal class VersionConfig
|
||||
|
||||
{
|
||||
public string version { get; set; }
|
||||
public string name { get; set; }
|
||||
public string path { get; set; }
|
||||
}
|
||||
}
|
||||
29
controller/helper/ConfigFile.cs
Normal file
29
controller/helper/ConfigFile.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeatSaber_Versions.controller.helper
|
||||
{
|
||||
internal class ConfigFile
|
||||
{
|
||||
static public bool isConfigFileThere(string path)
|
||||
{
|
||||
return File.Exists(path);
|
||||
}
|
||||
static public VersionConfigDict createEmptyConfig()
|
||||
{
|
||||
VersionConfig tmp = new VersionConfig();
|
||||
VersionConfigDict conf = new VersionConfigDict();
|
||||
|
||||
tmp.name = "Example";
|
||||
tmp.path = "C:\\Steam\\Beat Saber";
|
||||
tmp.version = "1.21.0";
|
||||
conf.versions = new Dictionary<string, VersionConfig>();
|
||||
conf.versions.Add(tmp.version, tmp);
|
||||
|
||||
return conf;
|
||||
}
|
||||
}
|
||||
}
|
||||
25
controller/helper/staticHelpers.cs
Normal file
25
controller/helper/staticHelpers.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeatSaber_Versions.controller.helper
|
||||
{
|
||||
internal class staticHelpers
|
||||
{
|
||||
static public bool IsSymbolic(string path)
|
||||
{
|
||||
FileInfo pathInfo = new FileInfo(path);
|
||||
return pathInfo.Attributes.HasFlag(FileAttributes.ReparsePoint);
|
||||
}
|
||||
static public bool IsElevated
|
||||
{
|
||||
get
|
||||
{
|
||||
return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
controller/structure/VersionConfig.cs
Normal file
10
controller/structure/VersionConfig.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace BeatSaber_Versions.controller
|
||||
{
|
||||
internal class VersionConfig
|
||||
|
||||
{
|
||||
public string? version { get; set; }
|
||||
public string? name { get; set; }
|
||||
public string? path { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeatSaber_Versions.controller
|
||||
namespace BeatSaber_Versions.controller
|
||||
{
|
||||
internal class VersionConfigDict
|
||||
{
|
||||
Reference in New Issue
Block a user