60 _lib = LoadLibrary(filename.c_str());
69 bool IsLoaded() {
return _lib != 0; }
70 operator HMODULE() {
return _lib; }
90 _lib = GetModuleHandle(filename.c_str());
99 inline HRESULT UseHR(HRESULT hr, LPCSTR file,
long line)
106 static const int bufferSize = 2000;
108 buffer.resize(bufferSize);
109 DWORD bytesWritten = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, hr, 0, &buffer[0], bufferSize, 0);
110 if(bytesWritten == 0)
112 DWORD error = GetLastError();
113 buffer =
"FormatMessage failed: code " + std::to_string(error);
118 buffer = file + std::string(
"(") + std::to_string(line) +
"): " + buffer;
120 OutputDebugStringA(buffer.c_str());
130 #define USEHR(hr) UseHR((hr), __FILE__, __LINE__)
131 #define CHECKHR(hr) SUCCEEDED(UseHR((hr), __FILE__, __LINE__))
134 #define CHECKHR(hr) SUCCEEDED((hr))
163 File(
const tstring& filename,
const tstring& openMode);
170 bool Open(
const tstring& filename,
const tstring& openMode);
185 operator bool()
const {
return IsOpen(); }
212 size_t Write(
const void* buffer,
size_t byteSize);
217 bool Write(
const std::string& buffer);
223 size_t Read(
void* buffer,
size_t byteSize);
229 bool ReadLine(std::string* line,
const std::string& delim =
"\n");
234 bool ReadAll(std::string* all);
254 bool IsDirectory()
const {
return (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; }
259 bool IsReadonly()
const {
return (dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0; }
264 bool IsHidden()
const {
return (dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0; }
269 bool IsSystemFile()
const {
return (dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) != 0; }
274 bool IsTemporary()
const {
return (dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) != 0; }
279 int64_t
GetFilesize()
const {
return int64_t(nFileSizeHigh) * 0x100000000 + int64_t(nFileSizeLow); }
371 assert(!_search->
Done());
378 assert(!_search->
Done());
382 bool operator==(
const iterator& rhs)
const
385 if(_search && rhs._end)
386 return _search->
Done();
389 bool operator!=(
const iterator& rhs)
const {
return !(*
this == rhs); }
427 static bool Exists(
const tstring& path);
432 static bool IsFile(
const tstring& path);
447 static bool HasExt(
const tstring& path);
452 static tstring
Join(
const tstring& p1,
const tstring& p2);
457 static tstring
Join(
const tstring& p1,
const tstring& p2,
const tstring& p3);
462 static tstring
Join(
const tstring& p1,
const tstring& p2,
const tstring& p3,
const tstring& p4);
467 static tstring
GetDrive(
const tstring& path);
472 static tstring
GetParent(
const tstring& path);
487 static tstring
GetExt(
const tstring& path);
493 static std::pair<tstring,tstring>
SplitDrive(
const tstring& path);
498 static std::pair<tstring,tstring>
SplitParent(
const tstring& path);
502 static std::pair<tstring,tstring>
SplitExt(
const tstring& path);
507 static tstring
ChangeFilename(
const tstring& path,
const tstring& name);
512 static tstring
ChangeExt(
const tstring& path,
const tstring& ext);
525 static tstring::size_type _GetDriveEnd(
const tstring& path, Drive_t* type);
527 static tstring _GetSeparators()
531 static bool _IsSeparator(TCHAR c)
533 return c == _T(
'/') || c == _T(
'\\');
bool IsSystemFile() const
Is the item reserved for system use?
Definition: util.h:269
static bool Exists(const tstring &path)
Check if the path points to an existing item.
Definition: util.inl:243
bool IsHidden() const
Is the item hidden in explorer?
Definition: util.h:264
bool Open(const tstring &filename, const tstring &openMode)
Opens a file with the specified mode (read/write, binary, ...)
Definition: util.inl:100
void Seek(int64_t offset, SEEK_FROM mode=FROM_START)
Move to a position inside the file.
Definition: util.inl:119
Windows 2008 Release 2 (same as Windows 7)
Definition: util.h:28
const FileSearchItem & Data() const
Data of the current file.
Definition: util.inl:235
bool IsReadonly() const
Is the item read only?
Definition: util.h:259
static tstring GetParent(const tstring &path)
Removes trailing file or directory from the path.
Definition: util.inl:334
bool Done() const
True if the iteration is at the end, meaning further calls to next won't work.
Definition: util.inl:220
iterator for STL algorithm integration
Definition: util.h:350
Windows Server 2003.
Definition: util.h:25
Windows 8.
Definition: util.h:31
bool Eof()
End of file.
Definition: util.inl:147
Windows XP.
Definition: util.h:24
Data about a file system item found by FileSearch.
Definition: util.h:249
static tstring GetDrive(const tstring &path)
Root of the path, either a drive letter (C:) or network root (\server)
Definition: util.inl:329
not sure if neoWidgets will even work for such systems
Definition: util.h:22
Retrieves address of already loaded DLL.
Definition: util.h:85
SEEK_FROM
Definition: util.h:142
bool IsDirectory() const
Is the item a directory?
Definition: util.h:254
static tstring GetFilename(const tstring &path)
Filename with extension.
Definition: util.inl:339
iterator()
Default constructor.
Definition: util.h:360
static tstring ChangeExt(const tstring &path, const tstring &ext)
Utility to change the extension while leaving the rest intact.
Definition: util.inl:475
FILE * GetInternalPtr() const
Direct access to internal file pointer.
Definition: util.h:239
Windows 2012 (same as Windows 8)
Definition: util.h:30
size_t Write(const void *buffer, size_t byteSize)
Write a block of memory to file.
Definition: util.inl:152
End of file.
Definition: util.h:146
tstring GetFilename() const
Return filename as string instance.
Definition: util.h:284
static tstring GetExt(const tstring &path)
Filename extension.
Definition: util.inl:349
Windows Vista.
Definition: util.h:26
Current file position.
Definition: util.h:145
Manipulation of Windows-style path strings.
Definition: util.h:420
File()
Empty constructor.
Definition: util.inl:82
static bool HasExt(const tstring &path)
Check for filename extension.
Definition: util.inl:269
Encapsulates loading of DLLs.
Definition: util.h:55
Start of file.
Definition: util.h:144
be forward compatible, the next windows version will surely come
Definition: util.h:34
static tstring Join(const tstring &p1, const tstring &p2)
Semi-intelligently combines parts into a correct path.
Definition: util.inl:283
iterator end()
STL algorithms integration.
Definition: util.h:408
static tstring ChangeFilename(const tstring &path, const tstring &name)
Utility to change the filename while leaving extension and parent intact.
Definition: util.inl:470
bool ReadAll(std::string *all)
Get the entire file as string.
Definition: util.inl:192
Windows 7.
Definition: util.h:29
Wrapper for the FindFirstFile API.
Definition: util.h:317
static const OSVersion & Get()
Singleton method.
Definition: util.inl:4
WIN_TYPE
Definition: util.h:20
Windows 2012 Release 2 (same as Windows 8.1)
Definition: util.h:32
static bool IsDirectory(const tstring &path)
Check if the item is a directory.
Definition: util.inl:256
static std::pair< tstring, tstring > SplitDrive(const tstring &path)
split path in two at the root
Definition: util.inl:381
static std::pair< tstring, tstring > SplitParent(const tstring &path)
split path into parent directory and filename
Definition: util.inl:409
Windows 8.1.
Definition: util.h:33
bool IsTemporary() const
Is the file marked temporary?
Definition: util.h:274
size_t Read(void *buffer, size_t byteSize)
Read from file into a block of memory.
Definition: util.inl:162
static tstring GetFilenameWithoutExt(const tstring &path)
Filename without extension.
Definition: util.inl:344
bool IsOpen() const
true if the file is open
Definition: util.h:180
int64_t Size()
Get size of file in bytes.
Definition: util.inl:138
static tstring GetCurrentDir()
Current working directory for this app.
Definition: util.inl:480
int64_t Tell()
Get current position inside the file.
Definition: util.inl:131
Windows 2000.
Definition: util.h:23
static bool IsAbsolute(const tstring &path)
Check if the path has a root.
Definition: util.inl:262
bool Ok() const
True if the search found at least one file.
Definition: util.inl:215
bool Close()
Closes the file.
Definition: util.inl:111
FileSearch(const tstring &searchPattern)
Starts the search.
Definition: util.inl:202
bool Next()
Iterate to next file in the search.
Definition: util.inl:225
bool ReadLine(std::string *line, const std::string &delim="\n")
Reads until one of the delimiters is found.
Definition: util.inl:167
iterator begin()
STL algorithms integration.
Definition: util.h:403
Contains the basic functions for file reading/writing.
Definition: util.h:152
Windows 2008 (same as Windows Vista)
Definition: util.h:27
int64_t GetFilesize() const
Utility to compute 64 bit filesize from members.
Definition: util.h:279
static std::pair< tstring, tstring > SplitExt(const tstring &path)
split path in two at the extension dot
Definition: util.inl:452
static bool IsFile(const tstring &path)
Check if the item is a file.
Definition: util.inl:250