This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
VersionDir.cs
208 lines (178 loc) · 6.23 KB
/
VersionDir.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
using System;
using System.IO;
using System.Linq;
using System.Threading;
using static RobloxTweaker.MainVariables;
using static RobloxTweaker.OtherUtils;
using static RobloxTweaker.TexturesManager;
namespace RobloxTweaker
{
internal class VersionDir
{
//Write File
public static void WriteFile()
{
Console.WriteLine("[Writing File]");
File.WriteAllText(SETTINGS_FILE, ROBLOX_VERSION_DIR);
Thread.Sleep(300);
}
//Read File
public static void ReadFile()
{
if (File.Exists(SETTINGS_FILE))
{
Console.WriteLine("[Reading File]");
ROBLOX_VERSION_DIR = File.ReadAllLines(SETTINGS_FILE)[0];
Validate();
ROBLOX_TEXTURES_DIR = ROBLOX_VERSION_DIR + PATH_TO_TEXTURES_DIR;
ROBLOX_CONTENT_DIR = ROBLOX_VERSION_DIR + PATH_TO_CONTENT_DIR;
ROBLOX_VERSION_DIR_TYPE = Type(ROBLOX_VERSION_DIR);
Thread.Sleep(300);
}
else
{
Console.WriteLine("[File not found]");
Thread.Sleep(1000);
Select();
WriteFile();
ReadFile();
}
}
//Select Directory
public static bool Select(bool canCancel = false)
{
Console.Clear();
int useCancel = -1;
if (canCancel)
{
useCancel = 1;
}
string[] dirs;
try
{
dirs = Directory.GetDirectories(ROBLOX_VERSIONS_DIR);
}
catch (DirectoryNotFoundException)
{
dirs = null;
Console.WriteLine("Roblox isn't installed...");
Thread.Sleep(3000);
Environment.Exit(2);
}
string[] valid_dirs = Array.Empty<string>();
for (int i = 0; i < dirs.Length; i++)
{
string version_folder = dirs[i].Split('\\').Last();
if (version_folder == ROBLOX_VERSION_DIR.Split('\\').Last())
{
continue;
}
else if (version_folder.StartsWith("version-") && version_folder.Length == 24)
{
valid_dirs = valid_dirs.Append(dirs[i]).ToArray();
}
}
if (valid_dirs.Length == 0)
{
Console.WriteLine("No Version was found, please try reinstalling Roblox...");
Thread.Sleep(3000);
Environment.Exit(2);
}
string title = "Select a Roblox version to use:";
string[] options = Array.Empty<string>();
for (int i = 0; i < valid_dirs.Length; i++)
{
try
{
string option = string.Format(
"{0} | {1} | Surface Textures: {2} | {3}",
valid_dirs[i].Split('\\').Last(),
Type(valid_dirs[i]),
CountTextures(valid_dirs[i] + PATH_TO_TEXTURES_DIR),
Directory.GetCreationTime(valid_dirs[i])
);
options = options.Append(option).ToArray();
} catch {
continue;
}
}
string[] extras = Array.Empty<string>();
if (File.Exists(SETTINGS_FILE))
{
extras = extras.Append(string.Format("Current Selected Version: {0}\nDirectory: {1}", ROBLOX_VERSION_DIR_TYPE, ROBLOX_VERSION_DIR)).ToArray();
}
int choice = Menu(title, options, extras, 0, useCancel, "\n");
Console.Clear();
if (choice == 0)
{
return false;
}
ROBLOX_VERSION_DIR = valid_dirs[choice - 1];
return true;
}
//Update
public static void Update(bool canCancel = false)
{
string old_dir = ROBLOX_VERSION_DIR.Split('\\').Last();
string old_type = ROBLOX_VERSION_DIR_TYPE;
bool selected = Select(canCancel);
if (!selected)
{
return;
}
WriteFile();
ReadFile();
string[] extras =
{
string.Format("New: {0} | {1}", ROBLOX_VERSION_DIR.Split('\\').Last(), ROBLOX_VERSION_DIR_TYPE),
string.Format("Old: {0} | {1}", old_dir, old_type)
};
_ = GenerateMenu("[Directory Updated]", Array.Empty<string>(), extras, 1);
}
//Get Type
public static string Type(string directory)
{
string[] files = Directory.GetFiles(directory);
for (int i = 0; i < files.Length; i++)
{
if (files[i].Split('\\').Last() == "RobloxPlayerBeta.exe")
{
return "Roblox Player";
}
else if (files[i].Split('\\').Last() == "RobloxStudioBeta.exe")
{
return "Roblox Studio";
}
}
return "Unknown";
}
//Validate Directory
public static void Validate()
{
string status;
bool valid;
string version_folder = ROBLOX_VERSION_DIR.Split('\\').Last();
if (!ROBLOX_VERSION_DIR.StartsWith(ROBLOX_VERSIONS_DIR) || !version_folder.StartsWith("version-") || version_folder.Length != 24 || !Directory.Exists(ROBLOX_VERSION_DIR))
{
status = "Invalid/Outdated";
valid = false;
}
else if (ROBLOX_VERSION_DIR.StartsWith(ROBLOX_VERSIONS_DIR) && version_folder.StartsWith("version-") && version_folder.Length == 24)
{
status = "Valid";
valid = true;
}
else
{
status = "Invalid?";
valid = false;
}
Console.WriteLine("[Directory: {0}]", status);
if (!valid)
{
Thread.Sleep(2000);
Update();
}
}
}
}