CD_OUT_SRC/CD_EXE.CPP
2021-09-03 17:50:32 +02:00

408 lines
10 KiB
C++
Raw Permalink Blame History

#include <dir.h>
#include <dos.h>
#include <alloc.h>
#include <process.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h> // Para getch();
#include <graphics.h> // Para outtextxy(...); y cleardevice(...);
#include "..\libs\make_bot\make_bot.h" // Fuciones de MAKE_BOTON
#include "cd_icons.h"
#include "cd_error.h"
#include "cd_file.h"
#include "CD_SND.H"
extern int /*far _cdecl*/ Fichero_cd_img(char Dinamicos_Estaticos);
#define DOS 1
#define WINDOWS 2
extern void Sonido(char Sonido);
void Init_EXE(int CurrIcon);
char *current_directory(char *path);
extern void Inicializa_Dibujo(int L_Imagen, char *N_Imagen2);
extern void Inicializa_Iconos(void);
extern void Coloca_Iconos_Dos_Windows(void);
extern char far *Icono; // 18
void InicializaSVGA(void);
extern char dac[256*3];
extern "C" void APAGA_PANTALLA(char *);
extern "C" void ENCIENDE_PANTALLA(char *);
extern void Inicializa_Apertura(void);
extern void Coloca_Iconos(int Start_Icon);
typedef struct {
unsigned int Exit_after_EXE : 1;
unsigned int With_Out_Sound : 1;
unsigned int Auto_Install : 1;
unsigned int Check_Free_Size : 1;
unsigned int Format_Always : 1;
unsigned int Without_Backgr : 1;
unsigned int Futura_Ampliac : 4;
} Cd_CFG;
extern Cd_CFG CD_CFG1;
char Restaura_Pantalla_CFG(void);
char Salva_Pantalla_CFG(void);
extern FILE *CD_in;
extern CD_FILE CD_in2;
extern int file_exists(char *filename);
extern int Muestra_Mensaje(int Mensaje, char *file);
void Init_EXE(int CurrIcon){
int ok = 0, exe = 0;
char curdir[80];
char Buffer[80];
int ERROR_SALVA = 0;
struct ffblk ffblk;
// Comprobamos que existe el fichero a ejecutar...
strcpy( Buffer, CD_in2.Dir_P );
Buffer[0] = getdisk() + 'A';
strcat( Buffer, "\\" );
strcat( Buffer, CD_in2.N_Exe );
strcat( Buffer, ".*" );
if ( findfirst( Buffer, &ffblk,0) != 0 )
/* if ( !file_exists(Buffer) )*/ { Muestra_Mensaje(114, "cd_out.img");
// Sonido("CD_OUT72.WAV");
Sonido( Error_114 );
return; }
ERROR_SALVA = Salva_Pantalla_CFG();
/*
void far *Mascara;
if( (Mascara = farmalloc( imagesize(118, 160, 521, 335) ) ) == NULL) {
closegraph();
cprintf("\n\rSALIENDO");
cprintf("\n\rImposible encontrar %dKbytes en el Heap", ok);
exit(SIN_MEMORIA);
}
getimage(118, 159, 521, 335, Mascara);
*/
// Imprime_Estaticos(10, "cd_out.img"); // Imprime botones estaticos 'Seccion 4'
Fichero_cd_img(10);
Imprime_Secuencia(3); // Imprime secuencia 1.
// Imprime_Estaticos(11, "cd_out.img"); // Imprime textos estaticos 'Seccion 5'
Fichero_cd_img(11);
while(!ok){ // Bucle infinito
switch( Comprueba_Secuencia( 3 ) ) { // Iniciamos comprobacion de 2<> sec
case 0: // No se pulso ningun BOTON
// Pero el raton fue presionado en
// algun sitio...
// Sonido("CD_OUT01.WAV");
Sonido( Mouse_Press );
break;
case -2: // Hay una tecla normal en BUFFER
switch( getch() ) { // La utilizamos
// Intro ( ACEPTAR )
case 13:
// Sonido("CD_OUT0E.WAV");
Sonido( Ok );
exe = 1;
ok = 1;
break;
// ESC ( CANCELAR )
case 14:
// Sonido("CD_OUT0F.WAV");
Sonido( Cancel );
exe = 0;
ok = 1;
break;
default:
// Sonido("CD_OUT02.WAV");
Sonido( Key_Press );
break;
}
break;
case -1: // Hay una tecla especial en BUFFER
getch(); // La eliminamos
break;
// Boton Aceptar
case 1:
exe = 1;
ok = 1;
break;
// Boton Cancelar
case 2:
exe = 0;
ok = 1;
break;
default:
while( kbhit() ) getch(); // Limpiamos posibles teclas en BUFFER
break;
}
}
// if ( CD_CFG1.Exit_after_EXE == 0)
ERROR_SALVA = Restaura_Pantalla_CFG();
/*
putimage(118, 160, Mascara, COPY_PUT);
farfree(Mascara);
*/
if ( exe == 1 ) {
/// Liberamos la memoria asignada para al DRIVER gr<67>fico...
current_directory(curdir);
APAGA_PANTALLA(dac);
closegraph();
Libera_Memoria();
/*
free(P_Raton1);
free(P_Raton2);
free(P_Raton3);
free(P_Raton4);
free(Pantalla);
*/
Libera_Raton_Animado();
farfree(Icono);
fclose(CD_in);
closegraph();
/*
C O M I E N Z A L A E J E C U C I O N D E L P R O G R A M A
*/
// if ( system( getenv( "COMSPEC") ) != 0 ) { printf("\n\nImposible salir a MS-DOS\n\n"); sleep(5); }
cprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ\n\r");
cprintf("<EFBFBD> JD & CD_OUT <20>\n\r");
cprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n\r");
cprintf("EJECUTANDO PROGRAMA: [%s]\n\r", Buffer);
strcpy( Buffer, CD_in2.Dir_P );
Buffer[0] = getdisk() + 'A';
chdir(Buffer);
if ( spawnl(P_WAIT, CD_in2.N_Exe, NULL) == -1 ) {
printf("Imposible ejecutar %s, el archivo no esta disponible", Buffer);
getch();
} else if ( CD_CFG1.Exit_after_EXE == 1 ) {
clrscr();
cprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ\n\r");
cprintf("<EFBFBD> JD & CD_OUT <20>\n\r");
cprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n\r");
cprintf("No se regresera a CD_OUT a petici<63>n del usuario...\n\r");
exit(1);
}
clrscr();
cprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ\n\r");
cprintf("<EFBFBD> JD & CD_OUT <20>\n\r");
cprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n\r");
cprintf("Regresando a CD_OUT...\n\r");
//// Recargamos el Programa...
chdir(curdir); // Refresamos a nuestro directorio
// de origen
InicializaSVGA(); // Reinicializamos la SVGA
APAGA_PANTALLA(dac); // Apagamos la Pantalla
Inicializa_Dibujo( (-1), "NADA"); // Inicializamos un nuevo dibujo
// if( carga_botones("cd_out.img") // Recarga botones del fichero "CD_out.img"
if ( Fichero_cd_img(0)
!= OK ) {
// Imprime_Estaticos( 112, "cd_out.img");
Fichero_cd_img(112);
Espera_Tecla_o_Raton();
closegraph();
cprintf("\n\rError en la CARGA DE BOTONES");
exit(112);
}
// Imprime_Estaticos( 1, "cd_out.img"); // Imprime botones estaticos 'Seccion 1'
Fichero_cd_img(1);
Imprime_Secuencia(1); // Imprime secuencia 1.
// Imprime_Estaticos( 2, "cd_out.img"); // Imprime botones estaticos 'Seccion 2'
// para los textos
Fichero_cd_img(2);
Inicializa_Iconos();
Coloca_Iconos_Dos_Windows();
Coloca_Iconos(CurrIcon);
ENCIENDE_PANTALLA(dac);
/*
if ( (Pantalla = malloc( JD_imagesize(0, 0, 21, 21) )) == NULL ) {
Imprime_Estaticos( SIN_CVN, "cd_out.img");
Espera_Tecla_o_Raton();
closegraph();
cprintf("\n\rError en la asignaci<63>n de memoria para la mascara del raton");
exit(2);
}
*/
Imprime_Bordes(1, 1, 251);
settextstyle( SMALL_FONT, HORIZ_DIR, 4);
Inicializa_Apertura();
PunteroRaton = 100;
inicializa_raton_grafico( 0, 0, 618, 460);
True_Push = ON; // Activa el TRUE PUSH ( PRESION REAL )
} else
if ( ERROR_SALVA == 1 ){
APAGA_PANTALLA(dac);
closegraph();
Libera_Memoria();
Libera_Raton_Animado();
/*
free(P_Raton1);
free(P_Raton2);
free(P_Raton3);
free(P_Raton4);
free(Pantalla);
*/
farfree(Icono);
fclose(CD_in);
printf( "Ha ocurrido un ERROR en el fichero Temporal CD_OUT.TMP" );
exit(2);
}
}
char *current_directory(char *path)
{
strcpy(path, "X:\\"); /* fill string with form of response: X:\ */
path[0] = 'A' + getdisk(); /* replace X with current drive letter */
getcurdir(0, path+3); /* fill rest of string with current directory */
return(path);
}
char Salva_Pantalla_CFG(void){
FILE *Salva;
// unsigned char Pixel_Line[405];
int t;
void *Imagen;
if ( (Salva = fopen( "C:\\CD_OUT.TMP", "wb" ) ) == NULL ) {
CD_CFG1.Exit_after_EXE = 1;
return 1;
}
// 118, 160, 521, 335
// 118,160 320,160 521,160
// * - *
// 118, 160, 320, 248
// 320, 160, 521, 248 118,248 320,248 521,248
// 118, 248, 320, 335 _ _ _
// 118, 248, 320, 335
//
// 118,335 320,335 521,335
// * - *
rewind(Salva);
t = JD_imagesize(118, 160, 320, 248);
if ( (Imagen = malloc( t )) == NULL ) { closegraph(); printf("No hay suficiente espacion en el HEAP o C:\\\n"); }
getimage(118, 160, 320, 248, Imagen);
fwrite( Imagen, t, 1, Salva );
fseek( Salva, t, SEEK_CUR);
t = JD_imagesize(320, 160, 521, 248);
if ( (Imagen = realloc( Imagen, t )) == NULL ) { closegraph(); printf("No hay suficiente espacion en el HEAP o C:\\\n"); }
getimage(320, 160, 521, 248, Imagen);
fwrite( Imagen, t, 1, Salva );
fseek( Salva, t, SEEK_CUR);
t = JD_imagesize(118, 248, 320, 335);
if ( (Imagen = realloc( Imagen, t )) == NULL ) { closegraph(); printf("No hay suficiente espacion en el HEAP o C:\\\n"); }
getimage(118, 248, 320, 335, Imagen);
fwrite( Imagen, t, 1, Salva );
fseek( Salva, t, SEEK_CUR);
t = JD_imagesize(320, 248, 521, 335);
if ( (Imagen = realloc( Imagen, t )) == NULL ) { closegraph(); printf("No hay suficiente espacion en el HEAP o C:\\\n"); }
getimage(320, 248, 521, 335, Imagen);
fwrite( Imagen, t, 1, Salva );
free(Imagen);
if ( fclose(Salva) == EOF ) {
CD_CFG1.Exit_after_EXE = 1;
return 1;
}
return 0;
}
char Restaura_Pantalla_CFG(void){
FILE *Restaura;
int t;
void *Imagen;
unsigned char Pixel_Line;
int x, y;
if ( (Restaura = fopen( "C:\\CD_OUT.TMP", "rb" ) ) == NULL ) {
CD_CFG1.Exit_after_EXE = 1;
return 1;
}
rewind(Restaura);
t = JD_imagesize(118, 160, 320, 248);
if ( (Imagen = malloc( t )) == NULL ) { closegraph(); printf("No hay suficiente espacion en el HEAP o C:\\\n"); }
fread( Imagen, t, 1, Restaura );
putimage(118, 160, Imagen, COPY_PUT);
fseek( Restaura, t, SEEK_CUR);
t = JD_imagesize(320, 160, 521, 248);
if ( (Imagen = realloc( Imagen, t )) == NULL ) { closegraph(); printf("No hay suficiente espacion en el HEAP o C:\\\n"); }
fread( Imagen, t, 1, Restaura );
putimage(320, 160, Imagen, COPY_PUT);
fseek( Restaura, t, SEEK_CUR);
t = JD_imagesize(118, 248, 320, 335);
if ( (Imagen = realloc( Imagen, t )) == NULL ) { closegraph(); printf("No hay suficiente espacion en el HEAP o C:\\\n"); }
fread( Imagen, t, 1, Restaura );
putimage(118, 248, Imagen, COPY_PUT);
fseek( Restaura, t, SEEK_CUR);
t = JD_imagesize(320, 248, 521, 335);
if ( (Imagen = realloc( Imagen, t )) == NULL ) { closegraph(); printf("No hay suficiente espacion en el HEAP o C:\\\n"); }
fread( Imagen, t, 1, Restaura );
putimage(320, 248, Imagen, COPY_PUT);
free(Imagen);
if ( fclose(Restaura) == EOF ) {
CD_CFG1.Exit_after_EXE = 1;
return 1;
}
if ( unlink("C:\\CD_OUT.TMP")!=0 ){
CD_CFG1.Exit_after_EXE = 1;
return 1;
}
return 0;
}