Code formating
This commit is contained in:
86
crc.c
86
crc.c
@@ -1,69 +1,67 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
unsigned long CRCTable[256];
|
unsigned long CRCTable[256];
|
||||||
int CRCTable_initialized=0;
|
int CRCTable_initialized = 0;
|
||||||
|
|
||||||
#define CRC32_POLYNOMIAL 0xEDB88320L
|
#define CRC32_POLYNOMIAL 0xEDB88320L
|
||||||
|
|
||||||
void CRCTable_Init(){
|
void CRCTable_Init() {
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
unsigned long crc;
|
unsigned long crc;
|
||||||
|
|
||||||
if(CRCTable_initialized){
|
if (CRCTable_initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CRCTable_initialized=1;
|
CRCTable_initialized = 1;
|
||||||
|
|
||||||
for (i=0;i<256;i++){
|
for (i = 0; i < 256; i++) {
|
||||||
crc=i;
|
crc = i;
|
||||||
for (j=8;j>0;j--){
|
for (j = 8; j > 0; j--) {
|
||||||
if (crc&1)
|
if (crc & 1)
|
||||||
crc=(crc>>1)^CRC32_POLYNOMIAL;
|
crc = (crc >> 1) ^ CRC32_POLYNOMIAL;
|
||||||
else
|
else
|
||||||
crc>>=1;
|
crc >>= 1;
|
||||||
}
|
}
|
||||||
CRCTable[i]=crc;
|
CRCTable[i] = crc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long CRC_Buffer(unsigned char *buffer, int len, unsigned long crc) {
|
||||||
unsigned long CRC_Buffer(unsigned char *buffer,int len,unsigned long crc){
|
unsigned char *p;
|
||||||
unsigned char *p;
|
unsigned long temp1;
|
||||||
unsigned long temp1;
|
unsigned long temp2;
|
||||||
unsigned long temp2;
|
|
||||||
|
|
||||||
// Calcular CRC del buffer
|
// Calcular CRC del buffer
|
||||||
p=(unsigned char*)buffer;
|
p = (unsigned char*) buffer;
|
||||||
while(len--!=0) {
|
while (len-- != 0) {
|
||||||
temp1=(crc>>8)&0x00FFFFFFL;
|
temp1 = (crc >> 8) & 0x00FFFFFFL;
|
||||||
temp2=CRCTable[((int)crc^*p++)&0xff];
|
temp2 = CRCTable[((int) crc ^ *p++) & 0xff];
|
||||||
crc=temp1^temp2;
|
crc = temp1 ^ temp2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(crc);
|
return (crc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long CRC_File(FILE *file) {
|
||||||
unsigned long CRC_File(FILE *file){
|
unsigned long crc;
|
||||||
unsigned long crc;
|
int count;
|
||||||
int count;
|
unsigned char buffer[512];
|
||||||
unsigned char buffer[512];
|
unsigned char *p;
|
||||||
unsigned char *p;
|
unsigned long temp1;
|
||||||
unsigned long temp1;
|
unsigned long temp2;
|
||||||
unsigned long temp2;
|
|
||||||
|
|
||||||
CRCTable_Init();
|
CRCTable_Init();
|
||||||
|
|
||||||
crc=0xFFFFFFFFL;
|
crc = 0xFFFFFFFFL;
|
||||||
for(;;){
|
for (;;) {
|
||||||
// Llenar el buffer
|
// Llenar el buffer
|
||||||
count=fread(buffer,1,512,file);
|
count = fread(buffer, 1, 512, file);
|
||||||
if(count==0)
|
if (count == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Calcular CRC del buffer
|
// Calcular CRC del buffer
|
||||||
crc=CRC_Buffer(buffer,count,crc);
|
crc = CRC_Buffer(buffer, count, crc);
|
||||||
}
|
}
|
||||||
return(crc^=0xFFFFFFFFL);
|
return (crc ^= 0xFFFFFFFFL);
|
||||||
}
|
}
|
||||||
|
|||||||
2
crc.h
2
crc.h
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
unsigned long CRC_Buffer(unsigned char *buffer,int len,unsigned long crc);
|
unsigned long CRC_Buffer(unsigned char *buffer, int len, unsigned long crc);
|
||||||
unsigned long CRC_File(FILE *file);
|
unsigned long CRC_File(FILE *file);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
591
filenode.c
591
filenode.c
@@ -7,547 +7,504 @@
|
|||||||
#include "fileutil.h"
|
#include "fileutil.h"
|
||||||
#include "filenode.h"
|
#include "filenode.h"
|
||||||
|
|
||||||
|
FileNode *_free_filenode = NULL;
|
||||||
|
int _n_filenode = 0;
|
||||||
FileNode *_free_filenode=NULL;
|
|
||||||
int _n_filenode=0;
|
|
||||||
#define FileNode_Tocho 1024
|
#define FileNode_Tocho 1024
|
||||||
FileNode *FileNode_New(){
|
FileNode *FileNode_New() {
|
||||||
FileNode *fn;
|
FileNode *fn;
|
||||||
|
|
||||||
if(_free_filenode==NULL){
|
if (_free_filenode == NULL ) {
|
||||||
FileNode *nodos;
|
FileNode *nodos;
|
||||||
int i;
|
int i;
|
||||||
// Reservar un tocho
|
// Reservar un tocho
|
||||||
nodos=malloc(sizeof(FileNode)*FileNode_Tocho);
|
nodos = malloc(sizeof(FileNode) * FileNode_Tocho);
|
||||||
for(i=0;i<FileNode_Tocho-1;i++){
|
for (i = 0; i < FileNode_Tocho - 1; i++) {
|
||||||
nodos[i].sig=&nodos[i+1];
|
nodos[i].sig = &nodos[i + 1];
|
||||||
}
|
}
|
||||||
nodos[FileNode_Tocho-1].sig=NULL;
|
nodos[FileNode_Tocho - 1].sig = NULL;
|
||||||
_free_filenode=&nodos[0];
|
_free_filenode = &nodos[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtener el primero libre
|
// Obtener el primero libre
|
||||||
fn=_free_filenode;
|
fn = _free_filenode;
|
||||||
_free_filenode=fn->sig;
|
_free_filenode = fn->sig;
|
||||||
_n_filenode++;
|
_n_filenode++;
|
||||||
|
|
||||||
// Iniciar
|
// Iniciar
|
||||||
fn->name[0]=0;
|
fn->name[0] = 0;
|
||||||
fn->flags=0;
|
fn->flags = 0;
|
||||||
fn->estado=EstadoFichero_Nada;
|
fn->estado = EstadoFichero_Nada;
|
||||||
fn->size=0;
|
fn->size = 0;
|
||||||
fn->crc=0;
|
fn->crc = 0;
|
||||||
fn->ft=0;
|
fn->ft = 0;
|
||||||
fn->child=NULL;
|
fn->child = NULL;
|
||||||
fn->n_childs=0;
|
fn->n_childs = 0;
|
||||||
fn->sig=NULL;
|
fn->sig = NULL;
|
||||||
fn->padre=NULL;
|
fn->padre = NULL;
|
||||||
|
|
||||||
return(fn);
|
return (fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNode_Delete(FileNode *fn){
|
void FileNode_Delete(FileNode *fn) {
|
||||||
fn->sig=_free_filenode;
|
fn->sig = _free_filenode;
|
||||||
_free_filenode=fn;
|
_free_filenode = fn;
|
||||||
_n_filenode--;
|
_n_filenode--;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNode_AddChild(FileNode *file,FileNode *file2){
|
void FileNode_AddChild(FileNode *file, FileNode *file2) {
|
||||||
if(!file2 || !file)
|
if (!file2 || !file)
|
||||||
return;
|
return;
|
||||||
file2->sig=file->child;
|
file2->sig = file->child;
|
||||||
file->child=file2;
|
file->child = file2;
|
||||||
file->n_childs++;
|
file->n_childs++;
|
||||||
file2->padre=file;
|
file2->padre = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileNode_SetEstadoRec(FileNode *file, EstadoFichero estado) {
|
||||||
void FileNode_SetEstadoRec(FileNode *file,EstadoFichero estado){
|
|
||||||
FileNode *fn_child;
|
FileNode *fn_child;
|
||||||
file->estado=estado;
|
file->estado = estado;
|
||||||
fn_child=file->child;
|
fn_child = file->child;
|
||||||
while(fn_child!=NULL){
|
while (fn_child != NULL ) {
|
||||||
FileNode_SetEstadoRec(fn_child,estado);
|
FileNode_SetEstadoRec(fn_child, estado);
|
||||||
fn_child=fn_child->sig;
|
fn_child = fn_child->sig;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNode_GetPath_Rec(FileNode *fn,char **pathnode){
|
void FileNode_GetPath_Rec(FileNode *fn, char **pathnode) {
|
||||||
if(fn->padre){
|
if (fn->padre) {
|
||||||
pathnode[0]=fn->padre->name;
|
pathnode[0] = fn->padre->name;
|
||||||
FileNode_GetPath_Rec(fn->padre,pathnode+1);
|
FileNode_GetPath_Rec(fn->padre, pathnode + 1);
|
||||||
}else{
|
} else {
|
||||||
pathnode[0]=NULL;
|
pathnode[0] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
char temppath[MaxPath];
|
char temppath[MaxPath];
|
||||||
char *FileNode_GetPath(FileNode *fn,char *path){
|
char *FileNode_GetPath(FileNode *fn, char *path) {
|
||||||
char *pathnodes[128];
|
char *pathnodes[128];
|
||||||
int levels,i;
|
int levels, i;
|
||||||
char *pathptr=temppath;
|
char *pathptr = temppath;
|
||||||
if(path)pathptr=path;
|
if (path)
|
||||||
|
pathptr = path;
|
||||||
|
|
||||||
FileNode_GetPath_Rec(fn,pathnodes);
|
FileNode_GetPath_Rec(fn, pathnodes);
|
||||||
levels=0;while(pathnodes[levels]){levels++;}
|
levels = 0;
|
||||||
strcpy(pathptr,"");
|
while (pathnodes[levels]) {
|
||||||
for(i=levels-1;i>=0;i--){
|
levels++;
|
||||||
strcat(pathptr,pathnodes[i]);
|
|
||||||
strcat(pathptr,"/");
|
|
||||||
}
|
}
|
||||||
strcat(pathptr,fn->name);
|
strcpy(pathptr, "");
|
||||||
|
for (i = levels - 1; i >= 0; i--) {
|
||||||
|
strcat(pathptr, pathnodes[i]);
|
||||||
|
strcat(pathptr, "/");
|
||||||
|
}
|
||||||
|
strcat(pathptr, fn->name);
|
||||||
return temppath;
|
return temppath;
|
||||||
}
|
}
|
||||||
char *FileNode_GetFullPath(FileNode *fn,char *basePath,char *path){
|
char *FileNode_GetFullPath(FileNode *fn, char *basePath, char *path) {
|
||||||
char *pathnodes[128];
|
char *pathnodes[128];
|
||||||
int levels,i;
|
int levels, i;
|
||||||
char *pathptr=temppath;
|
char *pathptr = temppath;
|
||||||
if(path)pathptr=path;
|
if (path)
|
||||||
|
pathptr = path;
|
||||||
|
|
||||||
FileNode_GetPath_Rec(fn,pathnodes);
|
FileNode_GetPath_Rec(fn, pathnodes);
|
||||||
levels=0;while(pathnodes[levels]){levels++;}
|
levels = 0;
|
||||||
strcpy(pathptr,basePath);
|
while (pathnodes[levels]) {
|
||||||
strcat(pathptr,"/");
|
levels++;
|
||||||
for(i=levels-2;i>=0;i--){
|
|
||||||
strcat(pathptr,pathnodes[i]);
|
|
||||||
strcat(pathptr,"/");
|
|
||||||
}
|
}
|
||||||
strcat(pathptr,fn->name);
|
strcpy(pathptr, basePath);
|
||||||
|
strcat(pathptr, "/");
|
||||||
|
for (i = levels - 2; i >= 0; i--) {
|
||||||
|
strcat(pathptr, pathnodes[i]);
|
||||||
|
strcat(pathptr, "/");
|
||||||
|
}
|
||||||
|
strcat(pathptr, fn->name);
|
||||||
return temppath;
|
return temppath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileNode_GetTamanho(FileNode *fn, char *file) {
|
||||||
|
fn->flags |= FileFlag_TieneTamanho;
|
||||||
void FileNode_GetTamanho(FileNode *fn,char *file){
|
fn->size = File_TamanhoFichero(file);
|
||||||
fn->flags|=FileFlag_TieneTamanho;
|
|
||||||
fn->size=File_TamanhoFichero(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNode_GetFecha(FileNode *fn,char *file){
|
void FileNode_GetFecha(FileNode *fn, char *file) {
|
||||||
fn->flags|=FileFlag_TieneFecha;
|
fn->flags |= FileFlag_TieneFecha;
|
||||||
fn->ft=FileTime_Get(file);
|
fn->ft = FileTime_Get(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNode_GetCRC(FileNode *fn,char *file){
|
void FileNode_GetCRC(FileNode *fn, char *file) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
f=fopen(file,"rb");
|
f = fopen(file, "rb");
|
||||||
if(!f){ return; }
|
if (!f) {
|
||||||
fn->flags|=FileFlag_TieneCRC;
|
return;
|
||||||
fn->crc=CRC_File(f);
|
}
|
||||||
|
fn->flags |= FileFlag_TieneCRC;
|
||||||
|
fn->crc = CRC_File(f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileNode_SaveNode(FileNode *fn, FILE *file) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void FileNode_SaveNode(FileNode *fn,FILE *file){
|
|
||||||
short name_len;
|
short name_len;
|
||||||
|
|
||||||
// Escribir nombre
|
// Escribir nombre
|
||||||
name_len=strlen(fn->name);
|
name_len = strlen(fn->name);
|
||||||
fwrite((void *)&name_len,sizeof(name_len),1,file);
|
fwrite((void *) &name_len, sizeof(name_len), 1, file);
|
||||||
fputs(fn->name,file);
|
fputs(fn->name, file);
|
||||||
|
|
||||||
// Escribir flags
|
// Escribir flags
|
||||||
fwrite((void *)&fn->flags,sizeof(fn->flags),1,file);
|
fwrite((void *) &fn->flags, sizeof(fn->flags), 1, file);
|
||||||
|
|
||||||
// Escribir estado
|
// Escribir estado
|
||||||
fputc((char)fn->estado,file);
|
fputc((char) fn->estado, file);
|
||||||
|
|
||||||
// Escribir tamanho
|
// Escribir tamanho
|
||||||
if(fn->flags&FileFlag_TieneTamanho){
|
if (fn->flags & FileFlag_TieneTamanho) {
|
||||||
fwrite((void *)&fn->size,sizeof(fn->size),1,file);
|
fwrite((void *) &fn->size, sizeof(fn->size), 1, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribir fecha
|
// Escribir fecha
|
||||||
if(fn->flags&FileFlag_TieneFecha){
|
if (fn->flags & FileFlag_TieneFecha) {
|
||||||
fwrite((void *)&fn->ft,sizeof(fn->ft),1,file);
|
fwrite((void *) &fn->ft, sizeof(fn->ft), 1, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribir CRC
|
// Escribir CRC
|
||||||
if(fn->flags&FileFlag_TieneCRC){
|
if (fn->flags & FileFlag_TieneCRC) {
|
||||||
fwrite((void *)&fn->crc,sizeof(fn->crc),1,file);
|
fwrite((void *) &fn->crc, sizeof(fn->crc), 1, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribir ficheros del directorio
|
// Escribir ficheros del directorio
|
||||||
if(fn->flags&FileFlag_Directorio){
|
if (fn->flags & FileFlag_Directorio) {
|
||||||
FileNode *fnc;
|
FileNode *fnc;
|
||||||
fwrite((void *)&fn->n_childs,sizeof(fn->n_childs),1,file);
|
fwrite((void *) &fn->n_childs, sizeof(fn->n_childs), 1, file);
|
||||||
fnc=fn->child;
|
fnc = fn->child;
|
||||||
while(fnc){
|
while (fnc) {
|
||||||
FileNode_SaveNode(fnc,file);
|
FileNode_SaveNode(fnc, file);
|
||||||
fnc=fnc->sig;
|
fnc = fnc->sig;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNode_Save(FileNode *fn,char *fichero){
|
void FileNode_Save(FileNode *fn, char *fichero) {
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char marca[5];
|
char marca[5];
|
||||||
int version;
|
int version;
|
||||||
|
|
||||||
if(!fn)
|
if (!fn)
|
||||||
return;
|
return;
|
||||||
file=fopen(fichero,"wb+");
|
file = fopen(fichero, "wb+");
|
||||||
if(!file)
|
if (!file)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Escribir marca y version
|
// Escribir marca y version
|
||||||
strcpy(marca,"sYnC");
|
strcpy(marca, "sYnC");
|
||||||
fwrite((void *)marca,sizeof(char),4,file);
|
fwrite((void *) marca, sizeof(char), 4, file);
|
||||||
version=FileNode_Version;
|
version = FileNode_Version;
|
||||||
fwrite((void *)&version,sizeof(int),1,file);
|
fwrite((void *) &version, sizeof(int), 1, file);
|
||||||
|
|
||||||
|
FileNode_SaveNode(fn, file);
|
||||||
FileNode_SaveNode(fn,file);
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileNode *FileNode_LoadNode(FILE *file) {
|
||||||
FileNode *FileNode_LoadNode(FILE *file){
|
|
||||||
short name_len;
|
short name_len;
|
||||||
FileNode *fn;
|
FileNode *fn;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
fn=FileNode_New();
|
fn = FileNode_New();
|
||||||
|
|
||||||
// Leer el nombre
|
// Leer el nombre
|
||||||
fread((void *)&name_len,sizeof(name_len),1,file);
|
fread((void *) &name_len, sizeof(name_len), 1, file);
|
||||||
fread((void *)fn->name,sizeof(char),name_len,file);
|
fread((void *) fn->name, sizeof(char), name_len, file);
|
||||||
fn->name[name_len]=0;
|
fn->name[name_len] = 0;
|
||||||
|
|
||||||
// Leer vanderas
|
// Leer vanderas
|
||||||
fread((void *)&fn->flags,sizeof(fn->flags),1,file);
|
fread((void *) &fn->flags, sizeof(fn->flags), 1, file);
|
||||||
|
|
||||||
// Leer estado
|
// Leer estado
|
||||||
fn->estado=fgetc(file);
|
fn->estado = fgetc(file);
|
||||||
|
|
||||||
// Leer tamanho
|
// Leer tamanho
|
||||||
if(fn->flags&FileFlag_TieneTamanho){
|
if (fn->flags & FileFlag_TieneTamanho) {
|
||||||
fread((void *)&fn->size,sizeof(fn->size),1,file);
|
fread((void *) &fn->size, sizeof(fn->size), 1, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leer fecha
|
// Leer fecha
|
||||||
if(fn->flags&FileFlag_TieneFecha){
|
if (fn->flags & FileFlag_TieneFecha) {
|
||||||
fread((void *)&fn->ft,sizeof(fn->ft),1,file);
|
fread((void *) &fn->ft, sizeof(fn->ft), 1, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leer CRC
|
// Leer CRC
|
||||||
if(fn->flags&FileFlag_TieneCRC){
|
if (fn->flags & FileFlag_TieneCRC) {
|
||||||
fread((void *)&fn->crc,sizeof(fn->crc),1,file);
|
fread((void *) &fn->crc, sizeof(fn->crc), 1, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leer ficheros del directorio
|
// Leer ficheros del directorio
|
||||||
if(fn->flags&FileFlag_Directorio){
|
if (fn->flags & FileFlag_Directorio) {
|
||||||
FileNode *fnca=NULL,*fnc;
|
FileNode *fnca = NULL, *fnc;
|
||||||
fread((void *)&fn->n_childs,sizeof(fn->n_childs),1,file);
|
fread((void *) &fn->n_childs, sizeof(fn->n_childs), 1, file);
|
||||||
for(i=0;i<fn->n_childs;i++){
|
for (i = 0; i < fn->n_childs; i++) {
|
||||||
fnc=FileNode_LoadNode(file);
|
fnc = FileNode_LoadNode(file);
|
||||||
fnc->padre=fn;
|
fnc->padre = fn;
|
||||||
if(!fnca){
|
if (!fnca) {
|
||||||
fn->child=fnc;
|
fn->child = fnc;
|
||||||
}else{
|
} else {
|
||||||
fnca->sig=fnc;
|
fnca->sig = fnc;
|
||||||
}
|
}
|
||||||
fnca=fnc;
|
fnca = fnc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return(fn);
|
return (fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileNode *FileNode_Load(char *fichero) {
|
||||||
FileNode *FileNode_Load(char *fichero){
|
|
||||||
FILE *file;
|
FILE *file;
|
||||||
FileNode *fn;
|
FileNode *fn;
|
||||||
char marca[5];
|
char marca[5];
|
||||||
int version;
|
int version;
|
||||||
|
|
||||||
file=fopen(fichero,"rb");
|
file = fopen(fichero, "rb");
|
||||||
if(!file)
|
if (!file)
|
||||||
return(NULL);
|
return (NULL );
|
||||||
|
|
||||||
// Leer marca y version
|
// Leer marca y version
|
||||||
fread((void *)marca,sizeof(char),4,file);
|
fread((void *) marca, sizeof(char), 4, file);
|
||||||
marca[4]=0;
|
marca[4] = 0;
|
||||||
if(strcmp(marca,"sYnC")){
|
if (strcmp(marca, "sYnC")) {
|
||||||
// Marca incorrecta
|
// Marca incorrecta
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return(NULL);
|
return (NULL );
|
||||||
}
|
}
|
||||||
fread((void *)&version,sizeof(int),1,file);
|
fread((void *) &version, sizeof(int), 1, file);
|
||||||
if(version!=FileNode_Version){
|
if (version != FileNode_Version) {
|
||||||
// Version incorrecta
|
// Version incorrecta
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return(NULL);
|
return (NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn = FileNode_LoadNode(file);
|
||||||
fn=FileNode_LoadNode(file);
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
return(fn);
|
return (fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileNode_PrintNode(FileNode *fn) {
|
||||||
void FileNode_PrintNode(FileNode *fn){
|
printf(FileNode_GetPath(fn, NULL ));
|
||||||
printf(FileNode_GetPath(fn,NULL));
|
if (fn->flags & FileFlag_Normal) {
|
||||||
if(fn->flags&FileFlag_Normal){
|
|
||||||
printf(" File");
|
printf(" File");
|
||||||
}else{
|
} else {
|
||||||
printf(" Dir");
|
printf(" Dir");
|
||||||
}
|
}
|
||||||
printf(" %d",fn->estado);
|
printf(" %d", fn->estado);
|
||||||
if(fn->estado==EstadoFichero_Nuevo){
|
if (fn->estado == EstadoFichero_Nuevo) {
|
||||||
printf(" Nuevo");
|
printf(" Nuevo");
|
||||||
}
|
}
|
||||||
if(fn->estado==EstadoFichero_Modificado){
|
if (fn->estado == EstadoFichero_Modificado) {
|
||||||
printf(" Modificado");
|
printf(" Modificado");
|
||||||
}
|
}
|
||||||
if(fn->estado==EstadoFichero_Borrado){
|
if (fn->estado == EstadoFichero_Borrado) {
|
||||||
printf(" Borrado!!!");
|
printf(" Borrado!!!");
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Tamanho
|
// Tamanho
|
||||||
if(fn->flags&FileFlag_TieneTamanho){
|
if(fn->flags&FileFlag_TieneTamanho){
|
||||||
printf("\\-Tamanho: %lld\n",fn->size);
|
printf("\\-Tamanho: %lld\n",fn->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fecha
|
// Fecha
|
||||||
if(fn->flags&FileFlag_TieneFecha){
|
if(fn->flags&FileFlag_TieneFecha){
|
||||||
printf("\\-Fecha : ");FileTime_Print(fn->ft);printf("\n");
|
printf("\\-Fecha : ");FileTime_Print(fn->ft);printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// CRC
|
// CRC
|
||||||
if(fn->flags&FileFlag_TieneCRC){
|
if(fn->flags&FileFlag_TieneCRC){
|
||||||
printf("\\-CRC : [%08X]\n",fn->crc);
|
printf("\\-CRC : [%08X]\n",fn->crc);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileNode_Print(FileNode *fn) {
|
||||||
|
FileNode *fnAux = fn;
|
||||||
|
int end = 0;
|
||||||
|
|
||||||
void FileNode_Print(FileNode *fn){
|
while (fnAux != NULL && !end) {
|
||||||
FileNode *fnAux=fn;
|
|
||||||
int end=0;
|
|
||||||
|
|
||||||
while(fnAux!=NULL && !end){
|
if (fnAux->padre != NULL ) {
|
||||||
|
|
||||||
if(fnAux->padre!=NULL){
|
|
||||||
FileNode_PrintNode(fnAux);
|
FileNode_PrintNode(fnAux);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fnAux->child){
|
if (fnAux->child) {
|
||||||
fnAux=fnAux->child;
|
fnAux = fnAux->child;
|
||||||
}else{
|
} else {
|
||||||
while(fnAux->sig==NULL){
|
while (fnAux->sig == NULL ) {
|
||||||
fnAux=fnAux->padre;
|
fnAux = fnAux->padre;
|
||||||
if(fnAux==fn || fnAux==NULL){
|
if (fnAux == fn || fnAux == NULL ) {
|
||||||
printf("End\n");
|
printf("End\n");
|
||||||
end=1;
|
end = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!end){
|
if (!end) {
|
||||||
fnAux=fnAux->sig;
|
fnAux = fnAux->sig;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FileNode_Build_Iterate(char *path, char *name, void *d);
|
||||||
|
|
||||||
|
FileNode *FileNode_Build(char *path) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int FileNode_Build_Iterate(char *path,char *name,void *d);
|
|
||||||
|
|
||||||
FileNode *FileNode_Build(char *path){
|
|
||||||
FileNode *file;
|
FileNode *file;
|
||||||
|
|
||||||
if(!File_ExistePath(path))
|
if (!File_ExistePath(path))
|
||||||
return(NULL);
|
return (NULL );
|
||||||
|
|
||||||
// Crear el nodo
|
// Crear el nodo
|
||||||
file=FileNode_New();
|
file = FileNode_New();
|
||||||
File_GetName(path,file->name);
|
File_GetName(path, file->name);
|
||||||
|
|
||||||
// Determinar si es un fichero o directorio
|
// Determinar si es un fichero o directorio
|
||||||
if(File_EsDirectorio(path)){
|
if (File_EsDirectorio(path)) {
|
||||||
// Obtener datos para los directorios
|
// Obtener datos para los directorios
|
||||||
file->flags|=FileFlag_Directorio;
|
file->flags |= FileFlag_Directorio;
|
||||||
FileNode_GetFecha(file,path);
|
FileNode_GetFecha(file, path);
|
||||||
File_IterateDir(path,FileNode_Build_Iterate,file);
|
File_IterateDir(path, FileNode_Build_Iterate, file);
|
||||||
}else{
|
} else {
|
||||||
// Obtener datos para los ficheros
|
// Obtener datos para los ficheros
|
||||||
file->flags|=FileFlag_Normal;
|
file->flags |= FileFlag_Normal;
|
||||||
FileNode_GetTamanho(file,path);
|
FileNode_GetTamanho(file, path);
|
||||||
FileNode_GetFecha(file,path);
|
FileNode_GetFecha(file, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(file);
|
return (file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FileNode_Build_Iterate(char *path, char *name, void *d) {
|
||||||
|
FileNode *file, *fn_padre = d;
|
||||||
|
;
|
||||||
|
|
||||||
int FileNode_Build_Iterate(char *path,char *name,void *d){
|
if (!strcmp(name, FileNode_Filename)) {
|
||||||
FileNode *file,*fn_padre=d;;
|
return (0);
|
||||||
|
|
||||||
if(!strcmp(name,FileNode_Filename)){
|
|
||||||
return(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file=FileNode_Build(path);
|
file = FileNode_Build(path);
|
||||||
FileNode_AddChild(fn_padre,file);
|
FileNode_AddChild(fn_padre, file);
|
||||||
|
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FileNode_Refresh_Iterate(char *path, char *name, void *d);
|
||||||
|
|
||||||
|
FileNode *FileNode_Refresh(FileNode *fn, char *path) {
|
||||||
|
if (!File_ExistePath(path)) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int FileNode_Refresh_Iterate(char *path,char *name,void *d);
|
|
||||||
|
|
||||||
FileNode *FileNode_Refresh(FileNode *fn,char *path){
|
|
||||||
if(!File_ExistePath(path)){
|
|
||||||
// El fichero/directorio ha sido borrado
|
// El fichero/directorio ha sido borrado
|
||||||
if(!fn){
|
if (!fn) {
|
||||||
fn=FileNode_New();
|
fn = FileNode_New();
|
||||||
File_GetName(path,fn->name);
|
File_GetName(path, fn->name);
|
||||||
}
|
}
|
||||||
FileNode_SetEstadoRec(fn,EstadoFichero_Borrado);
|
FileNode_SetEstadoRec(fn, EstadoFichero_Borrado);
|
||||||
return(fn);
|
return (fn);
|
||||||
}
|
}
|
||||||
if(!fn){
|
if (!fn) {
|
||||||
// El fichero ha sido creado
|
// El fichero ha sido creado
|
||||||
fn=FileNode_Build(path);
|
fn = FileNode_Build(path);
|
||||||
FileNode_SetEstadoRec(fn,EstadoFichero_Nuevo);
|
FileNode_SetEstadoRec(fn, EstadoFichero_Nuevo);
|
||||||
}else{
|
} else {
|
||||||
// Comprobar si ha sido modificado
|
// Comprobar si ha sido modificado
|
||||||
FileTime ft;
|
FileTime ft;
|
||||||
long long size;
|
long long size;
|
||||||
int crc;
|
int crc;
|
||||||
|
|
||||||
// Marcar normal
|
// Marcar normal
|
||||||
fn->estado=EstadoFichero_Nada;
|
fn->estado = EstadoFichero_Nada;
|
||||||
fn->flags&=~FileFlag_MarcaRevision;
|
fn->flags &= ~FileFlag_MarcaRevision;
|
||||||
|
|
||||||
// Determinar si es un fichero o directorio
|
// Determinar si es un fichero o directorio
|
||||||
if(File_EsDirectorio(path)){
|
if (File_EsDirectorio(path)) {
|
||||||
FileNode *fn_child;
|
FileNode *fn_child;
|
||||||
|
|
||||||
// Comparar datos de los directorios
|
// Comparar datos de los directorios
|
||||||
if(!(fn->flags&FileFlag_Directorio)){
|
if (!(fn->flags & FileFlag_Directorio)) {
|
||||||
fn->estado=EstadoFichero_Modificado;
|
fn->estado = EstadoFichero_Modificado;
|
||||||
fn->flags|=FileFlag_Directorio;
|
fn->flags |= FileFlag_Directorio;
|
||||||
fn->flags&=~FileFlag_Normal;
|
fn->flags &= ~FileFlag_Normal;
|
||||||
}
|
}
|
||||||
ft=FileTime_Get(path);
|
ft = FileTime_Get(path);
|
||||||
if(ft!=fn->ft){
|
if (ft != fn->ft) {
|
||||||
fn->estado=EstadoFichero_Modificado;
|
fn->estado = EstadoFichero_Modificado;
|
||||||
fn->ft=ft;
|
fn->ft = ft;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Marcar hijos para determinar cual es actualizado
|
// Marcar hijos para determinar cual es actualizado
|
||||||
fn_child=fn->child;while(fn_child){
|
fn_child = fn->child;
|
||||||
fn_child->flags|=FileFlag_MarcaRevision;
|
while (fn_child) {
|
||||||
fn_child=fn_child->sig;
|
fn_child->flags |= FileFlag_MarcaRevision;
|
||||||
|
fn_child = fn_child->sig;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escanear subdirectorios
|
// Escanear subdirectorios
|
||||||
File_IterateDir(path,FileNode_Refresh_Iterate,fn);
|
File_IterateDir(path, FileNode_Refresh_Iterate, fn);
|
||||||
|
|
||||||
// Buscar que sigan marcados (borrados)
|
// Buscar que sigan marcados (borrados)
|
||||||
fn_child=fn->child;while(fn_child){
|
fn_child = fn->child;
|
||||||
if(fn_child->flags&FileFlag_MarcaRevision){
|
while (fn_child) {
|
||||||
fn_child->flags&=~FileFlag_MarcaRevision;
|
if (fn_child->flags & FileFlag_MarcaRevision) {
|
||||||
FileNode_SetEstadoRec(fn_child,EstadoFichero_Borrado);
|
fn_child->flags &= ~FileFlag_MarcaRevision;
|
||||||
|
FileNode_SetEstadoRec(fn_child, EstadoFichero_Borrado);
|
||||||
}
|
}
|
||||||
fn_child=fn_child->sig;
|
fn_child = fn_child->sig;
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
// Comprar datos de los ficheros
|
// Comprar datos de los ficheros
|
||||||
if(!(fn->flags&FileFlag_Normal)){
|
if (!(fn->flags & FileFlag_Normal)) {
|
||||||
fn->estado=EstadoFichero_Modificado;
|
fn->estado = EstadoFichero_Modificado;
|
||||||
fn->flags|=FileFlag_Normal;
|
fn->flags |= FileFlag_Normal;
|
||||||
fn->flags&=~FileFlag_Directorio;
|
fn->flags &= ~FileFlag_Directorio;
|
||||||
}
|
}
|
||||||
size=File_TamanhoFichero(path);
|
size = File_TamanhoFichero(path);
|
||||||
if(size!=fn->size){
|
if (size != fn->size) {
|
||||||
fn->estado=EstadoFichero_Modificado;
|
fn->estado = EstadoFichero_Modificado;
|
||||||
fn->size=size;
|
fn->size = size;
|
||||||
}
|
}
|
||||||
ft=FileTime_Get(path);
|
ft = FileTime_Get(path);
|
||||||
if(ft!=fn->ft){
|
if (ft != fn->ft) {
|
||||||
fn->estado=EstadoFichero_Modificado;
|
fn->estado = EstadoFichero_Modificado;
|
||||||
fn->ft=ft;
|
fn->ft = ft;
|
||||||
}
|
}
|
||||||
if(fn->estado==EstadoFichero_Modificado){
|
if (fn->estado == EstadoFichero_Modificado) {
|
||||||
fn->flags&=~FileFlag_TieneCRC;
|
fn->flags &= ~FileFlag_TieneCRC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(fn);
|
return (fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileNode_Refresh_Iterate(char *path,char *name,void *d){
|
int FileNode_Refresh_Iterate(char *path, char *name, void *d) {
|
||||||
FileNode *fn=d;
|
FileNode *fn = d;
|
||||||
FileNode *fn_child;
|
FileNode *fn_child;
|
||||||
|
|
||||||
if(!strcmp(name,FileNode_Filename)){
|
if (!strcmp(name, FileNode_Filename)) {
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buscar el fichero entre los del arbol
|
// Buscar el fichero entre los del arbol
|
||||||
fn_child=fn->child;
|
fn_child = fn->child;
|
||||||
while(fn_child){
|
while (fn_child) {
|
||||||
if(!strcmp(fn_child->name,name)){
|
if (!strcmp(fn_child->name, name)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fn_child=fn_child->sig;
|
fn_child = fn_child->sig;
|
||||||
}
|
}
|
||||||
if(fn_child){
|
if (fn_child) {
|
||||||
// Existe, refrescar
|
// Existe, refrescar
|
||||||
FileNode_Refresh(fn_child,path);
|
FileNode_Refresh(fn_child, path);
|
||||||
}else{
|
} else {
|
||||||
// Nuevo, construir
|
// Nuevo, construir
|
||||||
fn_child=FileNode_Refresh(NULL,path);
|
fn_child = FileNode_Refresh(NULL, path);
|
||||||
FileNode_AddChild(fn,fn_child);
|
FileNode_AddChild(fn, fn_child);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
18
filenode.h
18
filenode.h
@@ -20,7 +20,7 @@ typedef enum {
|
|||||||
EstadoFichero_Borrado
|
EstadoFichero_Borrado
|
||||||
} EstadoFichero;
|
} EstadoFichero;
|
||||||
|
|
||||||
typedef struct FileNode_Tag{
|
typedef struct FileNode_Tag {
|
||||||
char name[MaxFilename];
|
char name[MaxFilename];
|
||||||
|
|
||||||
int flags;
|
int flags;
|
||||||
@@ -42,24 +42,22 @@ typedef struct FileNode_Tag{
|
|||||||
|
|
||||||
FileNode *FileNode_New();
|
FileNode *FileNode_New();
|
||||||
void FileNode_Delete(FileNode *fn);
|
void FileNode_Delete(FileNode *fn);
|
||||||
void FileNode_AddChild(FileNode *file,FileNode *file2);
|
void FileNode_AddChild(FileNode *file, FileNode *file2);
|
||||||
|
|
||||||
char *FileNode_GetFullPath(FileNode *fn,char *basePath,char *path);
|
char *FileNode_GetFullPath(FileNode *fn, char *basePath, char *path);
|
||||||
|
|
||||||
void FileNode_GetTamanho(FileNode *fn,char *file);
|
void FileNode_GetTamanho(FileNode *fn, char *file);
|
||||||
void FileNode_GetFecha(FileNode *fn,char *file);
|
void FileNode_GetFecha(FileNode *fn, char *file);
|
||||||
void FileNode_GetCRC(FileNode *fn,char *file);
|
void FileNode_GetCRC(FileNode *fn, char *file);
|
||||||
|
|
||||||
void FileNode_Save(FileNode *fn,char *fichero);
|
void FileNode_Save(FileNode *fn, char *fichero);
|
||||||
FileNode *FileNode_Load(char *fichero);
|
FileNode *FileNode_Load(char *fichero);
|
||||||
|
|
||||||
void FileNode_PrintNode(FileNode *fn);
|
void FileNode_PrintNode(FileNode *fn);
|
||||||
void FileNode_Print(FileNode *fn);
|
void FileNode_Print(FileNode *fn);
|
||||||
|
|
||||||
|
|
||||||
FileNode *FileNode_Build(char *path);
|
FileNode *FileNode_Build(char *path);
|
||||||
|
|
||||||
FileNode *FileNode_Refresh(FileNode *file,char *path);
|
FileNode *FileNode_Refresh(FileNode *file, char *path);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
822
filenodecmp.c
822
filenodecmp.c
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "filenode.h"
|
#include "filenode.h"
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
AccionFileCmp_Nada,
|
AccionFileCmp_Nada,
|
||||||
AccionFileCmp_IzquierdaADerecha,
|
AccionFileCmp_IzquierdaADerecha,
|
||||||
@@ -16,7 +15,6 @@ typedef enum {
|
|||||||
AccionFileCmp_CrearDirIzquierda
|
AccionFileCmp_CrearDirIzquierda
|
||||||
} AccionFileCmp;
|
} AccionFileCmp;
|
||||||
|
|
||||||
|
|
||||||
typedef struct Tag_AccionFileNode {
|
typedef struct Tag_AccionFileNode {
|
||||||
AccionFileCmp accion;
|
AccionFileCmp accion;
|
||||||
FileNode *izquierda;
|
FileNode *izquierda;
|
||||||
@@ -24,17 +22,18 @@ typedef struct Tag_AccionFileNode {
|
|||||||
struct Tag_AccionFileNode *sig;
|
struct Tag_AccionFileNode *sig;
|
||||||
} AccionFileNode;
|
} AccionFileNode;
|
||||||
|
|
||||||
|
|
||||||
AccionFileNode *AccionFileNode_Crear();
|
AccionFileNode *AccionFileNode_Crear();
|
||||||
void AccionFileNode_Destruir(AccionFileNode *afn);
|
void AccionFileNode_Destruir(AccionFileNode *afn);
|
||||||
AccionFileNode *AccionFileNode_CrearNormal(FileNode *fnIzq,FileNode *fnDer);
|
AccionFileNode *AccionFileNode_CrearNormal(FileNode *fnIzq, FileNode *fnDer);
|
||||||
|
|
||||||
AccionFileNode *AccionFileNode_BuildSync(FileNode *izquierda,FileNode *derecha);
|
AccionFileNode *AccionFileNode_BuildSync(FileNode *izquierda,
|
||||||
AccionFileNode *AccionFileNode_BuildCopy(FileNode *izquierda,FileNode *derecha);
|
FileNode *derecha);
|
||||||
|
AccionFileNode *AccionFileNode_BuildCopy(FileNode *izquierda,
|
||||||
|
FileNode *derecha);
|
||||||
|
|
||||||
void AccionFileNode_Print(AccionFileNode *afn);
|
void AccionFileNode_Print(AccionFileNode *afn);
|
||||||
|
|
||||||
void AccionFileNode_RunList(AccionFileNode *afn,
|
void AccionFileNode_RunList(AccionFileNode *afn, char *pathIzquierda,
|
||||||
char *pathIzquierda,char *pathDerecha);
|
char *pathDerecha);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
237
fileutil.c
237
fileutil.c
@@ -7,19 +7,19 @@
|
|||||||
#include <utime.h>
|
#include <utime.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define _WIN32_WINNT 0x0501
|
#define _WIN32_WINNT 0x0501
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "fileutil.h"
|
#include "fileutil.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
long long FileTime_to_POSIX(FILETIME ft){
|
long long FileTime_to_POSIX(FILETIME ft) {
|
||||||
LARGE_INTEGER date, adjust;
|
LARGE_INTEGER date, adjust;
|
||||||
|
|
||||||
// takes the last modified date
|
// takes the last modified date
|
||||||
@@ -36,7 +36,7 @@ long long FileTime_to_POSIX(FILETIME ft){
|
|||||||
return date.QuadPart / 10000000ll;
|
return date.QuadPart / 10000000ll;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILETIME POSIX_to_FileTime(FileTime ft){
|
FILETIME POSIX_to_FileTime(FileTime ft) {
|
||||||
LARGE_INTEGER date, adjust;
|
LARGE_INTEGER date, adjust;
|
||||||
FILETIME filetime;
|
FILETIME filetime;
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ FILETIME POSIX_to_FileTime(FileTime ft){
|
|||||||
return filetime;
|
return filetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileTime FileTime_Get(char *filename){
|
FileTime FileTime_Get(char *filename) {
|
||||||
HANDLE hFile;
|
HANDLE hFile;
|
||||||
FILETIME ftCreate, ftAccess, ftWrite;
|
FILETIME ftCreate, ftAccess, ftWrite;
|
||||||
hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
|
hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||||
@@ -65,11 +65,11 @@ FileTime FileTime_Get(char *filename){
|
|||||||
return(FileTime_to_POSIX(ftWrite));
|
return(FileTime_to_POSIX(ftWrite));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileTime_Set(char *filename,FileTime t){
|
void FileTime_Set(char *filename,FileTime t) {
|
||||||
HANDLE hFile;
|
HANDLE hFile;
|
||||||
FILETIME ftWrite;
|
FILETIME ftWrite;
|
||||||
hFile = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_WRITE,
|
hFile = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_WRITE,
|
||||||
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||||
ftWrite=POSIX_to_FileTime(t);
|
ftWrite=POSIX_to_FileTime(t);
|
||||||
SetFileTime(hFile, NULL, NULL, &ftWrite);
|
SetFileTime(hFile, NULL, NULL, &ftWrite);
|
||||||
CloseHandle(hFile);
|
CloseHandle(hFile);
|
||||||
@@ -77,169 +77,152 @@ void FileTime_Set(char *filename,FileTime t){
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
FileTime FileTime_Get(char *filename){
|
FileTime FileTime_Get(char *filename) {
|
||||||
struct stat fs;
|
struct stat fs;
|
||||||
lstat(filename,&fs);
|
lstat(filename, &fs);
|
||||||
return(fs.st_mtime);
|
return (fs.st_mtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileTime_Set(char *filename,FileTime t){
|
void FileTime_Set(char *filename, FileTime t) {
|
||||||
struct utimbuf utb;
|
struct utimbuf utb;
|
||||||
|
|
||||||
utb.actime=t;
|
utb.actime = t;
|
||||||
utb.modtime=t;
|
utb.modtime = t;
|
||||||
utime(filename,&utb);
|
utime(filename, &utb);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void FileTime_Print(FileTime t) {
|
||||||
void FileTime_Print(FileTime t){
|
|
||||||
struct tm *tms;
|
struct tm *tms;
|
||||||
|
|
||||||
tms=localtime((time_t *)&t);
|
tms = localtime((time_t *) &t);
|
||||||
printf("%04d-%02d-%02d %02d:%02d:%02d",
|
printf("%04d-%02d-%02d %02d:%02d:%02d", tms->tm_year + 1900,
|
||||||
tms->tm_year+1900,
|
tms->tm_mon + 1, tms->tm_mday, tms->tm_hour, tms->tm_min,
|
||||||
tms->tm_mon+1,
|
tms->tm_sec);
|
||||||
tms->tm_mday,
|
|
||||||
tms->tm_hour,
|
|
||||||
tms->tm_min,
|
|
||||||
tms->tm_sec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void File_GetName(char *path, char *name) {
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
i = strlen(path) - 1;
|
||||||
|
while (i >= 0) {
|
||||||
|
if (path[i] == '/' || path[i] == '\\') {
|
||||||
void File_GetName(char *path,char *name){
|
|
||||||
int i,j;
|
|
||||||
|
|
||||||
i=strlen(path)-1;
|
|
||||||
while(i>=0 ){
|
|
||||||
if(path[i]=='/' || path[i]=='\\'){
|
|
||||||
i++;
|
i++;
|
||||||
break;
|
break;
|
||||||
}else{
|
} else {
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(i<0)
|
if (i < 0)
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
j=0;
|
j = 0;
|
||||||
while(path[i]){
|
while (path[i]) {
|
||||||
name[j]=path[i];
|
name[j] = path[i];
|
||||||
i++;j++;
|
i++;
|
||||||
|
j++;
|
||||||
}
|
}
|
||||||
name[j]=0;
|
name[j] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
int File_ExistePath(char *path){
|
int File_ExistePath(char *path) {
|
||||||
unsigned rc;
|
unsigned rc;
|
||||||
rc=GetFileAttributes(path);
|
rc=GetFileAttributes(path);
|
||||||
|
|
||||||
if(rc==INVALID_FILE_ATTRIBUTES){
|
if(rc==INVALID_FILE_ATTRIBUTES) {
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
int File_EsDirectorio(char *dir){
|
int File_EsDirectorio(char *dir) {
|
||||||
unsigned rc;
|
unsigned rc;
|
||||||
rc=GetFileAttributes(dir);
|
rc=GetFileAttributes(dir);
|
||||||
|
|
||||||
if(rc==INVALID_FILE_ATTRIBUTES){
|
if(rc==INVALID_FILE_ATTRIBUTES) {
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
if(rc&FILE_ATTRIBUTE_DIRECTORY){
|
if(rc&FILE_ATTRIBUTE_DIRECTORY) {
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
int File_EsFichero(char *fichero){
|
int File_EsFichero(char *fichero) {
|
||||||
unsigned rc;
|
unsigned rc;
|
||||||
rc=GetFileAttributes(fichero);
|
rc=GetFileAttributes(fichero);
|
||||||
|
|
||||||
if(rc==INVALID_FILE_ATTRIBUTES){
|
if(rc==INVALID_FILE_ATTRIBUTES) {
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
if(rc&FILE_ATTRIBUTE_DIRECTORY){
|
if(rc&FILE_ATTRIBUTE_DIRECTORY) {
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
int File_ExistePath(char *path){
|
int File_ExistePath(char *path) {
|
||||||
struct stat info;
|
struct stat info;
|
||||||
|
|
||||||
if(lstat(path,&info)==-1){
|
if (lstat(path, &info) == -1) {
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
return(1);
|
return (1);
|
||||||
}
|
}
|
||||||
int File_EsDirectorio(char *dir){
|
int File_EsDirectorio(char *dir) {
|
||||||
struct stat info;
|
struct stat info;
|
||||||
|
|
||||||
if(lstat(dir,&info)==-1){
|
if (lstat(dir, &info) == -1) {
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
if(S_ISDIR(info.st_mode)){
|
if (S_ISDIR(info.st_mode)) {
|
||||||
return(1);
|
return (1);
|
||||||
}
|
}
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
int File_EsFichero(char *fichero){
|
int File_EsFichero(char *fichero) {
|
||||||
struct stat info;
|
struct stat info;
|
||||||
|
|
||||||
if(lstat(fichero,&info)==-1){
|
if (lstat(fichero, &info) == -1) {
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
if(S_ISDIR(info.st_mode)){
|
if (S_ISDIR(info.st_mode)) {
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
return(1);
|
return (1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
long long File_TamanhoFichero(char *fichero) {
|
||||||
|
|
||||||
long long File_TamanhoFichero(char *fichero){
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
long long tamanho;
|
long long tamanho;
|
||||||
|
|
||||||
f=fopen(fichero,"rb");
|
f = fopen(fichero, "rb");
|
||||||
if(!f)
|
if (!f)
|
||||||
return(-1);
|
return (-1);
|
||||||
|
|
||||||
fseek(f,0,SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
tamanho=ftell(f);
|
tamanho = ftell(f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return(tamanho);
|
return (tamanho);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
int File_CrearDir(char *path){
|
int File_CrearDir(char *path) {
|
||||||
return(_mkdir(path));
|
return(_mkdir(path));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
int File_CrearDir(char *path){
|
int File_CrearDir(char *path) {
|
||||||
return(mkdir(path,0777));
|
return (mkdir(path, 0777));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
void File_IterateDir(char *path,
|
void File_IterateDir(char *path,
|
||||||
int (*func)(char *path,char *name,void *data),void *data)
|
int (*func)(char *path,char *name,void *data),void *data)
|
||||||
{
|
{
|
||||||
int handle;
|
int handle;
|
||||||
struct _finddata_t fileinfo;
|
struct _finddata_t fileinfo;
|
||||||
@@ -250,20 +233,20 @@ void File_IterateDir(char *path,
|
|||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
snprintf(path_aux,MaxPath,
|
snprintf(path_aux,MaxPath,
|
||||||
"%s/*",path);
|
"%s/*",path);
|
||||||
handle=_findfirst(path_aux,&fileinfo);
|
handle=_findfirst(path_aux,&fileinfo);
|
||||||
if(handle==-1)
|
if(handle==-1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Recorrer el directorio
|
// Recorrer el directorio
|
||||||
do{
|
do {
|
||||||
if(strcmp(fileinfo.name,".") &&
|
if(strcmp(fileinfo.name,".") &&
|
||||||
strcmp(fileinfo.name,".."))
|
strcmp(fileinfo.name,".."))
|
||||||
{
|
{
|
||||||
// A partir de aqui hay un fichero
|
// A partir de aqui hay un fichero
|
||||||
// (o directorio)
|
// (o directorio)
|
||||||
snprintf(f_path,512,
|
snprintf(f_path,512,
|
||||||
"%s/%s",path,fileinfo.name);
|
"%s/%s",path,fileinfo.name);
|
||||||
fin=func(f_path,fileinfo.name,data);
|
fin=func(f_path,fileinfo.name,data);
|
||||||
}
|
}
|
||||||
findnext_rc=_findnext(handle,&fileinfo);
|
findnext_rc=_findnext(handle,&fileinfo);
|
||||||
@@ -274,80 +257,72 @@ void File_IterateDir(char *path,
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
void File_IterateDir(char *path,
|
void File_IterateDir(char *path,
|
||||||
int (*func)(char *path,char *name,void *data),void *data)
|
int (*func)(char *path, char *name, void *data), void *data) {
|
||||||
{
|
|
||||||
DIR *directorio;
|
DIR *directorio;
|
||||||
struct dirent *entidad_dir;
|
struct dirent *entidad_dir;
|
||||||
char f_path[MaxPath];
|
char f_path[MaxPath];
|
||||||
int fin=0;
|
int fin = 0;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
directorio=opendir(path);
|
directorio = opendir(path);
|
||||||
if(directorio==NULL)
|
if (directorio == NULL )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Recorrer el directorio
|
// Recorrer el directorio
|
||||||
do{
|
do {
|
||||||
entidad_dir=readdir(directorio);
|
entidad_dir = readdir(directorio);
|
||||||
if(entidad_dir!=NULL){
|
if (entidad_dir != NULL ) {
|
||||||
if(strcmp(entidad_dir->d_name,".") &&
|
if (strcmp(entidad_dir->d_name, ".")
|
||||||
strcmp(entidad_dir->d_name,".."))
|
&& strcmp(entidad_dir->d_name, "..")) {
|
||||||
{
|
|
||||||
// A partir de aqui hay un fichero
|
// A partir de aqui hay un fichero
|
||||||
// (o directorio)
|
// (o directorio)
|
||||||
snprintf(f_path,MaxPath,
|
snprintf(f_path, MaxPath, "%s/%s", path, entidad_dir->d_name);
|
||||||
"%s/%s",path,entidad_dir->d_name);
|
fin = func(f_path, entidad_dir->d_name, data);
|
||||||
fin=func(f_path,
|
|
||||||
entidad_dir->d_name,
|
|
||||||
data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}while(entidad_dir!=NULL && !fin);
|
} while (entidad_dir != NULL && !fin);
|
||||||
closedir(directorio);
|
closedir(directorio);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void File_Borrar(char *path) {
|
||||||
|
|
||||||
void File_Borrar(char *path){
|
|
||||||
unlink(path);
|
unlink(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void File_BorrarDirectorio(char *path){
|
void File_BorrarDirectorio(char *path) {
|
||||||
rmdir(path);
|
rmdir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define MaxBuffer 16384
|
#define MaxBuffer 16384
|
||||||
int File_Copiar( const char *pathOrig,const char *pathDest){
|
int File_Copiar(const char *pathOrig, const char *pathDest) {
|
||||||
FILE *fOrig,*fDest;
|
FILE *fOrig, *fDest;
|
||||||
char buffer[MaxBuffer];
|
char buffer[MaxBuffer];
|
||||||
int readLen=0;
|
int readLen = 0;
|
||||||
int writeLen=0;
|
int writeLen = 0;
|
||||||
int ok=0;
|
int ok = 0;
|
||||||
|
|
||||||
if((fOrig=fopen(pathOrig,"rb"))==NULL){
|
if ((fOrig = fopen(pathOrig, "rb")) == NULL ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if((fDest=fopen(pathDest,"wb"))==NULL){
|
if ((fDest = fopen(pathDest, "wb")) == NULL ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
do{
|
do {
|
||||||
readLen=fread(&buffer,1,MaxBuffer,fOrig);
|
readLen = fread(&buffer, 1, MaxBuffer, fOrig);
|
||||||
if(readLen>0){
|
if (readLen > 0) {
|
||||||
writeLen=fwrite(&buffer,1,readLen,fDest);
|
writeLen = fwrite(&buffer, 1, readLen, fDest);
|
||||||
if(writeLen!=readLen){
|
if (writeLen != readLen) {
|
||||||
// Error
|
// Error
|
||||||
fclose(fOrig);
|
fclose(fOrig);
|
||||||
fclose(fDest);
|
fclose(fDest);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}while(readLen==MaxBuffer);
|
} while (readLen == MaxBuffer);
|
||||||
|
|
||||||
if(feof(fOrig)){
|
if (feof(fOrig)) {
|
||||||
ok=1;
|
ok = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fOrig);
|
fclose(fOrig);
|
||||||
|
|||||||
10
fileutil.h
10
fileutil.h
@@ -1,24 +1,21 @@
|
|||||||
#ifndef _FILEUTIL_
|
#ifndef _FILEUTIL_
|
||||||
#define _FILEUTIL_
|
#define _FILEUTIL_
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// FileTime
|
// FileTime
|
||||||
|
|
||||||
typedef long long FileTime;
|
typedef long long FileTime;
|
||||||
|
|
||||||
FileTime FileTime_Get(char *filename);
|
FileTime FileTime_Get(char *filename);
|
||||||
void FileTime_Set(char *filename,FileTime t);
|
void FileTime_Set(char *filename, FileTime t);
|
||||||
void FileTime_Print(FileTime t);
|
void FileTime_Print(FileTime t);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////
|
///////////////////////////////////////////////
|
||||||
// File
|
// File
|
||||||
#define MaxPath 4096
|
#define MaxPath 4096
|
||||||
#define MaxFilename 512
|
#define MaxFilename 512
|
||||||
|
|
||||||
void File_GetName(char *path,char *name);
|
void File_GetName(char *path, char *name);
|
||||||
|
|
||||||
int File_ExistePath(char *path);
|
int File_ExistePath(char *path);
|
||||||
|
|
||||||
@@ -31,10 +28,9 @@ long long File_TamanhoFichero(char *ficheros);
|
|||||||
int File_CrearDir(char *path);
|
int File_CrearDir(char *path);
|
||||||
|
|
||||||
void File_IterateDir(char *path,
|
void File_IterateDir(char *path,
|
||||||
int (*func)(char *path,char *name,void *data),void *data);
|
int (*func)(char *path, char *name, void *data), void *data);
|
||||||
|
|
||||||
void File_Borrar(char *path);
|
void File_Borrar(char *path);
|
||||||
void File_BorrarDirectorio(char *path);
|
void File_BorrarDirectorio(char *path);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
288
main.c
288
main.c
@@ -8,246 +8,236 @@
|
|||||||
#include "filenode.h"
|
#include "filenode.h"
|
||||||
#include "filenodecmp.h"
|
#include "filenodecmp.h"
|
||||||
|
|
||||||
void help(char *exe){
|
void help(char *exe) {
|
||||||
char exeFilename[MaxPath];
|
char exeFilename[MaxPath];
|
||||||
File_GetName(exe,exeFilename);
|
File_GetName(exe, exeFilename);
|
||||||
printf("Modo de uso:\n");
|
printf("Modo de uso:\n");
|
||||||
printf(" %s info [file] {[file] {..}}\n",exeFilename);
|
printf(" %s info [file] {[file] {..}}\n", exeFilename);
|
||||||
printf(" %s scan [dir] [tree] \n",exeFilename);
|
printf(" %s scan [dir] [tree] \n", exeFilename);
|
||||||
printf(" %s rescan [dir] [tree] \n",exeFilename);
|
printf(" %s rescan [dir] [tree] \n", exeFilename);
|
||||||
printf(" %s read [file] [tree]\n",exeFilename);
|
printf(" %s read [file] [tree]\n", exeFilename);
|
||||||
printf(" %s dir [dir]\n",exeFilename);
|
printf(" %s dir [dir]\n", exeFilename);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" %s sync [dirIzquierda] [dirDerecha]\n",exeFilename);
|
printf(" %s sync [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||||
printf(" %s resync [dirIzquierda] [dirDerecha]\n",exeFilename);
|
printf(" %s resync [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||||
printf(" %s synctest [dirIzquierda] [dirDerecha]\n",exeFilename);
|
printf(" %s synctest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||||
printf(" %s resynctest [dirIzquierda] [dirDerecha]\n",exeFilename);
|
printf(" %s resynctest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" %s copy [dirIzquierda] [dirDerecha]\n",exeFilename);
|
printf(" %s copy [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||||
printf(" %s recopy [dirIzquierda] [dirDerecha]\n",exeFilename);
|
printf(" %s recopy [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||||
printf(" %s copytest [dirIzquierda] [dirDerecha]\n",exeFilename);
|
printf(" %s copytest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||||
printf(" %s recopytest [dirIzquierda] [dirDerecha]\n",exeFilename);
|
printf(" %s recopytest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileNode *checkDir(char *path, int recheck);
|
||||||
|
int sync(char *pathIzquierda, char *pathDerecha, int recheck, int dryrun);
|
||||||
|
|
||||||
FileNode *checkDir(char *path,int recheck);
|
int main(int argc, char *argv[]) {
|
||||||
int sync(char *pathIzquierda,char *pathDerecha,int recheck,int dryrun);
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char *argv[]){
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
unsigned long crc=0;
|
unsigned long crc = 0;
|
||||||
FileTime ft;
|
FileTime ft;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(argc<2){
|
if (argc < 2) {
|
||||||
help(argv[0]);
|
help(argv[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!strcmp(argv[1],"info") && argc>=3){
|
if (!strcmp(argv[1], "info") && argc >= 3) {
|
||||||
// Informacion de ficheros
|
// Informacion de ficheros
|
||||||
for(i=2;i<argc;i++){
|
for (i = 2; i < argc; i++) {
|
||||||
if(File_ExistePath(argv[i])){
|
if (File_ExistePath(argv[i])) {
|
||||||
f=fopen(argv[i],"rb");
|
f = fopen(argv[i], "rb");
|
||||||
if(f){
|
if (f) {
|
||||||
crc=CRC_File(f);
|
crc = CRC_File(f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
ft=FileTime_Get(argv[i]);
|
ft = FileTime_Get(argv[i]);
|
||||||
printf("%s:\t[%08X]\t",argv[i],crc);
|
printf("%s:\t[%08X]\t", argv[i], crc);
|
||||||
FileTime_Print(ft);printf("\n");
|
FileTime_Print(ft);
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else
|
} else if (!strcmp(argv[1], "scan") && argc == 4) {
|
||||||
if(!strcmp(argv[1],"scan") && argc==4){
|
|
||||||
// Scanear informacion de directorio y guardar arbol
|
// Scanear informacion de directorio y guardar arbol
|
||||||
FileNode *fn;
|
FileNode *fn;
|
||||||
printf("Building FileNode..\n");
|
printf("Building FileNode..\n");
|
||||||
fn=FileNode_Build(argv[2]);
|
fn = FileNode_Build(argv[2]);
|
||||||
FileNode_Save(fn,argv[3]);
|
FileNode_Save(fn, argv[3]);
|
||||||
}else
|
} else if (!strcmp(argv[1], "rescan") && argc == 4) {
|
||||||
if(!strcmp(argv[1],"rescan") && argc==4){
|
|
||||||
// Scanear informacion de directorio y guardar arbol
|
// Scanear informacion de directorio y guardar arbol
|
||||||
FileNode *fn;
|
FileNode *fn;
|
||||||
printf("Loading FileNode..\n");
|
printf("Loading FileNode..\n");
|
||||||
fn=FileNode_Load(argv[3]);
|
fn = FileNode_Load(argv[3]);
|
||||||
if(fn){
|
if (fn) {
|
||||||
printf("Rebuilding FileNode..\n");
|
printf("Rebuilding FileNode..\n");
|
||||||
fn=FileNode_Refresh(fn,argv[2]);
|
fn = FileNode_Refresh(fn, argv[2]);
|
||||||
FileNode_Save(fn,argv[3]);
|
FileNode_Save(fn, argv[3]);
|
||||||
}
|
}
|
||||||
}else
|
} else if (!strcmp(argv[1], "read") && argc == 3) {
|
||||||
if(!strcmp(argv[1],"read") && argc==3){
|
|
||||||
// Leer informacion de arbol
|
// Leer informacion de arbol
|
||||||
FileNode *fn;
|
FileNode *fn;
|
||||||
fn=FileNode_Load(argv[2]);
|
fn = FileNode_Load(argv[2]);
|
||||||
if(fn)FileNode_Print(fn);
|
if (fn)
|
||||||
}else
|
FileNode_Print(fn);
|
||||||
if(!strcmp(argv[1],"dir") && argc==3){
|
} else if (!strcmp(argv[1], "dir") && argc == 3) {
|
||||||
// Leer informacion de dir
|
// Leer informacion de dir
|
||||||
char *path=argv[2];
|
char *path = argv[2];
|
||||||
char dirNodesFile[MaxPath];
|
char dirNodesFile[MaxPath];
|
||||||
FileNode *fn;
|
FileNode *fn;
|
||||||
|
|
||||||
fn=checkDir(path,1);
|
fn = checkDir(path, 1);
|
||||||
if(fn){
|
if (fn) {
|
||||||
FileNode_Print(fn);
|
FileNode_Print(fn);
|
||||||
}
|
}
|
||||||
}else
|
} else if (!strcmp(argv[1], "sync") && argc == 4) {
|
||||||
if(!strcmp(argv[1],"sync") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
// Sincronizar dos directorios
|
||||||
char *pathIzquierda=argv[2];
|
char *pathIzquierda = argv[2];
|
||||||
char *pathDerecha=argv[3];
|
char *pathDerecha = argv[3];
|
||||||
sync(pathIzquierda,pathDerecha,1,0);
|
sync(pathIzquierda, pathDerecha, 1, 0);
|
||||||
}else
|
} else if (!strcmp(argv[1], "resync") && argc == 4) {
|
||||||
if(!strcmp(argv[1],"resync") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
// Sincronizar dos directorios
|
||||||
char *pathIzquierda=argv[2];
|
char *pathIzquierda = argv[2];
|
||||||
char *pathDerecha=argv[3];
|
char *pathDerecha = argv[3];
|
||||||
sync(pathIzquierda,pathDerecha,0,0);
|
sync(pathIzquierda, pathDerecha, 0, 0);
|
||||||
}else
|
} else if (!strcmp(argv[1], "synctest") && argc == 4) {
|
||||||
if(!strcmp(argv[1],"synctest") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
// Sincronizar dos directorios
|
||||||
char *pathIzquierda=argv[2];
|
char *pathIzquierda = argv[2];
|
||||||
char *pathDerecha=argv[3];
|
char *pathDerecha = argv[3];
|
||||||
sync(pathIzquierda,pathDerecha,1,1);
|
sync(pathIzquierda, pathDerecha, 1, 1);
|
||||||
}else
|
} else if (!strcmp(argv[1], "resynctest") && argc == 4) {
|
||||||
if(!strcmp(argv[1],"resynctest") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
// Sincronizar dos directorios
|
||||||
char *pathIzquierda=argv[2];
|
char *pathIzquierda = argv[2];
|
||||||
char *pathDerecha=argv[3];
|
char *pathDerecha = argv[3];
|
||||||
sync(pathIzquierda,pathDerecha,0,1);
|
sync(pathIzquierda, pathDerecha, 0, 1);
|
||||||
|
|
||||||
|
} else if (!strcmp(argv[1], "copy") && argc == 4) {
|
||||||
|
// Sincronizar dos directorios
|
||||||
|
char *pathIzquierda = argv[2];
|
||||||
|
char *pathDerecha = argv[3];
|
||||||
|
copy(pathIzquierda, pathDerecha, 1, 0);
|
||||||
|
} else if (!strcmp(argv[1], "recopy") && argc == 4) {
|
||||||
|
// Sincronizar dos directorios
|
||||||
|
char *pathIzquierda = argv[2];
|
||||||
|
char *pathDerecha = argv[3];
|
||||||
|
copy(pathIzquierda, pathDerecha, 0, 0);
|
||||||
|
} else if (!strcmp(argv[1], "copytest") && argc == 4) {
|
||||||
|
// Sincronizar dos directorios
|
||||||
|
char *pathIzquierda = argv[2];
|
||||||
|
char *pathDerecha = argv[3];
|
||||||
|
copy(pathIzquierda, pathDerecha, 1, 1);
|
||||||
|
} else if (!strcmp(argv[1], "recopytest") && argc == 4) {
|
||||||
|
// Sincronizar dos directorios
|
||||||
|
char *pathIzquierda = argv[2];
|
||||||
|
char *pathDerecha = argv[3];
|
||||||
|
copy(pathIzquierda, pathDerecha, 0, 1);
|
||||||
|
|
||||||
}else
|
} else {
|
||||||
if(!strcmp(argv[1],"copy") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
|
||||||
char *pathIzquierda=argv[2];
|
|
||||||
char *pathDerecha=argv[3];
|
|
||||||
copy(pathIzquierda,pathDerecha,1,0);
|
|
||||||
}else
|
|
||||||
if(!strcmp(argv[1],"recopy") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
|
||||||
char *pathIzquierda=argv[2];
|
|
||||||
char *pathDerecha=argv[3];
|
|
||||||
copy(pathIzquierda,pathDerecha,0,0);
|
|
||||||
}else
|
|
||||||
if(!strcmp(argv[1],"copytest") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
|
||||||
char *pathIzquierda=argv[2];
|
|
||||||
char *pathDerecha=argv[3];
|
|
||||||
copy(pathIzquierda,pathDerecha,1,1);
|
|
||||||
}else
|
|
||||||
if(!strcmp(argv[1],"recopytest") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
|
||||||
char *pathIzquierda=argv[2];
|
|
||||||
char *pathDerecha=argv[3];
|
|
||||||
copy(pathIzquierda,pathDerecha,0,1);
|
|
||||||
|
|
||||||
|
|
||||||
}else{
|
|
||||||
help(argv[0]);
|
help(argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileNode *checkDir(char *path, int recheck) {
|
||||||
|
|
||||||
FileNode *checkDir(char *path,int recheck){
|
|
||||||
char dirNodesFile[MaxPath];
|
char dirNodesFile[MaxPath];
|
||||||
FileNode *fn;
|
FileNode *fn;
|
||||||
// Comprobar directorio
|
// Comprobar directorio
|
||||||
snprintf(dirNodesFile,MaxPath,"%s/"FileNode_Filename,path);
|
snprintf(dirNodesFile, MaxPath, "%s/"FileNode_Filename, path);
|
||||||
if(recheck){
|
if (recheck) {
|
||||||
printf("Checking Directory.. %s\n",path);
|
printf("Checking Directory.. %s\n", path);
|
||||||
fn=FileNode_Load(dirNodesFile);
|
fn = FileNode_Load(dirNodesFile);
|
||||||
if(fn){
|
if (fn) {
|
||||||
fn=FileNode_Refresh(fn,path);
|
fn = FileNode_Refresh(fn, path);
|
||||||
}else{
|
} else {
|
||||||
fn=FileNode_Build(path);
|
fn = FileNode_Build(path);
|
||||||
}
|
}
|
||||||
FileNode_Save(fn,dirNodesFile);
|
FileNode_Save(fn, dirNodesFile);
|
||||||
}else{
|
} else {
|
||||||
printf("Loading Directory.. %s\n",path);
|
printf("Loading Directory.. %s\n", path);
|
||||||
fn=FileNode_Load(dirNodesFile);
|
fn = FileNode_Load(dirNodesFile);
|
||||||
if(!fn){
|
if (!fn) {
|
||||||
printf("Error, no nodesFile.fs\n");
|
printf("Error, no nodesFile.fs\n");
|
||||||
return NULL;
|
return NULL ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fn;
|
return fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sync(char *pathIzquierda,char *pathDerecha,int recheck,int dryrun){
|
int sync(char *pathIzquierda, char *pathDerecha, int recheck, int dryrun) {
|
||||||
char dirNodesFileIzq[MaxPath];
|
char dirNodesFileIzq[MaxPath];
|
||||||
char dirNodesFileDer[MaxPath];
|
char dirNodesFileDer[MaxPath];
|
||||||
FileNode *fnIzquierda,*fnDerecha;
|
FileNode *fnIzquierda, *fnDerecha;
|
||||||
|
|
||||||
// Comprobar y cargar directorios
|
// Comprobar y cargar directorios
|
||||||
if(!File_ExistePath(pathIzquierda) || !File_EsDirectorio(pathIzquierda)){
|
if (!File_ExistePath(pathIzquierda) || !File_EsDirectorio(pathIzquierda)) {
|
||||||
printf("Error, directory does not exist: %s\n",pathIzquierda);
|
printf("Error, directory does not exist: %s\n", pathIzquierda);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(!File_ExistePath(pathDerecha) || !File_EsDirectorio(pathDerecha)){
|
if (!File_ExistePath(pathDerecha) || !File_EsDirectorio(pathDerecha)) {
|
||||||
printf("Error, directory does not exist: %s\n",pathDerecha);
|
printf("Error, directory does not exist: %s\n", pathDerecha);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
fnIzquierda = checkDir(pathIzquierda, recheck);
|
||||||
|
if (!fnIzquierda) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
fnDerecha = checkDir(pathDerecha, recheck);
|
||||||
|
if (!fnDerecha) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
fnIzquierda=checkDir(pathIzquierda,recheck);
|
|
||||||
if(!fnIzquierda){return 0;}
|
|
||||||
fnDerecha=checkDir(pathDerecha,recheck);
|
|
||||||
if(!fnDerecha){return 0;}
|
|
||||||
|
|
||||||
|
|
||||||
// Construir acciones
|
// Construir acciones
|
||||||
printf("Building action list.. \n");
|
printf("Building action list.. \n");
|
||||||
AccionFileNode *afn=NULL;
|
AccionFileNode *afn = NULL;
|
||||||
afn=AccionFileNode_BuildSync(fnIzquierda,fnDerecha);
|
afn = AccionFileNode_BuildSync(fnIzquierda, fnDerecha);
|
||||||
|
|
||||||
if(dryrun){
|
if (dryrun) {
|
||||||
// Mostrar lista de acciones
|
// Mostrar lista de acciones
|
||||||
AccionFileNode_Print(afn);
|
AccionFileNode_Print(afn);
|
||||||
}else{
|
} else {
|
||||||
// Ejecutar lista de acciones
|
// Ejecutar lista de acciones
|
||||||
AccionFileNode_RunList(afn,pathIzquierda,pathDerecha);
|
AccionFileNode_RunList(afn, pathIzquierda, pathDerecha);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int copy(char *pathIzquierda,char *pathDerecha,int recheck,int dryrun){
|
int copy(char *pathIzquierda, char *pathDerecha, int recheck, int dryrun) {
|
||||||
char dirNodesFileIzq[MaxPath];
|
char dirNodesFileIzq[MaxPath];
|
||||||
char dirNodesFileDer[MaxPath];
|
char dirNodesFileDer[MaxPath];
|
||||||
FileNode *fnIzquierda,*fnDerecha;
|
FileNode *fnIzquierda, *fnDerecha;
|
||||||
|
|
||||||
// Comprobar y cargar directorios
|
// Comprobar y cargar directorios
|
||||||
if(!File_ExistePath(pathIzquierda) || !File_EsDirectorio(pathIzquierda)){
|
if (!File_ExistePath(pathIzquierda) || !File_EsDirectorio(pathIzquierda)) {
|
||||||
printf("Error, directory does not exist: %s\n",pathIzquierda);
|
printf("Error, directory does not exist: %s\n", pathIzquierda);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(!File_ExistePath(pathDerecha) || !File_EsDirectorio(pathDerecha)){
|
if (!File_ExistePath(pathDerecha) || !File_EsDirectorio(pathDerecha)) {
|
||||||
printf("Error, directory does not exist: %s\n",pathDerecha);
|
printf("Error, directory does not exist: %s\n", pathDerecha);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
fnIzquierda = checkDir(pathIzquierda, recheck);
|
||||||
|
if (!fnIzquierda) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
fnDerecha = checkDir(pathDerecha, recheck);
|
||||||
|
if (!fnDerecha) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
fnIzquierda=checkDir(pathIzquierda,recheck);
|
|
||||||
if(!fnIzquierda){return 0;}
|
|
||||||
fnDerecha=checkDir(pathDerecha,recheck);
|
|
||||||
if(!fnDerecha){return 0;}
|
|
||||||
|
|
||||||
|
|
||||||
// Construir acciones
|
// Construir acciones
|
||||||
printf("Building action list.. \n");
|
printf("Building action list.. \n");
|
||||||
AccionFileNode *afn=NULL;
|
AccionFileNode *afn = NULL;
|
||||||
afn=AccionFileNode_BuildCopy(fnIzquierda,fnDerecha);
|
afn = AccionFileNode_BuildCopy(fnIzquierda, fnDerecha);
|
||||||
|
|
||||||
if(dryrun){
|
if (dryrun) {
|
||||||
// Mostrar lista de acciones
|
// Mostrar lista de acciones
|
||||||
AccionFileNode_Print(afn);
|
AccionFileNode_Print(afn);
|
||||||
}else{
|
} else {
|
||||||
// Ejecutar lista de acciones
|
// Ejecutar lista de acciones
|
||||||
AccionFileNode_RunList(afn,pathIzquierda,pathDerecha);
|
AccionFileNode_RunList(afn, pathIzquierda, pathDerecha);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|||||||
10
util.c
10
util.c
@@ -4,12 +4,12 @@
|
|||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
char *String_Copy(char *str){
|
char *String_Copy(char *str) {
|
||||||
char *strnew;
|
char *strnew;
|
||||||
int len;
|
int len;
|
||||||
len=strlen(str);
|
len = strlen(str);
|
||||||
strnew=malloc(len+1);
|
strnew = malloc(len + 1);
|
||||||
strcpy(strnew,str);
|
strcpy(strnew, str);
|
||||||
return(strnew);
|
return (strnew);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user