d0ab8cc457
Files correlati : Ricompilazione Demo : [ ] Commento : riportata la versione 98.01.05 patch 34 git-svn-id: svn://10.65.10.50/trunk@7409 c028cbd2-c16b-5b4b-a496-9718f37d4682
88 lines
2.0 KiB
C++
Executable File
88 lines
2.0 KiB
C++
Executable File
#include <io.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <errno.h>
|
|
#include <files.h>
|
|
#include <windows.h>
|
|
|
|
typedef unsigned char bool ;
|
|
#define FALSE 0
|
|
#define TRUE 1
|
|
|
|
int main(int argc, char** argv);
|
|
bool fcopy(const char* orig, const char* dest);
|
|
bool fexist(const char* file);
|
|
int update_file(const char *from, const char * to);
|
|
|
|
bool fexist(
|
|
const char* file) // @parm Nome del file di cui contrallarne l'esistenza
|
|
{
|
|
int err = access(file, 0);
|
|
return err == 0;
|
|
}
|
|
|
|
bool fcopy(
|
|
const char* orig, // @parm Nome del file di origine
|
|
const char* dest) // @parm Nome del file di destinazione
|
|
// file <p dest> in coda al file <p orig> (default FALSE)
|
|
|
|
// @comm Nel caso vengano ravvisati degli errori durante l'operazione vengono
|
|
// creati dei box di comunicazione che indicano la causa del problema
|
|
{
|
|
|
|
// Copia il file su se stesso?
|
|
if (stricmp(orig, dest) == 0)
|
|
return TRUE; // Or FALSE?
|
|
|
|
FILE* i = fopen(orig, "rb");
|
|
if (!i) return fprintf(stderr,"Impossibile leggere il file %s", orig);
|
|
|
|
FILE* o = fopen(dest, "wb");
|
|
if (!o)
|
|
{
|
|
fclose(i);
|
|
return fprintf(stderr,"Impossibile scrivere il file ", dest);
|
|
}
|
|
|
|
const word size = 16*1024;
|
|
unsigned char * buffer=new unsigned char[size];
|
|
|
|
bool ok = TRUE;
|
|
while (ok)
|
|
{
|
|
const word letti = fread(buffer, 1, size, i);
|
|
ok = fwrite(buffer, 1, letti, o) == letti;
|
|
if (letti < size) break;
|
|
}
|
|
|
|
if (!ok) fprintf(stderr,"Errore di scrittura: probabile disco pieno!");
|
|
|
|
fclose(o);
|
|
fclose(i);
|
|
delete buffer;
|
|
return ok;
|
|
}
|
|
|
|
int update_file(const char *from, const char * to)
|
|
{
|
|
int r=0;
|
|
|
|
if (fexist(from))
|
|
{
|
|
if (fcopy(from,to))
|
|
r=remove(from);
|
|
}
|
|
return r;
|
|
}
|
|
|
|
int PASCAL WinMain(HINSTANCE _this, HINSTANCE _prev , LPSTR _cmd,int _mode)
|
|
{
|
|
int r=0;
|
|
char ba1exe[]="ba1.exe",ba1ex[]="ba1.ex_";
|
|
char ba0exe[]="ba0.exe",ba0ex[]="ba0.ex_";
|
|
|
|
update_file(ba1ex,ba1exe);
|
|
update_file(ba0ex,ba0exe);
|
|
return 0;
|
|
}
|