refs #4974 Changes

This commit is contained in:
Guillermo Bonet 2023-01-25 13:58:16 +01:00
parent fd3074d1ca
commit 1c65af2343
1 changed files with 71 additions and 63 deletions

View File

@ -60,19 +60,12 @@ var App = {
}, },
onLoad: function() { onLoad: function() {
// Initializes the global variables // Initializes the global variables
var split = Verdnatura.commandLine.match(/(?:[^\s"]+|"[^"]*")+/g); this.module = App.getModule();
this.appDir = this.getEnv('ProgramFiles') +'\\'+ Conf.appName;
if (split.length > 1) this.moduleDir = this.shell.SpecialFolders('AppData') +'\\'+ Conf.appName;
this.module = split[1].replace(/^"+|"+$/g, ''); this.mdbPath = this.moduleDir +'\\' + this.module;
if (!this.module) this.compressFile = this.getEnv('TEMP') +'\\'+ this.module +'.7z';
this.module = Conf.defaultModule; this.certFile = this.appDir +'\\cacert.pem';
this.appDir = this.getEnv('ProgramFiles') + '\\' + Conf.appName;
this.moduleDir = this.shell.SpecialFolders('AppData') + '\\' + Conf.appName;
this.compressFile = this.getEnv('TEMP') + '\\' + this.module + '.7z';
this.mdbFile = this.moduleDir + '\\' + this.module + '.mdb';
this.lockFile = this.moduleDir + '\\' + this.module + '.ldb';
this.certFile = this.appDir + '\\cacert.pem';
// Creates the necessary registry entries // Creates the necessary registry entries
var lastVersion = this.regRead(Conf.regPath, 'lastExecutedVersion'); var lastVersion = this.regRead(Conf.regPath, 'lastExecutedVersion');
@ -127,7 +120,7 @@ var App = {
var selectDatarouce = document.querySelector('#datasource'); var selectDatarouce = document.querySelector('#datasource');
var option = []; var option = [];
var odbcName; var odbcName;
var allOdbc = this.EnumValues('HKCU\\SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources\\') var allOdbc = this.enumValues(Conf.odbcPath +'ODBC Data Sources\\')
for (var y in allOdbc) { for (var y in allOdbc) {
if (allOdbc[y].slice(-3) == Conf.identifier) { if (allOdbc[y].slice(-3) == Conf.identifier) {
odbcName = allOdbc[y].replace(Conf.identifier, '') odbcName = allOdbc[y].replace(Conf.identifier, '')
@ -368,28 +361,11 @@ var App = {
mysqlConn.close(); mysqlConn.close();
// Check the cretentials and return the last version number // Check the cretentials and return the last version number
var version = this.fetchVersion(); this.fetchVersion();
// Check if there is a new version, and if there is, download it
if (version) {
this.disableUi(true, _('Updating'));
var remoteFile = version
? '.archive/'+ this.module +'/'+ version +'.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
this.openMdb();
} catch (err) { } catch (err) {
this.catchError(err); this.catchError(err);
} }
}, },
/** /**
* Gets information about the version to download. * Gets information about the version to download.
* cmdle * cmdle
@ -410,49 +386,68 @@ var App = {
this.request('GET', 'MdbVersions/findOne', params, function(err, res) { this.request('GET', 'MdbVersions/findOne', params, function(err, res) {
if (err) if (err)
throw new Error ('Version could not be retrieved: '+ err.message +': '); throw new Error ('Version could not be retrieved: '+ err.message +': ');
alert(this.lockFile)
// Checks if it's already open // Checks if it's already open
if (App.fso.fileExists(this.lockFile)) if (App.fso.fileExists(App.lockFile()))
try { try {
App.fso.deleteFile(this.lockFile); App.fso.deleteFile(App.lockFile());
return res.version; this.version = 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 // Checks if MDB exists
if (!App.fso.fileExists(this.mdbFile)) if (!App.fso.fileExists(App.mdbFile()))
return res.version; this.version = res.version;
// If it's abnormaly bigger, maybe is corrupted, so force download // If it's abnormaly bigger, maybe is corrupted, so force download
var file = App.fso.getFile(this.mdbFile); if (!this.version) {
var file = App.fso.getFile(App.mdbFile());
if (file.size > Conf.maxCorruptSize * 1024 * 1024) if (file.size > Conf.maxCorruptSize * 1024 * 1024)
return res.version; this.version = res.version;
// Obtains the local version number from the MDB file // Obtains the local version number from the MDB file
var localVersion = this.mdbGetValue( var localVersion = App.mdbGetValue(
'SELECT Version FROM tblVariables', 'SELECT Version FROM tblVariables',
'Version', parseInt 'Version', parseInt
); );
if (!localVersion) if (!localVersion)
localVersion = false; localVersion = false;
// Determines if should download // Determines if should download
return !localVersion || res.version === false || localVersion != res.version !localVersion || res.version === false || localVersion != res.version
? res.version ? this.version = res.version
: null; : this.version = null;
}
if (this.version) {
// Check if there is a new version, and if there is, download it
if (version) {
App.disableUi(true, _('Updating'));
var module = App.getModule();
var remoteFile = this.version
? '.archive/'+ module +'/'+ this.version +'.7z'
: 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
this.openMdb();
}
}); });
}, },
mdbGetValue: function(query, field, parseFn) { mdbGetValue: function(query, field, parseFn) {
var value; var value;
try { try {
if (this.fso.fileExists(this.mdbFile)) { if (this.fso.fileExists(this.mdbFile())) {
var mdbConn = new ActiveXObject('ADODB.Connection'); var mdbConn = new ActiveXObject('ADODB.Connection');
mdbConn.open(this.getODBCString({ mdbConn.open(this.getODBCString({
'Provider': 'Microsoft.Jet.OLEDB.4.0', 'Provider': 'Microsoft.Jet.OLEDB.4.0',
'Data Source': this.mdbFile 'Data Source': this.mdbFile()
})); }));
try { try {
@ -493,8 +488,8 @@ var App = {
stream.saveToFile(this.compressFile, 2); stream.saveToFile(this.compressFile, 2);
stream.close(); stream.close();
if (this.fso.fileExists(this.mdbFile)) if (this.fso.fileExists(this.mdbFile()))
this.fso.deleteFile(this.mdbFile); this.fso.deleteFile(this.mdbFile());
this.run('7za e "'+ this.compressFile +'" -o"'+ this.moduleDir +'"', true); this.run('7za e "'+ this.compressFile +'" -o"'+ this.moduleDir +'"', true);
this.fso.deleteFile(this.compressFile); this.fso.deleteFile(this.compressFile);
@ -503,7 +498,7 @@ var App = {
} }
try { try {
if (!this.fso.fileExists(this.mdbFile)) if (!this.fso.fileExists(this.mdbFile()))
throw new Error(_('MDB file not found')); throw new Error(_('MDB file not found'));
this.openMdb(); this.openMdb();
@ -521,7 +516,7 @@ var App = {
if (!this.fso.fileExists(accessBin)) if (!this.fso.fileExists(accessBin))
throw new Error(_('Microsoft Access 2003 is not installed')); throw new Error(_('Microsoft Access 2003 is not installed'));
this.shell.exec('"'+ accessBin +'" "'+ this.mdbFile +'"'); this.shell.exec('"'+ accessBin +'" "'+ this.mdbFile() +'"');
window.close(); window.close();
}, },
catchError: function(err) { catchError: function(err) {
@ -717,7 +712,7 @@ var App = {
Conf.identifier Conf.identifier
return odbcPath; return odbcPath;
}, },
EnumValues: function(RegKey) { enumValues: function(RegKey) {
var RootKey = new Object() var RootKey = new Object()
RootKey["HKCR"] = RootKey["HKEY_CLASSES_ROOT"] = 0x80000000; RootKey["HKCR"] = RootKey["HKEY_CLASSES_ROOT"] = 0x80000000;
RootKey["HKCU"] = RootKey["HKEY_CURRENT_USER"] = 0x80000001; RootKey["HKCU"] = RootKey["HKEY_CURRENT_USER"] = 0x80000001;
@ -729,13 +724,26 @@ var App = {
Locator = new ActiveXObject("WbemScripting.SWbemLocator"); Locator = new ActiveXObject("WbemScripting.SWbemLocator");
ServerConn = Locator.ConnectServer(null, "root\\default"); ServerConn = Locator.ConnectServer(null, "root\\default");
Registry = ServerConn.Get("StdRegProv"); Registry = ServerConn.Get("StdRegProv");
Method = Registry.Methods_.Item("EnumValues"); Method = Registry.Methods_.Item("enumValues");
p_In = Method.InParameters.SpawnInstance_(); p_In = Method.InParameters.SpawnInstance_();
p_In.hDefKey = RootVal; p_In.hDefKey = RootVal;
p_In.sSubKeyName = RegKey.substr(RegKey.indexOf("\\") + 1) p_In.sSubKeyName = RegKey.substr(RegKey.indexOf("\\") + 1)
p_Out = Registry.ExecMethod_(Method.Name, p_In); p_Out = Registry.ExecMethod_(Method.Name, p_In);
return p_Out.sNames.toArray(); return p_Out.sNames.toArray();
} }
},
getModule: function() {
var split = Verdnatura.commandLine.match(/(?:[^\s"]+|"[^"]*")+/g);
if (split.length > 1)
return split[1].replace(/^"+|"+$/g, '');
if (!this.module)
return Conf.defaultModule;
},
lockFile: function() {
return this.mdbPath +'.ldb';
},
mdbFile: function() {
return this.mdbPath +'.mdb';
} }
}; };