CloseHandle is failing me at the moment. It's a really trivial thing (apparently the filemaps aren't in the same scope as my function call. Any help would be great, I know I know how to fix this. It's something stupid)Code:#include <windows.h> int main(int argc, char* argv[]){ HANDLE hInFile = ::CreateFile(argv[1],GENERIC_READ,FILE_SHARE_READ, NULL,OPEN_EXISTING,FILE_ATTRIBUTE_READONLY,NULL); DWORD dwFileSize = ::GetFileSize(hInFile,NULL); HANDLE hMappedInFile = ::CreateFileMapping(hInFile, NULL, PAGE_READONLY, 0,0,NULL); LPBYTE lpMapInAddress = (LPBYTE) :: MapViewOfFile(hMappedInFile, FILE_MAP_READ,0,0,0); HANDLE hOutFile = ::CreateFile(argv[2],GENERIC_WRITE | GENERIC_READ, 0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); HANDLE hMappedOutFile = ::CreateFileMapping(hOutFile, NULL,PAGE_READWRITE, 0,dwFileSize,NULL); LPBYTE lpMapOutAddress = (LPBYTE) ::MapViewOfFile(hMappedOutFile, FILE_MAP_WRITE,0,0,0); char *p_in=(char*)lpMapInAddress; char* p_out=(char*)lpMapOutAddress; for(unsigned int x=0;x<dwFileSize;x++, p_in++){ char c= *p_in; if (c==0) c=0xff; *p_out++ = c; } /*::CloseHandle(hMappedInfile); ::CloseHandle(hMappedOutFile); ::CloseHandle(hInFile); ::CloseHandle(hOutFile); */ }
Other than that, it does a pretty nice memory mapped file copy for large files. This will totally own your system memory if you try something huge.
The code is incredibly self explanatory. If you don't get it, then it's beyond you anyway.
I'm thinking if someone wants to be nice, then a batch script for packaging all the M2TW/RTW mod files into a nice new directory would be excellent, because taking advantage of memory mapped IO is not a bad thing by any means.
Also, I forgot to tell you how to use the damned thing.
Command line it.
cp.exe -copyme.ihaveanextension -imacopy.ialsohaveanextension
It's 03:15am. I don't know why I just wrote this useless thing. It didn't take long by any means but still...wtf?
I think I'll write a CRC32 deal, then we can...
Have a public index of all the CRC32s of the vanilla files.
Have a nice system that actually tells us wtf to backup etc.
Produce the CRC32 of each modfile. Match it to it's vanilla counterpart. If it fails, copy, if not, don't worry! This could be useful at some point in someone's life.
I don't know. Have free code anyway. Compiles under GCC for me.
Also, the attachment deal is being a jerk. Find it at my webserver.
Make sure that you accept that it's not my fault if something screws up. If you think it's a virus, don't download it. I don't really care, to be honest with you.
Feedback would be excellent. Also, that batch script to package a mod...would own.





Reply With Quote




