979 lines
31 KiB
C++
979 lines
31 KiB
C++
/**************************************************************************\
|
||
|* *|
|
||
|* Indexador de Medios 1.0d *|
|
||
|* *|
|
||
|* *|
|
||
|* *|
|
||
|* *|
|
||
|* *|
|
||
|* *|
|
||
|* *|
|
||
|* *|
|
||
|* *|
|
||
\**************************************************************************/
|
||
|
||
#include <dir.h>
|
||
#include <conio.h>
|
||
#include <stdio.h>
|
||
#include <string.h>
|
||
#include <stdlib.h>
|
||
#include <dos.h>
|
||
|
||
#define NUM_LINEAS 20
|
||
|
||
char Buffer[80];
|
||
|
||
typedef struct
|
||
{
|
||
char FA[1024];
|
||
long NumArchivos;
|
||
int NumDirectorios;
|
||
} CABECERA_IM;
|
||
|
||
typedef struct
|
||
{
|
||
// unsigned char Nivel; // Nivel actual en el que me encuentro
|
||
char ff_attrib; /* attribute found */
|
||
int ff_ftime; /* file time */
|
||
int ff_fdate; /* file date */
|
||
long ff_fsize; /* file size */
|
||
char ff_name[13]; /* found file name */
|
||
char nivel;
|
||
} MINDEX;
|
||
|
||
typedef struct
|
||
{
|
||
char Nivel;
|
||
long PosDirectorio;
|
||
char ContraidoExpandido;
|
||
} MDIREC;
|
||
|
||
//MINDEX *MIndex;
|
||
|
||
void formatea_u_long( unsigned long Numero, char *Inter_Chg);
|
||
void GuardaMedio( char *DesdeDonde, unsigned char Nivel );
|
||
int ConstruyeIndice( char *DesdeDonde, char *NArchivo );
|
||
void Que_Color(void);
|
||
|
||
|
||
MINDEX MI;
|
||
MDIREC MD, far *Directorios;
|
||
CABECERA_IM CabIM;
|
||
|
||
FILE * HF, * HD;
|
||
|
||
void GuardaMedio( char *TiposArchivos, unsigned char Nivel )
|
||
{
|
||
struct ffblk ffblk;
|
||
int done;
|
||
|
||
// Guardamos toda la informaci<63>n desde el directorio Actual.
|
||
done = findfirst(TiposArchivos,&ffblk, FA_RDONLY | FA_HIDDEN | FA_SYSTEM | FA_DIREC | FA_ARCH );
|
||
while (!done)
|
||
{
|
||
MI.ff_attrib= ffblk.ff_attrib;
|
||
MI.ff_ftime = ffblk.ff_ftime;
|
||
MI.ff_fdate = ffblk.ff_fdate;
|
||
MI.ff_fsize = ffblk.ff_fsize;
|
||
sprintf( MI.ff_name, "%s", ffblk.ff_name );
|
||
MI.nivel = Nivel;
|
||
//////////////////////////////////////////////////////////////////////////
|
||
gotoxy( Nivel+1, wherey() );
|
||
cprintf( "%s [%d]\r\n", ffblk.ff_name, Nivel );
|
||
//////////////////////////////////////////////////////////////////////////
|
||
CabIM.NumArchivos++;
|
||
fwrite( &MI, sizeof(MINDEX), 1, HF );
|
||
|
||
if ( (ffblk.ff_attrib&FA_DIREC) && MI.ff_name[0] != '.' )
|
||
{
|
||
MD.PosDirectorio = CabIM.NumArchivos;
|
||
MD.Nivel = Nivel;
|
||
CabIM.NumDirectorios++;
|
||
fwrite( &MD, sizeof(MD), 1, HD );
|
||
if ( !chdir( ffblk.ff_name ) )
|
||
{
|
||
GuardaMedio( TiposArchivos, Nivel+1 );
|
||
chdir( ".." );
|
||
}
|
||
}
|
||
done = findnext(&ffblk);
|
||
}
|
||
}
|
||
|
||
char PathActual[512];
|
||
|
||
int ConstruyeIndice( char *DesdeDonde, char *NArchivo )
|
||
{
|
||
FILE *HF1, *HF2, *HFf;
|
||
struct ffblk ffblk;
|
||
long i;
|
||
char buffer[80];
|
||
|
||
int CurrDisk;
|
||
|
||
// Creamos dos ficheros temporales...
|
||
if ( (HF1 = fopen( "files.tmp", "wb" )) == NULL )
|
||
return -1;
|
||
if ( (HF2 = fopen( "direc.tmp", "wb" )) == NULL )
|
||
return -1;
|
||
|
||
CurrDisk = getdisk();
|
||
getcurdir( 0, PathActual );
|
||
|
||
// Recorremos todo el "medio" guardando una especie de copia de la FAT.
|
||
setdisk( ( DesdeDonde[0] - 'A' ) );
|
||
chdir(DesdeDonde);
|
||
CabIM.NumDirectorios= 0;
|
||
CabIM.NumArchivos = 0;
|
||
|
||
sprintf( buffer, "%c:\\*.*", DesdeDonde[0] );
|
||
|
||
findfirst(buffer,&ffblk, FA_LABEL );
|
||
sprintf( MI.ff_name, "%s", ffblk.ff_name );
|
||
MI.ff_name[8] = ffblk.ff_name[9];
|
||
MI.ff_name[9] = ffblk.ff_name[10];
|
||
MI.ff_name[10] = ffblk.ff_name[11];
|
||
MI.ff_name[11] = '\0';
|
||
|
||
MI.ff_attrib= ffblk.ff_attrib;
|
||
MI.ff_ftime = ffblk.ff_attrib;
|
||
|
||
MI.nivel = 0;
|
||
|
||
MD.PosDirectorio = 0;
|
||
MD.Nivel = 0;
|
||
MD.ContraidoExpandido = 1;
|
||
fwrite( &MD, sizeof(MD), 1, HF2 );
|
||
fwrite( &MI, sizeof(MI), 1, HF1 );
|
||
|
||
MD.ContraidoExpandido = 0;
|
||
HF = HF1; HD = HF2;
|
||
GuardaMedio( "*.*", 1 );
|
||
|
||
CabIM.NumDirectorios ++;
|
||
MD.PosDirectorio = -1;
|
||
MD.Nivel = 0;
|
||
MD.ContraidoExpandido = 0;
|
||
|
||
fwrite( &MD, sizeof(MD), 1, HF2 );
|
||
|
||
CabIM.NumArchivos++;
|
||
MI.ff_name[8] = ffblk.ff_name[9];
|
||
MI.ff_name[9] = ffblk.ff_name[10];
|
||
MI.ff_name[10] = ffblk.ff_name[11];
|
||
MI.ff_name[11] = '\0';
|
||
|
||
MI.ff_attrib= ffblk.ff_attrib;
|
||
MI.ff_ftime = ffblk.ff_attrib;
|
||
|
||
MI.nivel = 0;
|
||
|
||
fwrite( &MI, sizeof(MI), 1, HF1 );
|
||
|
||
fclose( HF1 );
|
||
fclose( HF2 );
|
||
|
||
chdir(PathActual);
|
||
setdisk(CurrDisk);
|
||
|
||
|
||
if ( (HF1 = fopen( "files.tmp", "rb" )) == NULL )
|
||
return -1;
|
||
if ( (HF2 = fopen( "direc.tmp", "rb" )) == NULL )
|
||
return -1;
|
||
if ( (HFf = fopen( NArchivo, "wb" )) == NULL )
|
||
return -1;
|
||
|
||
// Fusionamos los dos archivos en uno
|
||
fwrite( &CabIM, sizeof(CabIM), 1, HFf );
|
||
|
||
|
||
// Directorios
|
||
for ( i = 0; i <= CabIM.NumDirectorios; i++ )
|
||
{
|
||
fread( &MD, sizeof(MD), 1, HF2 );
|
||
fwrite( &MD, sizeof(MD), 1, HFf );
|
||
}
|
||
// Archivos
|
||
for ( i = 0; i <= CabIM.NumArchivos; i++ )
|
||
{
|
||
fread( &MI, sizeof(MI), 1, HF1 );
|
||
fwrite( &MI, sizeof(MI), 1, HFf );
|
||
}
|
||
|
||
fclose( HFf );
|
||
fclose( HF1 );
|
||
fclose( HF2 );
|
||
|
||
|
||
return 0;
|
||
}
|
||
|
||
|
||
void DibujaPantalla(void)
|
||
{
|
||
//123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-
|
||
clrscr();
|
||
// textbackground(BLUE);
|
||
textbackground( BLACK );
|
||
|
||
textcolor(LIGHTCYAN);
|
||
cprintf( "-x<><78><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ Nombre Tama<6D>o <20> Nombre Tama<6D>o " );
|
||
cprintf( " <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( " <20> <20> " );
|
||
cprintf( "<EFBFBD>x<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ" );
|
||
cprintf( "<EFBFBD> <20>" );
|
||
cprintf( "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" );
|
||
|
||
textcolor( YELLOW );
|
||
gotoxy( 31 , 1 ); cprintf( "Nombre Tama<6D>o" );
|
||
gotoxy( 57, 1 ); cprintf( "Nombre Tama<6D>o" );
|
||
|
||
textbackground( RED );
|
||
gotoxy( 2 , 1 ); cprintf( "x" );
|
||
gotoxy( 2, 22 ); cprintf( "x" );
|
||
|
||
// textbackground(BLUE);
|
||
textbackground( BLACK );
|
||
|
||
};
|
||
|
||
typedef struct
|
||
{
|
||
char Directorios;
|
||
char Ruta;
|
||
|
||
} CONFIG;
|
||
|
||
CONFIG config;
|
||
|
||
void MuestraDirectorio( int Row, int DirMuestra, char como );
|
||
void ContraeExpandeRama( MDIREC far *DesdeAqui, char ContraeExpande );
|
||
int AvanzaRetrocede( int PuntoInicio, char RetrocedeAvanza );
|
||
void MuestraDirectorios( long DirInicio );
|
||
void LeeDir(void);
|
||
void ReconstruyeDirectorio( int Nivel );
|
||
|
||
void MuestraArchivo( int RowFisica, int PosArch, char como );
|
||
void MuestraArchivos( long CurrTrnDir );
|
||
|
||
|
||
FILE *HFf;
|
||
|
||
void main(void)
|
||
{
|
||
int ok, i;
|
||
int OldNivel;
|
||
|
||
DibujaPantalla();
|
||
/*
|
||
window(2, 2, 25, 21);
|
||
ConstruyeIndice( "I:\\", "CDa.idm" );
|
||
window(1, 1, 80, 25);
|
||
return;*/
|
||
config.Directorios = 1;
|
||
config.Ruta = 1;
|
||
|
||
if ( ( HFf = fopen( "CDa.idm", "rb" ) ) != NULL )
|
||
{
|
||
|
||
long CurrRowDir;
|
||
long CurrTrnDir, OldCurrTrnDir, IniTrnDir;
|
||
long CurrTrnArch, CurrRowArch;
|
||
|
||
LeeDir();
|
||
|
||
CurrRowDir = 0;
|
||
CurrTrnDir = 0;
|
||
OldCurrTrnDir = 0;
|
||
IniTrnDir = 0;
|
||
|
||
// Construye el directorio actual
|
||
|
||
char VentanaActual = 1;
|
||
|
||
ok = 0;
|
||
|
||
if ( config.Directorios )
|
||
{
|
||
MuestraDirectorios( CurrTrnDir );
|
||
MuestraDirectorio( CurrRowDir, CurrTrnDir, 1 );
|
||
}
|
||
|
||
if ( config.Ruta )
|
||
{
|
||
sprintf( PathActual, "[%s]\\", MI.ff_name );
|
||
|
||
textcolor( YELLOW );
|
||
gotoxy( 2, 23 ); cprintf( " " );
|
||
gotoxy( 2, 23 ); cprintf( "%s", PathActual );
|
||
}
|
||
|
||
CurrTrnArch = CurrTrnDir+1;
|
||
CurrRowArch = 0;
|
||
|
||
MuestraArchivos( CurrTrnArch );
|
||
|
||
do {
|
||
if ( kbhit() )
|
||
{
|
||
if ( config.Directorios && VentanaActual == 1 )
|
||
MuestraDirectorio( CurrRowDir, CurrTrnDir, 0 );
|
||
else
|
||
MuestraArchivo( CurrRowArch, CurrTrnArch+1, 0 );
|
||
|
||
switch( getch() )
|
||
{
|
||
case 9:
|
||
if ( config.Directorios )
|
||
{
|
||
VentanaActual++; if ( VentanaActual > 2 ) VentanaActual = 1;
|
||
}
|
||
switch( VentanaActual )
|
||
{
|
||
case 1:
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*CurrTrnDir, SEEK_SET );
|
||
break;
|
||
case 2:
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*CurrTrnArch, SEEK_SET );
|
||
break;
|
||
}
|
||
fread( &MI, sizeof(MI), 1, HFf );
|
||
break;
|
||
case 13:
|
||
switch( VentanaActual )
|
||
{
|
||
case 1:
|
||
IniTrnDir = CurrTrnDir;
|
||
for ( i=0; i < CurrRowDir; i++ )
|
||
IniTrnDir = AvanzaRetrocede( IniTrnDir, -1 );
|
||
ContraeExpandeRama( &Directorios[CurrTrnDir], !Directorios[CurrTrnDir+1].ContraidoExpandido );
|
||
MuestraDirectorios( IniTrnDir );
|
||
break;
|
||
case 2:
|
||
// Retrocedemos / entramos en un directorio o mostramos las propiedades si es un archivo
|
||
if ( strcmp( MI.ff_name, ".." ) == 0 )
|
||
{
|
||
OldNivel = Directorios[CurrTrnDir].Nivel;
|
||
do {
|
||
CurrRowDir--; if ( CurrRowDir < 0 )
|
||
{
|
||
CurrRowDir = 0;
|
||
if ( CurrTrnDir != 0 )
|
||
{
|
||
movetext( 1, 2, 27, 20, 1, 3);
|
||
}
|
||
if ( config.Directorios && VentanaActual == 1 )
|
||
MuestraDirectorio( CurrRowDir, CurrTrnDir, 0 );
|
||
}
|
||
CurrTrnDir = AvanzaRetrocede( CurrTrnDir, -1 );
|
||
} while( Directorios[CurrTrnDir].Nivel != (OldNivel-1) && Directorios[CurrTrnDir].Nivel != 0 );
|
||
|
||
|
||
|
||
CurrTrnArch = Directorios[CurrTrnDir].PosDirectorio + 1;
|
||
CurrRowArch = 0;
|
||
MuestraArchivos( CurrTrnArch );
|
||
|
||
if ( config.Ruta )
|
||
{
|
||
ReconstruyeDirectorio( CurrTrnDir );
|
||
textcolor( YELLOW );
|
||
gotoxy( 2, 23 ); cprintf( " " );
|
||
gotoxy( 2, 23 ); cprintf( "%s", PathActual, MI.ff_name );
|
||
}
|
||
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*CurrTrnArch, SEEK_SET );
|
||
fread( &MI, sizeof(MI), 1, HFf );
|
||
|
||
|
||
} else {
|
||
// Penetramos en ese directorio...
|
||
// Si la rama no esta expandida, la expandimos
|
||
if ( MI.ff_attrib & FA_DIREC )
|
||
{
|
||
strcpy( Buffer, MI.ff_name );
|
||
if ( !Directorios[CurrTrnDir+1].ContraidoExpandido )
|
||
{
|
||
IniTrnDir = CurrTrnDir;
|
||
for ( i=0; i < CurrRowDir; i++ )
|
||
IniTrnDir = AvanzaRetrocede( IniTrnDir, -1 );
|
||
ContraeExpandeRama( &Directorios[CurrTrnDir], !Directorios[CurrTrnDir+1].ContraidoExpandido );
|
||
MuestraDirectorios( IniTrnDir );
|
||
}
|
||
// Ahora avanzamos hasta alcanzar al directorio
|
||
do {
|
||
OldCurrTrnDir = CurrTrnDir;
|
||
CurrTrnDir = AvanzaRetrocede( CurrTrnDir, 1 );
|
||
if ( OldCurrTrnDir != CurrTrnDir )
|
||
{
|
||
CurrRowDir++;
|
||
if ( CurrRowDir >= NUM_LINEAS )
|
||
{
|
||
CurrRowDir = NUM_LINEAS-1;
|
||
movetext( 1, 3, 27, 21, 1, 2 );
|
||
}
|
||
}
|
||
} while( strcmp( Buffer, MI.ff_name ) != 0 );
|
||
|
||
|
||
CurrTrnArch = Directorios[CurrTrnDir].PosDirectorio + 1;
|
||
CurrRowArch = 0;
|
||
MuestraArchivos( CurrTrnArch );
|
||
|
||
if ( config.Ruta )
|
||
{
|
||
ReconstruyeDirectorio( CurrTrnDir );
|
||
textcolor( YELLOW );
|
||
gotoxy( 2, 23 ); cprintf( " " );
|
||
gotoxy( 2, 23 ); cprintf( "%s", PathActual );
|
||
}
|
||
} else {
|
||
// MuestraPropiedades();
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
break;
|
||
case 27:
|
||
ok = 1;
|
||
break;
|
||
case 0:
|
||
switch( getch() )
|
||
{
|
||
case 64:
|
||
if ( config.Directorios )
|
||
{
|
||
VentanaActual++; if ( VentanaActual > 2 ) VentanaActual = 1;
|
||
}
|
||
switch( VentanaActual )
|
||
{
|
||
case 1:
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*CurrTrnDir, SEEK_SET );
|
||
break;
|
||
case 2:
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*CurrTrnArch, SEEK_SET );
|
||
break;
|
||
}
|
||
fread( &MI, sizeof(MI), 1, HFf );
|
||
break;
|
||
|
||
case 72:
|
||
switch( VentanaActual )
|
||
{
|
||
case 1:
|
||
CurrRowDir--; if ( CurrRowDir < 0 )
|
||
{
|
||
CurrRowDir = 0;
|
||
if ( CurrTrnDir != 0 )
|
||
{
|
||
movetext( 1, 2, 27, 20, 1, 3);
|
||
}
|
||
}
|
||
CurrTrnDir = AvanzaRetrocede( CurrTrnDir, -1 );
|
||
|
||
CurrTrnArch = Directorios[CurrTrnDir].PosDirectorio + 1;
|
||
CurrRowArch = 0;
|
||
MuestraArchivos( CurrTrnArch );
|
||
|
||
if ( config.Ruta )
|
||
{
|
||
ReconstruyeDirectorio( CurrTrnDir );
|
||
textcolor( YELLOW );
|
||
gotoxy( 2, 23 ); cprintf( " " );
|
||
gotoxy( 2, 23 ); cprintf( "%s", PathActual, MI.ff_name );
|
||
}
|
||
break;
|
||
case 2:
|
||
OldCurrTrnDir = CurrTrnArch; OldNivel = MI.nivel;
|
||
if ( CurrTrnArch == 1 ) break;
|
||
do {
|
||
CurrTrnArch--;
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*CurrTrnArch, SEEK_SET );
|
||
fread( &MI, sizeof(MI), 1, HFf );
|
||
} while ( MI.nivel > OldNivel );
|
||
if ( MI.nivel < OldNivel )
|
||
{
|
||
CurrTrnArch = OldCurrTrnDir;
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*CurrTrnArch, SEEK_SET );
|
||
fread( &MI, sizeof(MI), 1, HFf );
|
||
} else {
|
||
CurrRowArch--;
|
||
if ( CurrRowArch < 0 )
|
||
{
|
||
CurrRowArch = 0;
|
||
|
||
MuestraArchivos( CurrTrnArch );
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
break;
|
||
|
||
case 80:
|
||
switch( VentanaActual )
|
||
{
|
||
case 1:
|
||
OldCurrTrnDir = CurrTrnDir;
|
||
CurrTrnDir = AvanzaRetrocede( CurrTrnDir, 1 );
|
||
if ( OldCurrTrnDir != CurrTrnDir )
|
||
{
|
||
CurrRowDir++;
|
||
if ( CurrRowDir >= NUM_LINEAS )
|
||
{
|
||
CurrRowDir = NUM_LINEAS-1;
|
||
movetext( 1, 3, 27, 21, 1, 2 );
|
||
}
|
||
|
||
CurrTrnArch = Directorios[CurrTrnDir].PosDirectorio + 1;
|
||
CurrRowArch = 0;
|
||
MuestraArchivos( CurrTrnArch );
|
||
|
||
if ( config.Ruta )
|
||
{
|
||
ReconstruyeDirectorio( CurrTrnDir );
|
||
textcolor( YELLOW );
|
||
gotoxy( 2, 23 ); cprintf( " " );
|
||
gotoxy( 2, 23 ); cprintf( "%s", PathActual );
|
||
}
|
||
}
|
||
break;
|
||
case 2:
|
||
OldCurrTrnDir = CurrTrnArch; OldNivel = MI.nivel;
|
||
|
||
do {
|
||
CurrTrnArch++;
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*CurrTrnArch, SEEK_SET );
|
||
fread( &MI, sizeof(MI), 1, HFf );
|
||
} while ( MI.nivel > OldNivel );
|
||
if ( MI.nivel < OldNivel )
|
||
{
|
||
CurrTrnArch = OldCurrTrnDir;
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*CurrTrnArch, SEEK_SET );
|
||
fread( &MI, sizeof(MI), 1, HFf );
|
||
} else {
|
||
CurrRowArch++;
|
||
if ( CurrRowArch >= (config.Directorios ? 19*2 : 19*4) )
|
||
{
|
||
CurrRowArch = 0;
|
||
|
||
MuestraArchivos( CurrTrnArch );
|
||
}
|
||
}
|
||
|
||
break;
|
||
}
|
||
break;
|
||
|
||
}
|
||
break;
|
||
|
||
}
|
||
if ( config.Directorios && VentanaActual == 1 )
|
||
MuestraDirectorio( CurrRowDir, CurrTrnDir, 1 );
|
||
else
|
||
MuestraArchivo( CurrRowArch, CurrTrnArch, 1 );
|
||
|
||
|
||
}
|
||
} while( !ok );
|
||
|
||
|
||
if ( Directorios != NULL ) delete [] Directorios;
|
||
fclose( HFf );
|
||
}
|
||
|
||
textbackground( BLACK );
|
||
textcolor( LIGHTGRAY );
|
||
clrscr();
|
||
}
|
||
|
||
void ReconstruyeDirectorio( int Nivel )
|
||
{
|
||
char RutaActual[13];
|
||
int NivelA;
|
||
|
||
// Retrocedemos al nivel anterior
|
||
NivelA = Directorios[Nivel].Nivel;
|
||
// Nombre del Nivel 'anterior'
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*Directorios[Nivel].PosDirectorio, SEEK_SET );
|
||
fread( &MI, sizeof(MI), 1, HFf );
|
||
strcpy( RutaActual, MI.ff_name );
|
||
|
||
if ( NivelA > 0 )
|
||
{
|
||
while ( Directorios[Nivel].Nivel != NivelA - 1 ) Nivel--;
|
||
ReconstruyeDirectorio( Nivel );
|
||
}
|
||
|
||
if ( NivelA == 0 )
|
||
{
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*Directorios[NivelA].PosDirectorio, SEEK_SET );
|
||
fread( &MI, sizeof(MI), 1, HFf );
|
||
sprintf( PathActual, "[%s]\\", MI.ff_name );
|
||
} else {
|
||
strcat( PathActual, RutaActual );
|
||
strcat( PathActual, "\\" );
|
||
}
|
||
}
|
||
|
||
|
||
int AvanzaRetrocede( int PuntoInicio, char RetrocedeAvanza )
|
||
{
|
||
int oldPI, NivelE;
|
||
|
||
oldPI = PuntoInicio;
|
||
|
||
if ( PuntoInicio <= 1 && RetrocedeAvanza == -1 ) return 0;
|
||
|
||
do {
|
||
PuntoInicio+=RetrocedeAvanza;
|
||
} while ( !Directorios[PuntoInicio].ContraidoExpandido && Directorios[PuntoInicio].Nivel!=0 );
|
||
|
||
if ( Directorios[PuntoInicio].Nivel == 0 )
|
||
return oldPI;
|
||
|
||
return PuntoInicio;
|
||
}
|
||
|
||
void MuestraDirectorio( int Row, int DirMuestra, char como )
|
||
{
|
||
|
||
window(2, 2, 27, 23);
|
||
|
||
textcolor( LIGHTMAGENTA );
|
||
|
||
if ( como )
|
||
{
|
||
textbackground( LIGHTMAGENTA );
|
||
textcolor( BLACK );
|
||
} else {
|
||
// textbackground(BLUE);
|
||
textbackground( BLACK );
|
||
}
|
||
|
||
|
||
gotoxy( 1, Row+1 );
|
||
cprintf( " " );
|
||
|
||
gotoxy( 1+Directorios[DirMuestra].Nivel, Row+1 );
|
||
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*Directorios[DirMuestra].PosDirectorio, SEEK_SET );
|
||
fread( &MI, sizeof(MI), 1, HFf );
|
||
cprintf( "%c%s", Directorios[DirMuestra].Nivel < Directorios[DirMuestra+1].Nivel ? Directorios[DirMuestra+1].ContraidoExpandido ? '-' : '+' : '<EFBFBD>', MI.ff_name );
|
||
|
||
// textbackground(BLUE);
|
||
textbackground( BLACK );
|
||
|
||
|
||
window(1, 1, 80, 24);
|
||
|
||
}
|
||
|
||
|
||
void LeeDir()
|
||
{
|
||
long i;
|
||
int RowFisica;
|
||
|
||
rewind( HFf );
|
||
fread( &CabIM, sizeof(CabIM), 1, HFf );
|
||
|
||
if ( Directorios != NULL ) delete [] Directorios;
|
||
if ( ( Directorios = new MDIREC far [CabIM.NumDirectorios+1] ) != NULL )
|
||
{
|
||
fread( Directorios, sizeof(MDIREC), CabIM.NumDirectorios+1, HFf );
|
||
} else {
|
||
// No hay memoria suficiente
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
void MuestraArchivos( long CurrTrnDir )
|
||
{
|
||
int CurrNivel, RowFisica;
|
||
long CurrN;
|
||
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*CurrTrnDir, SEEK_SET );
|
||
fread( &MI, sizeof(MI), 1, HFf );
|
||
|
||
CurrN = CurrTrnDir;//Directorios[CurrTrnDir].PosDirectorio + 1;
|
||
|
||
CurrNivel = MI.nivel;//Directorios[CurrTrnDir].Nivel + 1;
|
||
|
||
for ( RowFisica=3; RowFisica<22; RowFisica++ )
|
||
{
|
||
gotoxy( 30, RowFisica );
|
||
cprintf( " <20> " );
|
||
}
|
||
|
||
// Miro si el archivo siguiente a este directorio es de un nivel superior
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*CurrN, SEEK_SET );
|
||
fread( &MI, sizeof(MI), 1, HFf );
|
||
if ( MI.nivel != CurrNivel )
|
||
return; // Parece que el directorio estaba vacio
|
||
|
||
// Continua solo mientra no estemos en un nivel inferior
|
||
for ( RowFisica = 0; MI.nivel >= CurrNivel
|
||
&& RowFisica < (config.Directorios ? 19*2 : 19*4); )
|
||
{
|
||
if ( MI.nivel == CurrNivel )
|
||
{
|
||
MuestraArchivo( RowFisica, CurrTrnDir, 0 );
|
||
RowFisica++;
|
||
}
|
||
CurrN++;
|
||
// fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*CurrN, SEEK_SET );
|
||
fread( &MI, sizeof(MI), 1, HFf );
|
||
}
|
||
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*CurrTrnDir, SEEK_SET );
|
||
fread( &MI, sizeof(MI), 1, HFf );
|
||
|
||
|
||
}
|
||
|
||
void MuestraArchivo( int RowFisica, int PosArch, char como )
|
||
{
|
||
int s, i;
|
||
|
||
if ( como )
|
||
{
|
||
textbackground( LIGHTMAGENTA );
|
||
textcolor( BLACK );
|
||
} else {
|
||
// textbackground(BLUE);
|
||
textbackground( BLACK );
|
||
}
|
||
|
||
// obtenemos la columna: 0 - 1 - 2
|
||
gotoxy( ( ( RowFisica / 19 ) + ( config.Directorios ? 1 : 0 ) ) * 26 + 5, 3 + RowFisica % 19 );
|
||
|
||
if ( MI.ff_name[0] != '.' && strstr( MI.ff_name, "." ) != NULL )
|
||
{
|
||
i = 0;
|
||
while ( MI.ff_name[i] != '.' ) i++;
|
||
MI.ff_name[i] = '\0';
|
||
sprintf( Buffer, "%-8s %-3s", MI.ff_name, &MI.ff_name[i+1] );
|
||
MI.ff_name[i] = '.';
|
||
} else
|
||
sprintf( Buffer, "%s", MI.ff_name );
|
||
|
||
|
||
|
||
Que_Color(); cprintf("%-12s", Buffer );
|
||
if( MI.ff_attrib & FA_DIREC ) cprintf(" <dir>");
|
||
else
|
||
{
|
||
textcolor(YELLOW); formatea_u_long( (unsigned long) MI.ff_fsize, Buffer );
|
||
cprintf(" %11s", Buffer );
|
||
}
|
||
}
|
||
|
||
void Que_Color(void){
|
||
|
||
char Extension[4];
|
||
int i;
|
||
|
||
/*// Todo lo que este oculto*/
|
||
if ( MI.ff_attrib & FA_HIDDEN ) { textcolor(GREEN); return; }
|
||
/*// Directorios*/
|
||
if ( MI.ff_attrib & FA_DIREC ) { textcolor(LIGHTMAGENTA); return; }
|
||
|
||
i = 0;
|
||
while ( MI.ff_name[i] != '.' ) i++;
|
||
Extension[0] = MI.ff_name[i+1];
|
||
Extension[1] = MI.ff_name[i+2];
|
||
Extension[2] = MI.ff_name[i+3];
|
||
Extension[3] = '\0';
|
||
|
||
/*// Ejecutaables *.BAT dee proceso por Lotes*/
|
||
if ( !strcmpi(Extension, "BAT") ) { textcolor(RED); return; }
|
||
/*// Ejecutables *.EXE*/
|
||
if ( !strcmpi(Extension, "EXE") ) { textcolor(LIGHTCYAN); return; }
|
||
/*// Ejecutables *.COM*/
|
||
if ( !strcmpi(Extension, "COM") ) { textcolor(LIGHTGREEN); return; }
|
||
|
||
/* //Texto*/
|
||
if ( !strcmpi(Extension, "TXT") ) { textcolor(WHITE); return; }
|
||
if ( !strcmpi(Extension, "DOC") ) { textcolor(WHITE); return; }
|
||
/*// Texto con formatos especiales*/
|
||
if ( !strcmpi(Extension, "WRI") ) { textcolor(WHITE); return; }
|
||
if ( !strcmpi(Extension, "WPC") ) { textcolor(WHITE); return; }
|
||
|
||
/*// M<>sica*/
|
||
if ( !strcmpi(Extension, "MID") ) { textcolor(BLUE); return; }
|
||
if ( !strcmpi(Extension, "MOD") ) { textcolor(BLUE); return; }
|
||
if ( !strcmpi(Extension, "VOC") ) { textcolor(BLUE); return; }
|
||
if ( !strcmpi(Extension, "CMF") ) { textcolor(BLUE); return; }
|
||
if ( !strcmpi(Extension, "WAV") ) { textcolor(BLUE); return; }
|
||
if ( !strcmpi(Extension, "S3M") ) { textcolor(BLUE); return; }
|
||
|
||
/* // Imagenes y videos*/
|
||
if ( !strcmpi(Extension, "FLI") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "FLC") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "MPG") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "MOV") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "AVI") ) { textcolor(MAGENTA); return; }
|
||
|
||
if ( !strcmpi(Extension, "CEL") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "PNG") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "PCX") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "GIF") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "JPG") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "LBM") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "TGA") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "DIB") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "MAC") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "WPG") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "BMP") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "PIC") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "RLE") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "CUT") ) { textcolor(MAGENTA); return; }
|
||
if ( !strcmpi(Extension, "TIF") ) { textcolor(MAGENTA); return; }
|
||
|
||
/* // Lenguajes*/
|
||
if ( !strcmpi(Extension, "C") ) { textcolor(BROWN); return; }
|
||
if ( !strcmpi(Extension, "CPP") ) { textcolor(BROWN); return; }
|
||
if ( !strcmpi(Extension, "C++") ) { textcolor(BROWN); return; }
|
||
if ( !strcmpi(Extension, "PAS") ) { textcolor(BROWN); return; }
|
||
if ( !strcmpi(Extension, "ASM") ) { textcolor(BROWN); return; }
|
||
if ( !strcmpi(Extension, "VBX") ) { textcolor(BROWN); return; }
|
||
if ( !strcmpi(Extension, "LIB") ) { textcolor(BROWN); return; }
|
||
if ( !strcmpi(Extension, "BAS") ) { textcolor(BROWN); return; }
|
||
|
||
/*// Compresores*/
|
||
if ( !strcmpi(Extension, "ZIP") ) { textcolor(LIGHTBLUE); return; }
|
||
if ( !strcmpi(Extension, "ARJ") ) { textcolor(LIGHTBLUE); return; }
|
||
if ( !strcmpi(Extension, "ARC") ) { textcolor(LIGHTBLUE); return; }
|
||
if ( !strcmpi(Extension, "AIN") ) { textcolor(LIGHTBLUE); return; }
|
||
if ( !strcmpi(Extension, "LZH") ) { textcolor(LIGHTBLUE); return; }
|
||
if ( !strcmpi(Extension, "TGZ") ) { textcolor(LIGHTBLUE); return; }
|
||
if ( !strcmpi(Extension, "RAR") ) { textcolor(LIGHTBLUE); return; }
|
||
|
||
/*
|
||
if ( !strcmpi(Extension, "") ) { textcolor(); return; }
|
||
if ( !strcmpi(Extension, "") ) { textcolor(); return; }
|
||
if ( !strcmpi(Extension, "") ) { textcolor(); return; }
|
||
*/
|
||
|
||
textcolor(LIGHTGRAY);
|
||
}
|
||
|
||
|
||
|
||
|
||
void MuestraDirectorios( long DirInicio )
|
||
{
|
||
int i, RowFisica = 0;
|
||
|
||
window(2, 2, 27, 21);
|
||
clrscr();
|
||
|
||
Directorios[0].ContraidoExpandido = 1;
|
||
|
||
for ( i=DirInicio; i < CabIM.NumDirectorios && RowFisica < NUM_LINEAS; i++ )
|
||
{
|
||
if ( Directorios[i].ContraidoExpandido )
|
||
{
|
||
gotoxy( 1+Directorios[i].Nivel, RowFisica+1 );
|
||
|
||
fseek( HFf, sizeof( CabIM ) + sizeof( MDIREC ) * (CabIM.NumDirectorios+1) + sizeof(MINDEX)*Directorios[i].PosDirectorio, SEEK_SET );
|
||
fread( &MI, sizeof(MI), 1, HFf );
|
||
cprintf( "%c%s", Directorios[i].Nivel < Directorios[i+1].Nivel ? Directorios[i+1].ContraidoExpandido ? '-' : '+' : '<EFBFBD>', MI.ff_name );
|
||
RowFisica++;
|
||
}
|
||
}
|
||
|
||
|
||
window(1, 1, 80, 24);
|
||
|
||
}
|
||
|
||
/**************************************************************************\
|
||
|* *|
|
||
|* ContraeExpandeRama *|
|
||
|* *|
|
||
|* Descripci<63>n: *|
|
||
|* Contrae o expande la rama seg<65>n el par<61>metro y apartir del *|
|
||
|* punto indicado... *|
|
||
|* *|
|
||
|* Entradas: Puntero al inicio de la expanci<63>n / contraccion *|
|
||
|* Accion a ejecutar: CONTRAE / EXPANDE *|
|
||
|* *|
|
||
|* Salidas: (ninguna) *|
|
||
|* *|
|
||
\**************************************************************************/
|
||
void ContraeExpandeRama( MDIREC far *DesdeAqui, char ContraeExpande )
|
||
{
|
||
int NivelE;
|
||
|
||
NivelE = DesdeAqui -> Nivel;
|
||
|
||
DesdeAqui++;
|
||
while( DesdeAqui -> Nivel > NivelE )
|
||
{
|
||
if ( ContraeExpande )
|
||
{
|
||
if ( DesdeAqui -> Nivel == NivelE + 1 )
|
||
DesdeAqui -> ContraidoExpandido = ContraeExpande;
|
||
} else
|
||
DesdeAqui -> ContraidoExpandido = ContraeExpande;
|
||
DesdeAqui++;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/*
|
||
//
|
||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20> <20> <20><> <20><><EFBFBD> <20><><EFBFBD> <20><> <20> <20><><EFBFBD><EFBFBD> <20> <20> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||
// <20> <20> <20> <20> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20><> <20> <20>
|
||
// <20><><EFBFBD> <20> <20> <20><><EFBFBD> <20> <20> <20><><EFBFBD><EFBFBD> <20> <20><> <20><><EFBFBD><EFBFBD> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20><><EFBFBD>
|
||
// <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20><> <20> <20> <20> <20> <20><> <20> <20>
|
||
// <20> <20><><EFBFBD><EFBFBD> <20> <20> <20> <20> <20> <20> <20> <20><><EFBFBD> <20> <20> <20><><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||
*/
|
||
void formatea_u_long( unsigned long Numero, char *Inter_Chg) {
|
||
|
||
char Buffer1[80];
|
||
char Buffer2[80];
|
||
int c;
|
||
|
||
sprintf(Buffer1, "%lu", Numero);
|
||
strcpy(Buffer2, "\0");
|
||
strrev(Buffer1);
|
||
c = strlen( Buffer1 );
|
||
while( c >= 3 ){
|
||
c -= 3;
|
||
strncat( Buffer2, Buffer1, 3);
|
||
strrev(Buffer1);
|
||
Buffer1[c] = '\0';
|
||
strrev(Buffer1);
|
||
if(strlen(Buffer1)!=0)
|
||
strcat( Buffer2, "." );
|
||
}
|
||
strcat( Buffer2, Buffer1);
|
||
strrev(Buffer2);
|
||
strcpy(Inter_Chg, Buffer2);
|
||
|
||
/*// return Buffer2;*/
|
||
}
|