-
Notifications
You must be signed in to change notification settings - Fork 0
/
2009scape.cs
99 lines (92 loc) · 2.81 KB
/
2009scape.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
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
class Program
{
static void Main()
{
Console.WriteLine("Start...");
// Define the file paths
string jarPath = "rt4-client.jar";
string javaInstaller = "java_installer.msi";
string configPath = "config.json";
string configContent = @"
{
""ip_management"": ""play.2009scape.org"",
""ip_address"": ""play.2009scape.org"",
""world"": 1,
""server_port"": 43594,
""wl_port"": 43595,
""js5_port"": 43595,
""ui_scale"": 1,
""fps"": 0
}";
try
{
// Extract resources
ExtractResource("Namespace.rt4-client.jar", jarPath);
ExtractResource("Namespace.java_installer.msi", javaInstaller);
// Write to config.json
Console.WriteLine("Writing to config.json...");
File.WriteAllText(configPath, configContent);
Console.WriteLine("Write complete.");
// Check if Java is installed
Console.WriteLine("Checking for Java installation...");
if (!IsJavaInstalled())
{
Console.WriteLine("Java not found. Installing Java...");
Process.Start(javaInstaller).WaitForExit();
}
else
{
Console.WriteLine("Java is already installed.");
}
// Run rt4-client.jar with Java
Console.WriteLine("Running rt4-client.jar with Java...");
Process.Start("java", "-jar " + jarPath).WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
Console.ReadLine();
}
}
static void ExtractResource(string resourceName, string filePath)
{
if (!File.Exists(filePath))
{
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
{
stream.CopyTo(fileStream);
}
}
}
static bool IsJavaInstalled()
{
try
{
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "java",
Arguments = "-version",
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (Process pr = Process.Start(psi))
{
using (StreamReader reader = pr.StandardError)
{
string output = reader.ReadToEnd();
return output.Contains("version");
}
}
}
catch
{
return false;
}
}
}