35 #if defined(__APPLE__) || (__FreeBSD__) 36 #define fseeko64 fseeko 65 Log::error(
"DiskFile::open(): file already open.\n");
69 #if defined(VL_PLATFORM_WINDOWS) 75 GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
NULL );
break;
78 GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
NULL );
break;
82 if (
mHandle == INVALID_HANDLE_VALUE)
83 #elif defined(__GNUG__) 85 std::vector<unsigned char> utf8;
114 #if defined(VL_PLATFORM_WINDOWS) 116 #elif defined(__GNUG__) 125 #if defined(VL_PLATFORM_WINDOWS) 127 HANDLE hdl = CreateFile(
128 (
const wchar_t*)
path().ptr(),
129 FILE_READ_ATTRIBUTES,
133 FILE_ATTRIBUTE_NORMAL,
137 if (
mHandle == INVALID_HANDLE_VALUE)
139 Log::error(
Say(
"DiskFile::size(): file '%s' does not seem to exist.\n") <<
path() );
143 #if defined(__MINGW32_VERSION) 144 DWORD
size = GetFileSize(hdl,
NULL);
146 if (size != INVALID_FILE_SIZE )
151 LARGE_INTEGER file_size;
152 BOOL ok = GetFileSizeEx( hdl, &file_size );
154 return ok ? file_size.QuadPart : -1;
156 #elif defined(__GNUG__) 159 memset(&mybuf, 0,
sizeof(
struct stat));
161 std::vector<unsigned char> utf8;
165 if (stat((
char*)&utf8[0], &mybuf) == -1)
168 return (
long long)mybuf.st_size;
176 #if defined(VL_PLATFORM_WINDOWS) 179 HANDLE hdl = CreateFile(
180 (
const wchar_t*)
path().ptr(),
181 FILE_READ_ATTRIBUTES,
185 FILE_ATTRIBUTE_NORMAL,
189 if (hdl != INVALID_HANDLE_VALUE)
196 #elif defined(__GNUG__) 197 std::vector<unsigned char> utf8;
201 FILE* fin = fopen( (
char*)&utf8[0],
"rb");
216 Log::error(
"DiskFile::read_Implementation() called on closed file!\n");
221 #if defined(VL_PLATFORM_WINDOWS) 226 long long file_size =
size();
227 byte_count = byte_count < file_size ? byte_count : (
long long)file_size;
230 char* ptr = (
char*)buffer;
231 DWORD NumberOfBytesRead = 0;
233 long long bytes = byte_count < 20*1024*1024 ? byte_count : 20*1024*1024;
234 while( ReadFile(
mHandle, ptr, (DWORD)bytes, &NumberOfBytesRead,
NULL ) && NumberOfBytesRead )
236 byte_count -= NumberOfBytesRead;
237 bytes = byte_count < 20*1024*1024 ? byte_count : 20*1024*1024;
238 ptr += NumberOfBytesRead;
239 count += NumberOfBytesRead;
241 #elif defined(__GNUG__) 242 char* ptr = (
char*)buffer;
243 long long bytes_read = 0;
244 while( (bytes_read = fread(ptr, 1, byte_count,
mHandle)) )
246 byte_count -= bytes_read;
251 perror(
"Error reading file: ");
260 Log::error(
"DiskFile::write_Implementation() called on closed file!\n");
265 #if defined(VL_PLATFORM_WINDOWS) 266 DWORD NumberOfBytesWritten = 0;
267 WriteFile(
mHandle, buffer, (DWORD)byte_count, &NumberOfBytesWritten,
NULL );
268 count = NumberOfBytesWritten;
269 #elif defined(__GNUG__) 270 count = fwrite( buffer, 1, byte_count,
mHandle );
272 perror(
"Error reading file: ");
281 Log::error(
"DiskFile::position_Implementation() called on closed file!\n");
285 #if defined(VL_PLATFORM_WINDOWS) 287 position.QuadPart = 0;
293 return position.QuadPart;
294 #elif defined(__GNUG__) 303 Log::error(
"DiskFile::seekSet_Implementation() called on closed file!\n");
307 #if defined(VL_PLATFORM_WINDOWS) 309 position.QuadPart = offset;
318 #elif defined(__GNUG__) 319 fseeko64(
mHandle, offset, SEEK_SET);
327 file->operator=(*this);
virtual long long size() const
Returns the file size in bytes or -1 on error.
A simple String formatting class.
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
virtual long long read_Implementation(void *buffer, long long byte_count)
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
const String & path() const
Returns the path of the file.
bool open(const String &path, EOpenMode mode)
The specified path is relative to the parent directory. See setPhysicalPath().
void toUTF8(std::vector< unsigned char > &utf8, bool include_utf8_signature=true) const
Encodes the String into a UTF8 encoded string.
Visualization Library main namespace.
virtual void close()
Closes the file.
DiskFile(const DiskFile &other)
virtual bool seekSet_Implementation(long long offset)
virtual long long position_Implementation() const
virtual ref< VirtualFile > clone() const
Creates a clone of this class instance.
void setPath(const String &name)
Changes the path bound to a VirtualFile. Use carefully this function, you shouldn't rename a VirtualF...
The ref<> class is used to reference-count an Object.
virtual bool exists() const
Returns true if the file exists.
long long position() const
Returns the current position in the file.
virtual bool isOpen() const
Returns true if the file has been opened.
virtual long long write_Implementation(const void *buffer, long long byte_count)