store a file into an archive
hi all
i´m currently programming a file packaging tool for my engine and i have one problem:
when i store a file into my package and extract it again the file is damaged. when i get the filesize in my app its the same like the windows explorer tells me and after extraction too.
i tried it with a text file and saw that my file reading and writing code changes some bytes(like the space into a square symbol) so what i want to know is how to read a file in without damaging it?
i hope you understand what i mean
thx for help.
--=[[TheMatrixXXX]]=--
yes sure i read/write in binary mode
--=[[TheMatrixXXX]]=--
[edited by - TheMatrixXXX on October 2, 2002 9:23:22 AM]
--=[[TheMatrixXXX]]=--
[edited by - TheMatrixXXX on October 2, 2002 9:23:22 AM]
ok here´s an example:
maybe you can tell me how you would copy a file with a method like that.
thx for help
--=[[TheMatrixXXX]]=--
unsigned char *FileData;FILE *in .....int FileSize = GetFileSize(in);FileData = (unsigned char*)malloc(FileSize);fread(FileData, 1, FileSize, in);fwrite(FileData, 1, FileSize, package);delete FileData;FileData = NULL;fclose(in);
maybe you can tell me how you would copy a file with a method like that.
thx for help
--=[[TheMatrixXXX]]=--
I see nothing wrong with that except that you delete something that you have malloc:ed. Use free for malloc, realloc and calloc, use delete for new, use delete [] for new [].
thx
do you think the unsigned char could be a problem?
do you have code to copy a file? maybe it would help to see something different.
thx for you replies
--=[[TheMatrixXXX]]=--
do you think the unsigned char could be a problem?
do you have code to copy a file? maybe it would help to see something different.
thx for you replies
--=[[TheMatrixXXX]]=--
int CopyFile(const char* szIn, const char* szOut){ FILE* in = fopen(szIn, "rb"); if (in == NULL) { return 0; } FILE* out = fopen(szOut, "wb"); if (out == NULL) { fclose(in); return 0; } const size_t BUFFER_SIZE = 1024; char buffer[BUFFER_SIZE]; size_t bytesRead; while (!feof(in)) { bytesRead = fread(buffer, 1, BUFFER_SIZE, in); if (ferror(in)) { fclose(in); fclose(out); return 0; } if (fwrite(buffer, 1, BUFFER_SIZE, bytesRead) < bytesRead) { fclose(in); fclose(out); return 0; } } fclose(in); fclose(out); return 1;}
ok thx i will try it.
--=[[TheMatrixXXX]]=--
[edited by - TheMatrixXXX on October 3, 2002 4:50:14 AM]
--=[[TheMatrixXXX]]=--
[edited by - TheMatrixXXX on October 3, 2002 4:50:14 AM]
BTW, it's not tested in any way, I wrote it all from top of my head.
[edited by - dalleboy on October 3, 2002 6:37:00 AM]
[edited by - dalleboy on October 3, 2002 6:37:00 AM]
ok i know now that the problem is not when is copy the file into the archive. i think i do something wrong when i extract the file again, but i don´t know what because the filesize is correct and the file is almost correct
in text files the text formation is damaged. the file looks very different when i open it again in notepad and compare it with the original file.
--=[[TheMatrixXXX]]=--
in text files the text formation is damaged. the file looks very different when i open it again in notepad and compare it with the original file.
--=[[TheMatrixXXX]]=--
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement