UPDATES: Implement and use method for normalizing interval value to accepted values

This commit is contained in:
Eugene Sandulenko 2016-04-01 21:29:29 +02:00
parent 14478a65f1
commit a743ec2e07
4 changed files with 22 additions and 14 deletions

View File

@ -80,7 +80,7 @@ MacOSXUpdateManager::MacOSXUpdateManager() {
setAutomaticallyChecksForUpdates(kUpdateStateDisabled);
} else {
setAutomaticallyChecksForUpdates(kUpdateStateEnabled);
setUpdateCheckInterval(ConfMan.getInt("updates_check"));
setUpdateCheckInterval(normalizeInterval(ConfMan.getInt("updates_check")));
}
}
@ -110,16 +110,7 @@ void MacOSXUpdateManager::setUpdateCheckInterval(int interval) {
if (interval == kUpdateIntervalNotSupported)
return;
const int *vals = getUpdateIntervals();
while (*vals != -1) {
if (interval == *vals)
break;
vals++;
}
if (*vals == -1)
interval = kUpdateIntervalOneDay;
interval = normalizeInterval(interval);
[sparkleUpdater setUpdateCheckInterval:(NSTimeInterval)interval];
}

View File

@ -38,6 +38,16 @@ const int *UpdateManager::getUpdateIntervals() {
return updateIntervals;
}
int UpdateManager::normalizeInterval(int interval) {
const int *val = updateIntervals;
while (*val != -1)
if (*val > interval)
return *val;
return val[-1]; // Return maximal acceptable value
}
const char *UpdateManager::updateIntervalToString(int interval) {
switch (interval) {
case kUpdateIntervalNotSupported:

View File

@ -105,9 +105,18 @@ public:
/**
* Returns string representation of a given interval.
*
* @param interval The interval.
* @return pointer to localized string of given interval.
*/
static const char *updateIntervalToString(int interval);
/**
* Rounds up the given interval to acceptable value.
*
* @param interval The interval.
* @return rounded up interval
*/
static int normalizeInterval(int interval);
};
} // End of namespace Common

View File

@ -1243,7 +1243,7 @@ GlobalOptionsDialog::GlobalOptionsDialog()
}
if (ConfMan.hasKey("updates_check"))
_updatesPopUp->setSelectedTag(ConfMan.getInt("updates_check"));
_updatesPopUp->setSelectedTag(Common::UpdateManager::normalizeInterval(ConfMan.getInt("updates_check")));
else
_updatesPopUp->setSelectedTag(Common::UpdateManager::kUpdateIntervalNotSupported);
@ -1397,8 +1397,6 @@ void GlobalOptionsDialog::close() {
} else {
g_system->getUpdateManager()->setAutomaticallyChecksForUpdates(Common::UpdateManager::kUpdateStateEnabled);
g_system->getUpdateManager()->setUpdateCheckInterval(_updatesPopUp->getSelectedTag());
ConfMan.setInt("updates_check", g_system->getUpdateManager()->getUpdateCheckInterval());
}
}
#endif