-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallFileReader.cs
More file actions
66 lines (60 loc) · 1.97 KB
/
Copy pathInstallFileReader.cs
File metadata and controls
66 lines (60 loc) · 1.97 KB
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
using System;
using System.Collections.Generic;
using System.Text;
namespace VModLoader
{
/// <summary>
/// Deals with reading/writing to install files.
/// </summary>
static internal class InstallFileReader
{
/// <summary>
/// Reads the given .vml file as install data.
/// </summary>
/// <param name="file">The install file to read.</param>
/// <returns>The installs loaded from the .vml</returns>
internal static List<Install> ReadInstallFile(string file)
{
List<Install> mods = [];
try
{
string[] lines = File.ReadAllLines(file);
for (int i = 0; i < lines.Length; i += 3)
{
if (i + 2 >= lines.Length)
{
break;
}
mods.Add(new Install(lines[i], lines[i + 1], lines[i + 2]));
}
} catch(Exception e)
{
Console.WriteLine($"Error when reading install file {file}: {e.Message}");
}
return mods;
}
/// <summary>
/// Writes the install data to a file.
/// </summary>
/// <param name="file">The file to write it to.</param>
/// <param name="installs">The installs to write to the file.</param>
internal static void WriteInstallFile(string file, List<Install> installs)
{
try
{
List<string> content = [];
foreach (Install inst in installs)
{
content.Add(inst.args);
content.Add(inst.executablePath);
content.Add(inst.name);
}
File.WriteAllLines(file, content);
}
catch (Exception e)
{
Console.WriteLine($"Error when writing to install file {file}: {e.Message}");
}
}
}
}