mirror of
https://github.com/Metabolix/HackBGRT.git
synced 2026-09-26 22:11:32 -07:00
Elevate privileges only when needed
This commit is contained in:
+19
-6
@@ -391,6 +391,25 @@ public class Setup: SetupHelper {
|
|||||||
* @param actions The actions to run.
|
* @param actions The actions to run.
|
||||||
*/
|
*/
|
||||||
protected void RunPrivilegedActions(IEnumerable<string> actions) {
|
protected void RunPrivilegedActions(IEnumerable<string> actions) {
|
||||||
|
if (!HasPrivileges() && !DryRun) {
|
||||||
|
var batchStr = Batch ? "batch" : "";
|
||||||
|
var self = Assembly.GetExecutingAssembly().Location;
|
||||||
|
var arg = String.Join(" ", actions);
|
||||||
|
var result = 0;
|
||||||
|
try {
|
||||||
|
result = RunElevated(self, $"is-elevated {batchStr} {arg}");
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SetupException($"Privileged action ({arg}) failed: {e.Message}");
|
||||||
|
}
|
||||||
|
if (result != 0) {
|
||||||
|
throw new SetupException($"Privileged action ({arg}) failed!");
|
||||||
|
}
|
||||||
|
Console.WriteLine($"Privileged action ({arg}) completed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
InitEspPath();
|
||||||
|
InitEspInfo();
|
||||||
bool allowSecureBoot = false;
|
bool allowSecureBoot = false;
|
||||||
foreach (var arg in actions) {
|
foreach (var arg in actions) {
|
||||||
Log($"Running action '{arg}'.");
|
Log($"Running action '{arg}'.");
|
||||||
@@ -439,12 +458,6 @@ public class Setup: SetupHelper {
|
|||||||
Console.WriteLine("This installer needs to be run as administrator!");
|
Console.WriteLine("This installer needs to be run as administrator!");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!HasPrivileges() && !DryRun) {
|
|
||||||
var self = Assembly.GetExecutingAssembly().Location;
|
|
||||||
return RunElevated(self, String.Join(" ", args.Prepend("is-elevated")));
|
|
||||||
}
|
|
||||||
InitEspPath();
|
|
||||||
InitEspInfo();
|
|
||||||
var actions = args.Where(s => privilegedActions.Contains(s));
|
var actions = args.Where(s => privilegedActions.Contains(s));
|
||||||
if (actions.Count() > 0) {
|
if (actions.Count() > 0) {
|
||||||
RunPrivilegedActions(actions);
|
RunPrivilegedActions(actions);
|
||||||
|
|||||||
Reference in New Issue
Block a user