Hi, Im trying to figure out(again) the best(fastest) way to handle file management..Im using Win32 api, so I always try to use the api routines(instead of the c++ ones), dont know if this is better, but I just feel it is better in this way..
( On "windows internals" book, the author says the c++ open routines in fact call window createfile routine, so using it direct makes more sense to me...but Im stil noob and maybe this is crap )
But the win32 api just have open, read and write operations( and set file pointer), while fstream have lots of specific routines...
Theres a best approach?
Should I do I/O direct to the file or should I load the entire file on an array, and manipulate the array?
The approach changes for ascii files?
I always get stucked on files..its too much little details you have to handle to manage a specific file type( skip comments, check what kind of info have in position 'x', get the info( formating )..The problem is that the file type specification are not constants, you cant just load it on your struct, because the bastard can have comments in any place, or have lots of different organization..(what a pin in the arse..)
My begining code to manage the file :
OPENFILENAME openFile = {0};
openFile.lStructSize = sizeof(OPENFILENAME);
openFile.hwndOwner = hWnd;
TCHAR szFilters[] = { TEXT("Any OBJ file\0*.OBJ;*.obj;*.Obj\0\0") };
openFile.lpstrFilter = szFilters;
TCHAR szFileName[256] = { TEXT("\0") };
openFile.lpstrFile = szFileName;
openFile.nMaxFile = 256;
TCHAR szFileTitle[256] = { TEXT("\0") };
openFile.lpstrFileTitle = szFileTitle;
openFile.nMaxFileTitle = 256;
TCHAR *szDir = _getcwd( NULL, 0 );
openFile.lpstrInitialDir = szDir;
DWORD dwOpenFlags = OFN_DONTADDTORECENT|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_NONETWORKBUTTON;
openFile.Flags = dwOpenFlags;
TCHAR szExt[] = { TEXT("obj") };
openFile.lpstrDefExt = szExt;
if( GetOpenFileName( &openFile ) ){
HANDLE hFile = CreateFile( openFile.lpstrFile, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
LARGE_INTEGER fsize = {0};
if( hFile != INVALID_HANDLE_VALUE ){
DWORD dwBytesRead;
GetFileSizeEx( hFile, &fsize );
myOBJ.pBufferData = new BYTE [fsize.QuadPart];
if( ReadFile( hFile, myOBJ.pBufferData, fsize.QuadPart, &dwBytesRead, NULL ) ){
//hardcore stuff goes here
}
}
CloseHandle( hFile );
}
delete [] szDir;