Localize UI text and add copy progress bar
This commit is contained in:
@@ -5,6 +5,7 @@ using Windows.Win32.System.Ioctl;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Win32.Storage.FileSystem;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
using static Windows.Win32.PInvoke;
|
||||
using static BadBuilder.Formatter.Constants;
|
||||
@@ -12,6 +13,7 @@ using static BadBuilder.Formatter.Utilities;
|
||||
|
||||
namespace BadBuilder.Formatter
|
||||
{
|
||||
[SupportedOSPlatform("windows")]
|
||||
public static class DiskFormatter
|
||||
{
|
||||
public static unsafe string FormatVolume(char driveLetter, long diskSize)
|
||||
@@ -35,30 +37,30 @@ namespace BadBuilder.Formatter
|
||||
process.WaitForExit();
|
||||
|
||||
if (process.ExitCode == 0) return "";
|
||||
else return Error($"Native format failed with exit code: {process.ExitCode}");
|
||||
else return Error($"Die native Formatierung ist mit dem Exitcode {process.ExitCode} fehlgeschlagen.");
|
||||
}
|
||||
|
||||
string devicePath = $"\\\\.\\{driveLetter}:";
|
||||
uint volumeID = GetVolumeID();
|
||||
|
||||
SafeFileHandle driveHandle = OpenDeviceHandle(devicePath);
|
||||
if (driveHandle.IsInvalid) return Error("Unable to open device. GetLastError: " + Marshal.GetLastWin32Error());
|
||||
if (driveHandle.IsInvalid) return Error("Gerät konnte nicht geöffnet werden. GetLastError: " + Marshal.GetLastWin32Error());
|
||||
|
||||
if (!EnableExtendedDASDIO(driveHandle) || !LockDevice(driveHandle))
|
||||
return Error($"Failed to initialize device access. GetLastError: {Marshal.GetLastWin32Error()}");
|
||||
return Error($"Gerätezugriff konnte nicht initialisiert werden. GetLastError: {Marshal.GetLastWin32Error()}");
|
||||
|
||||
DISK_GEOMETRY diskGeometry;
|
||||
if (!TryGetDiskGeometry(driveHandle, out diskGeometry))
|
||||
return Error($"Failed to get disk geometry. GetLastError: {Marshal.GetLastWin32Error()}");
|
||||
return Error($"Datenträgergeometrie konnte nicht ermittelt werden. GetLastError: {Marshal.GetLastWin32Error()}");
|
||||
|
||||
PARTITION_INFORMATION partitionInfo;
|
||||
bool isGPT = false;
|
||||
if (!TryGetPartitionInfo(driveHandle, ref diskGeometry, out partitionInfo, out isGPT))
|
||||
return Error($"Failed to get partition information. GetLastError: {Marshal.GetLastWin32Error()}");
|
||||
return Error($"Partitionsinformationen konnten nicht ermittelt werden. GetLastError: {Marshal.GetLastWin32Error()}");
|
||||
|
||||
uint totalSectors = (uint)(partitionInfo.PartitionLength / diskGeometry.BytesPerSector);
|
||||
if (!IsValidFAT32Size(totalSectors))
|
||||
return Error("Invalid drive size for FAT32.");
|
||||
return Error("Ungültige Laufwerksgröße für FAT32.");
|
||||
|
||||
FAT32BootSector bootSector = InitializeBootSector(diskGeometry, partitionInfo, totalSectors, volumeID);
|
||||
FAT32FsInfoSector fsInfo = InitializeFsInfo();
|
||||
@@ -69,12 +71,12 @@ namespace BadBuilder.Formatter
|
||||
return formatOutput;
|
||||
|
||||
if (!UnlockDevice(driveHandle) || !DismountVolume(driveHandle))
|
||||
return Error($"Failed to release the device. GetLastError: {Marshal.GetLastWin32Error()}");
|
||||
return Error($"Gerät konnte nicht freigegeben werden. GetLastError: {Marshal.GetLastWin32Error()}");
|
||||
|
||||
driveHandle.Dispose();
|
||||
|
||||
if (!SetVolumeLabel($"{driveLetter}:", "BADUPDATE"))
|
||||
return Error($"Unable to set volume label. GetLastError: {Marshal.GetLastWin32Error()}");
|
||||
return Error($"Volumenbezeichnung konnte nicht gesetzt werden. GetLastError: {Marshal.GetLastWin32Error()}");
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
@@ -222,7 +224,7 @@ namespace BadBuilder.Formatter
|
||||
uint clusterCount = userAreaSize / bootSector.SectorsPerCluster;
|
||||
|
||||
if (clusterCount < 65536 || clusterCount > 0x0FFFFFFF)
|
||||
return Error("The drive's cluster count is out of range (65536 < clusterCount < 0x0FFFFFFF)");
|
||||
return Error("Die Clusteranzahl des Laufwerks liegt außerhalb des gültigen Bereichs (65536 < clusterCount < 0x0FFFFFFF).");
|
||||
|
||||
fsInfo.FreeClusterCount = clusterCount - 1;
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ CloseHandle
|
||||
VirtualAlloc
|
||||
VirtualFree
|
||||
SetVolumeLabelW
|
||||
GUID
|
||||
DISK_GEOMETRY
|
||||
PARTITION_INFORMATION
|
||||
PARTITION_INFORMATION_EX
|
||||
@@ -1,12 +1,15 @@
|
||||
using Windows.Win32.Foundation;
|
||||
#pragma warning disable CA1416
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.System.Memory;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
using static Windows.Win32.PInvoke;
|
||||
using static BadBuilder.Formatter.Constants;
|
||||
|
||||
namespace BadBuilder.Formatter
|
||||
{
|
||||
[SupportedOSPlatform("windows")]
|
||||
static class Utilities
|
||||
{
|
||||
internal static byte[] StructToBytes<T>(T @struct) where T : struct
|
||||
@@ -80,7 +83,7 @@ namespace BadBuilder.Formatter
|
||||
fixed (byte* pData = &data[0])
|
||||
{
|
||||
if (!WriteFile(new HANDLE(hDevice.DangerousGetHandle()), pData, numberOfSectors * bytesPerSector, null, null))
|
||||
ExitWithError($"Unable to write sectors to FAT32 device, exiting. GetLastError: {Marshal.GetLastWin32Error()}");
|
||||
ExitWithError($"Sektoren konnten nicht auf das FAT32-Gerät geschrieben werden. Beende mit Fehler. GetLastError: {Marshal.GetLastWin32Error()}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +103,7 @@ namespace BadBuilder.Formatter
|
||||
writeSize = (numberOfSectors > burstSize) ? burstSize : numberOfSectors;
|
||||
|
||||
if (!WriteFile(new HANDLE(hDevice.DangerousGetHandle()), pZeroSector, writeSize * bytesPerSector, null, null))
|
||||
ExitWithError($"Unable to write sectors to FAT32 device, exiting. GetLastError: {Marshal.GetLastWin32Error()}");
|
||||
ExitWithError($"Sektoren konnten nicht auf das FAT32-Gerät geschrieben werden. Beende mit Fehler. GetLastError: {Marshal.GetLastWin32Error()}");
|
||||
|
||||
numberOfSectors -= writeSize;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user