Bug fixes, refactor

This commit is contained in:
juan 2020-03-03 14:07:02 +01:00
parent 548752f55f
commit 20808940d0
1 changed files with 37 additions and 53 deletions

View File

@ -35,7 +35,7 @@ var Locale = {
,"MDB file not found":
"No se encontro el fichero MDB"
,"Cache files have been deleted":
"Se han borrado todos los ficheros cacheados"
"Se han borrado todos los ficheros de la caché"
}
};
@ -227,19 +227,11 @@ var App = {
var version = this.fetchVersion();
if (version) {
if (version !== null) {
this.disableUi(true, _('Updating'));
var remoteFile;
if (version.code == 'last') {
remoteFile = this.module +'.7z?';
remoteFile += version.number
? 'v'+ version.number
: new Date().getTime();
} else {
remoteFile = '.archive/'+ this.module +'/'+ version.number;
}
var remoteFile = version
? '.archive/'+ this.module +'/'+ version +'.7z'
: this.module +'.7z?'+ new Date().getTime();
remoteFile = Conf.remoteUrl +'/'+ remoteFile;
var request = new ActiveXObject('MSXML2.XMLHTTP');
@ -258,66 +250,59 @@ var App = {
/**
* Gets information about the version to download.
*
* @return {Object} Version information or %null if local is up-to-date
* @return {Number|Boolean} Version number, %false if cannot
* fetch or %null if local is up-to-date
*/
fetchVersion: function() {
// Gets the last version number using the MySQL ODBC connection
var mysqlConn;
var mysqlConn = new ActiveXObject('ADODB.Connection');;
try {
mysqlConn = this.openOdbc({
mysqlConn.open(this.getOdbcString({
'Driver': '{MySQL ODBC 5.1 Driver}',
'Server': Conf.dbHost,
'Database': Conf.dbName,
'User': this.$('user').value,
'Password': this.$('password').value,
'SslVerify': 1,
'SslCa': this.certFile
});
'Uid': this.$('user').value,
'Pwd': this.$('password').value,
'Sslverify': 1,
'Sslca': this.certFile
}));
} catch (err) {
var dbErrors = mysqlConn.errors;
var dbErrors = mysqlConn && mysqlConn.errors;
if (dbErrors.count > 0) {
var newErr;
if (dbErrors && dbErrors.count > 0) {
var dbError = dbErrors.item(0);
switch (dbError.NativeError) {
case 1045: // Access denied
clearPassword = true;
newErr = new Error(_('Bad login'));
newErr.code = 'BadLogin';
err = new Error(_('Bad login'));
err.name = 'BadLogin';
break;
case 2003: // Can't connect
newErr = new Error(_('Server can\'t be reached'));
err = new Error(_('Server can\'t be reached'));
break;
default:
errorMsg = dbError.description;
err = new Error(dbError.description);
}
dbErrors.clear();
throw newErr;
} else
throw err;
dbErrors.clear();
}
throw err;
}
var sql = "SELECT version FROM versiones WHERE programa = '"+ this.module +"'";
var rs = mysqlConn.execute(sql);
var lastVersion = rs.EOF ? null : parseInt(rs.fields(0).value);
var version = {
code: 'last',
number: lastVersion
};
var version = rs.EOF ? false : parseInt(rs.fields(0).value);
rs.close();
mysqlConn.close();
if (this.$('previous-version').checked && lastVersion > 1)
version = {
code: 'previous',
number: lastVersion - 1
};
if (this.$('previous-version').checked && version > 1)
version -= 1;
// Checks if it's already open
@ -346,33 +331,32 @@ var App = {
var localVersion;
try {
var mdbConn = this.openOdbc({
var mdbConn = new ActiveXObject('ADODB.Connection');
mdbConn.open(this.getOdbcString({
'Provider': 'Microsoft.Jet.OLEDB.4.0',
'Data Source': this.mdbFile
});
}));
var oRs = new ActiveXObject('ADODB.Recordset');
oRs.Open('SELECT Version FROM tblVariables', mdbConn);
localVersion = oRs.EOF ? -1 : parseInt(oRs('Version'));
localVersion = oRs.EOF ? false : parseInt(oRs('Version'));
oRs.close();
mdbConn.close();
} catch (e) {}
// Compares the local version with the requested version
// Determines if should download
return !localVersion || localVersion != version.number
return !localVersion || version === false || localVersion != version
? version
: null;
},
openOdbc(options) {
getOdbcString: function(options) {
var optionsArray = [];
for (var option of options)
for (var option in options)
optionsArray.push(option +'='+ options[option]);
var conn = new ActiveXObject('ADODB.Connection');
return conn.open(optionsArray.join(';'));
return optionsArray.join(';');
},
onRequestReady: function(request) {
@ -428,7 +412,7 @@ var App = {
},
catchError: function(err) {
var clearPassword = err.code == 'BadLogin';
var clearPassword = err.name == 'BadLogin';
if (!this.$('remember').checked || clearPassword)
this.regWrite(Conf.dsPath, 'PWD', '', 'REG_SZ');