public RetCodes UnInstallUpdatesManually(List <MsUpdate> Updates) { if (mUpdateInstaller.IsBusy()) { return(RetCodes.Busy); } List <MsUpdate> FilteredUpdates = new List <MsUpdate>(); foreach (MsUpdate Update in Updates) { if (((int)Update.Attributes & (int)MsUpdate.UpdateAttr.Uninstallable) == 0) { AppLog.Line("Update can not be uninstalled: {0}", Update.Title); continue; } FilteredUpdates.Add(Update); } if (FilteredUpdates.Count == 0) { AppLog.Line("No updates selected or eligible for uninstallation"); return(RetCodes.NoUpdated); } mCurOperation = AgentOperation.RemoveingUpdates; OnProgress(-1, 0, 0, 0); if (!mUpdateInstaller.UnInstall(FilteredUpdates)) { OnFinished(RetCodes.InstallFailed); } return(RetCodes.InProgress); }
public void CancelOperations() { if (IsBusy()) { mCurOperation = AgentOperation.CancelingOperation; } // Note: at any given time only one (or none) of the 3 conditions can be true if (mCallback != null) { if (mSearchJob != null) { mSearchJob.RequestAbort(); } if (mDownloadJob != null) { mDownloadJob.RequestAbort(); } if (mInstalationJob != null) { mInstalationJob.RequestAbort(); } } else if (mUpdateDownloader.IsBusy()) { mUpdateDownloader.CancelOperations(); } else if (mUpdateInstaller.IsBusy()) { mUpdateInstaller.CancelOperations(); } }
private RetCodes SearchForUpdates() { mCurOperation = AgentOperation.CheckingUpdates; OnProgress(-1, 0, 0, 0); mCallback = new UpdateCallback(this); AppLog.Line("Searching for updates"); //for the above search criteria refer to // http://msdn.microsoft.com/en-us/library/windows/desktop/aa386526(v=VS.85).aspx try { //string query = "(IsInstalled = 0 and IsHidden = 0) or (IsInstalled = 1 and IsHidden = 0) or (IsHidden = 1)"; //string query = "(IsInstalled = 0 and IsHidden = 0) or (IsInstalled = 1 and IsHidden = 0) or (IsHidden = 1) or (IsInstalled = 0 and IsHidden = 0 and DeploymentAction='OptionalInstallation') or (IsInstalled = 1 and IsHidden = 0 and DeploymentAction='OptionalInstallation') or (IsHidden = 1 and DeploymentAction='OptionalInstallation')"; string query; if (MiscFunc.IsWindows7OrLower) { query = "(IsInstalled = 0 and IsHidden = 0) or (IsInstalled = 1 and IsHidden = 0) or (IsHidden = 1)"; } else { query = "(IsInstalled = 0 and IsHidden = 0 and DeploymentAction=*) or (IsInstalled = 1 and IsHidden = 0 and DeploymentAction=*) or (IsHidden = 1 and DeploymentAction=*)"; } mSearchJob = mUpdateSearcher.BeginSearch(query, mCallback, null); } catch (Exception err) { return(OnWuError(err)); } return(RetCodes.InProgress); }
protected void OnFinished(RetCodes ret, bool needReboot = false) { FinishedArgs args = new FinishedArgs(mCurOperation, ret, needReboot); mCurOperation = AgentOperation.None; Finished?.Invoke(this, args); }
private void SearchForUpdates() { mCurOperation = AgentOperation.CheckingUpdates; OnProgress(-1, 0, 0, 0); mCallback = new UpdateCallback(this); AppLog.Line("Searching for updates"); //for the above search criteria refer to // http://msdn.microsoft.com/en-us/library/windows/desktop/aa386526(v=VS.85).aspx mSearchJob = mUpdateSearcher.BeginSearch("(IsInstalled = 0 and IsHidden = 0) or (IsInstalled = 1 and IsHidden = 0) or (IsHidden = 1)", mCallback, null); }
public RetCodes DownloadUpdates(List <MsUpdate> Updates, bool Install = false) { if (mCallback != null) { return(RetCodes.Busy); } if (mDownloader == null) { mDownloader = mUpdateSession.CreateUpdateDownloader(); } mDownloader.Updates = new UpdateCollection(); foreach (MsUpdate Update in Updates) { IUpdate update = Update.GetUpdate(); if (update == null) { continue; } if (update.EulaAccepted == false) { update.AcceptEula(); } mDownloader.Updates.Add(update); } if (mDownloader.Updates.Count == 0) { AppLog.Line("No updates selected for download"); return(RetCodes.NoUpdated); } mCurOperation = Install ? AgentOperation.PreparingUpdates : AgentOperation.DownloadingUpdates; OnProgress(-1, 0, 0, 0); mCallback = new UpdateCallback(this); AppLog.Line("Downloading Updates... This may take several minutes."); try { mDownloadJob = mDownloader.BeginDownload(mCallback, mCallback, Updates); } catch (Exception err) { return(OnWuError(err)); } return(RetCodes.InProgress); }
public RetCodes UnInstallUpdates(List <MsUpdate> Updates) { if (mCallback != null) { return(RetCodes.Busy); } if (mInstaller == null) { mInstaller = mUpdateSession.CreateUpdateInstaller() as IUpdateInstaller; } mInstaller.Updates = new UpdateCollection(); foreach (MsUpdate Update in Updates) { IUpdate update = Update.GetUpdate(); if (update == null) { continue; } if (!update.IsUninstallable) { AppLog.Line("Update can not be uninstalled: {0}", update.Title); continue; } mInstaller.Updates.Add(update); } if (mDownloader.Updates.Count == 0) { AppLog.Line("No updates selected or eligible for uninstallation"); return(RetCodes.NoUpdated); } mCurOperation = AgentOperation.RemoveingUpdates; OnProgress(-1, 0, 0, 0); mCallback = new UpdateCallback(this); AppLog.Line("Removing Updates... This may take several minutes."); try { mInstalationJob = mInstaller.BeginUninstall(mCallback, mCallback, Updates); } catch (Exception err) { return(OnWuError(err)); } return(RetCodes.InProgress); }
public bool UnInstallUpdatesOffline(List <MsUpdate> Updates) { if (mUpdateInstaller.IsBusy()) { return(false); } mCurOperation = AgentOperation.RemoveingUpdtes; if (mUpdateInstaller.UnInstall(Updates)) { OnProgress(-1, 0, 0, 0); return(true); } return(false); }
private bool InstallUpdatesOffline(List <MsUpdate> Updates, MultiValueDictionary <string, string> AllFiles) { if (mUpdateInstaller.IsBusy()) { return(false); } mCurOperation = AgentOperation.InstallingUpdates; if (mUpdateInstaller.Install(Updates, AllFiles)) { OnProgress(-1, 0, 0, 0); return(true); } return(false); }
public void CancelOperations() { mUpdateDownloader.CancelOperations(); mUpdateInstaller.CancelOperations(); if (mSearchJob != null) { try { mUpdateSearcher.EndSearch(mSearchJob); } catch { } mSearchJob = null; } if (mDownloadJob != null) { try { mDownloader.EndDownload(mDownloadJob); } catch { } mDownloadJob = null; } if (mInstalationJob != null) { try { if (mCurOperation == AgentOperation.InstallingUpdates) { mInstaller.EndInstall(mInstalationJob); } else if (mCurOperation == AgentOperation.RemoveingUpdtes) { mInstaller.EndUninstall(mInstalationJob); } } catch { } mInstalationJob = null; } mCurOperation = AgentOperation.None; mCallback = null; }
private RetCodes InstallUpdates(List <MsUpdate> Updates) { if (mCallback != null) { return(RetCodes.Busy); } if (mInstaller == null) { mInstaller = mUpdateSession.CreateUpdateInstaller() as IUpdateInstaller; } mInstaller.Updates = new UpdateCollection(); foreach (MsUpdate Update in Updates) { IUpdate update = Update.GetUpdate(); if (update == null) { continue; } mInstaller.Updates.Add(update); } if (mInstaller.Updates.Count == 0) { AppLog.Line("No updates selected for instalation"); return(RetCodes.NoUpdated); } mCurOperation = AgentOperation.InstallingUpdates; OnProgress(-1, 0, 0, 0); mCallback = new UpdateCallback(this); AppLog.Line("Installing Updates... This may take several minutes."); try { mInstalationJob = mInstaller.BeginInstall(mCallback, mCallback, Updates); } catch (Exception err) { return(OnWuError(err)); } return(RetCodes.InProgress); }
public RetCodes UnInstallUpdatesOffline(List <MsUpdate> Updates) { if (mUpdateInstaller.IsBusy()) { return(RetCodes.Busy); } mCurOperation = AgentOperation.RemoveingUpdates; OnProgress(-1, 0, 0, 0); if (!mUpdateInstaller.UnInstall(Updates)) { OnFinished(RetCodes.InstallFailed); return(RetCodes.InstallFailed); } return(RetCodes.InProgress); }
private RetCodes InstallUpdatesManually(List <MsUpdate> Updates, MultiValueDictionary <string, string> AllFiles) { if (mUpdateInstaller.IsBusy()) { return(RetCodes.Busy); } mCurOperation = AgentOperation.InstallingUpdates; OnProgress(-1, 0, 0, 0); if (!mUpdateInstaller.Install(Updates, AllFiles)) { OnFinished(RetCodes.InstallFailed); return(RetCodes.InstallFailed); } return(RetCodes.InProgress); }
private bool InstallUpdates(List <MsUpdate> Updates) { if (mCallback != null) { return(false); } if (mInstaller == null) { mInstaller = mUpdateSession.CreateUpdateInstaller() as IUpdateInstaller; } mInstaller.Updates = new UpdateCollection(); foreach (MsUpdate Update in Updates) { IUpdate update = Update.GetUpdate(); if (update == null) { continue; } mInstaller.Updates.Add(update); } if (mInstaller.Updates.Count == 0) { AppLog.Line("No updates selected for instalation"); return(false); } mCurOperation = AgentOperation.InstallingUpdates; OnProgress(-1, 0, 0, 0); mCallback = new UpdateCallback(this); AppLog.Line("Installing Updates... This may take several minutes."); mInstalationJob = mInstaller.BeginInstall(mCallback, mCallback, Updates); return(true); }
public RetCodes SearchForUpdates(bool Download, bool IncludePotentiallySupersededUpdates = false) { if (mCallback != null) { return(RetCodes.Busy); } mUpdateSearcher.IncludePotentiallySupersededUpdates = IncludePotentiallySupersededUpdates; if (Download) { mCurOperation = AgentOperation.PreparingCheck; OnProgress(-1, 0, 0, 0); AppLog.Line("downloading wsusscn2.cab"); List <UpdateDownloader.Task> downloads = new List <UpdateDownloader.Task>(); UpdateDownloader.Task download = new UpdateDownloader.Task(); download.Url = Program.IniReadValue("Options", "OfflineCab", "http://go.microsoft.com/fwlink/p/?LinkID=74689"); download.Path = dlPath; download.FileName = "wsusscn2.cab"; downloads.Add(download); if (!mUpdateDownloader.Download(downloads)) { OnFinished(RetCodes.DownloadFailed); return(RetCodes.DownloadFailed); } return(RetCodes.InProgress); } RetCodes ret = SetupOffline(); if (ret < 0) { return(ret); } return(SearchForUpdates()); }
public RetCodes DownloadUpdatesManually(List <MsUpdate> Updates, bool Install = false) { if (mUpdateDownloader.IsBusy()) { return(RetCodes.Busy); } mCurOperation = Install ? AgentOperation.PreparingUpdates : AgentOperation.DownloadingUpdates; OnProgress(-1, 0, 0, 0); List <UpdateDownloader.Task> downloads = new List <UpdateDownloader.Task>(); foreach (MsUpdate Update in Updates) { if (Update.Downloads.Count == 0) { AppLog.Line("Error: No Download Url's found for update {0}", Update.Title); continue; } foreach (string url in Update.Downloads) { UpdateDownloader.Task download = new UpdateDownloader.Task(); download.Url = url; download.Path = dlPath + @"\" + Update.KB; download.KB = Update.KB; downloads.Add(download); } } if (!mUpdateDownloader.Download(downloads, Updates)) { OnFinished(RetCodes.DownloadFailed); return(RetCodes.DownloadFailed); } return(RetCodes.InProgress); }
public FinishedArgs(AgentOperation op, RetCodes ret, bool needReboot = false) { Op = op; Ret = ret; RebootNeeded = needReboot; }
protected void OnFinished(bool success, bool needReboot = false) { mCurOperation = AgentOperation.None; Finished?.Invoke(this, new FinishedArgs(success, needReboot)); }