public void BootImage() { byte[] memoryStream = new byte[33 * 512]; for (int i = 0; i < memoryStream.Length; ++i) { memoryStream[i] = (byte)i; } CDBuilder builder = new CDBuilder(); builder.SetBootImage(new MemoryStream(memoryStream), BootDeviceEmulation.HardDisk, 0x543); CDReader fs = new CDReader(builder.Build(), false); Assert.True(fs.HasBootImage); using (Stream bootImg = fs.OpenBootImage()) { Assert.Equal(memoryStream.Length, bootImg.Length); for (int i = 0; i < bootImg.Length; ++i) { if (memoryStream[i] != bootImg.ReadByte()) { Assert.True(false, "Boot image corrupted"); } } } Assert.Equal(BootDeviceEmulation.HardDisk, fs.BootEmulation); Assert.Equal(0x543, fs.BootLoadSegment); }
protected override void DoRun() { DirectoryInfo di = new DirectoryInfo(_srcDir.Value); if (!di.Exists) { Console.WriteLine("The source directory doesn't exist!"); Environment.Exit(1); } CDBuilder builder = new CDBuilder(); if (_volLabelSwitch.IsPresent) { builder.VolumeIdentifier = _volLabelSwitch.Value; } if (_bootImage.IsPresent) { builder.SetBootImage(new FileStream(_bootImage.Value, FileMode.Open, FileAccess.Read), BootDeviceEmulation.NoEmulation, 0); } PopulateFromFolder(builder, di, di.FullName); builder.Build(_isoFileParam.Value); }
public override bool Execute() { Log.LogMessage(MessageImportance.Normal, "Creating ISO file: '{0}'", FileName.ItemSpec); try { CDBuilder builder = new CDBuilder(); builder.UseJoliet = UseJoliet; if (!string.IsNullOrEmpty(VolumeLabel)) { builder.VolumeIdentifier = VolumeLabel; } Stream bootImageStream = null; if (BootImage != null) { bootImageStream = new FileStream(BootImage.GetMetadata("FullPath"), FileMode.Open, FileAccess.Read); builder.SetBootImage(bootImageStream, BootDeviceEmulation.NoEmulation, 0); builder.UpdateIsolinuxBootTable = UpdateIsolinuxBootTable; } foreach (var sourceFile in SourceFiles) { builder.AddFile(GetDestinationPath(sourceFile), sourceFile.GetMetadata("FullPath")); } try { builder.Build(FileName.ItemSpec); } finally { if (bootImageStream != null) { bootImageStream.Dispose(); } } } catch (Exception e) { Log.LogErrorFromException(e, true, true, null); return(false); } return(!Log.HasLoggedErrors); }
private string Run(int revision, string additionalFilePath, bool autoStartChecked) { string filename = string.Format("bootcd-{0}-dbg", revision); string filename7z = filename + ".7z"; string filenameIso = filename + ".iso"; if (!File.Exists(filenameIso)) { string filename7zTemp = filename7z + ".temp"; string filenameIsoTemp = filenameIso + ".temp"; if (!File.Exists(filename7z)) { File.Delete(filename7zTemp); WebClient wc = new WebClient(); try { wc.DownloadFile(revToUrl[revision], filename7zTemp); } catch (WebException) { return "File download failed:\n '" + revToUrl[revision] + "'"; } File.Move(filename7zTemp, filename7z); } File.Delete(filenameIsoTemp); FileStream isotmpfs = File.Create(filenameIsoTemp); FileStream szfs = File.Open(filename7z, FileMode.Open, FileAccess.Read); SevenZipExtractor sze = new SevenZipExtractor(szfs); sze.ExtractFile(filenameIso, isotmpfs); isotmpfs.Close(); szfs.Close(); File.Move(filenameIsoTemp, filenameIso); File.Delete(filename7z); } string vmName = string.Format("ReactOS_r{0}", revision); string diskName = Environment.CurrentDirectory + "\\" + vmName + "\\" + vmName + ".vdi"; if (File.Exists(diskName)) { FileStream fs = null; try { fs = File.Open(diskName, FileMode.Open, FileAccess.Read, FileShare.None); } catch (IOException) { return "Virtual machine '" + vmName + "' is already running"; } finally { if (fs != null) fs.Close(); } } string filenameIsoUnatt = filename + "_unatt.iso"; string filenameIsoUnattTemp = filenameIsoUnatt + ".temp"; File.Delete(filenameIsoUnattTemp); File.Delete(filenameIsoUnatt); FileStream isofs = File.Open(filenameIso, FileMode.Open, FileAccess.Read); CDReader cdr = new CDReader(isofs, true); CDBuilder cdb = new CDBuilder(); cdb.VolumeIdentifier = cdr.VolumeLabel; CloneCdDirectory("", cdr, cdb); if (!File.Exists("unattend.inf")) File.WriteAllText("unattend.inf", RosRegTest.Resources.unattend, Encoding.ASCII); string additionalFileName = null; if (additionalFilePath != null) additionalFileName = Path.GetFileName(additionalFilePath); string unattText = File.ReadAllText("unattend.inf", Encoding.ASCII); if (autoStartChecked && (additionalFileName != null)) unattText = unattText + "[GuiRunOnce]\n" + "cmd.exe /c start d:\\" + additionalFileName + "\n\n"; cdb.AddFile("reactos\\unattend.inf", Encoding.ASCII.GetBytes(unattText)); if (additionalFileName != null) cdb.AddFile(additionalFileName, additionalFilePath); Stream bootImgStr = cdr.OpenBootImage(); cdb.SetBootImage(bootImgStr, cdr.BootEmulation, cdr.BootLoadSegment); bootImgStr.Close(); cdb.Build(filenameIsoUnattTemp); isofs.Close(); File.Move(filenameIsoUnattTemp, filenameIsoUnatt); string fullIsoName = Environment.CurrentDirectory + "\\" + filenameIsoUnatt; string deleteVmCmd = string.Format("unregistervm --name {0}", vmName); string createVmCmd = string.Format( "createvm --name {0} --basefolder {1} --ostype WindowsXP --register", vmName, Environment.CurrentDirectory); string modifyVmCmd = string.Format("modifyvm {0} --memory 512 --vram 16 --nictype1 Am79C973 --audio none --boot1 disk --boot2 dvd", vmName); string storageCtlCmd = string.Format("storagectl {0} --name \"IDE Controller\" --add ide", vmName); string createMediumCmd = string.Format("createmedium disk --filename {0} --size 4096", diskName); string storageAttachCmd1 = string.Format("storageattach {0} --port 0 --device 0 --storagectl \"IDE Controller\" --type hdd --medium {1}", vmName, diskName); string storageAttachCmd2 = string.Format("storageattach {0} --port 1 --device 0 --storagectl \"IDE Controller\" --type dvddrive --medium {1}", vmName, fullIsoName); string startCmd = string.Format("startvm {0}", vmName); Exec(vboxManagePath, deleteVmCmd); Exec(vboxManagePath, createVmCmd); Exec(vboxManagePath, modifyVmCmd); Exec(vboxManagePath, storageCtlCmd); Exec(vboxManagePath, createMediumCmd); Exec(vboxManagePath, storageAttachCmd1); Exec(vboxManagePath, storageAttachCmd2); Exec(vboxManagePath, startCmd); return null; }