Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // -------------------------------------------------------------------------------------
- bool File::Open(String filename, File::Mode filemode)
- {
- DWORD fileAccessPolicy, fileCreationPolicy;
- HRESULT result;
- // Set the properties
- fileAccessPolicy = fileCreationPolicy = 0;
- if((Byte)filemode & (Byte)File::Mode::Read) { fileAccessPolicy += GENERIC_READ; fileCreationPolicy = OPEN_EXISTING; }
- //if(filemode & File::Mode::fWrite) { fileAccessPolicy += GENERIC_WRITE; fileCreationPolicy = CREATE_ALWAYS; }
- if((Byte)filemode & (Byte)File::Mode::Write || (Byte)filemode & (Byte)File::Mode::Overwrite) { fileAccessPolicy += GENERIC_WRITE; fileCreationPolicy = (Byte)filemode & (Byte)File::Mode::Overwrite ? CREATE_ALWAYS : OPEN_ALWAYS; }
- // Check if local path
- Int pos = filename.find(":");
- if(pos < 0) { filename = Path + "/" + filename; }
- // Open the file
- mFile = CreateFileW(widen(filename).c_str(), fileAccessPolicy, 0, nullptr, fileCreationPolicy, FILE_ATTRIBUTE_NORMAL, nullptr);
- if(FAILED(mFile)) { return false; }
- // Get the file info
- result = GetFileInformationByHandle(mFile, &mFileInfo);
- if(FAILED(result)) { return false; }
- // Set public file information
- FileSize = mFileInfo.nFileSizeLow;
- // Allocate some memory for the read operations
- Data = malloc(1024);
- // --
- Opened = true;
- //End = Position = 0;
- //Seek(File::Offset::Begin, 0);
- // Create a file object and return it
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement