-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilities.cs
More file actions
163 lines (147 loc) · 5.61 KB
/
Utilities.cs
File metadata and controls
163 lines (147 loc) · 5.61 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
using System;
using System.Diagnostics;
using System.IO;
using System.Security.Principal;
using Microsoft.Win32;
using System.IO.Compression;
using System.Windows.Forms;
using System.Threading;
using System.Threading.Tasks;
namespace Fluster_GUI
{
public static class Utilities
{
public static bool IsRunAsAdministrator()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
public static bool RemoveOfficialROBLOX()
{
string command = "Get-AppxPackage ROBLOXCORPORATION.ROBLOX.* | Remove-AppPackage";
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "powershell.exe",
Arguments = $"-Command {command}",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (Process process = new Process { StartInfo = psi })
{
process.Start();
process.WaitForExit();
return process.ExitCode == 0;
}
}
public static event Action<int> ProgressChanged;
public static bool ExtractZipFile(string zipFilePath, string extractPath, ProgressBar progressBar)
{
try
{
using (ZipArchive archive = ZipFile.OpenRead(zipFilePath))
{
int totalEntries = archive.Entries.Count;
int extractedEntries = 0;
foreach (ZipArchiveEntry entry in archive.Entries)
{
while (true)
{
try
{
entry.ExtractToFile(Path.Combine(extractPath, entry.FullName), true);
extractedEntries++;
int progressPercentage = (int)((double)extractedEntries / totalEntries * 100);
progressBar?.Invoke((MethodInvoker)(() => progressBar.Value = progressPercentage));
break;
}
catch (IOException)
{
break;
}
}
}
}
return true;
}
catch (Exception ex)
{
return false;
}
}
public static bool AddAppxPackage(string appxManifestPath)
{
string addAppxCommand = $"powershell -Command \"Add-AppxPackage -path '{appxManifestPath}' -register\"";
int resultCode = 0;
bool result = RunCommand(addAppxCommand, out resultCode);
if (result && resultCode == 0)
{
while (!Directory.Exists("C:\\Fluster\\microsoft.system.package.metadata"))
{
Thread.Sleep(1000);
}
return true;
}
else
{
return false;
}
}
private static bool RunCommand(string command, out int exitCode)
{
using (Process process = new Process())
{
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "cmd.exe",
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
process.StartInfo = psi;
process.Start();
using (StreamWriter sw = process.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
sw.WriteLine(command);
sw.WriteLine("exit");
}
}
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
exitCode = process.ExitCode;
return exitCode == 0;
}
}
public static bool ToggleDeveloperMode(bool enable)
{
try
{
RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppModelUnlock", true);
if (key != null)
{
// Set the AllowDevelopmentWithoutDevLicense registry value based on the 'enable' parameter
int valueToSet = enable ? 1 : 0;
key.SetValue("AllowDevelopmentWithoutDevLicense", valueToSet, RegistryValueKind.DWord);
key.Close();
MessageBox.Show(enable ? "Developer Mode enabled successfully." : "Developer Mode disabled successfully.");
return true;
}
else
{
MessageBox.Show("Failed to access the registry key.");
return false;
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
return false;
}
}
}
}