Beispiel #1
0
        public void SetUpdateCheck(UpdateCheckType type)
        {
            using (var uow = _db.UnitOfWork)
            {
                var bc = uow.BotConfig.GetOrCreate(set => set);
                _bc.BotConfig.CheckForUpdates = bc.CheckForUpdates = type;
                uow.Complete();
            }

            if (type == UpdateCheckType.None)
            {
                _updateTimer.Change(Timeout.Infinite, Timeout.Infinite);
            }
        }
Beispiel #2
0
        //private async Task<string> GetNewRelease()
        //{
        //    var client = new GitHubClient(new ProductHeaderValue("nadekobot"));
        //    var lu = _bc.BotConfig.LastUpdate;
        //    var release = (await client.Repository.Release.GetAll("Kwoth", "NadekoBot").ConfigureAwait(false)).FirstOrDefault();

        //    if (release == null || release.CreatedAt.UtcDateTime <= lu)
        //        return null;

        //    SetNewLastUpdate(release.CreatedAt.UtcDateTime);

        //    return Format.Bold(release.Name) + "\n\n" + release.Body.TrimTo(1500);
        //}

        public void SetUpdateCheck(UpdateCheckType type)
        {
            using (var uow = _db.GetDbContext())
            {
                var bc = uow.BotConfig.GetOrCreate(set => set);
                _bc.BotConfig.CheckForUpdates = bc.CheckForUpdates = type;
                uow.SaveChanges();
            }

            //if (type == UpdateCheckType.None)
            //{
            //    _updateTimer.Change(Timeout.Infinite, Timeout.Infinite);
            //}
        }
Beispiel #3
0
        /// <summary>
        /// Checks for update.
        /// </summary>
        /// <param name="feedType">Type of the feed.</param>
        public void CheckForUpdate(UpdateCheckType feedType)
        {
            switch (feedType)
            {
            case UpdateCheckType.BetaBuilds:
                CheckForUpdatesByUrl(_configuration.BetaBuildsUpdateInfoUri);
                break;

            case UpdateCheckType.AllBuilds:
                CheckForUpdatesByUrl(_configuration.AllBuildsUpdateInfoUri);
                break;

            case UpdateCheckType.ReleaseBuilds:
            default:
                CheckForUpdatesByUrl(_configuration.ReleaseBuildUpdateInfoUri);
                break;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Only perform update check if last used database has to be opened automatically
        /// If this is not the case, use KeePass standard check for updates
        /// </summary>
        private void KeyPromptFormAdded()
        {
            if (!PluginConfig.Active)
            {
                return;
            }
            UpdateCheckType uct = UpdateCheckRequired();

            if (uct == UpdateCheckType.NotRequired)
            {
                return;
            }
            if (uct == UpdateCheckType.OnlyTranslations)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(CheckPluginLanguages));
                return;
            }
            m_kpf = GlobalWindowManager.TopWindow as KeyPromptForm;
            UpdateCheckEx.EnsureConfigured(m_host.MainWindow);
            //Try calling the internal method UpdateCheckEx.RunPriv
            //==> Running this in a seperate threads does not force the user to wait
            //    in case of e. g. connection issues
            //==> Creating this seperate thread manually allows
            //      - to check for completion of the update check
            //      - show the update window BEFORE "Open Database" window is shown
            //      - Skip waiting in case of e. g. connection issues
            //
            //As fallback the public method UpdateCheckRunEx.Run is called
            //This method runs in a separate thread
            //==> Update window might be shown AFTER "Open Database" window is shown
            if (PluginConfig.CheckSync)
            {
                UpdateCheckBackground();
            }
            if ((m_UpdateCheckStatus == UpdateCheckStatus.NotChecked) || (m_UpdateCheckStatus == UpdateCheckStatus.Error))
            {
                UpdateCheckEx.Run(false, null);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Check whether searching for updates of plugins or translations shall be done
        /// </summary>
        /// <returns>Type of required update check</returns>
        private UpdateCheckType UpdateCheckRequired()
        {
            UpdateCheckType result = UpdateCheckType.NotRequired;

            if (m_bUpdateCheckDone)
            {
                return(result);
            }

            m_bUpdateCheckDone = true;
            if (!KeePass.Program.Config.Application.Start.CheckForUpdate)
            {
                return(result);
            }
            if (!KeePass.Program.Config.Application.Start.OpenLastFile)
            {
                return(result);
            }
            if (KeePass.Program.Config.Application.Start.MinimizedAndLocked)
            {
                return(result);
            }

            DateTime dtNow = DateTime.UtcNow, dtLast;
            string   strLast = KeePass.Program.Config.Application.LastUpdateCheck;

            if ((strLast.Length > 0) && TimeUtil.TryDeserializeUtc(strLast, out dtLast))
            {
                if (dtNow.Date != dtLast.Date)
                {
                    return(UpdateCheckType.Required);
                }
                return(UpdateCheckType.NotRequired);
            }
            return(UpdateCheckType.Required);
        }
Beispiel #6
0
        public bool Check(UpdateCheckType updateType)
        {
            try {
                lock (this) {
                    if (running)
                    {
                        return(false);
                    }
                    var lastChecked = new DateTime();
                    try {
                        lastChecked = Properties.Settings.Default.LastChecked;
                    }
                    catch (Exception) {
                    }
                    if (updateType == UpdateCheckType.Periodical && DateTime.Now.Subtract(lastChecked).Days < 7)
                    {
                        return(false);
                    }
                    Properties.Settings.Default.LastChecked = DateTime.Now;
                    Properties.Settings.Default.Save();

                    running = true;
                }

                var thread = new Thread(CheckInternal)
                {
                    IsBackground = true
                };
                thread.Start(updateType);
                return(true);
            }
            catch (Exception) {
            }

            return(false);
        }
Beispiel #7
0
 public async Task UpdatesCheck(UpdateCheckType type)
 {
     _service.SetUpdateCheck(type);
     await ReplyConfirmLocalized("updates_check_set", type.ToString()).ConfigureAwait(false);
 }