first commit (2004-06-30)

This commit is contained in:
José David Guillén 2021-09-01 18:20:30 +02:00
commit 1c2734ad7b
16 changed files with 1637 additions and 0 deletions

BIN
bin/LiveUpdate.exe Normal file

Binary file not shown.

BIN
bin/LiveUpdate.tds Normal file

Binary file not shown.

5
bin/liveUpdate.INI Normal file
View File

@ -0,0 +1,5 @@
[liveUpdate]
app=myTPV standard
# login=
# pass=

14
bin/versions.dat Normal file
View File

@ -0,0 +1,14 @@
[status]
msg=Ok
[apps]
lineas=4
l1_app=
gestion.exe
l1_ver=1.0.0.21
l2_app=comercial.exe
l2_ver=1.0.0.0
l3_app=Incidencias.exe
l3_ver=1.0.0.0
l4_app=QR_Designer.exe
l4_ver=1.0.0.0

40
liveUpdate.txt Normal file
View File

@ -0,0 +1,40 @@
17-jun-2004
23:21 Codificacion parcial del módulo PHP (lado del servidor), que valida las licencias por usuario
y controla los permisos de actualizaciones para las aplicaciones.
22:01 A ver, a ver...
25-abr-2004
14:49 Ya descarga tambien los ficheros, y aunque solo necesita un lavado
de cara en la interfaz, todo funciona como debería.
-- Pendiente:
Comprobar que el fichero que se ha bajado es correcto...
(y solo entonces sobreescribir con el otro)
Si el fichero no se puede sobreescribir porque esta en uso
acordarme que existe una entrada en el registro que permite
eliminar y renombrar ficheros, de forma automática una vez
reiniciado el sistema y proponer reiniciarlo una vez configurada
esta entrada.
Si el fichero estaba marcado con "Autoexec"
ejecutarlo una vez finalizada todas las descargas.
12:53 Haciendo que funcione...
22-abr-2004
17:10 que soñera
16:05 He estado compilando otras cosas, ahora si me pongo
con este proyecto...
15:47 a ver como nos lo montamos...
21-abr-2004
22:07 ... - iba a mirar algo, pero veamos otra cosa...
20-abr-2004
17:30 Ok! Casi listo para empezar a rellenar el código de descarga...
16:48 Despues de muchos cambios, casi voy haciendo que me funcione
aunque a veces, creo que sería mejor "reCodificar" por completo
todas las funciones para obtener los datos por internet, y mandar
a tomar "viento" a la pu..ta API de Microsoft.
(Y todo por la mierda de saber a priori, el tamaño de la descarga).
19-abr-2004
xx:xx Bueno, para que poner hora, si voy a estar TODO EL DÍA.
por fin comienzo el proyecto que tanto tiempo llebava en mente
y es que hoy día, si una aplicación (con tantas actualizaciones),
no posee un actualizador onLine, no esta completa...

153
src/LiveUpdate.bpr Normal file
View File

@ -0,0 +1,153 @@
<?xml version='1.0' encoding='utf-8' ?>
<!-- C++Builder XML Project -->
<PROJECT>
<MACROS>
<VERSION value="BCB.06.00"/>
<PROJECT value="..\bin\LiveUpdate.exe"/>
<OBJFILES value="..\obj\LiveUpdate.obj ..\obj\interfaz.obj ..\obj\donwloads.obj
..\obj\TMD5.obj"/>
<RESFILES value="LiveUpdate.res"/>
<IDLFILES value=""/>
<IDLGENFILES value=""/>
<DEFFILE value=""/>
<RESDEPEN value="$(RESFILES) interfaz.dfm"/>
<LIBFILES value=""/>
<LIBRARIES value="rtl.lib vcl.lib"/>
<SPARELIBS value="vcl.lib rtl.lib"/>
<PACKAGES value="vcl.bpi rtl.bpi dbrtl.bpi adortl.bpi vcldb.bpi vclx.bpi bdertl.bpi
vcldbx.bpi ibxpress.bpi dsnap.bpi cds.bpi bdecds.bpi qrpt.bpi teeui.bpi
teedb.bpi tee.bpi dss.bpi teeqr.bpi visualclx.bpi visualdbclx.bpi
dsnapcrba.bpi dsnapcon.bpi bcbsmp.bpi vclie.bpi xmlrtl.bpi inet.bpi
inetdbbde.bpi inetdbxpress.bpi inetdb.bpi nmfast.bpi webdsnap.bpi
bcbie.bpi websnap.bpi soaprtl.bpi dclocx.bpi dbexpress.bpi dbxcds.bpi
indy.bpi bcb2kaxserver.bpi ZCore.bpi ZParseSql.bpi ZPlain.bpi ZDbc.bpi
ZComponent.bpi"/>
<PATHCPP value=".;"/>
<PATHPAS value=".;"/>
<PATHRC value=".;"/>
<PATHASM value=".;"/>
<DEBUGLIBPATH value="$(BCB)\lib\debug"/>
<RELEASELIBPATH value="$(BCB)\lib\release"/>
<LINKER value="ilink32"/>
<USERDEFINES value="_DEBUG"/>
<SYSDEFINES value="NO_STRICT"/>
<MAINSOURCE value="LiveUpdate.cpp"/>
<INCLUDEPATH value="&quot;C:\Archivos de programa\Borland\CBuilder6\Projects&quot;;&quot;C:\Documents and Settings\jd\Mis documentos\CBuilder\LiveUpdate\src&quot;;$(BCB)\include;$(BCB)\include\vcl"/>
<LIBPATH value="&quot;C:\Archivos de programa\Borland\CBuilder6\Projects&quot;;&quot;C:\Documents and Settings\jd\Mis documentos\CBuilder\LiveUpdate\src&quot;;C:\programacion\VCLs\lib;$(BCB)\lib\obj;$(BCB)\lib"/>
<WARNINGS value="-w-par"/>
<OTHERFILES value=""/>
</MACROS>
<OPTIONS>
<IDLCFLAGS value="-I&quot;C:\Archivos de programa\Borland\CBuilder6\Projects&quot;
-I&quot;C:\Documents and Settings\jd\Mis documentos\CBuilder\LiveUpdate\src&quot;
-I$(BCB)\include -I$(BCB)\include\vcl -src_suffix cpp -D_DEBUG -boa"/>
<CFLAG1 value="-Od -H=$(BCB)\lib\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -5 -b- -k -y -v -vi-
-c -tW -tWM"/>
<PFLAGS value="-N2..\obj -N0..\obj -$YD -$W -$O- -$A8 -v -JPHNE -M"/>
<RFLAGS value=""/>
<AFLAGS value="/mx /w2 /zd"/>
<LFLAGS value="-l..\obj -I..\obj -D&quot;&quot; -aa -Tpe -x -Gn -v"/>
<OTHERFILES value=""/>
</OPTIONS>
<LINKER>
<ALLOBJ value="c0w32.obj sysinit.obj $(OBJFILES)"/>
<ALLRES value="$(RESFILES)"/>
<ALLLIB value="$(LIBFILES) $(LIBRARIES) import32.lib cp32mt.lib"/>
<OTHERFILES value=""/>
</LINKER>
<FILELIST>
<FILE FILENAME="LiveUpdate.res" FORMNAME="" UNITNAME="LiveUpdate.res" CONTAINERID="ResTool" DESIGNCLASS="" LOCALCOMMAND=""/>
<FILE FILENAME="LiveUpdate.cpp" FORMNAME="" UNITNAME="LiveUpdate" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
<FILE FILENAME="interfaz.cpp" FORMNAME="Form1" UNITNAME="interfaz" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
<FILE FILENAME="donwloads.cpp" FORMNAME="" UNITNAME="donwloads" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
<FILE FILENAME="TMD5.cpp" FORMNAME="" UNITNAME="TMD5" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
</FILELIST>
<BUILDTOOLS>
</BUILDTOOLS>
<IDEOPTIONS>
[Version Info]
IncludeVerInfo=1
AutoIncBuild=1
MajorVer=1
MinorVer=0
Release=0
Build=0
Debug=0
PreRelease=0
Special=0
Private=0
DLL=0
Locale=3082
CodePage=1252
[Version Info Keys]
CompanyName=
FileDescription=
FileVersion=1.0.0.0
InternalName=
LegalCopyright=
LegalTrademarks=
OriginalFilename=
ProductName=
ProductVersion=1.0.0.0
Comments=
[Excluded Packages]
c:\archivos de programa\borland\cbuilder6\Bin\dclite60.bpl=Borland Integrated Translation Environment
[HistoryLists\hlIncludePath]
Count=1
Item0=C:\Archivos de programa\Borland\CBuilder6\Projects;C:\Documents and Settings\jd\Mis documentos\CBuilder\LiveUpdate\src;$(BCB)\include;$(BCB)\include\vcl
[HistoryLists\hlLibraryPath]
Count=1
Item0=C:\Archivos de programa\Borland\CBuilder6\Projects;C:\Documents and Settings\jd\Mis documentos\CBuilder\LiveUpdate\src;C:\programacion\VCLs\lib;$(BCB)\lib\obj;$(BCB)\lib
[HistoryLists\hlDebugSourcePath]
Count=1
Item0=$(BCB)\source\vcl
[HistoryLists\hlConditionals]
Count=1
Item0=_DEBUG
[HistoryLists\hlIntOutputDir]
Count=1
Item0=..\obj
[HistoryLists\hlFinalOutputDir]
Count=2
Item0=..\bin\
Item1=..\bin
[HistoryLists\hIBPIOutputDir]
Count=1
Item0=..\obj
[Debugging]
DebugSourceDirs=$(BCB)\source\vcl
[Parameters]
RunParams=
Launcher=
UseLauncher=0
DebugCWD=
HostApplication=
RemoteHost=
RemotePath=
RemoteLauncher=
RemoteCWD=
RemoteDebug=0
[Compiler]
ShowInfoMsgs=0
LinkDebugVcl=0
LinkCGLIB=0
[CORBA]
AddServerUnit=1
AddClientUnit=1
PrecompiledHeaders=1
</IDEOPTIONS>
</PROJECT>

33
src/LiveUpdate.cpp Normal file
View File

@ -0,0 +1,33 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("interfaz.cpp", Form1);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------

BIN
src/LiveUpdate.res Normal file

Binary file not shown.

354
src/TMD5.cpp Normal file
View File

@ -0,0 +1,354 @@
/*
Resumen MD5
Autor: José David Guillén
Basado en el fuente PASCAL de Dimka Maslov }
Derived from the RSA Data Security, Inc.
MD5 Message-Digest Algorithm described in RFC 1321
http://www.faqs.org/rfcs/rfc1321.html
*/
#include "TMD5.hpp"
#include <mem.h>
/* Constants for MD5Transform routine.
*/
#define S11 7
#define S12 12
#define S13 17
#define S14 22
#define S21 5
#define S22 9
#define S23 14
#define S24 20
#define S31 4
#define S32 11
#define S33 16
#define S34 23
#define S41 6
#define S42 10
#define S43 15
#define S44 21
static unsigned char PADDING[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
/* F, G, H and I are basic MD5 functions.
*/
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
/* ROTATE_LEFT rotates x left n bits.
*/
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
Rotation is separate from addition to prevent recomputation.
*/
#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
//------------------------------------------------------------------------------
void __fastcall TMD5::MD5Encode(unsigned char *Output, UINT4 *Input, const unsigned int Len)
{
UINT4 i,j;
for (i = 0, j = 0; j < Len; i++, j += 4)
{
Output[j] = (unsigned char)(Input[i] & 0xFF);
Output[j+1] = (unsigned char)( (Input[i] >> 8 ) & 0xFF);
Output[j+2] = (unsigned char)( (Input[i] >> 16 ) & 0xFF);
Output[j+3] = (unsigned char)( (Input[i] >> 24 ) & 0xFF);
}
}
//------------------------------------------------------------------------------
void __fastcall TMD5::MD5Decode(UINT4 *Output, const unsigned char *Input, const UINT4 Len)
{
UINT4 i,j;
for (i = 0, j = 0; j < Len; i++, j += 4)
Output[i] = ((UINT4)(Input[j])) | ((UINT4)(Input[j+1]) << 8) |
((UINT4)(Input[j+2]) << 16) | ((UINT4)(Input[j+3]) << 24);
}
//------------------------------------------------------------------------------
void __fastcall TMD5::MD5_memcpy(PByteArray Output, const PByteArray Input, UINT4 Len)
{
memcpy( Output, Input, Len );
}
//------------------------------------------------------------------------------
void __fastcall TMD5::MD5_memset(PByteArray Output, int Value, UINT4 Len)
{
setmem( Output, Len, (Byte)Value );
/*
for ( ; Len>0; Len-- )
Output[Len-1] = (Byte)Value;
*/
}
//------------------------------------------------------------------------------
void __fastcall TMD5::MD5Transform(UINT4 State[4], const unsigned char Buffer[64])
{
UINT4 a,b,c,d;
UINT4 x[16];
a=State[0]; b=State[1]; c=State[2]; d=State[3];
MD5Decode( x, Buffer, 64);
/* Round 1 */
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
/* Round 2 */
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
/* Round 3 */
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
/* Round 4 */
II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
State[0] += a;
State[1] += b;
State[2] += c;
State[3] += d;
MD5_memset( (PByteArray)x, 0, sizeof(x) );
}
//------------------------------------------------------------------------------
void __fastcall TMD5::MD5Init(TMD5Context *Context)
{
setmem( (void *)Context, sizeof(TMD5Context), 0);
Context->state[0] = 0x67452301;
Context->state[1] = 0xefcdab89;
Context->state[2] = 0x98badcfe;
Context->state[3] = 0x10325476;
}
//------------------------------------------------------------------------------
void __fastcall TMD5::MD5Update(TMD5Context *Context, const unsigned char *Input, const unsigned int InputLen)
{
unsigned int i, index, partLen;
/* Compute number of bytes mod 64 */
index = (unsigned int)((Context->count[0] >> 3) & 0x3F);
/* Update number of bits */
if ((Context->count[0] += ((UINT4)InputLen << 3)) < ((UINT4)InputLen << 3))
Context->count[1]++;
Context->count[1] += ((UINT4)InputLen >> 29);
partLen = 64 - index;
/* Transform as many times as possible.*/
if (InputLen >= partLen)
{
MD5_memcpy((PByteArray)&Context->buffer[index], (PByteArray)Input, partLen);
MD5Transform (Context->state, Context->buffer);
for (i = partLen; i + 63 < InputLen; i += 64)
MD5Transform (Context->state, &Input[i]);
index = 0;
}
else
i = 0;
/* Buffer remaining input */
MD5_memcpy((PByteArray)&Context->buffer[index], (PByteArray)&Input[i], InputLen-i);
}
//------------------------------------------------------------------------------
void __fastcall TMD5::MD5Final(unsigned char Digest[16], TMD5Context *Context)
{
unsigned char bits[8];
UINT4 index, padLen;
MD5Encode( bits, Context->count, 8);
index = (UINT4)( ( Context->count[0] >> 3) & 0x3F);
padLen = (index < 56) ? (56 - index) : (120 - index);
MD5Update(Context, PADDING, padLen);
MD5Update(Context, bits, 8);
MD5Encode(Digest, Context->state, 16);
MD5_memset((PByteArray)Context, 0, sizeof(*Context));
}
//------------------------------------------------------------------------------
AnsiString __fastcall TMD5::MD5DigestToStr(const TMD5Digest &Digest)
{
AnsiString Result;
int i;
Result="";
for ( i=0; i<=15; i++ )
Result = Result + IntToHex(Digest.v[i], 2);
return Result;
}
//------------------------------------------------------------------------------
TMD5Digest __fastcall TMD5::MD5String(const AnsiString S)
{
return MD5Buffer((PChar)S.c_str(), S.Length());
}
//------------------------------------------------------------------------------
TMD5Digest __fastcall TMD5::MD5File(const AnsiString FileName)
{
TMD5Digest Result;
TFileStream *F;
F = new TFileStream(FileName, fmOpenRead);
try {
Result=MD5Stream(F);
} __finally {
delete F;
}
return Result;
}
//------------------------------------------------------------------------------
/* Classes::*/
TMD5Digest __fastcall TMD5::MD5Stream(const Classes::TStream *Stream)
{
TMD5Context Context;
TMD5Digest Result;
Byte Buffer[4096];
int Size;
int ReadBytes;
int TotalBytes;
int SavePos;
MD5Init(&Context);
Size=Stream->Size;
SavePos=Stream->Position;
TotalBytes=0;
try {
Stream->Seek(0, soFromBeginning);
do {
ReadBytes=Stream->Read(Buffer, sizeof(Buffer));
TotalBytes+=ReadBytes;
MD5Update(&Context, Buffer, ReadBytes);
} while( !( (ReadBytes == 0) || (TotalBytes == Size) ) );
} __finally {
Stream->Seek(SavePos, soFromBeginning);
}
MD5Final((unsigned char *)&Result, &Context);
return Result;
}
//------------------------------------------------------------------------------
TMD5Digest __fastcall TMD5::MD5Buffer(const void *Buffer, int Size)
{
TMD5Context Context;
TMD5Digest Result;
MD5Init(&Context);
MD5Update(&Context, (unsigned char *)Buffer, Size);
MD5Final((unsigned char *)&Result, &Context);
return Result;
}
//------------------------------------------------------------------------------
bool __fastcall TMD5::MD5DigestCompare(const TMD5Digest &Digest1, const TMD5Digest &Digest2)
{
bool Result;
Result=true;
if (Digest1.A != Digest2.A) Result=false;
if (Digest1.B != Digest2.B) Result=false;
if (Digest1.C != Digest2.C) Result=false;
if (Digest1.D != Digest2.D) Result=false;
return Result;
}
//------------------------------------------------------------------------------

76
src/TMD5.hpp Normal file
View File

@ -0,0 +1,76 @@
#ifndef tmd5HPP
#define tmd5HPP
#include <Classes.hpp> // Pascal unit
#include <SysUtils.hpp> // Pascal unit
#include <Windows.hpp> // Pascal unit
#include <SysInit.hpp> // Pascal unit
#include <System.hpp> // Pascal unit
typedef struct TMD5Digest
{
union
{
struct
{
Byte v[16];
};
struct
{
int A, B, C, D;
};
};
} *PMD5Digest;
/* TIPOS */
typedef unsigned long int UINT4;
/*
typedef UINT4 TArray4UINT4[4];
typedef TArray4UINT4 *PArray4UINT4;
typedef UINT4 TArray2UINT4[2];
typedef TArray2UINT4 *PArray2UINT4;
typedef Byte TArray16Byte[16];
typedef TArray16Byte *PArray16Byte;
typedef Byte TArray64Byte[64];
typedef TArray64Byte *PArray64Byte;
*/
/*
typedef Byte TByteArray;
typedef TByteArray *PByteArray;
*/
typedef UINT4 TUINT4Array;
typedef TUINT4Array *PUINT4Array;
struct TMD5Context
{
UINT4 state[4];
UINT4 count[2];
unsigned char buffer[64];
};
typedef TMD5Context *PMD5Context;
class TMD5 {
private:
/* FUNCIONES */
void __fastcall MD5Encode(unsigned char *Output, UINT4 *Input, const unsigned int Len);
void __fastcall MD5Decode(UINT4 *Output, const unsigned char *Input, const UINT4 Len);
void __fastcall MD5_memcpy(PByteArray Output, const PByteArray Input, UINT4 Len);
void __fastcall MD5_memset(PByteArray Output, int Value, UINT4 Len);
void __fastcall MD5Transform(UINT4 State[4], const unsigned char Buffer[64]);
void __fastcall MD5Init(TMD5Context *Context);
void __fastcall MD5Update(TMD5Context *Context, const unsigned char *Input, const unsigned int InputLen);
void __fastcall MD5Final(unsigned char *Digest, TMD5Context *Context);
public:
AnsiString __fastcall MD5DigestToStr(const TMD5Digest &Digest);
TMD5Digest __fastcall MD5String(const AnsiString S);
TMD5Digest __fastcall MD5File(const AnsiString FileName);
TMD5Digest __fastcall MD5Stream(const Classes::TStream* Stream);
TMD5Digest __fastcall MD5Buffer(const void *Buffer, int Size);
bool __fastcall MD5DigestCompare(const TMD5Digest &Digest1, const TMD5Digest &Digest2);
};
#endif // TMD5

394
src/donwloads.cpp Normal file
View File

@ -0,0 +1,394 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#include <wininet.h>
#pragma hdrstop
// To resolve externals
// such as HttpOpenRequestA, InternetCrackUrlA,
// InternetReadFile, InternetCloseHandle,
// HttpSendRequestA, HttpQueryInfoA, and InternetOpenA
#pragma comment(lib, "WinInet.lib")
#include <string.h>
#include "donwloads.h"
#include <stdio.h>
#pragma package(smart_init)
//---------------------------------------------------------------------------
// Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall downloads::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
//---------------------------------------------------------------------------
__fastcall downloads::downloads(bool CreateSuspended)
: TThread(CreateSuspended)
{
// CreateSuspended = true;
file_target = NULL;
url_source = NULL;
validURL = false;
}
//---------------------------------------------------------------------------
bool __fastcall downloads::downloadFile( char *filename, char *url )
{
bGotFileSize = false;
file_target = filename;
url_source = url;
AnsiString m_sURLToDownload = AnsiString(url);
validURL=true;
//Validate the URL
URL_COMPONENTS uc;
TCHAR achHostName[256];
TCHAR achUrlPath[256];
memset( &uc, 0, sizeof(uc) );
uc.dwStructSize = sizeof(uc);
uc.lpszHostName = achHostName;
uc.dwHostNameLength = 256;
uc.lpszUrlPath = achUrlPath;
uc.dwUrlPathLength = 256;
if (!InternetCrackUrl((char *)m_sURLToDownload.data(), 0, ICU_ESCAPE, &uc ))
{
//Try sticking "http://" before it
m_sURLToDownload = AnsiString("http://") + m_sURLToDownload;
if (!InternetCrackUrl((char *)m_sURLToDownload.data(), m_sURLToDownload.Length(), 0, &uc ))
// if (!AfxParseURL(m_sURLToDownload, m_dwServiceType, m_sServer, m_sObject, m_nPort))
validURL=false;
}
if ( validURL )
{
m_dwServiceType = uc.nScheme;
m_sServer = uc.lpszHostName;
m_sObject = uc.lpszUrlPath;
m_nPort = uc.nPort;
m_sUserName = uc.lpszUserName;
m_sPassword = uc.lpszPassword;
}
return validURL;
}
//---------------------------------------------------------------------------
void CALLBACK downloads::OnStatusCallBack(HINTERNET hInternet, DWORD dwContext, DWORD dwInternetStatus,
LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
{
//Convert from the SDK C world to the C++ world
downloads* pDlg = (downloads*) dwContext;
switch (dwInternetStatus)
{
case INTERNET_STATUS_RESOLVING_NAME:
{
pDlg->SetStatus((LPCTSTR) lpvStatusInformation); /*"RESOLVING_NAME:: ", */
break;
}
case INTERNET_STATUS_NAME_RESOLVED:
{
pDlg->SetStatus((LPCTSTR) lpvStatusInformation); /*"RESOLVED_NAME:: ", */
break;
}
case INTERNET_STATUS_CONNECTING_TO_SERVER:
{
pDlg->SetStatus((LPCTSTR) lpvStatusInformation); /*"CONNECTING:: ", */
break;
}
case INTERNET_STATUS_CONNECTED_TO_SERVER:
{
pDlg->SetStatus((LPCTSTR) lpvStatusInformation); /*"CONNECTED:: ", */
break;
}
case INTERNET_STATUS_REDIRECT:
{
pDlg->SetStatus((LPCTSTR) lpvStatusInformation); /*"REDIRECTING:: ", */
break;
}
default:
{
break;
}
}
}
//---------------------------------------------------------------------------
void __fastcall downloads::SetStatus(const char *sCaption)
{
// Actualizar aqui la barra de estados
// m_ctrlStatus.SetWindowText(sCaption);
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall downloads::updateTimeLeft(void)
{
if ( labelTimeLeft )
labelTimeLeft->Caption=msg;
}
void __fastcall downloads::updateTransferRate(void)
{
if ( labelTransferRate )
labelTransferRate->Caption=msg;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall downloads::updateProgress(void)
{
if ( m_ctrlProgress )
m_ctrlProgress->Position=passINT;
}
void __fastcall downloads::SetPercentage(int nPercentage)
{
passINT = nPercentage;
Synchronize( updateProgress );
}
void __fastcall downloads::SetProgress(DWORD dwBytesRead)
{
passINT = dwBytesRead/1024;
Synchronize( updateProgress );
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall downloads::updateProgressRange()
{
if ( m_ctrlProgress )
m_ctrlProgress->Max=passINT;
}
void __fastcall downloads::SetProgressRange(DWORD dwFileSize)
{
passINT = (short)((dwFileSize+512)/1024);
Synchronize( updateProgressRange );
}
//---------------------------------------------------------------------------
void __fastcall downloads::Execute()
{
//---- Place thread code here ----
if (!validURL) return;
HINTERNET m_hInternetSession, m_hHttpFile, m_hHttpConnection;
FILE *fout;
if ( (fout = fopen( file_target, "w" ))!=NULL )
{
//URLDownloadToFile(
try {
// while (!Terminated)
{
m_hInternetSession = InternetOpen("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
if ( m_hInternetSession )
{
// Configuramos la funcion "callback"
if(InternetSetStatusCallback(m_hInternetSession, OnStatusCallBack)!=INTERNET_INVALID_STATUS_CALLBACK)
{
// hFile = InternetOpenUrl( hINet, url_source, NULL, 0, 0, 0 ) ;
//Make the connection to the HTTP server
if (m_sUserName.data()!=NULL)
m_hHttpConnection = ::InternetConnect(m_hInternetSession, (char *)m_sServer.data(), m_nPort, (char *)m_sUserName.data(),
(char *)m_sPassword.data(), m_dwServiceType, 0, (DWORD) this);
else
m_hHttpConnection = ::InternetConnect(m_hInternetSession, (char *)m_sServer.data(), m_nPort, NULL,
NULL, m_dwServiceType, 0, (DWORD) this);
if ( m_hHttpConnection )
{
//Issue the request to read the file
char *ppszAcceptTypes[2]={"*/*",NULL};
// strcpy( ppszAcceptTypes[0], "*/*"); //We support accepting any mime file type since this is a simple download of a file
// ppszAcceptTypes[1] = NULL;
m_hHttpFile = HttpOpenRequest(m_hHttpConnection, NULL, (char *)m_sObject.data(), NULL, NULL, (const char **)ppszAcceptTypes, INTERNET_FLAG_RELOAD |
INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_KEEP_CONNECTION, (DWORD) this);
if ( m_hHttpFile )
{
if ( ::HttpSendRequest(m_hHttpFile, NULL, 0, NULL, 0) )
{
//Check the HTTP status code
TCHAR szStatusCode[32];
DWORD dwInfoSize = 32;
if (HttpQueryInfo(m_hHttpFile, HTTP_QUERY_STATUS_CODE, szStatusCode, &dwInfoSize, NULL))
{
//Update the status control to reflect that we are getting the file information
SetStatus("Obteniendo informacion del archivo");
// Get the length of the file.
TCHAR szContentLength[32];
DWORD dwInfoSize = 32;
DWORD dwFileSize = 0;
BOOL bGotFileSize = FALSE;
if (HttpQueryInfo(m_hHttpFile, HTTP_QUERY_CONTENT_LENGTH, szContentLength, &dwInfoSize, NULL))
{
//Set the progress control range
bGotFileSize = true;
dwFileSize = (DWORD) AnsiString(szContentLength).ToDouble();
SetProgressRange(dwFileSize);
}
//Update the status to say that we are now downloading the file
SetStatus("Descargando fichero");
DWORD dwStartTicks = ::GetTickCount();
DWORD dwCurrentTicks = dwStartTicks;
DWORD dwBytesRead = 0;
char szReadBuf[1024];
DWORD dwBytesToRead = 1024;
DWORD dwTotalBytesRead = 0;
DWORD dwLastTotalBytes = 0;
DWORD dwLastPercentage = 0;
while ( !Terminated && InternetReadFile( m_hHttpFile, szReadBuf, dwBytesToRead, &dwBytesRead ) )
{
if ( dwBytesRead == 0 ) break;
fwrite( szReadBuf, dwBytesRead, 1, fout );
//Increment the total number of bytes read
dwTotalBytesRead += dwBytesRead;
UpdateControlsDuringTransfer(dwStartTicks, dwCurrentTicks, dwTotalBytesRead, dwLastTotalBytes,
dwLastPercentage, bGotFileSize, dwFileSize);
}
}
}
InternetCloseHandle( m_hHttpFile );
} // OpenRequest
InternetCloseHandle( m_hHttpConnection );
} // InternetConnect
} // InternetCallBack
InternetCloseHandle( m_hInternetSession );
} // InternetOpen
}
} catch(...) {
// nothing
}
fclose(fout);
}
}
//---------------------------------------------------------------------------
void __fastcall downloads::UpdateControlsDuringTransfer(DWORD dwStartTicks, DWORD& dwCurrentTicks, DWORD dwTotalBytesRead, DWORD& dwLastTotalBytes,
DWORD& dwLastPercentage, BOOL bGotFileSize, DWORD dwFileSize)
{
if (bGotFileSize)
{
//Update the percentage downloaded in the caption
DWORD dwPercentage = (DWORD) (dwTotalBytesRead * 100.0 / dwFileSize);
if (dwPercentage != dwLastPercentage)
{
SetPercentage(dwPercentage);
dwLastPercentage = dwPercentage;
//Update the progress control bar
SetProgress(dwTotalBytesRead);
}
}
//Update the transfer rate amd estimated time left every second
DWORD dwNowTicks = GetTickCount();
DWORD dwTimeTaken = dwNowTicks - dwCurrentTicks;
if (dwTimeTaken > 1000)
{
double KbPerSecond = ((double)(dwTotalBytesRead) - (double)(dwLastTotalBytes)) / ((double)(dwTimeTaken));
SetTransferRate(KbPerSecond);
//Setup for the next time around the loop
dwCurrentTicks = dwNowTicks;
dwLastTotalBytes = dwTotalBytesRead;
if (bGotFileSize)
{
//Update the estimated time left
if (dwTotalBytesRead)
{
DWORD dwSecondsLeft = (DWORD) (((double)dwNowTicks - dwStartTicks) / dwTotalBytesRead *
(dwFileSize - dwTotalBytesRead) / 1000);
SetTimeLeft(dwSecondsLeft, dwTotalBytesRead, dwFileSize);
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall downloads::SetTransferRate(double KbPerSecond)
{
AnsiString sRate;
if (KbPerSecond < 1)
{
sRate.printf("%0.0f Bytes/seg", KbPerSecond*1024);
}
else if (KbPerSecond < 10)
{
sRate.printf("%0.2f KB/seg", KbPerSecond);
}
else
{
sRate.printf("%0.0f KB/seg", KbPerSecond);
}
msg=sRate;
Synchronize( updateTransferRate );
}
//---------------------------------------------------------------------------
void __fastcall downloads::SetTimeLeft(DWORD dwSecondsLeft, DWORD dwBytesRead, DWORD dwFileSize)
{
AnsiString sCopied;
if (dwBytesRead < 1024)
{
sCopied.printf("%d Bytes", dwBytesRead );
}
else if (dwBytesRead < 1048576)
{
sCopied.printf("%0.1f KB",dwBytesRead/1024.0);
}
else
{
sCopied.printf("%0.2f MB",dwBytesRead/1048576.0);
}
AnsiString sTotal;
if (dwFileSize < 1024)
{
sTotal.printf("%d Bytes", dwFileSize);
}
else if (dwFileSize < 1048576)
{
sTotal.printf("%0.1f KB", dwFileSize/1024.0);
}
else
{
sTotal.printf("%0.1f MB", dwFileSize/1048576.0);
}
AnsiString sOf;
sOf = sCopied+" de "+sTotal;
AnsiString sTime;
if (dwSecondsLeft < 60)
{
sTime.printf("%d seg",dwSecondsLeft);
}
else
{
DWORD dwMinutes = dwSecondsLeft / 60;
DWORD dwSeconds = dwSecondsLeft % 60;
if (dwSeconds == 0)
sTime.printf("%d min", dwMinutes);
else
sTime.printf("%d min %d seg", dwMinutes, dwSeconds);
}
AnsiString sTimeLeft;
sTimeLeft.printf( "%s (%s copiado)",sTime,sOf);
msg = sTimeLeft;
Synchronize( updateTimeLeft );
}
//---------------------------------------------------------------------------

53
src/donwloads.h Normal file
View File

@ -0,0 +1,53 @@
//---------------------------------------------------------------------------
#ifndef donwloadsH
#define donwloadsH
//---------------------------------------------------------------------------
#include <ComCtrls.hpp>
#include <Classes.hpp>
//---------------------------------------------------------------------------
class downloads : public TThread
{
private:
int passINT;
AnsiString msg;
DWORD m_dwServiceType,m_nPort;
AnsiString m_sServer, m_sObject, m_sUserName, m_sPassword;
bool bGotFileSize, validURL;
void __fastcall SetStatus(const char *sCaption);
void __fastcall updateTimeLeft(void);
void __fastcall updateTransferRate(void);
void __fastcall SetTransferRate(double KbPerSecond);
void __fastcall updateProgress(void);
void __fastcall SetPercentage(int nPercentage);
void __fastcall SetProgress(DWORD dwBytesRead);
void __fastcall updateProgressRange(void);
void __fastcall SetProgressRange(DWORD dwFileSize);
void __fastcall SetTimeLeft(DWORD dwSecondsLeft, DWORD dwBytesRead, DWORD dwFileSize);
void __fastcall UpdateControlsDuringTransfer(DWORD dwStartTicks, DWORD& dwCurrentTicks, DWORD dwTotalBytesRead, DWORD& dwLastTotalBytes,
DWORD& dwLastPercentage, BOOL bGotFileSize, DWORD dwFileSize);
static void CALLBACK OnStatusCallBack(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus,
LPVOID lpvStatusInformation, DWORD dwStatusInformationLength);
protected:
void __fastcall Execute();
char *file_target, *url_source;
public:
TProgressBar *m_ctrlProgress;
TLabel *labelTimeLeft;
TLabel *labelTransferRate;
__fastcall downloads(bool CreateSuspended);
bool __fastcall downloadFile( char *filename, char *url );
};
//---------------------------------------------------------------------------
#endif

254
src/interfaz.cpp Normal file
View File

@ -0,0 +1,254 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#include <inifiles.hpp>
#pragma hdrstop
#include "interfaz.h"
#include "donwloads.h"
#include "TMD5.hpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
TabSheet1->TabVisible = false;
TabSheet2->TabVisible = false;
TabSheet3->TabVisible = false;
PageControl1->ActivePage = TabSheet1;
checkUpdates = new downloads(true);
hiloCorriendo = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
SpeedButton1->Visible = false;
Label4->Visible = true;
ProgressBar1->Visible = true;
AnsiString ver,url;
TIniFile *ini;
ini = new TIniFile( ExtractFileDir( Application->ExeName ) + "\\liveUpdate.INI" );
app = ini->ReadString( "liveUpdate", "app", "" );
login = ini->ReadString( "liveUpdate", "login", "" );
pass = ini->ReadString( "liveUpdate", "pass", "" );
TMD5 md5;
url = "http://updates.infdj.com/checkUpdate.php?app=";
// url = "http://www.infdj.com/pages/PortalMusica/db/discos/53_44_c_295_A_Llul - Halo.mp3";
app = md5.MD5DigestToStr(md5.MD5String(app));
if ( !app.IsEmpty() ) url += app;
if ( !login.IsEmpty() ) url += "&user="+login;
if ( !pass.IsEmpty() ) url += "&pass="+pass;
checkUpdates->downloadFile( ".\\versions.dat", (char *)url.data() );
checkUpdates->m_ctrlProgress=ProgressBar1;
checkUpdates->labelTimeLeft=Label4;
checkUpdates->labelTransferRate=Label5;
checkUpdates->Resume();
hiloCorriendo = true;
checkUpdates->WaitFor();
hiloCorriendo = false;
if ( FileExists(".\\versions.dat" ) )
{
int nApps; // Nº de aplicaciones que componen el paquete
AnsiString msg, app,ver;
bool autoexec;
TIniFile *upd;
upd = new TIniFile( ".\\versions.dat" );
msg = upd->ReadString( "status", "msg", "error" );
if ( msg.Pos("error") > 0 )
{
ShowMessage(msg);
} else {
StringGrid1->FixedCols = 0;
StringGrid1->ColCount = 3;
StringGrid1->Cells[0][0] = "Módulo";
StringGrid1->ColWidths[0] = 200;
StringGrid1->Cells[1][0] = "versión";
StringGrid1->ColWidths[1] = 80;
StringGrid1->Cells[2][0] = "exe";
StringGrid1->ColWidths[2] = 20;
StringGrid1->RowCount = 1;
nApps = upd->ReadInteger( "apps","lineas",0);
for ( int i=1; i<=nApps; i++ )
{
app = upd->ReadString("apps","l"+AnsiString(i)+"_app","");
ver = upd->ReadString("apps","l"+AnsiString(i)+"_ver","");
autoexec = upd->ReadBool("apps","l"+AnsiString(i)+"_autoexec",false);
// Vemos si las versiones son superiores
if ( !app.IsEmpty() && !ver.IsEmpty() && ver > ini->ReadString(app,"ver","") )
{
StringGrid1->RowCount++;
StringGrid1->FixedRows = 1;
// Añadimos esta aplicacion al listado de descargas...
StringGrid1->Cells[0][StringGrid1->RowCount-1] = app;
StringGrid1->Cells[1][StringGrid1->RowCount-1] = ver;
StringGrid1->Cells[2][StringGrid1->RowCount-1] = autoexec ? "si":"no";
}
PageControl1->ActivePage = TabSheet2;
}
}
delete upd;
}
delete ini;
//
// http://updates.infdj.com/checkUpdates.php?app=<MD5("APP")>[&login=<user>&pass=<pwd>]
//
// Esto devuelve una lista con de los componentes de la APP en el siguiente formato:
// (la primera linea de esta lista indicará error o correcto)
//
// nombre_fichero|version|ruta relativa|tamaño|auto-ejecutar
//
// Ejm. para el TPVwin
//
// [status]
// msg=<Mensaje de error>
// [apps]
// lineas=4
// l1_app=TPV_ventas.exe
// l1_ver=1.0.1
// l1_autoexec=no
// mySQL_TPV.exe|1.2.0||1334321|no
// QR_Preview.exe|1.2.0||133421|no
// always_update.exe|1.0||133221|si << Esta puede servir para ejecutar las AUTO-ACTUALIZACIONES especiales
//
// Si hubiera error:
//
// error Se produjo un error desconocido. Intentelo mas tarde
// error Su licencia no incluye las actualizaciones
// error Su licencia ha expirado
// error Ya descargó con exito esta actualizacion desde otro equipo
// error Nombre de usuario o password incorrectos
//
// Despues de descargar una actualizacion y ejecutarla...
// se debe actualizar el fichero de versiones actuales:
//
// liveUpdate.ini
//
// [liveUpdate]
// user=xxxx
// version=1.0
// pass=<MD5(pwd)>
// app=TPVwin
// [apps]
// nombre=version ; mySQL_TPV.exe=1.1.0
//
//
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
if ( hiloCorriendo && checkUpdates )
{
checkUpdates->Terminate();
checkUpdates->WaitFor();
hiloCorriendo = false;
delete checkUpdates;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IniciaDescargas(TObject *Sender)
{
if ( StringGrid1->RowCount < 1 ) return;
AnsiString file;
urlDownload = "http://updates.infdj.com/downloadFile.php?app=";
if ( !app.IsEmpty() ) urlDownload += app;
if ( !login.IsEmpty() ) urlDownload += "&user="+login;
if ( !pass.IsEmpty() ) urlDownload += "&pass="+pass;
urlDownload += "&mod=";
file = urlDownload+StringGrid1->Cells[0][1];
// Pintamos de verde la fila que nos estamos descargando...
/*
currentRow = 1;
StringGrid1->Repaint();
checkUpdates->downloadFile( ".\\"+StringGrid1->Cells[0][1], (char *)urlDownload.data() );
checkUpdates->m_ctrlProgress=ProgressBar1;
checkUpdates->labelTimeLeft=Label4;
checkUpdates->labelTransferRate=Label5;
checkUpdates->OnTerminate(nextState);
checkUpdates->Resume();
*/
currentRow = 0;
nextState(this);
SpeedButton2->Visible = false;
Label6->Visible = true;
Label7->Visible = true;
ProgressBar2->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::nextState(System::TObject* Sender)
{
currentRow++;
if ( currentRow < StringGrid1->RowCount )
{
AnsiString file;
file = urlDownload+StringGrid1->Cells[0][currentRow];
StringGrid1->Repaint();
ShowMessage( file );
if ( checkUpdates )
{
delete checkUpdates;
checkUpdates = NULL;
}
checkUpdates = new downloads(true);
checkUpdates->downloadFile( (char *)AnsiString(".\\"+StringGrid1->Cells[0][currentRow]).data(), (char *)file.data() );
checkUpdates->m_ctrlProgress=ProgressBar1;
checkUpdates->labelTimeLeft=Label4;
checkUpdates->labelTransferRate=Label5;
checkUpdates->OnTerminate = nextState;
checkUpdates->Resume();
hiloCorriendo = true;
} else {
PageControl1->ActivePage = TabSheet3;
hiloCorriendo = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
TColor c;
// Redibujamos la rejilla
if ( ARow < currentRow )
{
c = cl3DLight;
} else
if ( ARow == currentRow )
{
c = clMoneyGreen;
} else
// ARow > currentRow
{
c = clWindow;
}
StringGrid1->Canvas->Font->Color = c;
// StringGrid1->DrawCell( ACol, ARow, Rect, State );
}
//---------------------------------------------------------------------------

BIN
src/interfaz.ddp Normal file

Binary file not shown.

205
src/interfaz.dfm Normal file
View File

@ -0,0 +1,205 @@
object Form1: TForm1
Left = 197
Top = 112
Width = 565
Height = 333
Caption = 'Em'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 0
Top = 0
Width = 150
Height = 299
Align = alLeft
Caption = 'Panel1'
TabOrder = 0
end
object PageControl1: TPageControl
Left = 150
Top = 0
Width = 407
Height = 299
ActivePage = TabSheet1
Align = alClient
TabIndex = 0
TabOrder = 1
object TabSheet1: TTabSheet
Caption = 'TabSheet1'
object Label1: TLabel
Left = 8
Top = 8
Width = 104
Height = 24
Caption = 'Live Update!'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -19
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object SpeedButton1: TSpeedButton
Left = 88
Top = 208
Width = 201
Height = 22
Caption = 'Buscar actualizaciones ahora'
Flat = True
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
OnClick = SpeedButton1Click
end
object Label2: TLabel
Left = 8
Top = 40
Width = 361
Height = 20
Caption = 'Esta aplicaci'#243'n intentar'#225' localizar nuevas versiones'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label3: TLabel
Left = 8
Top = 64
Width = 110
Height = 20
Caption = 'de su producto.'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label4: TLabel
Left = 88
Top = 128
Width = 197
Height = 20
Caption = 'Buscando actualizaciones...'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
Visible = False
end
object Label5: TLabel
Left = 88
Top = 176
Width = 4
Height = 20
Caption = '.'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object ProgressBar1: TProgressBar
Left = 88
Top = 152
Width = 201
Height = 17
Min = 0
Max = 100
TabOrder = 0
Visible = False
end
end
object TabSheet2: TTabSheet
Caption = 'TabSheet2'
ImageIndex = 1
object SpeedButton2: TSpeedButton
Left = 88
Top = 208
Width = 201
Height = 22
Caption = 'Descargar actualizaciones'
Flat = True
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
OnClick = IniciaDescargas
end
object Label6: TLabel
Left = 88
Top = 184
Width = 197
Height = 20
Caption = 'Buscando actualizaciones...'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
Visible = False
end
object Label7: TLabel
Left = 88
Top = 232
Width = 4
Height = 20
Caption = '.'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
Visible = False
end
object StringGrid1: TStringGrid
Left = 0
Top = 0
Width = 399
Height = 177
Align = alTop
Color = clWhite
RowCount = 2
TabOrder = 0
OnDrawCell = StringGrid1DrawCell
RowHeights = (
24
24)
end
object ProgressBar2: TProgressBar
Left = 88
Top = 208
Width = 201
Height = 17
Min = 0
Max = 100
TabOrder = 1
Visible = False
end
end
object TabSheet3: TTabSheet
Caption = 'TabSheet3'
ImageIndex = 2
end
end
end

56
src/interfaz.h Normal file
View File

@ -0,0 +1,56 @@
//---------------------------------------------------------------------------
#ifndef interfazH
#define interfazH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
#include "donwloads.h"
#include <Grids.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TPanel *Panel1;
TPageControl *PageControl1;
TTabSheet *TabSheet1;
TTabSheet *TabSheet2;
TTabSheet *TabSheet3;
TLabel *Label1;
TSpeedButton *SpeedButton1;
TLabel *Label2;
TLabel *Label3;
TLabel *Label4;
TProgressBar *ProgressBar1;
TLabel *Label5;
TStringGrid *StringGrid1;
TSpeedButton *SpeedButton2;
TLabel *Label6;
TProgressBar *ProgressBar2;
TLabel *Label7;
void __fastcall SpeedButton1Click(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall IniciaDescargas(TObject *Sender);
void __fastcall StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State);
private: // User declarations
AnsiString urlDownload;
bool hiloCorriendo;
downloads *checkUpdates;
AnsiString app,login,pass;
int currentRow;
void __fastcall nextState(System::TObject* Sender);
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif