- Ara al carregar un arxiu la variable on guardar el tamany s'envia com un punter, així es pot ignorar.
This commit is contained in:
@@ -193,7 +193,7 @@ namespace file
|
||||
}
|
||||
|
||||
// Obté un "FILE*" al arxiu que se li demana, independentment de la font (arxius individual en carpeta, o arxiu de recursos)
|
||||
FILE *getFilePointer(const std::string resourcename, int &filesize, const bool binary)
|
||||
FILE *getFilePointer(const std::string resourcename, int *filesize, const bool binary)
|
||||
{
|
||||
// Si tenim configurat agafar els recursos de arxiu, pero encara no tenim la taula de continguts carregada...
|
||||
if (file_source == SOURCE_FILE and toc.size() == 0)
|
||||
@@ -231,7 +231,7 @@ namespace file
|
||||
}
|
||||
|
||||
// Agafem el tamany del recurs de la taula de continguts
|
||||
filesize = toc[count].size;
|
||||
if (filesize) *filesize = toc[count].size;
|
||||
|
||||
// obrim l'arxiu de recursos
|
||||
f = fopen(resource_filename.c_str(), binary ? "rb" : "r");
|
||||
@@ -252,7 +252,7 @@ namespace file
|
||||
// Si estem pillant els recursos de carpeta, simplement obrim el arxiu en questió i tornem el FILE* associat.
|
||||
f = fopen((resource_folder + resourcename).c_str(), binary ? "rb" : "r");
|
||||
fseek(f, 0, SEEK_END);
|
||||
filesize = ftell(f);
|
||||
if (filesize) *filesize = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
@@ -261,20 +261,23 @@ namespace file
|
||||
}
|
||||
|
||||
// Obté un buffer de memòria en format "char*" del arxiu que se li demana, independentment de la font (arxius individual en carpeta, o arxiu de recursos)
|
||||
char *getFileBuffer(const std::string resourcename, int &filesize)
|
||||
char *getFileBuffer(const std::string resourcename, int *filesize)
|
||||
{
|
||||
int size;
|
||||
// Usem la funció anterior per a obtinde un FILE*, independentment de on pillem els recursos
|
||||
FILE *f = getFilePointer(resourcename, filesize, true);
|
||||
FILE *f = getFilePointer(resourcename, &size, true);
|
||||
|
||||
// Reservem memòria per al buffer
|
||||
char *buffer = (char *)malloc(filesize);
|
||||
char *buffer = (char *)malloc(size);
|
||||
|
||||
// llegim el contingut del arxiu i el fiquem en el buffer
|
||||
fread(buffer, filesize, 1, f);
|
||||
fread(buffer, size, 1, f);
|
||||
|
||||
// Tanquem l'arxiu
|
||||
fclose(f);
|
||||
|
||||
if (filesize) *filesize = size;
|
||||
|
||||
// Tornem el buffer. OJO! recordar alliberar-lo amb free(buffer) quan acabem amb ell.
|
||||
return buffer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user