-
Notifications
You must be signed in to change notification settings - Fork 2
/
LibList.cs
62 lines (51 loc) · 1.25 KB
/
LibList.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
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ModLauncher
{
class LibList
{
private string Filename { get; set; }
public LibList(string gamePath, string modDirectory)
{
this.Filename = gamePath + "\\" + modDirectory + "\\scripts\\liblist.gam";
Console.WriteLine(this.Filename);
}
private bool GetValue(string line, string forSearch, out string value)
{
value = "";
try
{
line = line.Trim();
int forSearchLength = forSearch.Length;
int findMaterial = line.IndexOf(forSearch);
if (findMaterial < 0) // If there's no forSearch in line
return false;
if (findMaterial > 0) // If forSearch is further than 0 symbol, i.e.: "name" "game" - it's just value, not parameter name
return false;
value = line.Substring(forSearchLength + 1).Replace('/', '\\').Trim(trimChars: '"');
return true;
}
catch { }
return false;
}
public string GetGameName()
{
string[] file = new string[] { };
try
{
file = File.ReadAllLines(this.Filename);
}
catch { }
foreach (string line in file)
{
string value = "";
bool foundGameName = GetValue(line, "game", out value);
if (foundGameName)
return value;
}
return "";
}
}
}