-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
179 lines (165 loc) · 6.04 KB
/
Program.cs
File metadata and controls
179 lines (165 loc) · 6.04 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
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
/// <summary>
/// DeleteJavaCheck-rewritten is an improved version from my original DeleteJavaCheck program with more automation
/// Current Version: 2.0.1
/// Changelog:
/// - Rereleased V2.0, but with the missing packages
/// </summary>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.IO;
using System.Reflection;
namespace DeleteJavaCheck_Rewritten
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("DeleteJavaCheck 2.0 (Assembly: {0}) Running!", Assembly.GetEntryAssembly().GetName().Version);
string targetFile = @"\javacheck.jar";
bool checkCustom = ReadSettings();
DestroyOld(targetFile);
DestroyNew(targetFile);
if (checkCustom)
{
DestroyCustom(targetFile);
}
EndProgram();
}
static bool ReadSettings()
{
try
{
System.Collections.Specialized.NameValueCollection appSettings = ConfigurationManager.AppSettings;
if (appSettings.Count == 0)
{
Console.WriteLine("AppSettings is empty. Will not check custom installs!");
}
else
{
string directoryPath = appSettings[0];
if (Directory.Exists(directoryPath))
{
Console.WriteLine("Will check: {0}", directoryPath);
return true;
}
else
{
Console.WriteLine("Custom installation directory: '{0}' is not valid", directoryPath);
}
}
}
catch (ConfigurationErrorsException)
{
Console.WriteLine("Error reading app settings");
}
return false;
}
static void WriteSetting()
{
Console.WriteLine("Enter the new directory (that ends with \\game)");
string dir = Console.ReadLine();
try
{
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var settings = configFile.AppSettings.Settings;
settings["customLocation"].Value = dir;
configFile.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
}
catch (ConfigurationErrorsException)
{
Console.WriteLine("Error writing app settings!");
}
}
static void WriteSection(string phrase, char character)
{
string border = new string(character, phrase.Length + 4);
Console.WriteLine(border);
Console.WriteLine("{0} {1} {0}", character, phrase);
Console.WriteLine(border);
}
// destroys javacheck.jar in the current launcher, but the one that doesn't support Bedrock
static void DestroyOld(string targetFile)
{
Console.WriteLine("\n");
WriteSection("Checking Old Launcher", "=".ToCharArray()[0]);
string targetDir = @"C:\Program Files (x86)\Minecraft Launcher\game";
if (Directory.Exists(targetDir))
{
Console.WriteLine("Java Launcher Exists!");
targetDir += targetFile;
if (File.Exists(targetDir))
{
File.Delete(targetDir);
Console.WriteLine("File deleted!");
}
else
{
Console.WriteLine("File already deleted!");
}
}
else
{
Console.WriteLine("Java Laucher doesn't exist or you have a custom installation location!");
}
}
// destroys javacheck.jar in the new Microsoft Store launcher
static void DestroyNew(string targetFile)
{
Console.WriteLine("\n");
WriteSection("Checking New Launcher", "=".ToCharArray()[0]);
string targetDir = @"%LOCALAPPDATA%\Packages\Microsoft.4297127D64EC6_8wekyb3d8bbwe\LocalCache\Local\game";
targetDir = Environment.ExpandEnvironmentVariables(targetDir);
if (Directory.Exists(targetDir))
{
Console.WriteLine("Bedrock Launcher Exists!");
targetDir += targetFile;
if (File.Exists(targetDir))
{
File.Delete(targetDir);
Console.WriteLine("File deleted!");
}
else
{
Console.WriteLine("File already deleted!");
}
}
else
{
Console.WriteLine("Bedrock Laucher Doesn't Exist!");
}
}
// destroys javacheck.jar in the user's custom install
static void DestroyCustom(string targetFile)
{
Console.WriteLine("\n");
WriteSection("Checking Custom Launcher", "=".ToCharArray()[0]);
string targetDir = ConfigurationManager.AppSettings[0];
targetDir += targetFile;
if (File.Exists(targetDir))
{
File.Delete(targetDir);
Console.WriteLine("File deleted!");
}
else
{
Console.WriteLine("File already deleted!");
}
}
static void EndProgram()
{
Console.WriteLine("\nProgram completed. Enter one of the following options:");
Console.WriteLine("1: Enter/update custom file directory");
Console.WriteLine("Enter: Quit");
string userInput = Console.ReadLine();
if (userInput == "1")
{
WriteSetting();
}
}
}
}