check local version in updater

This commit is contained in:
Antelle 2016-02-07 14:49:31 +03:00
parent f1b1c8a8d5
commit 0c8a73b099
2 changed files with 24 additions and 15 deletions

View File

@ -122,7 +122,7 @@ var Updater = {
}
if (!startedByUser && that.getAutoUpdateType() === 'install') {
that.update(startedByUser);
} else if (UpdateModel.instance.get('lastVersion') !== RuntimeInfo.version) {
} else if (that.compareVersions(UpdateModel.instance.get('lastVersion'), RuntimeInfo.version) > 0) {
UpdateModel.instance.set('updateStatus', 'found');
}
},
@ -140,32 +140,40 @@ var Updater = {
},
canAutoUpdate: function() {
var launcherVersion = Launcher.version.split('.');
var minLauncherVersion = UpdateModel.instance.get('lastCheckUpdMin');
if (minLauncherVersion) {
minLauncherVersion = minLauncherVersion.split('.');
for (var num = 0; num < minLauncherVersion.length; num++) {
var min = minLauncherVersion[num] | 0,
actual = launcherVersion[num] | 0;
if (min < actual) {
return true;
}
if (min > actual) {
UpdateModel.instance.set({ updateStatus: 'ready', updateManual: true });
return false;
}
var cmp = this.compareVersions(Launcher.version, minLauncherVersion);
if (cmp < 0) {
UpdateModel.instance.set({ updateStatus: 'ready', updateManual: true });
return false;
}
}
return true;
},
compareVersions: function(left, right) {
left = left.split('.');
right = right.split('.');
for (var num = 0; num < left.length; num++) {
var partLeft = left[num] | 0,
partRight = right[num] | 0;
if (partLeft < partRight) {
return -1;
}
if (partLeft > partRight) {
return 1;
}
}
return 0;
},
update: function(startedByUser, successCallback) {
var ver = UpdateModel.instance.get('lastVersion');
if (!this.enabled) {
logger.info('Updater is disabled');
return;
}
if (ver === RuntimeInfo.version) {
if (this.compareVersions(RuntimeInfo.version, ver) >= 0) {
logger.info('You are using the latest version');
return;
}

View File

@ -91,7 +91,8 @@ var SettingsGeneralView = Backbone.View.extend({
return errMsg;
case 'ok':
var msg = Locale.setGenCheckedAt + ' ' + Format.dtStr(UpdateModel.instance.get('lastCheckDate')) + ': ';
if (RuntimeInfo.version === UpdateModel.instance.get('lastVersion')) {
var cmp = Updater.compareVersions(RuntimeInfo.version, UpdateModel.instance.get('lastVersion'));
if (cmp >= 0) {
msg += Locale.setGenLatestVer;
} else {
msg += Locale.setGenNewVer.replace('{}', UpdateModel.instance.get('lastVersion')) + ' ' +