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(); } }
private void 错误提示测试ToolStripMenuItem_Click(object sender, EventArgs e) { FormatAlert fa = new FormatAlert("ces"); fa.ShowDialog(); //BootFileOperation.BcdbootWriteBootFile("h:", "h:", FirmwareType.BIOS); }