-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLegacyConfig.cs
230 lines (189 loc) · 7.34 KB
/
LegacyConfig.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
using log4net;
using log4net.Core;
using System;
using System.IO;
using Terraria;
using Terraria.IO;
using Terraria.ModLoader;
using Terraria.ModLoader.Config;
namespace GoldensMisc
{
//This used to be the old way of handling configs, before tModLoader added the "official" ModConfig.
public static class LegacyConfig
{
static bool AltStaffs = true;
const string AltStaffsKey = "AltStaffs";
static bool MagicStones = true;
const string MagicStonesKey = "MagicStones";
static bool GodStone = true;
const string GodStoneKey = "GodStone";
static bool DemonCrown = true;
const string DemonCrownKey = "DemonCrown";
static bool HeartLocket = true;
const string HeartLocketKey = "HeartLocket";
static bool Magnets = true;
const string MagnetsKey = "Magnet";
static bool NinjaGear = true;
const string NinjaGearKey = "NinjaGear";
static bool ReinforcedVest = true;
const string ReinforcedVestKey = "ReinforcedVest";
static bool AncientForges = true;
const string AncientForgesKey = "AncientForges";
static bool RedBrickFurniture = true;
const string RedBrickFurnitureKey = "RedBrickFurniture";
static bool AncientMuramasa = true;
const string AncientMuramasaKey = "AncientMuramasa";
static bool GasterBlaster = true;
const string GasterBlasterKey = "GasterBlaster";
static bool SpearofJustice = true;
const string SpearofJusticeKey = "SpearofJustice";
static bool WormholeMirror = true;
const string WormholeMirrorKey = "WormholeMirror";
static bool CellPhoneUpgrade = true;
const string CellPhoneUpgradeKey = "WormholePhone";
static bool RodofWarping = true;
const string RodofWarpingKey = "RodofWarping";
static float RodofWarpingChaosState = 1f;
const string RodofWarpingChaosStateKey = "RodofWarpingChaosState";
static bool EmblemofDeath = true;
const string EmblemofDeathKey = "EmblemofDeath";
static bool BuildingMaterials = true;
const string BuildingMaterialsKey = "BuildingMaterials";
static bool BaseballBats = true;
const string BaseballBatsKey = "BaseballBats";
static bool AncientOrb = true;
const string AncientOrbKey = "AncientOrb";
static bool CellPhoneResprite = true;
const string CellPhoneRespriteKey = "CellPhoneResprite";
static bool ExtraDyes = true;
const string ExtraDyesKey = "ExtraDyes";
static bool Autofisher = true;
const string AutofisherKey = "Autofisher";
static bool MechanicsRodOften = true;
const string MechanicsRodOftenKey = "MechanicsRodOften";
static bool ChestVacuum = true;
const string ChestVacuumKey = "ChestVacuum";
static string ConfigPath = Path.Combine(Main.SavePath, "Mod Configs", "Miscellania.json");
static string OldConfigFolderPath = Path.Combine(Main.SavePath, "Mod Configs", "Miscellania");
static string OldConfigPath = Path.Combine(OldConfigFolderPath, "config.json");
static string OldConfigVersionPath = Path.Combine(OldConfigFolderPath, "config.version");
static readonly Preferences Configuration = new Preferences(ConfigPath);
//We might not be able to use the mod's Logger as Config.Load() is called before Mod.Load()
//So we make our own
static ILog Logger = LogManager.GetLogger("MiscellaniaConfig");
public static void Load()
{
if(Directory.Exists(OldConfigFolderPath))
{
if(File.Exists(OldConfigPath))
{
if(!File.Exists(ConfigPath))
{
Logger.Warn("Found config file in old folder! Moving config...");
File.Move(OldConfigPath, ConfigPath);
}
else
{
Logger.Warn("Found config file in old folder! Deleting...");
File.Delete(OldConfigPath);
}
}
if(File.Exists(OldConfigVersionPath))
File.Delete(OldConfigVersionPath);
if(Directory.GetFiles(OldConfigFolderPath).Length == 0 && Directory.GetDirectories(OldConfigFolderPath).Length == 0)
Directory.Delete(OldConfigFolderPath);
else
Logger.Warn("Old config folder still cotains some files/directories. They will not get deleted.");
}
if (!File.Exists(ConfigPath))
return;
SetDefaults();
if(!ReadConfig())
{
Logger.Error("Failed to read legacy config file!");
}
MoveToNewFormat();
//SaveConfig();
}
public static void SetDefaults()
{
AltStaffs = true;
MagicStones = true;
GodStone = true;
DemonCrown = true;
HeartLocket = true;
Magnets = true;
NinjaGear = true;
ReinforcedVest = true;
AncientForges = true;
RedBrickFurniture = true;
AncientMuramasa = true;
GasterBlaster = true;
SpearofJustice = true;
WormholeMirror = true;
CellPhoneUpgrade = true;
CellPhoneResprite = true;
RodofWarping = true;
RodofWarpingChaosState = 1f;
EmblemofDeath = true;
BuildingMaterials = true;
BaseballBats = true;
AncientOrb = true;
CellPhoneResprite = true;
ExtraDyes = true;
Autofisher = true;
MechanicsRodOften = true;
ChestVacuum = true;
}
public static bool ReadConfig()
{
if(Configuration.Load())
{
Configuration.Get(AltStaffsKey, ref AltStaffs);
Configuration.Get(MagicStonesKey, ref MagicStones);
Configuration.Get(GodStoneKey, ref GodStone);
Configuration.Get(DemonCrownKey, ref DemonCrown);
Configuration.Get(HeartLocketKey, ref HeartLocket);
Configuration.Get(MagnetsKey, ref Magnets);
Configuration.Get(NinjaGearKey, ref NinjaGear);
Configuration.Get(ReinforcedVestKey, ref ReinforcedVest);
Configuration.Get(AncientForgesKey, ref AncientForges);
Configuration.Get(RedBrickFurnitureKey, ref RedBrickFurniture);
Configuration.Get(AncientMuramasaKey, ref AncientMuramasa);
Configuration.Get(GasterBlasterKey, ref GasterBlaster);
Configuration.Get(SpearofJusticeKey, ref SpearofJustice);
Configuration.Get(WormholeMirrorKey, ref WormholeMirror);
Configuration.Get(CellPhoneUpgradeKey, ref CellPhoneUpgrade);
Configuration.Get(CellPhoneRespriteKey, ref CellPhoneResprite);
Configuration.Get(RodofWarpingKey, ref RodofWarping);
Configuration.Get(RodofWarpingChaosStateKey, ref RodofWarpingChaosState);
Configuration.Get(EmblemofDeathKey, ref EmblemofDeath);
Configuration.Get(BuildingMaterialsKey, ref BuildingMaterials);
Configuration.Get(BaseballBatsKey, ref BaseballBats);
Configuration.Get(ExtraDyesKey, ref ExtraDyes);
Configuration.Get(AutofisherKey, ref Autofisher);
Configuration.Get(AncientOrbKey, ref AncientOrb);
Configuration.Get(MechanicsRodOftenKey, ref MechanicsRodOften);
Configuration.Get(ChestVacuumKey, ref ChestVacuum);
return true;
}
return false;
}
private static void MoveToNewFormat()
{
Logger.Warn("Migrating to new config format...");
string newConfigPathClient = Path.Combine(ConfigManager.ModConfigPath,
nameof(GoldensMisc) + '_' + ClientConfig.ConfigName + ".json");
var newConfigClient = new Preferences(newConfigPathClient);
newConfigClient.Put(CellPhoneRespriteKey, CellPhoneResprite);
newConfigClient.Save();
string newConfigPathServer = Path.Combine(ConfigManager.ModConfigPath,
nameof(GoldensMisc) + '_' + ServerConfig.ConfigName + ".json");
if(!File.Exists(newConfigPathServer))
File.Move(ConfigPath, newConfigPathServer);
else
File.Delete(ConfigPath);
}
}
}