Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e7047c9

Browse files
committed
Adding Globals for user selectable options.
1 parent 02d178e commit e7047c9

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
This file is part of Module Manager Watch Dog
3+
©2020-2023 Lisias T : http://lisias.net <support@lisias.net>
4+
5+
Module Manager Watch Dog is licensed as follows:
6+
* SKL 1.0 : https://ksp.lisias.net/SKL-1_0.txt
7+
8+
Module Manager Watchdog is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11+
12+
You should have received a copy of the SKL Standard License 1.0
13+
along with Module Manager Watch Dog. If not, see
14+
<https://ksp.lisias.net/SKL-1_0.txt>.
15+
16+
*/
17+
using System;
18+
using SIO = System.IO;
19+
20+
namespace ModuleManagerWatchDog
21+
{
22+
public class Globals
23+
{
24+
private static Globals INSTANCE = null;
25+
public static Globals Instance => INSTANCE ?? (INSTANCE = new Globals());
26+
27+
private const string NODE = "ModuleManagerWatchDog";
28+
private const string DATAFILE = NODE + ".cfg";
29+
private readonly string ROOT = SIO.Path.Combine(KSPUtil.ApplicationRootPath, "PluginData");
30+
31+
internal bool IsValid;
32+
private bool dirty = false;
33+
34+
private bool prefersMyFork = false;
35+
public bool PrefersMyFork {
36+
get => this.prefersMyFork;
37+
internal set
38+
{
39+
this.dirty = true;
40+
this.prefersMyFork = value;
41+
}
42+
}
43+
44+
private Globals()
45+
{
46+
string path = SIO.Path.Combine(ROOT, DATAFILE);
47+
this.dirty = false;
48+
bool r = true;
49+
try
50+
{
51+
ConfigNode cn = ConfigNode.Load(path).GetNode(NODE);
52+
r &= this.prefersMyFork = cn.TryGetValue("PrefersMyFork", ref this.prefersMyFork);
53+
}
54+
catch (Exception)
55+
{
56+
this.prefersMyFork = false;
57+
r = false;
58+
}
59+
this.IsValid = r;
60+
}
61+
62+
internal void Save()
63+
{
64+
if (!this.dirty) return;
65+
string path = SIO.Path.Combine(ROOT, DATAFILE);
66+
Log.force("Writing {0}", path);
67+
try
68+
{
69+
ConfigNode cn = new ConfigNode(NODE);
70+
ConfigNode ccn = cn.AddNode(NODE);
71+
ccn.SetValue("PrefersMyFork", this.prefersMyFork, true);
72+
cn.Save(path);
73+
}
74+
catch (Exception e)
75+
{
76+
Log.error("Could not write {0} due {1}!", path, e.Message);
77+
}
78+
}
79+
}
80+
}

‎Source/ModuleManagerWatchDog/ModuleManagerWatchDog.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<Compile Include="GUI\FatalError.cs" />
5252
<Compile Include="Util\SanityLib.cs" />
5353
<Compile Include="Properties\LegalMamboJambo.cs" />
54+
<Compile Include="Globals.cs" />
5455
</ItemGroup>
5556
<ItemGroup>
5657
<None Include="Properties\Version.tt">

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /