コード例 #1
0
ファイル: QEMUISO.cs プロジェクト: vaginessa/SharpBoot
        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);
            };
        }
コード例 #2
0
ファイル: QEMUISO.cs プロジェクト: zdimension/SharpBoot
        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);
            };
        }
コード例 #3
0
        public void Generate()
        {
            Thread.CurrentThread.CurrentCulture   = new CultureInfo(Settings.Default.Lang);
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(Settings.Default.Lang);


            var f = Program.GetTemporaryDirectory();

            lblStatus.Text = Strings.Init;
            Thread.Sleep(1000);

            var ext = new SevenZipExtractor();

            var isodir = _usb ? OutputFilepath : Path.Combine(f, "iso");

            if (_usb)
            {
                // format
                if (
                    MessageBox.Show(Strings.FormatWillErase.Replace(@"\n", "\n"), "SharpBoot", MessageBoxButtons.YesNo) !=
                    DialogResult.Yes)
                {
                    abort = true;
                    return;
                }
                var tries = 1;
                while (true)
                {
                    if (tries == 5)
                    {
                        MessageBox.Show(Strings.FormatError, "SharpBoot", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        abort = true;
                        return;
                    }
                    ChangeProgress(0, 100, Strings.Formatting);
                    var askform = new AskPath();
                    askform.SetTextMode(Text, Strings.VolumeLabel, string.Concat(Title.Where(char.IsLetter)));
                    var volumeLabel = "";
                    if (askform.ShowDialog() == DialogResult.OK)
                    {
                        volumeLabel = askform.FileName;
                    }
                    else
                    {
                        abort = true;
                        return;
                    }
                    uint res = 1;
                    if ((res = Utils.FormatDrive(OutputFilepath.Substring(0, 2), filesystem,
                                                 label: volumeLabel)) == 0)
                    {
                        ChangeProgress(100, 100, Strings.Formatting);

                        break;
                    }
                    else
                    {
                        switch (res)
                        {
                        case 3:
                            MessageBox.Show(Strings.NeedAdmin, "SharpBoot", MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                            abort = true;
                            return;

                        case 2:
                            abort = true;
                            return;
                        }
                        if (
                            MessageBox.Show(Strings.FormatError, "SharpBoot", MessageBoxButtons.RetryCancel,
                                            MessageBoxIcon.Error) == DialogResult.Cancel)
                        {
                            abort = true;
                            return;
                        }
                    }
                    tries++;
                }
            }

            if (bwkISO.CancellationPending)
            {
                abort = true;
                return;
            }

            var sylp = Path.Combine(isodir, "boot", bloader.FolderName);

            bloader.WorkingDir = sylp;
            bloader.Resolution = Res;

            if (!Directory.Exists(sylp))
            {
                Directory.CreateDirectory(sylp);
            }

            var isoroot = Path.Combine(isodir, "images");


            var mkisofsexe = Path.Combine(f, "mkisofs", "mkisofs.exe");
            var archs      = Path.Combine(f, "arch");

            Directory.CreateDirectory(archs);

            File.WriteAllBytes(Path.Combine(archs, "basedisk.7z"), Resources.basedisk);
            File.WriteAllBytes(Path.Combine(archs, "bloader.7z"), bloader.Archive);
            if (!_usb)
            {
                File.WriteAllBytes(Path.Combine(archs, "mkisofs.7z"), Resources.mkisofs);
            }

            ChangeProgress(0, 100, Strings.ExtractBaseDisk + " 1/6");
            ext.Extract(Path.Combine(archs, "basedisk.7z"), isodir);
            ChangeProgress(10, 100, Strings.ExtractBaseDisk + " 2/6");
            ext.Extract(Path.Combine(archs, "bloader.7z"), isodir);
            if (bloader is Syslinux)
            {
                var theme = new SyslinuxTheme
                {
                    Resolution = Res,
                    noback     = IsoBackgroundImage == "$$NONE$$"
                };
                ChangeProgress(20, 100, Strings.ExtractBaseDisk + " 3/6");
                File.WriteAllText(Path.Combine(sylp, "theme.cfg"), theme.GetCode());
                if (Program.UseCyrillicFont)
                {
                    File.WriteAllBytes(Path.Combine(sylp, "cyrillic_cp866.psf"), Resources._866_8x16);
                }
            }

            if (bwkISO.CancellationPending)
            {
                abort = true;
                return;
            }

            Image img = null;

            ChangeProgress(30, 100, Strings.ExtractBaseDisk + " 4/6");
            if (IsoBackgroundImage == "")
            {
                var ms = new MemoryStream(Resources.sharpboot);
                img = Image.FromStream(ms);
            }
            else if (IsoBackgroundImage != "$$NONE$$")
            {
                img = Image.FromFile(IsoBackgroundImage);
            }
            ChangeProgress(35, 100, Strings.ExtractBaseDisk + " 5/6");
            bloader.SetImage(img, Res);
            ChangeProgress(45, 100, Strings.ExtractBaseDisk + " 6/6");
            if (!_usb)
            {
                ChangeProgress(50, 100, Strings.Extracting.FormatEx("Mkisofs"));

                ext.Extract(Path.Combine(archs, "mkisofs.7z"), Path.Combine(f, "mkisofs"));
            }
            ChangeProgressBar(60, 100);
            Program.SafeDel(archs);

            if (bwkISO.CancellationPending)
            {
                abort = true;
                return;
            }

            // copier les fichiers dans le rep temporaire
            ChangeProgress(0, Images.Count, Strings.CopyISOfiles);
            for (var i = 0; i < Images.Count; i++)
            {
                var current = Images[i].FilePath;
                ChangeProgress(i, Images.Count, string.Format(Strings.Copying, Path.GetFileName(current)));
                while (!Directory.Exists(isoroot))
                {
                    Directory.CreateDirectory(isoroot);
                }
                for (var j = 0; j < 5; j++)
                {
                    try
                    {
                        XCopy.Copy(current, Path.Combine(isoroot, Path.GetFileName(current)), true,
                                   true,
                                   (o, pce) => { ChangeProgressBar(pce.ProgressPercentage, 100); });
                        break;
                    }
                    catch
                    {
                    }
                }
            }
            ChangeProgressBar(0, CustomFiles.Count);

            for (var i = 0; i < CustomFiles.Count; i++)
            {
                var current = CustomFiles.ToList()[i];
                var local   = current.Key;
                var remote  = current.Value;
                if (remote.StartsWith("/"))
                {
                    remote = remote.Substring(1);
                }
                ChangeProgress(i, CustomFiles.Count, string.Format(Strings.Copying, Path.GetFileName(local)));
                while (!Directory.Exists(isodir))
                {
                    Directory.CreateDirectory(isodir);
                }
                for (var j = 0; j < 5; j++)
                {
                    try
                    {
                        XCopy.Copy(local, Path.Combine(isodir, remote), true,
                                   true,
                                   (o, pce) => { ChangeProgressBar(pce.ProgressPercentage, 100); });
                        break;
                    }
                    catch
                    {
                    }
                }
            }

            if (bwkISO.CancellationPending)
            {
                abort = true;
                return;
            }

            ChangeProgress(0, Categories.Count, Strings.GenMenus);


            var main = new BootMenu(Title, true);

            main.Items.Add(new BootMenuItem(Strings.BootFromHDD.RemoveAccent(), Strings.BootFromHDD.RemoveAccent(),
                                            EntryType.BootHDD));

            var ii = 0;

            //var itype = new Func<string, EntryType>(fn => Path.GetExtension(fn).ToLower() == ".img" ? EntryType.IMG : EntryType.ISO);

            if (bwkISO.CancellationPending)
            {
                abort = true;
                return;
            }

            foreach (var c in Categories)
            {
                if (string.IsNullOrWhiteSpace(c))
                {
                    ChangeProgress(ii, Categories.Count, Strings.GenMainMenu);
                    Images.Where(x => x.Category == c).All(x =>
                    {
                        main.Items.Add(new BootMenuItem(x.Name.RemoveAccent(), x.Description.RemoveAccent(),
                                                        x.EntryType, x.FilePath, false, x.CustomCode));
                        return(true);
                    });
                }
                else
                {
                    ChangeProgress(ii, Categories.Count, string.Format(Strings.GenMenu, c));
                    var t = new BootMenu(c, false);
                    Images.Where(x => x.Category == c).All(x =>
                    {
                        t.Items.Add(new BootMenuItem(x.Name.RemoveAccent(), x.Description.RemoveAccent(),
                                                     x.EntryType, x.FilePath, false, x.CustomCode));
                        return(true);
                    });

                    File.WriteAllText(Path.Combine(sylp, Utils.CRC32(c)) + bloader.FileExt,
                                      bloader.GetCode(t), Program.GetEnc());
                    main.Items.Add(new BootMenuItem(c, c, EntryType.Category, Utils.CRC32(c), false));
                }

                ii++;

                if (bwkISO.CancellationPending)
                {
                    abort = true;
                    return;
                }
            }
            if (bloader is Syslinux)
            {
                File.WriteAllText(Path.Combine(sylp, "syslinux.cfg"), bloader.GetCode(main), Program.GetEnc());
            }
            else if (bloader is Grub4DOS)
            {
                File.WriteAllText(Path.Combine(isodir, "menu.lst"), bloader.GetCode(main));
            }
            else if (bloader is Grub2)
            {
                File.WriteAllText(Path.Combine(sylp, "grub.cfg"), bloader.GetCode(main));
            }

            if (bwkISO.CancellationPending)
            {
                abort = true;
                return;
            }

            if (_usb)
            {
                ChangeProgress(23, 100, string.Format(Strings.InstallingBoot, bloader.DisplayName, OutputFilepath));
                bloader.Install(OutputFilepath);
                GenF(f);
            }
            else
            {
                // TODO: Implement working progress printing (I can't get OutputDataReceived to work on my computer)
                ChangeProgress(23, 100, Strings.CreatingISO);
                Thread.Sleep(500);
                var p = new Process
                {
                    StartInfo =
                    {
                        UseShellExecute = false,
                        FileName        = mkisofsexe

                                          /*RedirectStandardOutput = true,
                                           * RedirectStandardError = true*/
                    }
                };
                p.StartInfo.Arguments += " " + bloader.CmdArgs +
                                         " -publisher \"SharpBoot\" -no-emul-boot -boot-load-size 4 -boot-info-table -r -J -b " +
                                         bloader.BinFile;
                p.StartInfo.Arguments += " -o \"" + OutputFilepath + "\" \"" + isodir + "\"";
                p.EnableRaisingEvents  = true;

                /*var a = new Action<object, DataReceivedEventArgs>((o, args) => MessageBox.Show(args.Data));
                 *
                 * p.OutputDataReceived += new DataReceivedEventHandler(a);
                 * p.ErrorDataReceived += new DataReceivedEventHandler(a);*/
                bool exitCaught = false;
                p.Exited += delegate
                {
                    exitCaught = true;
                    GenF(f);
                };

                Thread.Sleep(500);

                if (bwkISO.CancellationPending)
                {
                    abort = true;
                    return;
                }
                ChangeProgress(33, 100, string.Format(Strings.Extracting, "Mkisofs"));
                int iter = 0;
                while (true)
                {
                    if (iter == 5)
                    {
                        MessageBox.Show("Extraction of Mkisofs failed after: 5 attempts. Aborting.");
                        abort = true;
                        return;
                    }
                    if (!File.Exists(mkisofsexe))
                    {
                        if (!Directory.Exists(archs))
                        {
                            Directory.CreateDirectory(archs);
                        }
                        File.WriteAllBytes(Path.Combine(archs, "mkisofs.7z"), Resources.mkisofs);
                        ext.Extract(Path.Combine(archs, "mkisofs.7z"), Path.Combine(f, "mkisofs"));
                    }
                    else
                    {
                        break;
                    }
                    Thread.Sleep(500);
                    iter++;
                }
                try
                {
                    p.Start();
                }
                catch (FileNotFoundException)
                {
                }

                /*p.BeginOutputReadLine();
                 *
                 * using (var reader = p.StandardOutput)
                 * {
                 * while (!reader.EndOfStream)
                 * {
                 *  var o = reader.ReadLine().Trim();
                 *  var pp = o.Substring(1, 5).Trim();
                 *  var d = decimal.Parse(pp);
                 *  if (o[0] == ' ' && o[3] == '.' && o[6] == '%')
                 *  {
                 *      ChangeProgress(Convert.ToInt32(Math.Round(d, 0, MidpointRounding.AwayFromZero)), 100, Strings.CopyISOfiles + "\t" + pp + "%");
                 *  }
                 * }
                 * }*/
                if (!p.HasExited)
                {
                    p.WaitForExit(2000);
                }
                Thread.Sleep(500);
                if (!exitCaught)
                {
                    GenF(f);
                }
            }
            Program.SupportAccent = false;

            ext.Close();
        }
コード例 #4
0
ファイル: Bootloaders.cs プロジェクト: zdimension/SharpBoot
        public static void Install(string l, IBootloader bl)
        {
            var d = Program.GetTemporaryDirectory();
            File.WriteAllBytes(Path.Combine(d, "bloader.7z"), bl.Archive);
            var ext = new SevenZipExtractor();
            ext.Extract(Path.Combine(d, "bloader.7z"), l);
            ext.Close();
            bl.Install(l);
         

            return;

            /*if (bl == Bootloaders.Grub2)
            {
                var grub2_mbr = new byte[]
                {
                    0xEB, 0x63, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0xFF, 0xFA, 0x90, 0x90, 0xF6, 0xC2, 0x80, 0x74,
                    0x05, 0xF6, 0xC2, 0x70, 0x74, 0x02, 0xB2, 0x80, 0xEA, 0x79, 0x7C, 0x00,
                    0x00, 0x31, 0xC0, 0x8E, 0xD8, 0x8E, 0xD0, 0xBC, 0x00, 0x20, 0xFB, 0xA0,
                    0x64, 0x7C, 0x3C, 0xFF, 0x74, 0x02, 0x88, 0xC2, 0x52, 0xBE, 0x80, 0x7D,
                    0xE8, 0x17, 0x01, 0xBE, 0x05, 0x7C, 0xB4, 0x41, 0xBB, 0xAA, 0x55, 0xCD,
                    0x13, 0x5A, 0x52, 0x72, 0x3D, 0x81, 0xFB, 0x55, 0xAA, 0x75, 0x37, 0x83,
                    0xE1, 0x01, 0x74, 0x32, 0x31, 0xC0, 0x89, 0x44, 0x04, 0x40, 0x88, 0x44,
                    0xFF, 0x89, 0x44, 0x02, 0xC7, 0x04, 0x10, 0x00, 0x66, 0x8B, 0x1E, 0x5C,
                    0x7C, 0x66, 0x89, 0x5C, 0x08, 0x66, 0x8B, 0x1E, 0x60, 0x7C, 0x66, 0x89,
                    0x5C, 0x0C, 0xC7, 0x44, 0x06, 0x00, 0x70, 0xB4, 0x42, 0xCD, 0x13, 0x72,
                    0x05, 0xBB, 0x00, 0x70, 0xEB, 0x76, 0xB4, 0x08, 0xCD, 0x13, 0x73, 0x0D,
                    0x5A, 0x84, 0xD2, 0x0F, 0x83, 0xD8, 0x00, 0xBE, 0x8B, 0x7D, 0xE9, 0x82,
                    0x00, 0x66, 0x0F, 0xB6, 0xC6, 0x88, 0x64, 0xFF, 0x40, 0x66, 0x89, 0x44,
                    0x04, 0x0F, 0xB6, 0xD1, 0xC1, 0xE2, 0x02, 0x88, 0xE8, 0x88, 0xF4, 0x40,
                    0x89, 0x44, 0x08, 0x0F, 0xB6, 0xC2, 0xC0, 0xE8, 0x02, 0x66, 0x89, 0x04,
                    0x66, 0xA1, 0x60, 0x7C, 0x66, 0x09, 0xC0, 0x75, 0x4E, 0x66, 0xA1, 0x5C,
                    0x7C, 0x66, 0x31, 0xD2, 0x66, 0xF7, 0x34, 0x88, 0xD1, 0x31, 0xD2, 0x66,
                    0xF7, 0x74, 0x04, 0x3B, 0x44, 0x08, 0x7D, 0x37, 0xFE, 0xC1, 0x88, 0xC5,
                    0x30, 0xC0, 0xC1, 0xE8, 0x02, 0x08, 0xC1, 0x88, 0xD0, 0x5A, 0x88, 0xC6,
                    0xBB, 0x00, 0x70, 0x8E, 0xC3, 0x31, 0xDB, 0xB8, 0x01, 0x02, 0xCD, 0x13,
                    0x72, 0x1E, 0x8C, 0xC3, 0x60, 0x1E, 0xB9, 0x00, 0x01, 0x8E, 0xDB, 0x31,
                    0xF6, 0xBF, 0x00, 0x80, 0x8E, 0xC6, 0xFC, 0xF3, 0xA5, 0x1F, 0x61, 0xFF,
                    0x26, 0x5A, 0x7C, 0xBE, 0x86, 0x7D, 0xEB, 0x03, 0xBE, 0x95, 0x7D, 0xE8,
                    0x34, 0x00, 0xBE, 0x9A, 0x7D, 0xE8, 0x2E, 0x00, 0xCD, 0x18, 0xEB, 0xFE,
                    0x47, 0x52, 0x55, 0x42, 0x20, 0x00, 0x47, 0x65, 0x6F, 0x6D, 0x00, 0x48,
                    0x61, 0x72, 0x64, 0x20, 0x44, 0x69, 0x73, 0x6B, 0x00, 0x52, 0x65, 0x61,
                    0x64, 0x00, 0x20, 0x45, 0x72, 0x72, 0x6F, 0x72, 0x0D, 0x0A, 0x00, 0xBB,
                    0x01, 0x00, 0xB4, 0x0E, 0xCD, 0x10, 0xAC, 0x3C, 0x00, 0x75, 0xF4, 0xC3
                };

                var dp = @"\\.\" + l.Substring(0, 2);
                /*var dh = Utils.CreateFile(dp, 0xC0000000, 0x03, IntPtr.Zero, 0x03, DeviceIO.FILE_FLAG_WRITE_THROUGH | DeviceIO.FILE_FLAG_NO_BUFFERING, IntPtr.Zero);
                if (dh.IsInvalid)
                {
                    dh.Close();
                    dh.Dispose();
                    dh = null;
                    throw new Exception("Win32 Exception : 0x" +
                                        Convert.ToString(Marshal.GetHRForLastWin32Error(), 16).PadLeft(8, '0'));
                }
                var ds = new FileStream(dh, FileAccess.ReadWrite);

                var buf = new byte[512];
                ds.Read(buf, 0, 512);
                //Array.Copy(grub2_mbr, buf, grub2_mbr.Length);
                ds.Position = 0;

                //ds.Write(buf, 0, 512);
                

                for (var i = 0; i < grub2_mbr.Length; i++)
                {
                    ds.WriteByte(grub2_mbr[i]);
                }


                //ds.Close();
                //ds.Dispose();
                if (!dh.IsClosed) dh.Close();
                dh.Dispose();
                dh = null;* /


                using (var da = new DriveAccess(dp))
                {
                    foreach (byte t in grub2_mbr)
                    {
                        da.driveStream.WriteByte(t);
                    }
                }


                return;
            }

            var exename = bl == Bootloaders.Grub4DOS ? "grubinst.exe" : "syslinux.exe";

            var d = Program.GetTemporaryDirectory();
            var exepath = Path.Combine(d, exename);
            File.WriteAllBytes(exepath, bl == Bootloaders.Grub4DOS ? Resources.grubinst : Resources.syslinux);

            var p = new Process
            {
                StartInfo =
                {
                    CreateNoWindow = true,
                    UseShellExecute = true,
                    FileName = exepath,
                    Verb = "runas"
                }
            };
            var driveletter = l.ToLower().Substring(0, 2);
            if (bl == Bootloaders.Grub4DOS)
            {
                var deviceId = Utils.GetPhysicalPath(driveletter);
                
                p.StartInfo.Arguments = " --skip-mbr-test --no-backup-mbr -t=0 (hd" + string.Concat(deviceId.Where(char.IsDigit)) + ")";
            }
            else
            {
                p.StartInfo.Arguments = " -m -a " + driveletter;
            }
            p.Start();
            p.WaitForExit();

            Program.SafeDel(d);*/
        }
コード例 #5
0
ファイル: Bootloaders.cs プロジェクト: zdimension/SharpBoot
        public override void SetImage(Image image, Size sz)
        {
            if (image == null)
            {
                noback = true;
                return;
            }

            var width = sz.Width;
            var height = sz.Height;

            var destRect = new Rectangle(0, 0, width, height);
            var destImage = new Bitmap(width, height, PixelFormat.Format16bppRgb555);

            destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            using (var graphics = Graphics.FromImage(destImage))
            {
                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                    graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                }
            }

            var imgf = Path.Combine(WorkingDir, "sharpboot.bmp");

            destImage.Save(imgf, ImageFormat.Bmp);

            var convertdir = Path.Combine(WorkingDir, "imagemagick");
            Directory.CreateDirectory(convertdir);
            File.WriteAllBytes(Path.Combine(convertdir, "convert.7z"), Resources.imagemagick);

            var ext = new SevenZipExtractor();
            ext.Extract(Path.Combine(convertdir, "convert.7z"), convertdir);


            var p = new Process
            {
                StartInfo =
                {
                    UseShellExecute = false,
                    FileName = Path.Combine(convertdir, "convert.exe"),
                    CreateNoWindow = true,
                    WorkingDirectory = convertdir
                }
            };
            p.StartInfo.Arguments += " ../sharpboot.bmp ../sharpboot.xpm.lzma";
            Thread.Sleep(300);
            var begin = DateTime.Now;
            while(!File.Exists(p.StartInfo.FileName))
            {
                if ((DateTime.Now - begin).TotalSeconds > 15)
                {
                    break;
                }
            }
            begin = DateTime.Now;
            p.Start();
            while (!File.Exists(Path.Combine(WorkingDir, "sharpboot.xpm.lzma")))
            {
                if (p.HasExited)
                {
                    p.Start();
                    continue;
                }
                if ((DateTime.Now - begin).TotalSeconds > 15)
                {
                    break;
                }
            }
            Thread.Sleep(1000);
            File.Delete(imgf);
            ext.Close();
            while (Directory.Exists(convertdir))
            {
                try
                {
                    Directory.Delete(convertdir, true);
                }
                catch
                {
                }
            }
        }
コード例 #6
0
ファイル: Bootloaders.cs プロジェクト: memoarfaa/SharpBoot
        public static void Install(string l, IBootloader bl)
        {
            var d = Program.GetTemporaryDirectory();

            File.WriteAllBytes(Path.Combine(d, "bloader.7z"), bl.Archive);
            var ext = new SevenZipExtractor();

            ext.Extract(Path.Combine(d, "bloader.7z"), l);
            ext.Close();
            bl.Install(l);


            return;

            /*if (bl == Bootloaders.Grub2)
             * {
             *  var grub2_mbr = new byte[]
             *  {
             *      0xEB, 0x63, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             *      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             *      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             *      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             *      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             *      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             *      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             *      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00,
             *      0x00, 0x00, 0x00, 0x00, 0xFF, 0xFA, 0x90, 0x90, 0xF6, 0xC2, 0x80, 0x74,
             *      0x05, 0xF6, 0xC2, 0x70, 0x74, 0x02, 0xB2, 0x80, 0xEA, 0x79, 0x7C, 0x00,
             *      0x00, 0x31, 0xC0, 0x8E, 0xD8, 0x8E, 0xD0, 0xBC, 0x00, 0x20, 0xFB, 0xA0,
             *      0x64, 0x7C, 0x3C, 0xFF, 0x74, 0x02, 0x88, 0xC2, 0x52, 0xBE, 0x80, 0x7D,
             *      0xE8, 0x17, 0x01, 0xBE, 0x05, 0x7C, 0xB4, 0x41, 0xBB, 0xAA, 0x55, 0xCD,
             *      0x13, 0x5A, 0x52, 0x72, 0x3D, 0x81, 0xFB, 0x55, 0xAA, 0x75, 0x37, 0x83,
             *      0xE1, 0x01, 0x74, 0x32, 0x31, 0xC0, 0x89, 0x44, 0x04, 0x40, 0x88, 0x44,
             *      0xFF, 0x89, 0x44, 0x02, 0xC7, 0x04, 0x10, 0x00, 0x66, 0x8B, 0x1E, 0x5C,
             *      0x7C, 0x66, 0x89, 0x5C, 0x08, 0x66, 0x8B, 0x1E, 0x60, 0x7C, 0x66, 0x89,
             *      0x5C, 0x0C, 0xC7, 0x44, 0x06, 0x00, 0x70, 0xB4, 0x42, 0xCD, 0x13, 0x72,
             *      0x05, 0xBB, 0x00, 0x70, 0xEB, 0x76, 0xB4, 0x08, 0xCD, 0x13, 0x73, 0x0D,
             *      0x5A, 0x84, 0xD2, 0x0F, 0x83, 0xD8, 0x00, 0xBE, 0x8B, 0x7D, 0xE9, 0x82,
             *      0x00, 0x66, 0x0F, 0xB6, 0xC6, 0x88, 0x64, 0xFF, 0x40, 0x66, 0x89, 0x44,
             *      0x04, 0x0F, 0xB6, 0xD1, 0xC1, 0xE2, 0x02, 0x88, 0xE8, 0x88, 0xF4, 0x40,
             *      0x89, 0x44, 0x08, 0x0F, 0xB6, 0xC2, 0xC0, 0xE8, 0x02, 0x66, 0x89, 0x04,
             *      0x66, 0xA1, 0x60, 0x7C, 0x66, 0x09, 0xC0, 0x75, 0x4E, 0x66, 0xA1, 0x5C,
             *      0x7C, 0x66, 0x31, 0xD2, 0x66, 0xF7, 0x34, 0x88, 0xD1, 0x31, 0xD2, 0x66,
             *      0xF7, 0x74, 0x04, 0x3B, 0x44, 0x08, 0x7D, 0x37, 0xFE, 0xC1, 0x88, 0xC5,
             *      0x30, 0xC0, 0xC1, 0xE8, 0x02, 0x08, 0xC1, 0x88, 0xD0, 0x5A, 0x88, 0xC6,
             *      0xBB, 0x00, 0x70, 0x8E, 0xC3, 0x31, 0xDB, 0xB8, 0x01, 0x02, 0xCD, 0x13,
             *      0x72, 0x1E, 0x8C, 0xC3, 0x60, 0x1E, 0xB9, 0x00, 0x01, 0x8E, 0xDB, 0x31,
             *      0xF6, 0xBF, 0x00, 0x80, 0x8E, 0xC6, 0xFC, 0xF3, 0xA5, 0x1F, 0x61, 0xFF,
             *      0x26, 0x5A, 0x7C, 0xBE, 0x86, 0x7D, 0xEB, 0x03, 0xBE, 0x95, 0x7D, 0xE8,
             *      0x34, 0x00, 0xBE, 0x9A, 0x7D, 0xE8, 0x2E, 0x00, 0xCD, 0x18, 0xEB, 0xFE,
             *      0x47, 0x52, 0x55, 0x42, 0x20, 0x00, 0x47, 0x65, 0x6F, 0x6D, 0x00, 0x48,
             *      0x61, 0x72, 0x64, 0x20, 0x44, 0x69, 0x73, 0x6B, 0x00, 0x52, 0x65, 0x61,
             *      0x64, 0x00, 0x20, 0x45, 0x72, 0x72, 0x6F, 0x72, 0x0D, 0x0A, 0x00, 0xBB,
             *      0x01, 0x00, 0xB4, 0x0E, 0xCD, 0x10, 0xAC, 0x3C, 0x00, 0x75, 0xF4, 0xC3
             *  };
             *
             *  var dp = @"\\.\" + l.Substring(0, 2);
             *  /*var dh = Utils.CreateFile(dp, 0xC0000000, 0x03, IntPtr.Zero, 0x03, DeviceIO.FILE_FLAG_WRITE_THROUGH | DeviceIO.FILE_FLAG_NO_BUFFERING, IntPtr.Zero);
             *  if (dh.IsInvalid)
             *  {
             *      dh.Close();
             *      dh.Dispose();
             *      dh = null;
             *      throw new Exception("Win32 Exception : 0x" +
             *                          Convert.ToString(Marshal.GetHRForLastWin32Error(), 16).PadLeft(8, '0'));
             *  }
             *  var ds = new FileStream(dh, FileAccess.ReadWrite);
             *
             *  var buf = new byte[512];
             *  ds.Read(buf, 0, 512);
             *  //Array.Copy(grub2_mbr, buf, grub2_mbr.Length);
             *  ds.Position = 0;
             *
             *  //ds.Write(buf, 0, 512);
             *
             *
             *  for (var i = 0; i < grub2_mbr.Length; i++)
             *  {
             *      ds.WriteByte(grub2_mbr[i]);
             *  }
             *
             *
             *  //ds.Close();
             *  //ds.Dispose();
             *  if (!dh.IsClosed) dh.Close();
             *  dh.Dispose();
             *  dh = null;* /
             *
             *
             *  using (var da = new DriveAccess(dp))
             *  {
             *      foreach (byte t in grub2_mbr)
             *      {
             *          da.driveStream.WriteByte(t);
             *      }
             *  }
             *
             *
             *  return;
             * }
             *
             * var exename = bl == Bootloaders.Grub4DOS ? "grubinst.exe" : "syslinux.exe";
             *
             * var d = Program.GetTemporaryDirectory();
             * var exepath = Path.Combine(d, exename);
             * File.WriteAllBytes(exepath, bl == Bootloaders.Grub4DOS ? Resources.grubinst : Resources.syslinux);
             *
             * var p = new Process
             * {
             *  StartInfo =
             *  {
             *      CreateNoWindow = true,
             *      UseShellExecute = true,
             *      FileName = exepath,
             *      Verb = "runas"
             *  }
             * };
             * var driveletter = l.ToLower().Substring(0, 2);
             * if (bl == Bootloaders.Grub4DOS)
             * {
             *  var deviceId = Utils.GetPhysicalPath(driveletter);
             *
             *  p.StartInfo.Arguments = " --skip-mbr-test --no-backup-mbr -t=0 (hd" + string.Concat(deviceId.Where(char.IsDigit)) + ")";
             * }
             * else
             * {
             *  p.StartInfo.Arguments = " -m -a " + driveletter;
             * }
             * p.Start();
             * p.WaitForExit();
             *
             * Program.SafeDel(d);*/
        }
コード例 #7
0
ファイル: Bootloaders.cs プロジェクト: memoarfaa/SharpBoot
        public override void SetImage(Image image, Size sz)
        {
            if (image == null)
            {
                noback = true;
                return;
            }

            var width  = sz.Width;
            var height = sz.Height;

            var destRect  = new Rectangle(0, 0, width, height);
            var destImage = new Bitmap(width, height, PixelFormat.Format16bppRgb555);

            destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            using (var graphics = Graphics.FromImage(destImage))
            {
                graphics.CompositingMode    = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode      = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode    = PixelOffsetMode.HighQuality;

                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                    graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                }
            }

            var imgf = Path.Combine(WorkingDir, "sharpboot.bmp");

            destImage.Save(imgf, ImageFormat.Bmp);

            var convertdir = Path.Combine(WorkingDir, "imagemagick");

            Directory.CreateDirectory(convertdir);
            File.WriteAllBytes(Path.Combine(convertdir, "convert.7z"), Resources.imagemagick);

            var ext = new SevenZipExtractor();

            ext.Extract(Path.Combine(convertdir, "convert.7z"), convertdir);


            var p = new Process
            {
                StartInfo =
                {
                    UseShellExecute  = false,
                    FileName         = Path.Combine(convertdir, "convert.exe"),
                    CreateNoWindow   = true,
                    WorkingDirectory = convertdir
                }
            };

            p.StartInfo.Arguments += " ../sharpboot.bmp ../sharpboot.xpm.lzma";
            Thread.Sleep(300);
            var begin = DateTime.Now;

            while (!File.Exists(p.StartInfo.FileName))
            {
                if ((DateTime.Now - begin).TotalSeconds > 15)
                {
                    break;
                }
            }
            begin = DateTime.Now;
            p.Start();
            while (!File.Exists(Path.Combine(WorkingDir, "sharpboot.xpm.lzma")))
            {
                if (p.HasExited)
                {
                    p.Start();
                    continue;
                }
                if ((DateTime.Now - begin).TotalSeconds > 15)
                {
                    break;
                }
            }
            Thread.Sleep(1000);
            File.Delete(imgf);
            ext.Close();
            while (Directory.Exists(convertdir))
            {
                try
                {
                    Directory.Delete(convertdir, true);
                }
                catch
                {
                }
            }
        }