Exemplo n.º 1
0
        public static void CleanTemp()
        {

            ProcessManager.SyncCMD("taskkill /f /IM imagex_x86.exe");
            ProcessManager.SyncCMD("taskkill /f /IM imagex_x64.exe");

            //KILL.Start();
            //KILL.WaitForExit();

            if (System.IO.Directory.Exists("V:\\"))
            {
                DetachVHDExtra();

            }
            if (System.IO.Directory.Exists("V:\\"))
            {
                DetachVHDExtra();
                //MsgManager.getResString("Msg_LetterV")
                //盘符V不能被占用!

            }
            if (System.IO.Directory.Exists("V:\\"))
            {
                ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_LetterV", MsgManager.ci));
                er.ShowDialog();
            }
            //if (useiso) { ProcessManager.SyncCMD("\""+Application.StartupPath + "\\files\\" + "\\isocmd.exe\" -eject 0: "); }
            try
            {
                //File.Delete ()

                FileOperation.DeleteFile(WTGModel.diskpartScriptPath + "\\create.txt");
                FileOperation.DeleteFile(WTGModel.diskpartScriptPath + "\\removex.txt");
                FileOperation.DeleteFile(WTGModel.diskpartScriptPath + "\\detach.txt");
                FileOperation.DeleteFile(WTGModel.diskpartScriptPath + "\\uefi.txt");
                FileOperation.DeleteFile(WTGModel.diskpartScriptPath + "\\uefimbr.txt");
                FileOperation.DeleteFile(WTGModel.diskpartScriptPath + "\\dp.txt");
                FileOperation.DeleteFile(WTGModel.diskpartScriptPath + "\\attach.txt");
                FileOperation.DeleteFile(Environment.GetEnvironmentVariable("TEMP") + "\\win8.vhd");
                FileOperation.DeleteFile(Environment.GetEnvironmentVariable("TEMP") + "\\win8.vhdx");
                FileOperation.DeleteFile(WTGModel.userSettings.VHDTempPath + "\\win8.vhd");
                FileOperation.DeleteFile(WTGModel.userSettings.VHDTempPath + "\\win8.vhdx");
            }
            catch (Exception ex)
            {
                //MsgManager.getResString("Msg_DeleteTempError")
                //程序删除临时文件出错!可重启程序或重启电脑重试!\n
                MessageBox.Show(MsgManager.GetResString("Msg_DeleteTempError", MsgManager.ci) + ex.ToString());
                Log.WriteLog("DeleteVHDTemp.log", ex.ToString());
                //shouldcontinue = false;
            }

        }
Exemplo n.º 2
0
 private void FileValidation()
 {
     if (StringUtility.IsChina(WTGModel.diskpartScriptPath))
     {
         if (StringUtility.IsChina(Application.StartupPath))
         {
             ErrorMsg er = new ErrorMsg(MsgManager.GetResString("IsChinaMsg", MsgManager.ci));
             er.ShowDialog();
             Environment.Exit(0);
         }
         else
         {
             WTGModel.diskpartScriptPath = WTGModel.logPath;
         }
     }
     ProcessManager.SyncCMD("taskkill /f /IM BOOTICE.exe");
     //ProcessManager.KillProcessByName("bootice.exe");
     //解压文件
     UnZipClass.UnZip(Application.StartupPath + "\\files.dat", WTGModel.applicationFilesPath);
 }
Exemplo n.º 3
0
        private void UefiMbrVHDVHDX()
        {
            VHDOperation vo = new VHDOperation();
            vo.Execute();

            if (System.IO.File.Exists(WTGOperation.ud + WTGOperation.win8VHDFileName))
            {
                //finish f = new finish();
                //f.ShowDialog();
            }
            else
            {
                ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_VHDCreationError", MsgManager.ci));
                er.ShowDialog();
                //shouldcontinue = false;
            }
            //removeLetterX();
            FinishSuccessful();
            //Finish f = new Finish();
            //f.ShowDialog();
        }
Exemplo n.º 4
0
        private void UefiGptVhdVhdx()
        {
            VHDOperation vo = new VHDOperation();
            vo.Execute();

            if (File.Exists(WTGOperation.ud + WTGOperation.win8VHDFileName))
            {

            }
            else
            {
                //                //MsgManager.getResString("Msg_VHDCreationError")
                //VHD文件创建出错!
                ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_VHDCreationError", MsgManager.ci));
                er.ShowDialog();
                //MessageBox.Show("Win8 VHD文件不存在!,可到论坛发帖求助!\n建议将程序目录下logs文件夹打包上传,谢谢!","出错啦!",MessageBoxButtons .OK ,MessageBoxIcon.Error );
                //System.Diagnostics.Process.Start("http://bbs.luobotou.org/forum-88-1.html");
            }
        }
Exemplo n.º 5
0
 private void toolStripMenuItemvhdx_Click(object sender, EventArgs e)
 {
     if (comboBox1.SelectedIndex == 0) { MessageBox.Show(MsgManager.GetResString("Msg_chooseud", MsgManager.ci)); return; }
     WTGOperation.ud = comboBox1.SelectedItem.ToString().Substring(0, 2) + "\\";//优盘
     try
     {
         ProcessManager.ECMD("xcopy.exe", "\"" + WTGOperation.applicationFilesPath + "\\" + "vhd" + "\\" + "*.*" + "\"" + " " + WTGOperation.ud + " /e /h /y");
         ProcessManager.ECMD("xcopy.exe", "\"" + WTGOperation.applicationFilesPath + "\\" + "vhdx" + "\\" + "*.*" + "\"" + " " + WTGOperation.ud + "\\boot\\ /e /h /y");
     }
     catch (Exception ex)
     {
         ErrorMsg err = new ErrorMsg(ex.Message);
         err.Show();
     }
 }
Exemplo n.º 6
0
        private void NonUEFIVHDVHDX()
        {
            VHDOperation vo = new VHDOperation();
            vo.Execute();
            if (!System.IO.File.Exists(WTGOperation.ud + WTGOperation.win8VHDFileName))
            {
                //MsgManager.getResString("Msg_VHDCreationError")
                //Win8 VHD文件不存在!未知错误原因!
                ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_VHDCreationError", MsgManager.ci));
                er.ShowDialog();
            }

            else if (!System.IO.File.Exists(WTGOperation.ud + "\\Boot\\BCD"))
            {
                //MsgManager.getResString("Msg_VHDBcdbootError")
                //VHD模式下BCDBOOT执行出错!
                ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_VHDBcdbootError", MsgManager.ci));
                er.ShowDialog();
            }
            else if (!File.Exists(WTGOperation.ud + "bootmgr"))
            {
                ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_bootmgrError", MsgManager.ci));
                er.ShowDialog();
                //MessageBox.Show("文件写入出错!bootmgr不存在!\n请检查写入过程是否中断\n如有疑问,请访问官方论坛!");
            }
            else
            {
                FinishSuccessful();
            }
        }
Exemplo n.º 7
0
        private void NonUEFITypical()
        {
            ImageOperation.AutoChooseWimIndex(ref WTGOperation.wimPart, WTGOperation.win7togo);
            ImageOperation.ImageApply(checkBoxwimboot.Checked, WTGOperation.isEsd, WTGOperation.imagexFileName, WTGOperation.imageFilePath, WTGOperation.wimPart, WTGOperation.ud, WTGOperation.ud);
            if (WTGOperation.win7togo != 0) { ImageOperation.Win7REG(WTGOperation.ud); }

            BootFileOperation.BooticeWriteMBRPBRAndAct(WTGOperation.ud);
            ProcessManager.ECMD(WTGOperation.applicationFilesPath + "\\" + WTGOperation.bcdbootFileName, WTGOperation.ud.Substring(0, 3) + "windows  /s  " + WTGOperation.ud.Substring(0, 2) + " /f ALL");

            if (WTGOperation.win7togo == 0) { ImageOperation.ImageExtra(WTGOperation.userSettings.InstallDonet35, checkBox_san_policy.Checked, WTGOperation.userSettings.DisableWinRe, WTGOperation.ud, wimbox.Text); }

            if (!System.IO.File.Exists(WTGOperation.ud + "\\Boot\\BCD"))
            {
                //MsgManager.getResString("Msg_BCDError")
                //引导文件写入出错!boot文件夹不存在!
                ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_BCDError", MsgManager.ci));
                er.ShowDialog();
                //MessageBox.Show("引导文件写入出错!boot文件夹不存在\n请看论坛教程!", "出错啦", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //System.Diagnostics.Process.Start("http://bbs.luobotou.org/thread-1625-1-1.html");
            }
            else if (!System.IO.File.Exists(WTGOperation.ud + "bootmgr"))
            {
                //MsgManager.getResString("Msg_bootmgrError")
                //文件写入出错!bootmgr不存在!\n请检查写入过程是否中断
                ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_bootmgrError", MsgManager.ci));
                er.ShowDialog();

                //MessageBox.Show("文件写入出错!bootmgr不存在!\n请检查写入过程是否中断\n如有疑问,请访问官方论坛!");
            }
            else
            {
                FinishSuccessful();
            }
        }
Exemplo n.º 8
0
        private void FileValidate()
        {
            if (StringUtility.IsChina(WTGOperation.diskpartScriptPath))
            {
                if (StringUtility.IsChina(Application.StartupPath))
                {
                    ErrorMsg er = new ErrorMsg(MsgManager.GetResString("IsChinaMsg", MsgManager.ci));
                    er.ShowDialog();
                    Environment.Exit(0);
                }
                else
                {
                    WTGOperation.diskpartScriptPath = WTGOperation.logPath;
                }
            }

            //解压文件
            UnZipClass.UnZip(Application.StartupPath + "\\files.dat", StringUtility.Combine(Path.GetTempPath(), "WTGA"));
        }
Exemplo n.º 9
0
        private void 复制VHD启动文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //MsgManager.getResString("Msg_chooseud")
            if (comboBox1.SelectedIndex == 0) { MessageBox.Show(MsgManager.GetResString("Msg_chooseud", MsgManager.ci)); return; }
            WTGOperation.ud = comboBox1.SelectedItem.ToString().Substring(0, 2) + "\\";//优盘
            try
            {
                ProcessManager.ECMD("takeown.exe", " /f \"" + WTGOperation.ud + "\\boot\\" + "\" /r /d y && icacls \"" + WTGOperation.ud + "\\boot\\" + "\" /grant administrators:F /t");
                ProcessManager.ECMD("xcopy.exe", "\"" + WTGOperation.applicationFilesPath + "\\" + "vhd" + "\\" + "*.*" + "\"" + " " + WTGOperation.ud + " /e /h /y");
            }
            catch (UserCancelException ex)
            {
                ErrorMsg em = new ErrorMsg(ex.Message);
                em.Show();
            }

            //copyvhdbootfile();
        }
Exemplo n.º 10
0
        private void 写入引导文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0) { MessageBox.Show(MsgManager.GetResString("Msg_chooseud", MsgManager.ci)); return; }

            WTGOperation.ud = comboBox1.SelectedItem.ToString().Substring(0, 2) + "\\";//优盘
            if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_ConfirmChoose", MsgManager.ci) + WTGOperation.ud.Substring(0, 1) + MsgManager.GetResString("Msg_Disk_Space", MsgManager.ci) + DiskOperation.GetHardDiskSpace(WTGOperation.ud) / 1024 / 1024 + MsgManager.GetResString("Msg_FormatTip", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo)) { return; }
            try
            {
                ProcessManager.ECMD(WTGOperation.applicationFilesPath + "\\" + WTGOperation.bcdbootFileName, WTGOperation.ud.Substring(0, 3) + "windows  /s  " + WTGOperation.ud.Substring(0, 2) + " /f ALL");

                BootFileOperation.BcdbootWriteBootFile(WTGOperation.ud, WTGOperation.ud, WTGOperation.bcdbootFileName, FirmwareType.BIOS);
                MessageBox.Show(MsgManager.GetResString("Msg_Complete", MsgManager.ci));
            }
            catch (UserCancelException ex)
            {
                ErrorMsg em = new ErrorMsg(ex.Message);
                em.Show();
            }
        }
Exemplo n.º 11
0
        public static void UnZip(string zipFilePath, string unZipDir)
        {
            if (zipFilePath == string.Empty)
            {
                throw new Exception("压缩文件不能为空!");
            }
            if (!File.Exists(zipFilePath))
            {
                throw new FileNotFoundException("压缩文件不存在!");
            }
            //解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹  
            if (unZipDir == string.Empty)
                unZipDir = zipFilePath.Replace(Path.GetFileName(zipFilePath), Path.GetFileNameWithoutExtension(zipFilePath));
            if (!unZipDir.EndsWith("/"))
                unZipDir += "/";
            if (!Directory.Exists(unZipDir))
                Directory.CreateDirectory(unZipDir);

            using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipFilePath)))
            {

                ZipEntry theEntry;
                while ((theEntry = s.GetNextEntry()) != null)
                {
                    string directoryName = Path.GetDirectoryName(theEntry.Name);
                    string fileName = Path.GetFileName(theEntry.Name);
                    if (directoryName.Length > 0)
                    {
                        Directory.CreateDirectory(unZipDir + directoryName);
                    }
                    if (!directoryName.EndsWith("/"))
                        directoryName += "/";
                    if (fileName != string.Empty)
                    {
                        try
                        {
                            using (FileStream streamWriter = File.Create(unZipDir + theEntry.Name))
                            {

                                int size = 2048;
                                byte[] data = new byte[2048];
                                while (true)
                                {
                                    size = s.Read(data, 0, data.Length);
                                    if (size > 0)
                                    {
                                        streamWriter.Write(data, 0, size);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            ErrorMsg err = new ErrorMsg(ex.Message.Substring(0, 20) + "...");
                            err.ShowDialog();
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        private void NonUEFIVHDVHDX(bool legacyUdiskUefi)
        {
            VHDOperation vo = new VHDOperation();
            vo.Execute();
            if (!legacyUdiskUefi)
            {
                BootFileOperation.BooticeWriteMBRPBRAndAct(WTGModel.ud);
            }
            if (!File.Exists(WTGModel.ud + WTGModel.win8VHDFileName))
            {
                //MsgManager.getResString("Msg_VHDCreationError")
                //Win8 VHD文件不存在!未知错误原因!
                ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_VHDCreationError", MsgManager.ci));
                er.ShowDialog();
            }

            else if (!File.Exists(WTGModel.ud + "\\Boot\\BCD"))
            {
                //MsgManager.getResString("Msg_VHDBcdbootError")
                //VHD模式下BCDBOOT执行出错!
                ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_VHDBcdbootError", MsgManager.ci));
                er.ShowDialog();
            }
            else if (!File.Exists(WTGModel.ud + "bootmgr"))
            {
                ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_bootmgrError", MsgManager.ci));
                er.ShowDialog();
                //MessageBox.Show("文件写入出错!bootmgr不存在!\n请检查写入过程是否中断\n如有疑问,请访问官方论坛!");
            }
            else
            {
                if (!legacyUdiskUefi)
                {
                    FinishSuccessful();
                }
            }

        }
Exemplo n.º 13
0
        private void UefiGptVhdVhdx()
        {
            VHDOperation vo = new VHDOperation();
            vo.Execute();

            RemoveLetterX();

            if (File.Exists(WTGModel.ud + WTGModel.win8VHDFileName))
            {
                FinishSuccessful();
            }
            else
            {

                //VHD文件创建出错!
                ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_VHDCreationError", MsgManager.ci));
                er.ShowDialog();
                //MessageBox.Show("Win8 VHD文件不存在!,可到论坛发帖求助!\n建议将程序目录下logs文件夹打包上传,谢谢!","出错啦!",MessageBoxButtons .OK ,MessageBoxIcon.Error );

            }
        }
Exemplo n.º 14
0
 public void Execute()
 {
     CleanTemp();
     try
     {
         if (choosedFileType == "vhd" || choosedFileType == "vhdx")
         {
             CopyVHD();
             if (commonBootFiles)
             {
                 CopyVHDBootFiles();
             }
             else
             {
                 TwiceAttachVHDAndWriteBootFile();
             }
         }
         else
         {
             CreateVHD();
             VHDExtra();
             WriteBootFiles();
             DetachVHD();
             CopyVHD();
             TwiceAttachVHDAndWriteBootFile();
             //BootFileOperation.BooticeWriteMBRPBRAndAct(WTGOperation.ud);
             if (VhdType != "fixed") VHDDynamicSizeIns();
         }
     }
     catch (UserCancelException)
     {
         throw;
     }
     catch (VHDException ex)
     {
         ErrorMsg em = new ErrorMsg(ex.Message);
         em.ShowDialog();
     }
     catch (Exception ex)
     {
         MessageBox.Show("程序出现严重错误!\n" + ex.ToString());
         Log.WriteLog("VHDFatalError.log", ex.ToString());
     }
 }
Exemplo n.º 15
0
        private void diskpart重新分区ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //MsgManager.getResString("Msg_chooseud")
            if (comboBox1.SelectedIndex == 0) { MessageBox.Show(MsgManager.GetResString("Msg_chooseud", MsgManager.ci)); return; }
            WTGOperation.ud = comboBox1.SelectedItem.ToString().Substring(0, 2) + "\\";//优盘
            //MsgManager.getResString("Msg_XPNotCOMP")
            //XP系统不支持此操作
            //MsgManager.getResString("Msg_ClearPartition")
            //此操作将会清除移动磁盘所有分区的所有数据,确认?
            if (System.Environment.OSVersion.ToString().Contains("5.1") || System.Environment.OSVersion.ToString().Contains("5.2")) { MessageBox.Show(MsgManager.GetResString("Msg_chooseud", MsgManager.ci)); return; }
            if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_ClearPartition", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; }

            //if (DialogResult.No == MessageBox.Show("您确定要继续吗?", "警告!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; }
            //Msg_Complete
            try
            {
                DiskOperation.DiskPartReformatUD();
                //diskPart();
                MessageBox.Show(MsgManager.GetResString("Msg_Complete", MsgManager.ci));
            }
            catch (Exception ex)
            {
                ErrorMsg em = new ErrorMsg(ex.Message);
                em.Show();
            }
        }
Exemplo n.º 16
0
        private void SetVhdProp()
        {
            try
            {
                if (Path.GetExtension(imageFilePath) == ".vhd" || Path.GetExtension(imageFilePath) == ".vhdx")
                {
                    VhdType = string.Empty;
                    VhdSize = string.Empty;
                    VhdFileName = string.Empty;
                    ExtensionType = string.Empty;
                    VhdPath = imageFilePath;
                    NeedCopy = true;
                }
                else
                {
                    //    ////////////////vhd设定///////////////////////
                    //    string vhd_type = "expandable";
                    //    vhd_size = "";
                    if (isFixedVHD)
                    {
                        VhdType = "fixed";
                    }
                    else
                    {
                        VhdType = "expandable";
                    }
                    if (userSetSize != 0)
                    {
                        VhdSize = (userSetSize * 1024).ToString();
                    }
                    else
                    {
                        if (!isWimBoot)
                        {
                            if (DiskOperation.GetHardDiskFreeSpace(ud) / 1024 >= 21504) { VhdSize = "20480"; }
                            else { VhdSize = (DiskOperation.GetHardDiskFreeSpace(ud) / 1024 - 500).ToString(); }
                        }
                        else
                        {
                            if (DiskOperation.GetHardDiskFreeSpace(ud) / 1024 >= 24576) { VhdSize = "20480"; }
                            else { VhdSize = (DiskOperation.GetHardDiskFreeSpace(ud) / 1024 - 4096).ToString(); }
                        }
                    }

                    //Win8VHDFileName = userSettings.VHDNameWithoutExt + "." + choosedFileType;

                    ////////////////判断临时文件夹,VHD needcopy?///////////////////
                    int vhdmaxsize;
                    if (isFixedVHD)
                    {
                        vhdmaxsize = int.Parse(VhdSize) * 1024 + 1024;
                    }
                    else
                    {
                        vhdmaxsize = 10485670;
                    }

                    if (DiskOperation.GetHardDiskFreeSpace(WTGOperation.userSettings.VHDTempPath.Substring(0, 2) + "\\") <= vhdmaxsize || StringUtility.IsChina(WTGOperation.userSettings.VHDTempPath) || isUefiGpt || isUefiMbr || isWimBoot || isNoTemp)
                    {
                        this.NeedCopy = false;
                        this.VhdPath = StringUtility.Combine(WTGOperation.ud, win8VHDFileName);
                    }
                    else
                    {
                        this.NeedCopy = true;
                        this.VhdPath = StringUtility.Combine(WTGOperation.userSettings.VHDTempPath, win8VHDFileName);
                    }

                }
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(this.ExtensionType);
                sb.AppendLine(this.NeedCopy.ToString());
                sb.AppendLine(this.VhdFileName);
                sb.AppendLine(this.VhdPath);
                sb.AppendLine(this.VhdSize);
                sb.AppendLine(this.VhdType);
                Log.WriteLog("VHDInfo.log", sb.ToString());
            }
            catch (Exception ex)
            {
                Log.WriteLog("SetVhdProp.log", ex.ToString());
                ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_VHDCreationError", MsgManager.ci));
                er.ShowDialog();
            }
        }
Exemplo n.º 17
0
        private void GoWrite()
        {

            try
            {
                //wimpart = ChoosePart.part;//读取选择分卷,默认选择第一分卷
                #region 各种提示
                //各种提示
                if (lblWim.Text.ToLower().Substring(lblWim.Text.Length - 3, 3) != "wim" && lblWim.Text.ToLower().Substring(lblWim.Text.Length - 3, 3) != "esd" && lblWim.Text.ToLower().Substring(lblWim.Text.Length - 3, 3) != "vhd" && lblWim.Text.ToLower().Substring(lblWim.Text.Length - 4, 4) != "vhdx")//不是WIM文件
                {
                    //镜像文件选择错误!请选择install.wim!
                    MessageBox.Show(MsgManager.GetResString("Msg_chooseinstallwim", MsgManager.ci), MsgManager.GetResString("Msg_error", MsgManager.ci), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    //请选择install.wim文件
                    if (!System.IO.File.Exists(lblWim.Text))
                    {
                        MessageBox.Show(MsgManager.GetResString("Msg_chooseinstallwim", MsgManager.ci), MsgManager.GetResString("Msg_error", MsgManager.ci), MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }//文件不存在.
                    WTGModel.imageFilePath = lblWim.Text;
                }


                if (!Directory.Exists(WTGModel.ud))
                {
                    MessageBox.Show(MsgManager.GetResString("Msg_chooseud", MsgManager.ci) + "!", MsgManager.GetResString("Msg_error", MsgManager.ci), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }//是否选择优盘
                if (DiskOperation.GetHardDiskSpace(WTGModel.ud) <= 12582912) //优盘容量<12 GB提示
                {
                    //MsgManager.getResString("Msg_DiskSpaceWarning") 
                    //可移动磁盘容量不足16G,继续写入可能会导致程序出错!您确定要继续吗?
                    if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_DiskSpaceWarning", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
                    {
                        return;
                    }
                }


                if (DiskOperation.GetHardDiskSpace(WTGModel.ud) <= numericUpDown1.Value * 1048576)
                {
                    //优盘容量小于VHD设定大小,请修改设置!
                    //MsgManager.getResString("Msg_DiskSpaceError")
                    MessageBox.Show(MsgManager.GetResString("Msg_DiskSpaceError", MsgManager.ci), MsgManager.GetResString("Msg_error", MsgManager.ci), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                //MsgManager.getResString("Msg_ConfirmChoose")
                //请确认您所选择的
                //MsgManager.getResString("Msg_Disk_Space") 盘,容量
                //Msg_FormatTip

                //GB 是将要写入的优盘或移动硬盘\n误格式化,后果自负!
                StringBuilder formatTip = new StringBuilder();
                formatTip.AppendLine(MsgManager.GetResString("Msg_ConfirmChoose", MsgManager.ci));
                formatTip.AppendFormat(WTGModel.udString);
                formatTip.AppendLine(MsgManager.GetResString("Msg_FormatTip", MsgManager.ci));
                if (checkBoxDiskpart.Checked && !checkBoxUefigpt.Checked && !checkBoxUefimbr.Checked)//勾选重新分区提示
                {
                    formatTip.AppendLine(MsgManager.GetResString("Msg_Repartition", MsgManager.ci));
                    FormatAlert fa = new FormatAlert(formatTip.ToString());
                    //MsgManager.getResString("Msg_Repartition")
                    //您勾选了重新分区,优盘或移动硬盘上的所有文件将被删除!\n注意是整个磁盘,不是一个分区!
                    if (DialogResult.Yes != fa.ShowDialog())
                    {
                        return;
                    }

                    DiskOperation.DiskPartReformatUD();
                }
                else//普通格式化提示
                {
                    if (!WTGModel.userSettings.DoNotFormat)
                    {
                        formatTip.AppendLine(MsgManager.GetResString("Msg_FormatWarning", MsgManager.ci));
                        FormatAlert fa = new FormatAlert(formatTip.ToString());
                        if (DialogResult.Yes != fa.ShowDialog())
                        {
                            return;
                        }
                    }
                    else
                    {
                        FormatAlert fa = new FormatAlert(formatTip.ToString());
                        if (DialogResult.Yes != fa.ShowDialog())
                        {
                            return;
                        }
                    }
                }
                #endregion

                SystemSleepManagement.PreventSleep();

                //删除旧LOG文件
                Log.DeleteAllLogs();
                ProcessManager.KillProcessByName("bootice.exe");
                WriteProgramRunInfoToLog();

                writeSw.Restart();

                if (checkBoxUefigpt.Checked)
                {
                    //UEFI+GPT
                    if (System.Environment.OSVersion.ToString().Contains("5.1") || System.Environment.OSVersion.ToString().Contains("5.2"))
                    {
                        //MsgManager.getResString("Msg_XPUefiError")
                        //XP系统不支持UEFI模式写入
                        MessageBox.Show(MsgManager.GetResString("Msg_XPUefiError", MsgManager.ci)); return;
                    }
                    if (WTGModel.udString.Contains("Removable Disk"))
                    {
                        //普通优盘UEFI
                        WTGModel.isLegacyUdiskUefi = true;
                        RemoveableDiskUefiGpt();
                        FinishSuccessful();

                       
                    }
                    else
                    {
                        //MsgManager.getResString("Msg_UefiFormatWarning")
                        //您所选择的是UEFI模式,此模式将会格式化您的整个移动磁盘!\n注意是整个磁盘!!!\n程序将会删除所有优盘分区!
                        if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_UefiFormatWarning", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; }

                        DiskpartScriptManager dsm = new DiskpartScriptManager();
                        dsm.RunDiskpartScriptByScriptFile(DiskOperation.GenerateGPTAndUEFIScript(WTGModel.userSettings.EFIPartitionSize.ToString(), WTGModel.ud));

                        //ProcessManager.ECMD("diskpart.exe", " /s \"" + WTGOperation.diskpartScriptPath + "\\uefi.txt\"");
                        if (radiobtnLegacy.Checked)
                        {
                            //UEFI+GPT 传统
                            UefiGptTypical();


                        }
                        else // UEFI+GPT VHD、VHDX模式
                        {

                            UefiGptVhdVhdx();
                        }
                    }
                }
                else if (checkBoxUefimbr.Checked)
                {
                    //UEFI+MBR
                    if (WTGModel.udString.Contains("Removable Disk"))
                    {
                        MessageBox.Show(MsgManager.GetResString("Msg_UefiError", MsgManager.ci), MsgManager.GetResString("Msg_error", MsgManager.ci), MessageBoxButtons.OK, MessageBoxIcon.Error);
                        VisitWeb("http://bbs.luobotou.org/thread-6506-1-1.html");
                        return;
                    }
                    if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_UefiFormatWarning", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; }
                    DiskpartScriptManager dsm = new DiskpartScriptManager();
                    dsm.RunDiskpartScriptByScriptFile(DiskOperation.GenerateMBRAndUEFIScript(WTGModel.userSettings.EFIPartitionSize.ToString(), WTGModel.ud));

                    //ProcessManager.ECMD("diskpart.exe", " /s \"" + WTGOperation.diskpartScriptPath + "\\uefimbr.txt\"");

                    if (radiobtnLegacy.Checked)
                    {
                        UEFIMBRTypical();

                    }
                    else //uefi MBR VHD、VHDX模式
                    {
                        UefiMbrVHDVHDX();
                    }

                    //MessageBox.Show("UEFI模式写入完成!\n请重启电脑用优盘启动\n如有问题,可去论坛反馈!", "完成啦!", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else //非UEFI模式
                {
                    //传统
                    #region 格式化
                    if (WTGModel.udString.Contains("Removable Disk") && radiobtnLegacy.Checked)
                    {
                        if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_Legacywarning", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; }
                    }

                    if (!checkBoxDiskpart.Checked && !WTGModel.userSettings.DoNotFormat)//普通格式化
                    {
                        ProcessManager.ECMD("cmd.exe", "/c format " + WTGModel.ud.Substring(0, 2) + "/FS:ntfs /q /V: /Y");
                        //
                    }
                    //if (WTGOperation.forceFormat) //强制格式化
                    //{
                    //    System.Diagnostics.Process ud1 = System.Diagnostics.Process.Start(Application.StartupPath + "\\files\\" + "\\fbinst.exe", (" " + WTGOperation.ud.Substring(0, 2) + " format -r -f"));//Format disk
                    //    ud1.WaitForExit();
                    //}
                    #endregion
                    ///////////////////////////////////正式开始////////////////////////////////////////////////
                    if (radiobtnLegacy.Checked)
                    {
                        NonUEFITypical();

                    }
                    else //非UEFI VHD VHDX
                    {
                        NonUEFIVHDVHDX(false);
                    }
                }

            }
            catch (UserCancelException ex)
            {
                ErrorMsg em = new ErrorMsg(ex.Message);
                em.ShowDialog();
            }
            catch (Exception ex)
            {

                ErrorMsg em = new ErrorMsg(ex.Message);
                em.ShowDialog();
            }
            finally
            {
                writeSw.Stop();
                SystemSleepManagement.ResotreSleep();
            }
        }