mirror of
https://github.com/Metabolix/HackBGRT.git
synced 2026-09-12 07:06:06 -07:00
Try to avoid mistaking C: for ESP
This commit is contained in:
+36
-14
@@ -22,6 +22,9 @@ public sealed class Esp {
|
|||||||
/** Output of mountvol. */
|
/** Output of mountvol. */
|
||||||
private static string MountvolOutput;
|
private static string MountvolOutput;
|
||||||
|
|
||||||
|
/** Possible drive letter for the ESP. */
|
||||||
|
public static string DriveLetters = "ABZYXWVUTSRQPONMLKJIHGFEDC";
|
||||||
|
|
||||||
/** Does MountvolOutput contain /S? */
|
/** Does MountvolOutput contain /S? */
|
||||||
public static bool MountvolESPNotSupported {
|
public static bool MountvolESPNotSupported {
|
||||||
get {
|
get {
|
||||||
@@ -80,11 +83,17 @@ public sealed class Esp {
|
|||||||
*
|
*
|
||||||
* @return true if the drive was found.
|
* @return true if the drive was found.
|
||||||
*/
|
*/
|
||||||
public static bool Find() {
|
public static bool FindOrMount() {
|
||||||
if (MountInstance != null) {
|
return Location != null || FindWithMountvol() || Mount() || TryAllDrives();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
Setup.Log("Esp.Find()");
|
|
||||||
|
/**
|
||||||
|
* Find the EFI System Partition, if it's already mounted.
|
||||||
|
*
|
||||||
|
* @return true if the drive was found.
|
||||||
|
*/
|
||||||
|
private static bool FindWithMountvol() {
|
||||||
|
Setup.Log("Esp: Detect from mountvol output.");
|
||||||
try {
|
try {
|
||||||
// Match "The EFI System Partition is mounted at E:\" with some language support.
|
// Match "The EFI System Partition is mounted at E:\" with some language support.
|
||||||
MountvolOutput = Setup.Execute("mountvol", "", false);
|
MountvolOutput = Setup.Execute("mountvol", "", false);
|
||||||
@@ -93,17 +102,29 @@ public sealed class Esp {
|
|||||||
if (m.Success && TryPath(m.Groups[1].Captures[0].Value)) {
|
if (m.Success && TryPath(m.Groups[1].Captures[0].Value)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Setup.Log("Esp.Find: no match");
|
Setup.Log("Esp: no match");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Setup.Log($"Esp.Find: {e.ToString()}");
|
Setup.Log($"Esp: {e.ToString()}");
|
||||||
}
|
}
|
||||||
for (char c = 'A'; c <= 'Z'; ++c) {
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try all drive letters to find the EFI System Partition.
|
||||||
|
*
|
||||||
|
* @return true if the drive was found.
|
||||||
|
*/
|
||||||
|
private static bool TryAllDrives() {
|
||||||
|
Setup.Log("Esp: Detect by trying all drive letters.");
|
||||||
|
foreach (char c in DriveLetters) {
|
||||||
if (TryPath(c + ":\\")) {
|
if (TryPath(c + ":\\")) {
|
||||||
Setup.Log($"Esp.Find: found {c}");
|
Setup.Log($"Esp: found {c}");
|
||||||
|
if (c == 'C') {
|
||||||
|
Setup.Log("Esp: WARNING: It's unlikely that C: is really the ESP.");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Setup.Log("Esp.Find: not found");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,14 +133,15 @@ public sealed class Esp {
|
|||||||
*
|
*
|
||||||
* @return true if the drive was mounted, false otherwise.
|
* @return true if the drive was mounted, false otherwise.
|
||||||
*/
|
*/
|
||||||
public static bool Mount() {
|
private static bool Mount() {
|
||||||
if (MountInstance != null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (MountvolESPNotSupported) {
|
if (MountvolESPNotSupported) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (char c = 'A'; c <= 'Z'; ++c) {
|
Setup.Log("Esp: Try to mount with mountvol.");
|
||||||
|
foreach (char c in DriveLetters) {
|
||||||
|
if (Directory.Exists(c + ":\\")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Setup.Log($"Esp.Mount: {c}");
|
Setup.Log($"Esp.Mount: {c}");
|
||||||
if (Setup.Execute("mountvol", c + ": /S", true) != null) {
|
if (Setup.Execute("mountvol", c + ": /S", true) != null) {
|
||||||
MountInstance = new Esp();
|
MountInstance = new Esp();
|
||||||
|
|||||||
+4
-1
@@ -298,7 +298,7 @@ public class Setup {
|
|||||||
throw new SetupException("The ESP path doesn't look like an EFI System Partition.");
|
throw new SetupException("The ESP path doesn't look like an EFI System Partition.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Esp.Location == null && !Esp.Find() && !Esp.Mount() && !Batch) {
|
if (!Esp.FindOrMount() && !Batch) {
|
||||||
WriteLine("EFI System Partition was not found.");
|
WriteLine("EFI System Partition was not found.");
|
||||||
if (Esp.MountvolESPNotSupported) {
|
if (Esp.MountvolESPNotSupported) {
|
||||||
WriteLine("Your computer doesn't support mountvol /S. You have to mount ESP manually.");
|
WriteLine("Your computer doesn't support mountvol /S. You have to mount ESP manually.");
|
||||||
@@ -317,6 +317,9 @@ public class Setup {
|
|||||||
throw new SetupException("EFI System Partition was not found.");
|
throw new SetupException("EFI System Partition was not found.");
|
||||||
}
|
}
|
||||||
WriteLine($"EFI System Partition location is {Esp.Location}");
|
WriteLine($"EFI System Partition location is {Esp.Location}");
|
||||||
|
if (Esp.Location.StartsWith("C:")) {
|
||||||
|
WriteLine("Warning: EFI System Partition is not normally C: drive.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user