public static extern void DismUnmountImage( [NotNull] string mountPath, DismCommitAndUnmountFlags flags, [CanBeNull] SafeWaitHandle cancelEvent, [CanBeNull] DismProgressCallback progress, IntPtr userData );
public static async Task <DismFeatureInfo> EnableWindowsFeatures(string featureName, DismProgressCallback dismProgressCallback) { if (string.IsNullOrWhiteSpace(featureName)) { throw new ArgumentException(); } DismApi.Initialize(DismLogLevel.LogErrors); DismFeatureInfo retVal; try { using (var session = DismApi.OpenOnlineSession()) { DismApi.EnableFeatureByPackageName(session, featureName, null, false, true, new List <string>(), dismProgressCallback); retVal = DismApi.GetFeatureInfo(session, featureName); } } finally { DismApi.Shutdown(); } await Task.Delay(200).ConfigureAwait(false); return(retVal); }
public static extern void DismCommitImage( uint session, DismCommitAndUnmountFlags flags, [CanBeNull] SafeWaitHandle cancelEvent, [CanBeNull] DismProgressCallback progress, IntPtr userData );
public static extern void DismRemovePackage( uint session, [NotNull] string identifier, PackageIdentifier packageIdentifier, [CanBeNull] SafeWaitHandle cancelEvent, [CanBeNull] DismProgressCallback progress, IntPtr userData );
public static extern void DismCheckImageHealth( uint session, bool scanImage, [CanBeNull] SafeWaitHandle cancelEvent, [CanBeNull] DismProgressCallback progress, IntPtr userData, out ImageHealthState imageHealth );
public static extern void DismDisableFeature( uint session, [NotNull] string featureName, [CanBeNull] string packageName, bool removePayload, [CanBeNull] SafeWaitHandle cancelEvent, [CanBeNull] DismProgressCallback progress, IntPtr userData );
public static extern void DismAddPackage( uint session, [NotNull] string packagePath, bool ignoreCheck, bool preventPending, [CanBeNull] SafeWaitHandle cancelEvent, [CanBeNull] DismProgressCallback progress, IntPtr userData );
public static extern void DismRestoreImageHealth( uint session, [CanBeNull, MarshalAs(UnmanagedType.LPArray)] string[] sourcePaths, uint sourcePathCount, bool limitAccess, [CanBeNull] SafeWaitHandle cancelEvent, [CanBeNull] DismProgressCallback progress, IntPtr userData );
public static extern void DismMountImage( [NotNull] string imageFilePath, [NotNull] string mountPath, uint imageIndex, [CanBeNull] string imageName, DismImageIdentifier imageIdentifier, ImageMountOptions flags, [CanBeNull] SafeWaitHandle cancelEvent, [CanBeNull] DismProgressCallback progress, IntPtr userData );
/// <summary> /// Initializes a new instance of the DismProgress class. /// </summary> /// <param name="callback">A DismProgressCallback to call when progress is made.</param> /// <param name="userData">A custom object to pass to the callback.</param> internal DismProgress(DismProgressCallback callback, object userData) { // Save the managed callback method _callback = callback; // Save the user data UserData = userData; // Create an EventWaitHandle so the operation can be canceled _eventHandle = new EventWaitHandle(false, EventResetMode.ManualReset); }
public static extern void DismEnableFeature( uint session, [NotNull] string featureName, [CanBeNull] string identifier, PackageIdentifier packageIdentifier, bool limitAccess, [CanBeNull, MarshalAs(UnmanagedType.LPArray)] string[] sourcePaths, uint sourcePathCount, bool enableAll, [CanBeNull] SafeWaitHandle cancelEvent, [CanBeNull] DismProgressCallback progress, IntPtr userData );
public static extern int DismAddCapability(DismSession session, string name, [MarshalAs(UnmanagedType.Bool)] bool limitAccess, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 6)] string[] sourcePaths, UInt32 sourcePathCount, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
internal DismProgress(DismProgressCallback callback, object userData) { _callback = callback; UserData = userData; _eventHandle = new EventWaitHandle(false, EventResetMode.ManualReset); }
public static extern int DismRemoveCapability(DismSession session, string name, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
public static extern int DismRemovePackage(DismSession session, string identifier, DismPackageIdentifier packageIdentifier, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
public static extern int DismRestoreImageHealth(DismSession session, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 2)] string[] sourcePaths, UInt32 sourcePathCount, [MarshalAs(UnmanagedType.Bool)] bool limitAccess, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
public static extern int DismEnableFeature(DismSession session, string featureName, string identifier, DismPackageIdentifier packageIdentifier, [MarshalAs(UnmanagedType.Bool)] bool limitAccess, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 6)] string[] sourcePaths, UInt32 sourcePathCount, [MarshalAs(UnmanagedType.Bool)] bool enableAll, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
public static extern int DismMountImage(string imageFilePath, string mountPath, UInt32 imageIndex, string imageName, DismImageIdentifier imageIdentifier, UInt32 flags, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
public static extern int DismUnmountImage(string mountPath, UInt32 flags, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
public static extern int DismAddPackage(DismSession session, string packagePath, [MarshalAs(UnmanagedType.Bool)] bool ignoreCheck, [MarshalAs(UnmanagedType.Bool)] bool preventPending, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
public static extern int DismCheckImageHealth(DismSession session, [MarshalAs(UnmanagedType.Bool)] bool scanImage, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData, out DismImageHealthState imageHealth);
public static extern int DismCommitImage(DismSession session, UInt32 flags, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
public static extern int DismDisableFeature(DismSession session, string featureName, string packageName, [MarshalAs(UnmanagedType.Bool)] bool removePayload, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
public static extern int _DismSetEdition(DismSession session, string editionID, string productKey, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
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"); }