コード例 #1
0
ファイル: Form1.cs プロジェクト: CakeRepository/Friendly-Dism
        /// <summary>
        /// Mount the Wim and set UI to mounted
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mountWimButtom_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(wimFileTextBox.Text) || !String.IsNullOrEmpty(exportPathTextBox.Text) || !String.IsNullOrEmpty(indexTextBox.Text))
            {
                DismApi.Initialize(DismLogLevel.LogErrors);
                Task t = Task.Factory.StartNew(() =>
                {
                    if (this.InvokeRequired)
                    {
                        this.Invoke((MethodInvoker)(() =>
                        {
                            loadingPanel.Visible = true;
                            mainPanel.Enabled = false;
                            mainPanel.Visible = false;
                            uiControlMounted(true);
                        }));
                    }
                    try
                    {
                        DismMountImageOptions s = new DismMountImageOptions();
                        string imagePath        = wimFileTextBox.Text;
                        string mountPath        = exportPathTextBox.Text;
                        int imageIndex          = Convert.ToInt32(indexTextBox.Text);

                        // Create the mount dir if it doesn't exit
                        if (Directory.Exists(mountPath) == false)
                        {
                            Directory.CreateDirectory(mountPath);
                        }
                        // Mount the image
                        DismApi.MountImage(imagePath, mountPath, imageIndex, false, s, dismProgress_action);
                        MountPath = mountPath;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex);
                    }
                    finally
                    {
                        if (this.InvokeRequired)
                        {
                            this.Invoke((MethodInvoker)(() =>
                            {
                                loadingPanel.Visible = false;
                                mainPanel.Enabled = true;
                                mainPanel.Visible = true;
                            }));
                        }
                        // Shut down the DismApi
                        DismApi.Shutdown();
                    }
                });
            }
            else
            {
                MessageBox.Show("Please Select the WIM Folder and Mount Folder paths. DISM Approves");
            }
        }
コード例 #2
0
        public async Task <bool> MountImage(string mountPath, ProgressBar pb)
        {
            await Task.Factory.StartNew(() =>
            {
                DismApi.MountImage(_wimPath, mountPath, _index, false, DismMountImageOptions.None,
                                   delegate(DismProgress progress) { pb.SetValue(progress.Current); });
            });


            return(true);
        }
コード例 #3
0
        private DismSession GetSession()
        {
            foreach (DismMountedImageInfo mountedImageInfo in DismApi.GetMountedImages())
            {
                DismApi.UnmountImage(mountedImageInfo.MountPath, false);
            }

            DismApi.CleanupMountpoints();

            DismApi.MountImage(InstallWimPath, MountPath, 1);

            return(DismApi.OpenOfflineSession(MountPath));
        }
コード例 #4
0
        private void integrate_wim()
        {
            //block buttons
            en_dis_able_everything(false);
            //clear progress bar
            refresh_progress_bar_total(0, 100);
            //status bar
            refresh_status_label("Status", "Busy");

            //not necessary, but looks more clear
            List <string> path     = new List <string>();
            List <string> vol      = new List <string>();
            List <string> name     = new List <string>();
            List <string> platform = new List <string>();
            List <string> lang     = new List <string>();
            List <string> ver      = new List <string>();

            for (int i = 0; i < lv_ptr.Items.Count; i++)
            {
                path.Add(lv_ptr.Items[i].SubItems[0].Text);
                vol.Add(lv_ptr.Items[i].SubItems[1].Text);
                name.Add(lv_ptr.Items[i].SubItems[2].Text);
                platform.Add(lv_ptr.Items[i].SubItems[3].Text);
                lang.Add(lv_ptr.Items[i].SubItems[4].Text);
                ver.Add(lv_ptr.Items[i].SubItems[5].Text);
            }

            if (this.textBox_mnt_point.Text.Length == 0)
            {
                mount_point = Environment.GetEnvironmentVariable("tmp") + "\\wim_integrator_mnt_point";
            }
            else
            {
                mount_point = this.textBox_mnt_point.Text;
            }
            if (this.textBox_tmp_folder.Text.Length == 0)
            {
                tmp_folder = des_wim_path + ".temp";
            }
            else
            {
                tmp_folder = this.textBox_tmp_folder.Text;
            }

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

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

            DismProgressCallback prog_callback = refresh_progress_bar_step;

            DismApi.Initialize(DismLogLevel.LogErrors);

            //main loop
            for (int i = 0; i < lv_ptr.Items.Count; i++)
            {
                src_wim_path = path[i];
                src_wim_vol  = Convert.ToInt32(vol[i]);
                string vol_name = name[i] + "_" +
                                  platform[i] + "_" +
                                  lang[i] + "_" +
                                  ver[i];

                //mount vol

                //clear progress bar
                refresh_progress_bar_step(0, 100);
                //status bar
                refresh_status_label("DISM", "Mounting");

                lv_ptr.Items[i].BackColor = Color.Gold;//color
                DismApi.MountImage(src_wim_path, mount_point, src_wim_vol, true, prog_callback);

                //imagex
                lv_ptr.Items[i].BackColor = Color.Aqua;//color
                Process imagex = new Process();
                imagex.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
                imagex.StartInfo.CreateNoWindow         = true;
                imagex.StartInfo.UseShellExecute        = false;
                imagex.StartInfo.RedirectStandardOutput = true;
                imagex.StartInfo.RedirectStandardError  = true;

                string imagex_flag = "/scroll /compress" + " " + comp_lv + " " + "/temp" + " " + "\"" + tmp_folder + "\"" + " ";
                //imagex cannot create new image by using append, must use capture insted, everything else is the same, stupid.
                string imagex_operation;
                if (i == 0)
                {
                    imagex_operation = "/capture" + " ";
                }
                else
                {
                    imagex_operation = "/append" + " ";
                }
                string imagex_option = "\"" + mount_point + "\"" + " " + "\"" + des_wim_path + "\"" + " " + "\"" + vol_name + "\"";
                imagex.StartInfo.FileName  = "imagex.exe";
                imagex.StartInfo.Arguments = imagex_flag + imagex_operation + imagex_option;

                imagex.Start();

                //clear progress bar
                refresh_progress_bar_step(0, 100);
                string progress;
                while (!imagex.HasExited)
                {
                    progress = imagex.StandardOutput.ReadLine();
                    if (progress != null)
                    {
                        if (progress.StartsWith("[") && !progress.Contains("ERROR"))
                        {
                            refresh_progress_bar_step(Convert.ToInt32(progress.Substring(2, 3)), 100);
                        }
                        //status bar
                        refresh_status_label("IMAGEX", progress);
                    }
                    //avoid load cpu
                    //since there is no any ReadReady() kind of stuff, I have to use this dirty and easy way
                    Thread.Sleep(10);
                }

                //umount vol

                //clear progress bar
                refresh_progress_bar_step(0, 100);
                //status bar
                refresh_status_label("DISM", "Unmounting");

                lv_ptr.Items[i].BackColor = Color.DodgerBlue;//color
                DismApi.UnmountImage(mount_point, false, prog_callback);

                if (imagex.ExitCode == 0)//color
                {
                    lv_ptr.Items[i].BackColor = Color.Lime;
                }
                else
                {
                    lv_ptr.Items[i].BackColor = Color.Red;
                }

                refresh_progress_bar_total(i + 1, lv_ptr.Items.Count);
            }

            DismApi.Shutdown();
            if (Directory.Exists(mount_point))
            {
                Directory.Delete(mount_point, true);
            }
            if (Directory.Exists(tmp_folder))
            {
                Directory.Delete(tmp_folder, true);
            }

            //unblock buttos
            en_dis_able_everything(true);
            refresh_status_label("Status", "Ready");
        }