Made some basic start to the config stuff. More will come later.
This commit is contained in:
parent
24fde24746
commit
68336df868
@ -1,12 +1,14 @@
|
|||||||
global using Nerd_STF.Mathematics;
|
global using Nerd_STF.Mathematics;
|
||||||
|
global using Newtonsoft.Json;
|
||||||
global using SharpCompress.Archives.Rar;
|
global using SharpCompress.Archives.Rar;
|
||||||
global using SharpCompress.Archives.SevenZip;
|
global using SharpCompress.Archives.SevenZip;
|
||||||
global using SharpCompress.Readers;
|
global using SharpCompress.Readers;
|
||||||
global using SrcMod.Shell;
|
|
||||||
global using SrcMod.Shell.Interop;
|
global using SrcMod.Shell.Interop;
|
||||||
global using SrcMod.Shell.Modules.ObjectModels;
|
global using SrcMod.Shell.Modules.ObjectModels;
|
||||||
|
global using SrcMod.Shell.ObjectModels;
|
||||||
global using System;
|
global using System;
|
||||||
global using System.Collections.Generic;
|
global using System.Collections.Generic;
|
||||||
|
global using System.ComponentModel;
|
||||||
global using System.Diagnostics;
|
global using System.Diagnostics;
|
||||||
global using System.Formats.Tar;
|
global using System.Formats.Tar;
|
||||||
global using System.IO;
|
global using System.IO;
|
||||||
|
|||||||
46
SrcMod/Shell/ObjectModels/ShellConfig.cs
Normal file
46
SrcMod/Shell/ObjectModels/ShellConfig.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
namespace SrcMod.Shell.ObjectModels;
|
||||||
|
|
||||||
|
public class ShellConfig
|
||||||
|
{
|
||||||
|
public const string FilePath = "config.json";
|
||||||
|
|
||||||
|
public static ShellConfig Defaults => new()
|
||||||
|
{
|
||||||
|
SteamDirectories = new[]
|
||||||
|
{
|
||||||
|
"Temp"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static ShellConfig LoadedConfig => p_data ?? Defaults;
|
||||||
|
|
||||||
|
private static ShellConfig? p_data;
|
||||||
|
|
||||||
|
public string[] SteamDirectories;
|
||||||
|
|
||||||
|
public static void LoadConfig(string basePath)
|
||||||
|
{
|
||||||
|
string fullPath = Path.Combine(basePath, FilePath);
|
||||||
|
|
||||||
|
if (!File.Exists(fullPath))
|
||||||
|
{
|
||||||
|
p_data = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
StreamReader reader = new(fullPath);
|
||||||
|
JsonTextReader jsonReader = new(reader);
|
||||||
|
p_data = Serializer.Deserialize<ShellConfig>(jsonReader);
|
||||||
|
jsonReader.Close();
|
||||||
|
reader.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SaveConfig(string basePath)
|
||||||
|
{
|
||||||
|
string fullPath = Path.Combine(basePath, FilePath);
|
||||||
|
|
||||||
|
StreamWriter writer = new(fullPath);
|
||||||
|
JsonTextWriter jsonWriter = new(writer);
|
||||||
|
Serializer.Serialize(jsonWriter, p_data);
|
||||||
|
jsonWriter.Close();
|
||||||
|
writer.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,12 +1,10 @@
|
|||||||
using System.ComponentModel;
|
namespace SrcMod.Shell;
|
||||||
|
|
||||||
namespace SrcMod.Shell;
|
|
||||||
|
|
||||||
public class Shell
|
public class Shell
|
||||||
{
|
{
|
||||||
public const string Author = "That_One_Nerd";
|
public const string Author = "That_One_Nerd";
|
||||||
public const string Name = "SrcMod";
|
public const string Name = "SrcMod";
|
||||||
public const string Version = "Alpha 0.3.2";
|
public const string Version = "Alpha 0.3.3";
|
||||||
|
|
||||||
public readonly string? ShellDirectory;
|
public readonly string? ShellDirectory;
|
||||||
|
|
||||||
@ -50,6 +48,10 @@ public class Shell
|
|||||||
|
|
||||||
WorkingDirectory = Directory.GetCurrentDirectory();
|
WorkingDirectory = Directory.GetCurrentDirectory();
|
||||||
|
|
||||||
|
// Load config.
|
||||||
|
if (ShellDirectory is null) Write("[WARNING] Could not load config from shell location. Defaults will be used.");
|
||||||
|
else ShellConfig.LoadConfig(ShellDirectory);
|
||||||
|
|
||||||
// Load modules and commands.
|
// Load modules and commands.
|
||||||
List<Assembly?> possibleAsms = new()
|
List<Assembly?> possibleAsms = new()
|
||||||
{
|
{
|
||||||
@ -250,6 +252,9 @@ public class Shell
|
|||||||
activeCommand.Dispose();
|
activeCommand.Dispose();
|
||||||
activeCommand = null;
|
activeCommand = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ShellDirectory is null) Write("[WARNING] Could not save config to shell location. Any changes will be ignored.");
|
||||||
|
else ShellConfig.SaveConfig(ShellDirectory);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||||
<ApplicationIcon>Logo.ico</ApplicationIcon>
|
<ApplicationIcon>Logo.ico</ApplicationIcon>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
|
<NoWin32Manifest>true</NoWin32Manifest>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
@ -31,6 +32,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Nerd_STF" Version="2.3.2" />
|
<PackageReference Include="Nerd_STF" Version="2.3.2" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="SharpCompress" Version="0.33.0" />
|
<PackageReference Include="SharpCompress" Version="0.33.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
using System.Text;
|
namespace SrcMod.Shell;
|
||||||
|
|
||||||
namespace SrcMod.Shell;
|
|
||||||
|
|
||||||
public static class Tools
|
public static class Tools
|
||||||
{
|
{
|
||||||
|
public static JsonSerializer Serializer { get; private set; }
|
||||||
|
|
||||||
private static int loadingPosition = -1;
|
private static int loadingPosition = -1;
|
||||||
private static int lastLoadingBufferSize = 0;
|
private static int lastLoadingBufferSize = 0;
|
||||||
private static int lastLoadingValue = -1;
|
private static int lastLoadingValue = -1;
|
||||||
@ -12,6 +12,14 @@ public static class Tools
|
|||||||
|
|
||||||
public static bool LoadingBarEnabled { get; private set; }
|
public static bool LoadingBarEnabled { get; private set; }
|
||||||
|
|
||||||
|
static Tools()
|
||||||
|
{
|
||||||
|
Serializer = JsonSerializer.Create(new()
|
||||||
|
{
|
||||||
|
Formatting = Formatting.Indented
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public static void DisplayWithPages(IEnumerable<string> lines, ConsoleColor? color = null)
|
public static void DisplayWithPages(IEnumerable<string> lines, ConsoleColor? color = null)
|
||||||
{
|
{
|
||||||
int written = 0;
|
int written = 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user