-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data.cs
137 lines (125 loc) · 4.81 KB
/
Data.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
/*
ttfs2mix TTFS to MIX utility
Copyright (C) 2020 Unstoppable
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
*/
using System;
using System.Globalization;
using System.IO;
using System.Reflection;
namespace Ttfs2Mix
{
public struct PathsStruct
{
public string FileBase { get; internal set; }
public string FileClient { get; internal set; }
public string FileFDS { get; internal set; }
public bool UseRenFolder { get; internal set; }
}
internal static class Data
{
public static CultureInfo DefaultCulture => CultureInfo.InvariantCulture; // To fix upper-lower wrong character issues.
public static string ExeLocation => Path.GetDirectoryName(AppContext.BaseDirectory);
public static PathsStruct ReadPaths()
{
//For paths
string fBase = "Renegade";
string fClient = "Client";
string fFDS = "FDS";
bool useRenFolder = false;
if (File.Exists(Path.Combine(ExeLocation, "data", "paths.ini")))
{
using (StreamReader fs = File.OpenText(Path.Combine(ExeLocation, "data", "paths.ini")))
{
bool isValidPaths = false;
while (!fs.EndOfStream)
{
string buf = fs.ReadLine();
if (buf.ToLower(DefaultCulture).Equals("[paths]"))
{
isValidPaths = true;
}
else if(isValidPaths)
{
string Key = buf.Substring(0, buf.IndexOf('='));
string Value = buf.Remove(0, Key.Length + 1);
switch (Key.ToLower(DefaultCulture))
{
case "filebase":
fBase = Value;
break;
case "fileclient":
fClient = Value;
break;
case "filefds":
fFDS = Value;
break;
case "userenfolder":
useRenFolder = Value == "true" || Value == "1";
break;
}
}
}
}
}
return new PathsStruct
{
FileBase = fBase,
FileClient = fClient,
FileFDS = fFDS,
UseRenFolder = useRenFolder
};
}
public static string GetTTFSDirectory(PathsStruct Paths)
{
try
{
if (Paths.UseRenFolder)
{
if (Directory.Exists(Path.Combine(ExeLocation, Paths.FileBase, Paths.FileClient))) //Client
{
return Path.Combine(ExeLocation, Paths.FileBase, Paths.FileClient, "ttfs");
}
else if (Directory.Exists(Path.Combine(ExeLocation, Paths.FileBase, Paths.FileFDS))) //Server
{
return Path.Combine(ExeLocation, Paths.FileBase, Paths.FileFDS, "ttfs");
}
else
{
return null;
}
}
else
{
var AppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
if (Directory.Exists(Path.Combine(AppData, Paths.FileBase, Paths.FileClient))) //Client
{
return Path.Combine(AppData, Paths.FileBase, Paths.FileClient, "ttfs");
}
else if (Directory.Exists(Path.Combine(ExeLocation, Paths.FileBase, Paths.FileFDS))) //This case will be always server.
{
return Path.Combine(ExeLocation, Paths.FileBase, Paths.FileFDS, "ttfs");
}
else
{
return null;
}
}
}
catch(Exception ex)
{
if (ex is ArgumentException or ArgumentNullException)
{
return null;
}
else
{
throw;
}
}
}
}
}