Errores solucionados, Ahora se utiliza la nueva ruta de descarga de los archivos Access

This commit is contained in:
Juan Ferrer Toribio 2016-03-31 12:51:45 +02:00
parent 70cbbcbd44
commit c0756ff258
3 changed files with 80 additions and 54 deletions

View File

Before

Width:  |  Height:  |  Size: 264 KiB

After

Width:  |  Height:  |  Size: 264 KiB

Binary file not shown.

View File

@ -1,22 +1,17 @@
var Modules =
{
'tpv': 'TPV_MySQL2',
'ent': 'ENT_MySQL',
'com': 'COM_MySQL',
'enc': 'ENC_MySQL',
'eti': 'ETI',
'lab': 'LAB_MySQL'
};
var App =
var Conf =
{
appName: 'Verdnatura',
dsName: 'verdnatura',
dsPath: 'HKCU\\Software\\ODBC\\ODBC.INI\\verdnatura',
regPath: 'HKCU\\Software\\Verdnatura',
remoteUrl: 'https://www.verdnatura.es/download',
regPath: 'HKCU\\Software\\Verdnatura\\vn-access',
remoteUrl: 'https://www.verdnatura.es/vn-access',
dbHost: 'db.verdnatura.es',
defaultModule: 'tpv'
};
var App =
{
shell: new ActiveXObject ('WScript.Shell'),
fso: new ActiveXObject ('scripting.filesystemobject'),
@ -38,19 +33,18 @@ var App =
if (split.length > 1)
this.module = split[1].replace (/^"+|"+$/g, '');
if (!this.module || Modules[this.module] === undefined)
this.module = 'tpv';
this.fileName = Modules[this.module];
this.appDir = this.getEnv ('ProgramFiles') +'\\'+ this.appName;
this.moduleDir = this.shell.SpecialFolders ('AppData') +'\\'+ this.appName;
this.remoteFile = this.remoteUrl +'/'+ this.fileName +'.7z';
this.compressFile = this.getEnv ('TEMP') +'\\'+ this.fileName +'.7z';
this.mdbFile = this.moduleDir +'\\'+ this.fileName +'.mdb';
if (!this.module)
this.module = Conf.defaultModule;
this.appDir = this.getEnv ('ProgramFiles') +'\\'+ Conf.appName;
this.moduleDir = this.shell.SpecialFolders ('AppData') +'\\'+ Conf.appName;
this.remoteFile = Conf.remoteUrl +'/'+ this.module +'.7z';
this.compressFile = this.getEnv ('TEMP') +'\\'+ this.module +'.7z';
this.mdbFile = this.moduleDir +'\\'+ this.module +'.mdb';
// Crea las entradas necesarias en el registro
var configured = this.regRead (this.regPath, 'configured');
var configured = this.regRead (Conf.regPath, 'configured');
if (!configured)
{
@ -75,8 +69,8 @@ var App =
var params = {
'Driver' : driverPath,
'DESCRIPTION' : this.appName,
'SERVER' : this.dbHost,
'DESCRIPTION' : Conf.appName,
'SERVER' : Conf.dbHost,
'DATABASE' : 'vn2008',
'SSLCA' : this.appDir +'\\cacert.pem',
'SSLVERIFY' : 1,
@ -84,7 +78,7 @@ var App =
};
this.createOdbc (
this.dsName,
Conf.dsName,
'Mysql ODBC 5.1 Driver',
params
);
@ -96,8 +90,8 @@ var App =
var params = {
'Driver' : driverPath,
'DESCRIPTION' : this.appName,
'Servername' : this.dbHost,
'DESCRIPTION' : Conf.appName,
'Servername' : Conf.dbHost,
'DATABASE' : 'vn',
'UID' : '',
'USERNAME' : '',
@ -112,14 +106,14 @@ var App =
// Marca la aplicación como configurada
this.regWrite (this.regPath, 'configured', 1, 'REG_DWORD');
this.regWrite (Conf.regPath, 'configured', 1, 'REG_DWORD');
}
// Carga los datos del formulario
var user = this.regRead (this.dsPath, 'UID');
var password = this.regRead (this.dsPath, 'PWD');
var remember = this.regRead (this.regPath, 'remember');
var user = this.regRead (Conf.dsPath, 'UID');
var password = this.regRead (Conf.dsPath, 'PWD');
var remember = this.regRead (Conf.regPath, 'remember');
if (user)
this.$('user').value = user;
@ -199,21 +193,21 @@ var App =
if (!password || password === '')
throw new Error ('Introduce una contraseña');
this.regWrite (this.dsPath, 'UID', user, 'REG_SZ');
this.regWrite (this.dsPath, 'PWD', password, 'REG_SZ');
this.regWrite (Conf.dsPath, 'UID', user, 'REG_SZ');
this.regWrite (Conf.dsPath, 'PWD', password, 'REG_SZ');
// Obtiene la última versión usando la conexión ODBC de MySQL
var mysqlConn = new ActiveXObject ('ADODB.Connection');
try {
mysqlConn.Open (this.dsName);
mysqlConn.open (Conf.dsName);
}
catch (e) {
throw new Error ('Usuario o contraseña incorrectos');
}
var sql = 'SELECT version FROM vn2008.versiones WHERE programa = \''+ this.module +'\'';
var sql = 'SELECT version FROM versiones WHERE programa = \''+ this.module +'\'';
var rs = mysqlConn.execute (sql);
var lastVersion = parseInt (rs.fields(0).value);
@ -224,8 +218,8 @@ var App =
var localVersion = -1;
if (this.fso.FileExists (this.mdbFile))
{
if (this.fso.fileExists (this.mdbFile))
try {
var mdbConn = new ActiveXObject ('ADODB.Connection');
mdbConn.open ('Provider=Microsoft.Jet.OLEDB.4.0; Data Source='+ this.mdbFile +';');
@ -236,9 +230,10 @@ var App =
oRs.close ();
mdbConn.close ();
}
catch (e) {}
// Compara la versión local con la última versión
if (localVersion < lastVersion)
{
this._disableUi (true, 'Actualizando');
@ -252,7 +247,7 @@ var App =
}
catch (e)
{
//this.regWrite (this.dsPath, 'PWD', '', 'REG_SZ');
this.clearPassword ();
this._disableUi (false);
this.reset ();
this.showMessage (e.message);
@ -268,36 +263,67 @@ var App =
if (request.status !== 200)
throw new Error ('Error al actualizar: '+ request.statusText);
if (this.fso.FileExists (this.compressFile))
this.fso.DeleteFile (this.compressFile);
if (this.fso.fileExists (this.compressFile))
this.fso.deleteFile (this.compressFile);
var stream = new ActiveXObject ('ADODB.Stream');
stream.Open ();
stream.open ();
stream.Type = 1; //adTypeBinary
stream.Write (request.responseBody);
stream.write (request.responseBody);
stream.Position = 0;
stream.SaveToFile (this.compressFile, 2);
stream.Close ();
stream.saveToFile (this.compressFile, 2);
stream.close ();
if (this.fso.FileExists (this.mdbFile))
this.fso.DeleteFile (this.mdbFile);
if (this.fso.fileExists (this.mdbFile))
this.fso.deleteFile (this.mdbFile);
// XXX: Code for the old installer modules
var oldModules = {
'tpv': 'TPV_MySQL2',
'ent': 'ENT_MySQL',
'com': 'COM_MySQL',
'enc': 'ENC_MySQL',
'eti': 'ETI',
'lab': 'LAB_MySQL'
};
var oldMdb = this.moduleDir +'\\'+ oldModules[this.module] +'.mdb';
if (this.fso.fileExists (oldMdb))
this.fso.deleteFile (oldMdb);
// XXX: End
this.run ('7za e "'+ this.compressFile +'" -o"'+ this.moduleDir +'"', true);
this.fso.DeleteFile (this.compressFile);
this.fso.deleteFile (this.compressFile);
// XXX: Code for the old installer modules
if (!this.fso.fileExists (this.mdbFile) && this.fso.fileExists (oldMdb))
this.fso.moveFile (oldMdb, this.mdbFile);
// XXX: End
this.openMdb ();
}
catch (e)
{
this.clearPassword ();
this.showMessage (e.message);
}
this._disableUi (false);
},
clearPassword: function ()
{
this.regWrite (Conf.dsPath, 'PWD', '', 'REG_SZ');
},
openMdb: function ()
{
var remember = this.$('remember').checked ? 1 : 0;
this.regWrite (this.regPath, 'remember', remember, 'REG_DWORD');
this.regWrite (Conf.regPath, 'remember', remember, 'REG_DWORD');
this.shell.exec ('"%ProgramFiles%\\Microsoft Office\\OFFICE11\\MSACCESS.EXE" "'+
this.mdbFile +'" /cmd "'+ this.$('user').value +'"');
@ -350,13 +376,13 @@ var App =
getEnv: function (varName)
{
return this.shell.ExpandEnvironmentStrings ('%'+ varName +'%');
return this.shell.expandEnvironmentStrings ('%'+ varName +'%');
},
regRead: function (path, key)
{
try {
var value = this.shell.RegRead (path +'\\'+ key);
var value = this.shell.regRead (path +'\\'+ key);
}
catch (e) {
var value = null;
@ -367,7 +393,7 @@ var App =
regWrite: function (path, key, value, type)
{
this.shell.RegWrite (path +'\\'+ key, value, type);
this.shell.regWrite (path +'\\'+ key, value, type);
},
regWrites: function (path, type, values)