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 { FileName = path, UseShellExecute = true };
28 Process.Start(pi);
29 }
30
32 protected override Task<int> Run(BadSettingsSystemSettings settings)
33 {
34 BadSettings? setting = string.IsNullOrEmpty(settings.Path)
35 ? BadSettingsProvider.RootSettings
37
38 if (settings.Edit)
39 {
40 if (BadSettingsProvider.RootSettings == setting)
41 {
42 //Open the Settings folder
43 //Directory: $Console.DataDirectory/settings
45 .FindProperty<string>("Console.DataDirectory")! +
46 "/settings"
47 )
48 );
49
50 return Task.FromResult(0);
51 }
52
53 if (setting == null)
54 {
55 BadConsole.WriteLine($"Setting '{settings.Path}' not found.");
56
57 return Task.FromResult(1);
58 }
59
60 if (!setting.HasSourcePath)
61 {
62 BadConsole.WriteLine($"Setting '{settings.Path}' has no source path.");
63
64 return Task.FromResult(1);
65 }
66
67 //Open the source file in the default editor
68 string path = Path.GetFullPath(setting.SourcePath);
69 OpenWithDefault(path);
70
71 return Task.FromResult(0);
72 }
73
74 BadConsole.WriteLine(setting?.ToString() ?? "null");
75
76 return Task.FromResult(0);
77 }
78}
Exposes the BadScript Runtime Functionality to Consumers.
Definition BadRuntime.cs:30
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:78
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.
string SourcePath
The Source Path of the Settings 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.