BadScript 2
Loading...
Searching...
No Matches
BadSettingsSystem.cs
Go to the documentation of this file.
1using System.Diagnostics;
2
5
10
14public class BadSettingsSystem : BadConsoleSystem<BadSettingsSystemSettings>
15{
20 public BadSettingsSystem(BadRuntime runtime) : base(runtime) { }
21
23 public override string Name => "settings";
24
25 private void OpenWithDefault(string path)
26 {
27 ProcessStartInfo pi = new ProcessStartInfo
28 {
29 FileName = path,
30 UseShellExecute = true
31 };
32 Process.Start(pi);
33 }
35 protected override Task<int> Run(BadSettingsSystemSettings settings)
36 {
37 BadSettings? setting = string.IsNullOrEmpty(settings.Path) ? BadSettingsProvider.RootSettings : BadSettingsProvider.RootSettings.FindProperty(settings.Path);
38
39 if(settings.Edit)
40 {
41 if (BadSettingsProvider.RootSettings == setting)
42 {
43 //Open the Settings folder
44 //Directory: $Console.DataDirectory/settings
45 OpenWithDefault(Path.GetFullPath(BadSettingsProvider.RootSettings.FindProperty<string>("Console.DataDirectory")! + "/settings"));
46 return Task.FromResult(0);
47 }
48
49 if (setting == null)
50 {
51 BadConsole.WriteLine($"Setting '{settings.Path}' not found.");
52 return Task.FromResult(1);
53 }
54
55 if (!setting.HasSourcePath)
56 {
57 BadConsole.WriteLine($"Setting '{settings.Path}' has no source path.");
58 return Task.FromResult(1);
59 }
60
61 //Open the source file in the default editor
62 string path = Path.GetFullPath(setting.SourcePath);
63 OpenWithDefault(path);
64
65 return Task.FromResult(0);
66 }
67 BadConsole.WriteLine(setting?.ToString() ?? "null");
68
69 return Task.FromResult(0);
70 }
71}
Exposes the BadScript Runtime Functionality to Consumers.
Definition BadRuntime.cs:28
Wrapper class for the console abstraction.
Definition BadConsole.cs:12
static void WriteLine(string str)
Writes a string to the console and appends a newline.
Definition BadConsole.cs:76
Implements a Console System that uses a settings object of Type T.
BadSettingsSystem(BadRuntime runtime)
Creates a new BadSettingsSystem instance.
override Task< int > Run(BadSettingsSystemSettings settings)
Public Api for the Settings System.
BadSettings? FindProperty(string propertyPath)
Finds a property based on the property path relative to this object.
Helper class that can be used to automatically load a settings object from a file.
static BadSettings RootSettings
Returns the Root Settings Object.
Contains a Console Abstraction Layer to be able to Simulate Console Input/Output over the Network.
Definition BadConsole.cs:6
Contains the 'settings' console command implementation.
Contains the Settings Implementation.