コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: WuAgent.cs プロジェクト: OldMaCKY/wumgr
        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();
            }
        }
コード例 #3
0
ファイル: WuAgent.cs プロジェクト: x-danger/wumgr
        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);
        }
コード例 #4
0
ファイル: WuAgent.cs プロジェクト: OldMaCKY/wumgr
        protected void OnFinished(RetCodes ret, bool needReboot = false)
        {
            FinishedArgs args = new FinishedArgs(mCurOperation, ret, needReboot);

            mCurOperation = AgentOperation.None;

            Finished?.Invoke(this, args);
        }
コード例 #5
0
ファイル: WuAgent.cs プロジェクト: hobbit19/wumgr
        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);
        }
コード例 #6
0
ファイル: WuAgent.cs プロジェクト: OldMaCKY/wumgr
        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);
        }
コード例 #7
0
ファイル: WuAgent.cs プロジェクト: OldMaCKY/wumgr
        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);
        }
コード例 #8
0
ファイル: WuAgent.cs プロジェクト: hobbit19/wumgr
        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);
        }
コード例 #9
0
ファイル: WuAgent.cs プロジェクト: hobbit19/wumgr
        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);
        }
コード例 #10
0
ファイル: WuAgent.cs プロジェクト: hobbit19/wumgr
        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;
        }
コード例 #11
0
ファイル: WuAgent.cs プロジェクト: OldMaCKY/wumgr
        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);
        }
コード例 #12
0
ファイル: WuAgent.cs プロジェクト: OldMaCKY/wumgr
        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);
        }
コード例 #13
0
ファイル: WuAgent.cs プロジェクト: OldMaCKY/wumgr
        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);
        }
コード例 #14
0
ファイル: WuAgent.cs プロジェクト: hobbit19/wumgr
        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);
        }
コード例 #15
0
ファイル: WuAgent.cs プロジェクト: OldMaCKY/wumgr
        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());
        }
コード例 #16
0
ファイル: WuAgent.cs プロジェクト: OldMaCKY/wumgr
        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);
        }
コード例 #17
0
ファイル: WuAgent.cs プロジェクト: OldMaCKY/wumgr
 public FinishedArgs(AgentOperation op, RetCodes ret, bool needReboot = false)
 {
     Op           = op;
     Ret          = ret;
     RebootNeeded = needReboot;
 }
コード例 #18
0
ファイル: WuAgent.cs プロジェクト: hobbit19/wumgr
        protected void OnFinished(bool success, bool needReboot = false)
        {
            mCurOperation = AgentOperation.None;

            Finished?.Invoke(this, new FinishedArgs(success, needReboot));
        }