public static GetPhysicalPath ( string letter ) : string | ||
letter | string | |
return | string |
public static void LaunchQemu(string iso, bool usb = false) { var f = Program.GetTemporaryDirectory(); Paths.Add(f); var floppy = Path.GetExtension(iso).ToLower() == ".img"; var ext = new SevenZipExtractor(); File.WriteAllBytes(Path.Combine(f, "qemutmp.7z"), Resources.qemu); ext.Extract(Path.Combine(f, "qemutmp.7z"), f); var p = new Process { StartInfo = { UseShellExecute = false }, EnableRaisingEvents = true }; p.StartInfo.FileName = Path.Combine(f, "qemu.exe"); p.StartInfo.WorkingDirectory = f; if (usb) { var logicalDiskId = iso.Substring(0, 2); var deviceId = Utils.GetPhysicalPath(logicalDiskId); p.StartInfo.Arguments = " -L . -boot c -drive file=" + deviceId + ",if=ide,index=0,media=disk -m 512 -localtime"; p.StartInfo.UseShellExecute = true; p.StartInfo.Verb = "runas"; } else { p.StartInfo.Arguments = "-m 512 -localtime -M pc " + (floppy ? "-fda" : "-cdrom") + " \"" + iso + "\""; } Thread.Sleep(300); p.Start(); ext.Close(); p.Exited += (sender, args) => { Program.SafeDel(f); Paths.Remove(f); }; }
public static void InstallMBR(string l, byte[] theMbr) { var mbr = new byte[512]; using ( var device = Utils.CreateFile(Utils.GetPhysicalPath(l.ToLower().Substring(0, 2)), 0x80000000 | 0x40000000, 1 | 2, IntPtr.Zero, 3, /*Utils.FILE_ATTRIBUTE_SYSTEM | Utils.FILE_FLAG_SEQUENTIAL_SCAN*/ Utils.FILE_FLAG_NO_BUFFERING, IntPtr.Zero)) { if (device.IsInvalid) { throw new IOException("Unable to access drive. Win32 Error Code " + Marshal.GetLastWin32Error()); } using (FileStream src = new FileStream(device, FileAccess.ReadWrite)) { src.Read(mbr, 0, 512); Array.Copy(theMbr, mbr, theMbr.Length); src.Position = 0; src.Write(mbr, 0, 512); } } }