|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
| 3 | +using System.Drawing; |
3 | 4 | using System.IO; |
4 | 5 | using System.Linq; |
5 | 6 | using System.Text; |
@@ -36,6 +37,16 @@ public static Mod Load(string localDir) |
36 | 37 | file?.UpdateLocalPath(localDir); |
37 | 38 | } |
38 | 39 |
|
| 40 | + if ((mod.IconObject == null) && (string.IsNullOrEmpty(mod.IconFile) == false)) |
| 41 | + { |
| 42 | + try |
| 43 | + { |
| 44 | + mod.IconObject = Image.FromFile(mod.IconFile); |
| 45 | + } |
| 46 | + catch |
| 47 | + { } |
| 48 | + } |
| 49 | + |
39 | 50 | return mod; |
40 | 51 | } |
41 | 52 |
|
@@ -116,6 +127,7 @@ public void CompleteInstall(string localDir) |
116 | 127 | var fe = Path.GetExtension(oivfile)?.ToLowerInvariant(); |
117 | 128 | if (fe == ".cwmm") continue; |
118 | 129 | var file = new ModFile(oivfile); |
| 130 | + file.LocalPath = file.SourcePath; |
119 | 131 | Files.Add(file); |
120 | 132 | } |
121 | 133 | } |
@@ -154,6 +166,7 @@ public void CompleteInstall(string localDir) |
154 | 166 |
|
155 | 167 | Log($"CompleteInstall: {DateTime.Now}"); |
156 | 168 |
|
| 169 | + SaveLogFile(); |
157 | 170 | } |
158 | 171 |
|
159 | 172 | public static ModType GetModType(string file) |
@@ -213,64 +226,73 @@ private void AddModFilesFromDir(string sourceDir) |
213 | 226 |
|
214 | 227 |
|
215 | 228 |
|
| 229 | + |
216 | 230 | private void LoadCWMMFile() |
217 | 231 | { |
| 232 | + Files.Clear(); |
218 | 233 | var fp = GetCWMMFilePath(); |
219 | 234 | if (string.IsNullOrEmpty(fp)) return; |
220 | 235 | if (File.Exists(fp) == false) return; |
221 | 236 | Log($"LoadCWMMFile: {fp}"); |
222 | | - try |
| 237 | + var f = new SimpleKvpFile(fp, true); |
| 238 | + if (f.FileError != null) |
223 | 239 | { |
224 | | - var lines = File.ReadAllLines(fp); |
225 | | - if (lines.Length < 6) return; |
226 | | - Name = lines[0]; |
227 | | - IconFile = lines[1]; |
228 | | - SourcePath = lines[2]; |
229 | | - Enum.TryParse(lines[3], out Type); |
230 | | - Enum.TryParse(lines[4], out Status); |
231 | | - int.TryParse(lines[5], out LoadOrder); |
232 | | - Files.Clear(); |
233 | | - for (int i = 6; i < lines.Length; i++) |
234 | | - { |
235 | | - AddModFile(lines[i]); |
236 | | - } |
| 240 | + Log($"Error: {f.FileError}"); |
237 | 241 | } |
238 | | - catch (Exception ex) |
| 242 | + Name = f.GetItem("Name"); |
| 243 | + IconFile = f.GetItem("Icon"); |
| 244 | + SourcePath = f.GetItem("Source"); |
| 245 | + Enum.TryParse(f.GetItem("Type"), out Type); |
| 246 | + Enum.TryParse(f.GetItem("Status"), out Status); |
| 247 | + int.TryParse(f.GetItem("Order"), out LoadOrder); |
| 248 | + int.TryParse(f.GetItem("Files"), out var count); |
| 249 | + for (var i = 0; i < count; i++) |
239 | 250 | { |
240 | | - Log($"Error: {ex}"); |
| 251 | + var mf = f.GetItem($"File{i}"); |
| 252 | + AddModFile(mf); |
241 | 253 | } |
242 | 254 | } |
243 | 255 | private void SaveCWMMFile() |
244 | 256 | { |
245 | 257 | var fp = GetCWMMFilePath(); |
246 | 258 | if (string.IsNullOrEmpty(fp)) return; |
247 | 259 | Log($"SaveCWMMFile: {fp}"); |
248 | | - try |
| 260 | + var f = new SimpleKvpFile(fp); |
| 261 | + f.SetItem("Name", Name); |
| 262 | + f.SetItem("Icon", IconFile); |
| 263 | + f.SetItem("Source", SourcePath); |
| 264 | + f.SetItem("Type", Type.ToString()); |
| 265 | + f.SetItem("Status", Status.ToString()); |
| 266 | + f.SetItem("Order", LoadOrder.ToString()); |
| 267 | + f.SetItem("Files", Files.Count.ToString()); |
| 268 | + for (var i = 0; i < Files.Count; i++) |
249 | 269 | { |
250 | | - var sb = new StringBuilder(); |
251 | | - sb.AppendLine(Name); |
252 | | - sb.AppendLine(IconFile); |
253 | | - sb.AppendLine(SourcePath); |
254 | | - sb.AppendLine(Type.ToString()); |
255 | | - sb.AppendLine(Status.ToString()); |
256 | | - sb.AppendLine(LoadOrder.ToString()); |
257 | | - foreach (var file in Files) |
258 | | - { |
259 | | - sb.AppendLine(file.SourcePath); |
260 | | - } |
261 | | - var str = sb.ToString(); |
262 | | - File.WriteAllText(fp, str); |
| 270 | + f.SetItem($"File{i}", Files[i].SourcePath); |
| 271 | + } |
| 272 | + f.Save(); |
| 273 | + if (f.FileError != null) |
| 274 | + { |
| 275 | + Log($"Error: {f.FileError}"); |
263 | 276 | } |
264 | | - catch (Exception ex) |
| 277 | + } |
| 278 | + private void SaveLogFile() |
| 279 | + { |
| 280 | + try |
265 | 281 | { |
266 | | - Log($"Error: {ex}"); |
| 282 | + var fp = GetLogFilePath(); |
| 283 | + File.AppendAllLines(fp, LogItems); |
267 | 284 | } |
| 285 | + catch { } |
268 | 286 | } |
269 | 287 |
|
270 | 288 | private string GetCWMMFilePath() |
271 | 289 | { |
272 | 290 | return $"{LocalPath}\\mod.cwmm"; |
273 | 291 | } |
| 292 | + private string GetLogFilePath() |
| 293 | + { |
| 294 | + return $"{LocalPath}\\log.cwmm"; |
| 295 | + } |
274 | 296 |
|
275 | 297 |
|
276 | 298 | private void Log(string s) |
|
0 commit comments