void File::open(const std::string& filename, OpenMode mode, bool no_override) { // check that we don't have anything opened! /// \todo maybe we could just close the old file here... but /// then, this could also lead to errors... assert(mHandle == 0); // open depending on mode if( mode == OPEN_WRITE ) { if(no_override && FileSystem::getSingleton().exists(filename)) { BOOST_THROW_EXCEPTION(FileAlreadyExistsException(filename)); } mHandle = PHYSFS_openWrite(filename.c_str()); } else { mHandle = PHYSFS_openRead(filename.c_str()); } if (!mHandle) { BOOST_THROW_EXCEPTION(FileLoadException(filename)); } mFileName = filename; }
utils::File::File(const zchar* const filename, FileAccess access, FileShare share, FileMode mode, FileType type) { hFile = CreateFileW(filename, static_cast<DWORD>(access), static_cast<DWORD>(share), nullptr, static_cast<DWORD>(mode), static_cast<DWORD>(type), nullptr); if (hFile == INVALID_HANDLE_VALUE) { OutputDebugStringW(L"Something is wrong:\n"); auto error = GetLastError(); switch (error) { case ERROR_FILE_EXISTS: OutputDebugStringW(L"File already exists.\n"); throw FileAlreadyExistsException(); case ERROR_FILE_NOT_FOUND: OutputDebugStringW(L"File not found.\n"); throw FileNotFoundException(); case ERROR_SHARING_VIOLATION: OutputDebugStringW(L"File cannot be shared.\n"); throw FileSharingViolationException(); default: OutputDebugStringW(L"Reason is not defined.\n"); throw FileException(); } } }