refs #4974 Solved bug app open error

This commit is contained in:
Guillermo Bonet 2023-02-07 19:02:05 +01:00
parent cc79a76120
commit 1a6f22e539
1 changed files with 51 additions and 45 deletions

View File

@ -405,58 +405,64 @@ var App = {
); );
}, },
onVersionRequest: function(err, res) { onVersionRequest: function(err, res) {
if (err) try {
throw new Error ('Version could not be retrieved: '+ err.message +': '); if (err)
throw new Error ('Version could not be retrieved: '+ err.message +': ');
var lastVersion; var lastVersion;
// Checks if it's already open // Checks if it's already open
if (this.fso.fileExists(this.lockFile)) if (this.fso.fileExists(this.lockFile))
try { try {
this.fso.deleteFile(this.lockFile); this.fso.deleteFile(this.lockFile);
lastVersion = res.version; lastVersion = res.version;
} catch (e) { } catch (e) {
throw new Error(_('Application it\'s already open')); throw new Error(_('Application it\'s already open'));
} }
// Checks if MDB exists
if (!this.fso.fileExists(this.mdbFile))
lastVersion = res.version;
// If it's abnormaly bigger, maybe is corrupted, so force download // Checks if MDB exists
if (!lastVersion) { if (!this.fso.fileExists(this.mdbFile))
var file = this.fso.getFile(this.mdbFile);
if (file.size > Conf.maxCorruptSize * 1024 * 1024)
lastVersion = res.version; lastVersion = res.version;
// Obtains the local version number from the MDB file // If it's abnormaly bigger, maybe is corrupted, so force download
var localVersion = this.mdbGetValue( if (!lastVersion) {
'SELECT Version FROM tblVariables', var file = this.fso.getFile(this.mdbFile);
'Version', parseInt if (file.size > Conf.maxCorruptSize * 1024 * 1024)
); lastVersion = res.version;
if (!localVersion)
localVersion = false;
// Determines if should download // Obtains the local version number from the MDB file
!localVersion || res.version === false || localVersion != res.version var localVersion = this.mdbGetValue(
? lastVersion = res.version 'SELECT Version FROM tblVariables',
: lastVersion = null; 'Version', parseInt
);
if (!localVersion)
localVersion = false;
// Determines if should download
!localVersion || res.version === false || localVersion != res.version
? lastVersion = res.version
: lastVersion = null;
}
// Check if there is a new version, and if there is, download it
if (lastVersion) {
this.disableUi(true, _('Updating'));
var remoteFile = lastVersion
? '.archive/'+ this.module +'/'+ lastVersion +'.7z'
: this.module +'.7z?'+ new Date().getTime();
remoteFile = Conf.cdnURL +'/'+ remoteFile;
var request = new ActiveXObject('MSXML2.XMLHTTP.6.0');
request.open('GET', remoteFile, true);
request.onreadystatechange = function() {
App.onRequestReady(request);
};
request.send();
} else
App.openMdb();
}
catch (err) {
this.catchError(err);
} }
// Check if there is a new version, and if there is, download it
if (lastVersion) {
this.disableUi(true, _('Updating'));
var remoteFile = lastVersion
? '.archive/'+ this.module +'/'+ lastVersion +'.7z'
: this.module +'.7z?'+ new Date().getTime();
remoteFile = Conf.cdnURL +'/'+ remoteFile;
var request = new ActiveXObject('MSXML2.XMLHTTP.6.0');
request.open('GET', remoteFile, true);
request.onreadystatechange = function() {
App.onRequestReady(request);
};
request.send();
} else
App.openMdb();
}, },
mdbGetValue: function(query, field, parseFn) { mdbGetValue: function(query, field, parseFn) {
var value; var value;