Skip to content

Commit 1b2d00a

Browse files
committed
Code improvements
1 parent d6447d3 commit 1b2d00a

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

Files.Launcher/Win32API.cs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,6 @@ public static string[] CommandLineToArgs(string commandLine)
9393
}
9494
}
9595

96-
public static void UnlockBitlockerDrive(string drive, string password)
97-
{
98-
try
99-
{
100-
Process process = new Process();
101-
process.StartInfo.UseShellExecute = true;
102-
process.StartInfo.Verb = "runas";
103-
process.StartInfo.FileName = "powershell.exe";
104-
process.StartInfo.CreateNoWindow = true;
105-
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
106-
process.StartInfo.Arguments = $"-command \"$SecureString = ConvertTo-SecureString '{password}' -AsPlainText -Force; Unlock-BitLocker -MountPoint '{drive}' -Password $SecureString\"";
107-
process.Start();
108-
process.WaitForExit(30 * 1000);
109-
}
110-
catch (Win32Exception)
111-
{
112-
// If user cancels UAC
113-
}
114-
}
115-
11696
public static (string icon, bool isCustom) GetFileOverlayIcon(string path)
11797
{
11898
var shfi = new Shell32.SHFILEINFO();
@@ -149,13 +129,19 @@ private static void RunPowershellCommand(string command, bool runAsAdmin)
149129
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
150130
process.StartInfo.Arguments = command;
151131
process.Start();
132+
process.WaitForExit(30 * 1000);
152133
}
153134
catch (Win32Exception)
154135
{
155136
// If user cancels UAC
156137
}
157138
}
158139

140+
public static void UnlockBitlockerDrive(string drive, string password)
141+
{
142+
RunPowershellCommand($"-command \"$SecureString = ConvertTo-SecureString '{password}' -AsPlainText -Force; Unlock-BitLocker -MountPoint '{drive}' -Password $SecureString\"", true);
143+
}
144+
159145
public static void OpenFormatDriveDialog(string drive)
160146
{
161147
// format requires elevation

Files/Filesystem/DriveItem.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ public async Task Update()
6868
try
6969
{
7070
// Delay is needed to apply the new name
71-
var properties = await Task.Delay(TimeSpan.FromSeconds(2)).ContinueWith(
72-
_ => Root.Properties.RetrievePropertiesAsync(new[] { "System.ItemNameDisplay" }).AsTask().WithTimeout(TimeSpan.FromSeconds(5)),
73-
TaskContinuationOptions.OnlyOnRanToCompletion).Unwrap();
71+
var properties = await Root.Properties.RetrievePropertiesAsync(new[] { "System.ItemNameDisplay" })
72+
.AsTask().WithTimeout(TimeSpan.FromSeconds(5));
7473
Text = (string)properties["System.ItemNameDisplay"];
7574
}
7675
catch (NullReferenceException)
7776
{
78-
7977
}
8078
}
8179

0 commit comments

Comments
 (0)