Example #1
0
        public void CopyVHD()
        {
            //if (!ShouldContinue) return;

            if (NeedCopy)
            {
                if (File.Exists(VhdPath))
                {
                    //Application.DoEvent
                    //s();
                    //Thread.Sleep(100);
                    //Application.DoEvents();
                    //BigFileCopy(VhdPath, WTGModel.ud + WTGModel.userSettings.VHDNameWithoutExt + "." + WTGModel.vhdExtension, 32);
                    ProcessManager.AppendText(MsgManager.GetResString("Msg_Copy", MsgManager.ci));
                    ProcessManager.ECMD(WTGModel.applicationFilesPath + "\\fastcopy.exe", " /auto_close \"" + this.VhdPath + "\" /to=\"" + WTGModel.ud + "\"", MsgManager.GetResString("Msg_Copy", MsgManager.ci));

                    //BigFileCopy ()
                    //MsgManager.getResString("Msg_Copy")
                    //复制文件中...大约需要10分钟~1小时,请耐心等待!\r\n
                }
                if ((WTGModel.choosedImageType == "vhd" && !this.VhdPath.EndsWith("win8.vhd")) || (WTGModel.choosedImageType == "vhdx" && !this.VhdPath.EndsWith("win8.vhdx")))
                {
                    //Rename
                    //MsgManager.getResString("Msg_RenameError")
                    //重命名错误
                    try
                    {
                        File.Move(WTGModel.ud + this.VhdPath.Substring(this.VhdPath.LastIndexOf("\\") + 1), WTGModel.ud + WTGModel.vhdNameWithoutExt + "." + WTGModel.choosedImageType);
                    }
                    catch (Exception ex) { MessageBox.Show(MsgManager.GetResString("Msg_RenameError", MsgManager.ci) + ex.ToString()); }
                }
            }
        }
Example #2
0
 private void writeprogress_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (IsUserClosing)
     {
         DialogResult dResult = MessageBox.Show(MsgManager.GetResString("Msg_WritingAbort"), MsgManager.GetResString("Msg_Tip"), MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
         if (dResult == DialogResult.Yes)
         {
             IsUserClosing      = false;
             OnClosingException = new UserCancelException();
         }
         else
         {
             e.Cancel = true;
         }
     }
     try
     {
         //if (System.IO.Directory .Exists ())
         FileStream fs = new FileStream(WTGModel.logPath + "\\" + DateTime.Now.ToFileTime() + ".log", FileMode.Create, FileAccess.Write);
         fs.SetLength(0);
         StreamWriter sw = new StreamWriter(fs, Encoding.Default);
         string       ws = "";
         ws = Application.StartupPath + "\r\n程序版本:" + Application.ProductVersion + "\r\n" + System.DateTime.Now;
         sw.WriteLine(ws);
         ws = textBox1.Text;
         sw.WriteLine(ws);
         sw.Close();
         textBox1.Text = "";
     }
     catch (Exception ex)
     {
         Log.WriteLog("WriteProgressFormClosingError.log", ex.ToString());
     }
 }
Example #3
0
        public static void SyncCMD(List <string> cmds)
        {
            Process process = new Process();

            try
            {
                process.StartInfo.FileName = "cmd.exe";

                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardInput  = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;
                process.StartInfo.CreateNoWindow         = true;
                process.Start();
                foreach (var cmd in cmds)
                {
                    process.StandardInput.WriteLine(cmd);
                }
                process.StandardInput.WriteLine("exit");

                process.WaitForExit();
            }
            catch (Exception ex)
            {
                MessageBox.Show(MsgManager.GetResString("Msg_Failure", MsgManager.ci) + ex.ToString());
            }
            finally
            {
                process.Close();
            }
        }
Example #4
0
        private static void ExecuteCMD(string StartFileName, string StartFileArg, params string[] Txt)
        {
            Process process = new Process();

            //wp.ShowDialog();

            try
            {
                AppendText("Command:" + StartFileName + StartFileArg + "\r\n");
                for (int i = 0; i < Txt.Length; i++)
                {
                    AppendText(Txt[i]);
                }
                process.StartInfo.FileName               = StartFileName;
                process.StartInfo.Arguments              = StartFileArg;
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardInput  = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;
                process.StartInfo.CreateNoWindow         = true;
                process.OutputDataReceived              += new DataReceivedEventHandler(process_OutputDataReceived);
                process.EnableRaisingEvents              = true;
                process.Exited += new EventHandler(progress_Exited);
                process.Start();
                process.BeginOutputReadLine();
            }
            catch (Exception ex)
            {
                //MsgManager.getResString("Msg_Failure")
                //操作失败
                MessageBox.Show(MsgManager.GetResString("Msg_Failure", MsgManager.ci) + ex.ToString());
            }
        }
Example #5
0
        public static int SyncCMD(string cmd)
        {
            Process process  = new Process();
            int     exitcode = 1;

            try
            {
                process.StartInfo.FileName = "cmd.exe";

                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardInput  = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;
                process.StartInfo.CreateNoWindow         = true;
                process.Start();
                process.StandardInput.WriteLine(cmd);

                process.StandardInput.WriteLine("exit");

                process.WaitForExit();
                exitcode = process.ExitCode;
            }
            catch (Exception ex)
            {
                MessageBox.Show(MsgManager.GetResString("Msg_Failure", MsgManager.ci) + ex.ToString());
            }
            finally
            {
                process.Close();
            }
            return(exitcode);
        }
Example #6
0
        public void CreateVHD()
        {
            //if (!ShouldContinue) return;
            //else ShouldContinue = false;
            StringBuilder sb = new StringBuilder();

            if (WTGModel.choosedImageType == "vhd")
            {
                //sb.AppendLine("create vdisk file=" + this.VhdPath + " type=" + this.VhdType + " maximum=" + this.VhdSize);
                sb.AppendLine("select vdisk file=\"" + VhdPath + "\"");
                sb.AppendLine("attach vdisk");
                sb.AppendLine("assign letter=v");
                sb.AppendLine("exit");
            }
            else
            {
                sb.AppendLine("create vdisk file=\"" + this.VhdPath + "\" type=" + this.VhdType + " maximum=" + this.VhdSize);
                sb.AppendLine("select vdisk file=\"" + this.VhdPath + "\"");
                sb.AppendLine("attach vdisk");
                if (WTGModel.vhdPartitionType == "GPT")
                {
                    sb.AppendLine("convert gpt");
                }
                sb.AppendLine("create partition primary");
                sb.AppendLine("format fs=ntfs quick");
                sb.AppendLine("assign letter=v");
                sb.AppendLine("exit");
            }
            DiskpartScriptManager dsm = new DiskpartScriptManager();

            Log.WriteLog("CreateVHDScript.log", sb.ToString());
            //MessageBox.Show(sb.ToString());
            dsm.Args = sb.ToString();
            dsm.RunDiskpartScript();

            //try
            //{
            if (!Directory.Exists("V:\\"))
            {
                throw new VHDException(MsgManager.GetResString("Msg_VHDCreationError"));
            }

            if (WTGModel.choosedImageType != "vhd" && WTGModel.choosedImageType != "vhdx")
            {
                ApplyToVdisk();
            }
            if (WTGModel.choosedImageType != "vhd" && WTGModel.choosedImageType != "vhdx" && !WTGModel.isWimBoot && !File.Exists(@"v:\windows\regedit.exe"))
            {
                throw new VHDException(MsgManager.GetResString("Msg_ApplyError"));
                //ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_ApplyError", MsgManager.ci));
                //er.ShowDialog();
                //this.ShouldContinue = false;
            }
            //else
            //{
            //    this.ShouldContinue = true;
            //}
        }
Example #7
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.vhdTempPath + "\\win8.vhd");
                FileOperation.DeleteFile(WTGModel.vhdTempPath + "\\win8.vhdx");
                FileOperation.DeleteFile(WTGModel.vhdTempPath + "\\" + WTGModel.vhdNameWithoutExt + ".vhd");
                FileOperation.DeleteFile(WTGModel.vhdTempPath + "\\" + WTGModel.vhdNameWithoutExt + ".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;
            }
        }
 /// <summary>
 /// WIN7 TO GO注册表处理
 /// </summary>
 /// <param name="installdrive">系统盘所在盘盘符例如E:</param>
 public static void Win7REG(string installdrive)
 {
     try
     {
         ProcessManager.SyncCMD("reg.exe load HKU\\sys " + installdrive + "Windows\\System32\\Config\\SYSTEM  > \"" + WTGModel.logPath + "\\Win7REGLoad.log\"");
         int errorlevel = ProcessManager.SyncCMD("reg.exe import \"" + WTGModel.applicationFilesPath + "\\usb.reg\" >nul &if %errorlevel% ==0 (echo 注册表导入成功) else (echo 注册表导入失败)" + " > \"" + WTGModel.logPath + "\\Win7REGImport.log\"");
         ProcessManager.SyncCMD("reg.exe unload HKU\\sys " + " > \"" + WTGModel.logPath + "\\Win7REGLoad.log\"");
         Log.WriteLog("ImportReg.log", errorlevel.ToString());
         Fixletter("C:", installdrive);
     }
     catch (Exception err)
     {
         //MsgManager.getResString("Msg_win7usberror")
         //处理WIN7 USB启动时出现问题
         MessageBox.Show(MsgManager.GetResString("Msg_win7usberror", MsgManager.ci) + err.ToString());
     }
 }
Example #9
0
        private void TwiceAttachVHDAndWriteBootFile()
        {
            if (!NeedTwiceAttach)
            {
                return;
            }
            //if (!ShouldContinue) return;
            //AttachVHD(StringOperation.Combine(WTGOperation.WTGModel.ud, win8VhdFile));

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("select vdisk file=" + StringUtility.Combine(WTGModel.ud, WTGModel.win8VHDFileName));
            sb.AppendLine("attach vdisk");
            sb.AppendLine("sel partition 1");
            sb.AppendLine("assign letter=v");
            sb.AppendLine("exit");
            DiskpartScriptManager dsm = new DiskpartScriptManager();

            dsm.Args = sb.ToString();
            dsm.RunDiskpartScript();


            if (!Directory.Exists("V:\\"))
            {
                Log.WriteLog("TwiceAttachVhdError.log", "二次加载VHD失败");
                throw new VHDException(MsgManager.GetResString("Msg_VHDCreationError", MsgManager.ci));
            }
            //需要二次加载,一定不是需要写入X盘的UEFI模式
            if (WTGModel.ntfsUefiSupport)
            {
                BootFileOperation.BcdbootWriteBootFile(@"V:\", WTGModel.ud, FirmwareType.ALL);
            }
            else
            {
                BootFileOperation.BcdbootWriteBootFile(@"V:\", WTGModel.ud, FirmwareType.BIOS);
            }
            DetachVHD(StringUtility.Combine(WTGModel.ud, WTGModel.win8VHDFileName));
            if (!File.Exists(WTGModel.ud + "\\Boot\\BCD"))
            {
                CopyVHDBootFiles();
                //Log.WriteLog ("TwiceAttachFailed.log")
            }
        }
Example #10
0
 public void VHDDynamicSizeIns()
 {
     //if (!this.ShouldContinue) return;
     //MsgManager.getResString("FileName_VHD_Dynamic")
     //VHD模式说明.TXT
     using (FileStream fs1 = new FileStream(WTGModel.ud + MsgManager.GetResString("FileName_VHD_Dynamic", MsgManager.ci), FileMode.Create, FileAccess.Write))
     {
         fs1.SetLength(0);
         using (StreamWriter sw1 = new StreamWriter(fs1, Encoding.Default))
         {
             //try
             //{
             //MsgManager.getResString("Msg_VHDDynamicSize")
             //您创建的VHD为动态大小VHD,实际VHD容量:
             ////MsgManager.getResString("Msg_VHDDynamicSize2")
             //在VHD系统启动后将自动扩充为实际容量。请您在优盘留有足够空间确保系统正常启动!
             sw1.WriteLine(MsgManager.GetResString("Msg_VHDDynamicSize", MsgManager.ci) + this.VhdSize + "MB\n");
             sw1.WriteLine(MsgManager.GetResString("Msg_VHDDynamicSize2", MsgManager.ci));
         }
         //}
         //catch { }
         //sw1.Close();
     }
 }
Example #11
0
        private void SetVhdProp()
        {
            try
            {
                if (Path.GetExtension(WTGModel.imageFilePath) == ".vhd" || Path.GetExtension(WTGModel.imageFilePath) == ".vhdx")
                {
                    VhdType       = string.Empty;
                    VhdSize       = string.Empty;
                    VhdFileName   = string.Empty;
                    ExtensionType = string.Empty;
                    VhdPath       = WTGModel.imageFilePath;
                    NeedCopy      = true;
                }
                else
                {
                    //    ////////////////vhd设定///////////////////////
                    //    string vhd_type = "expandable";
                    //    vhd_size = "";
                    if (WTGModel.isFixedVHD)
                    {
                        VhdType = "fixed";
                    }
                    else
                    {
                        VhdType = "expandable";
                    }
                    if (WTGModel.userSetSize != 0)
                    {
                        VhdSize = (WTGModel.userSetSize * 1024).ToString();
                    }
                    else
                    {
                        long hardDiskFreeSpace = (long)WTGModel.UdObj.Size / 1048576;
                        //MessageBox.Show(hardDiskFreeSpace.ToString ());
                        //MessageBox.Show(hardDiskFreeSpace.ToString());
                        if (!WTGModel.isWimBoot)
                        {
                            if (hardDiskFreeSpace >= (int.Parse(vhdDefaultSize) + 1024))
                            {
                                VhdSize = vhdDefaultSize;
                            }
                            else
                            {
                                VhdSize = hardDiskFreeSpace == 0 ? vhdDefaultSize : (hardDiskFreeSpace - 500).ToString();
                            }
                        }
                        else
                        {
                            if (hardDiskFreeSpace >= (int.Parse(vhdDefaultSize) + 4096))
                            {
                                VhdSize = vhdDefaultSize;
                            }
                            else
                            {
                                VhdSize = hardDiskFreeSpace == 0 ? vhdDefaultSize : (hardDiskFreeSpace - 4096).ToString();
                            }
                        }
                    }

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


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

                    if (DiskOperation.GetHardDiskFreeSpace(WTGModel.vhdTempPath.Substring(0, 2) + "\\") <= vhdmaxsize || StringUtility.IsChina(WTGModel.vhdTempPath) || (WTGModel.isUefiGpt && !WTGModel.isLegacyUdiskUefi) || WTGModel.isUefiMbr || WTGModel.isWimBoot || WTGModel.isNoTemp)
                    {
                        this.NeedCopy = false;
                        this.VhdPath  = StringUtility.Combine(WTGModel.ud, WTGModel.win8VHDFileName);
                    }
                    else
                    {
                        this.NeedCopy = true;
                        this.VhdPath  = StringUtility.Combine(WTGModel.vhdTempPath, WTGModel.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();
            }
        }