Common: Code clean up of common

This commit is contained in:
zilmar 2022-10-03 18:34:42 +10:30
parent 82d9027374
commit 92054583d4
31 changed files with 878 additions and 668 deletions

View File

@ -19,7 +19,8 @@ private:
class CGuard
{
public:
CGuard(CriticalSection& sectionName) : m_cs(sectionName)
CGuard(CriticalSection & sectionName) :
m_cs(sectionName)
{
m_cs.enter();
}
@ -27,6 +28,7 @@ public:
{
m_cs.leave();
}
private:
CriticalSection & m_cs;
CGuard(const CGuard & copy);

View File

@ -2,9 +2,9 @@
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#include <dlfcn.h>
#include <errno.h>
#include <unistd.h>
#endif
DynLibHandle DynamicLibraryOpen(const char * pccLibraryPath, bool ShowErrors)
@ -48,4 +48,3 @@ void * DynamicLibraryGetProc(DynLibHandle Lib, const char * ProcedureName)
return dlsym(Lib, ProcedureName);
#endif
}

View File

@ -95,9 +95,18 @@ bool CFile::Open(const char * lpszFileName, uint32_t nOpenFlags)
ULONG dwShareMode = 0;
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
if ((nOpenFlags & shareDenyWrite) == shareDenyWrite) { dwShareMode &= ~FILE_SHARE_WRITE; }
if ((nOpenFlags & shareDenyRead) == shareDenyRead) { dwShareMode &= ~FILE_SHARE_READ; }
if ((nOpenFlags & shareExclusive) == shareExclusive) { dwShareMode = 0; }
if ((nOpenFlags & shareDenyWrite) == shareDenyWrite)
{
dwShareMode &= ~FILE_SHARE_WRITE;
}
if ((nOpenFlags & shareDenyRead) == shareDenyRead)
{
dwShareMode &= ~FILE_SHARE_READ;
}
if ((nOpenFlags & shareExclusive) == shareExclusive)
{
dwShareMode = 0;
}
// Map modeNoInherit flag
SECURITY_ATTRIBUTES sa;

View File

@ -1,7 +1,7 @@
#include "HighResTimeStamp.h"
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#ifdef _WIN32
#include <Windows.h>
#else

View File

@ -1,7 +1,7 @@
#include "IniFile.h"
#include "StdString.h"
#include <stdlib.h>
#include <stdarg.h>
#include <stdlib.h>
CIniFileBase::CIniFileBase(CFileBase & FileObject, const char * FileName) :
m_lastSectionSearch(0),
@ -23,7 +23,10 @@ CIniFileBase::~CIniFileBase(void)
void CIniFileBase::fInsertSpaces(int Pos, int NoOfSpaces)
{
enum { fIS_MvSize = 0x2000 };
enum
{
fIS_MvSize = 0x2000
};
unsigned char Data[fIS_MvSize + 1];
int SizeToRead, result;
@ -39,7 +42,10 @@ void CIniFileBase::fInsertSpaces(int Pos, int NoOfSpaces)
do
{
SizeToRead = end - Pos;
if (SizeToRead > fIS_MvSize) { SizeToRead = fIS_MvSize; }
if (SizeToRead > fIS_MvSize)
{
SizeToRead = fIS_MvSize;
}
if (SizeToRead > 0)
{
m_File.Seek(SizeToRead * -1, CFileBase::current);
@ -63,7 +69,10 @@ void CIniFileBase::fInsertSpaces(int Pos, int NoOfSpaces)
do
{
SizeToRead = end - ReadPos;
if (SizeToRead > fIS_MvSize) { SizeToRead = fIS_MvSize; }
if (SizeToRead > fIS_MvSize)
{
SizeToRead = fIS_MvSize;
}
m_File.Seek(ReadPos, CFileBase::begin);
m_File.Read(Data, SizeToRead);
m_File.Seek(WritePos, CFileBase::begin);
@ -84,7 +93,10 @@ void CIniFileBase::fInsertSpaces(int Pos, int NoOfSpaces)
int CIniFileBase::GetStringFromFile(char *& String, std::unique_ptr<char> & Data, int & MaxDataSize, int & DataSize, int & ReadPos)
{
enum { BufferIncrease = 0x2000 };
enum
{
BufferIncrease = 0x2000
};
if (MaxDataSize == 0)
{
ReadPos = 0;
@ -217,7 +229,10 @@ void CIniFileBase::SaveCurrentSection(void)
do
{
result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos);
if (result <= 1) { continue; }
if (result <= 1)
{
continue;
}
if (strlen(CleanLine(Input)) <= 1 || Input[0] != '[')
{
EndPos = (long)((m_File.GetPosition() - DataSize) + ReadPos);
@ -326,8 +341,14 @@ bool CIniFileBase::MoveToSectionNameData(const char * lpSectionName, bool Change
do
{
result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos);
if (result <= 1) { continue; }
if (strlen(CleanLine(Input)) <= 1) { continue; }
if (result <= 1)
{
continue;
}
if (strlen(CleanLine(Input)) <= 1)
{
continue;
}
// We only care about sections
char * CurrentSection = Input;
@ -337,9 +358,15 @@ bool CIniFileBase::MoveToSectionNameData(const char * lpSectionName, bool Change
CurrentSection += 3;
}
if (CurrentSection[0] != '[') { continue; }
if (CurrentSection[0] != '[')
{
continue;
}
int lineEndPos = (int)strlen(CurrentSection) - 1;
if (CurrentSection[lineEndPos] != ']') { continue; }
if (CurrentSection[lineEndPos] != ']')
{
continue;
}
// Take off the ']' from the end of the string
CurrentSection[lineEndPos] = 0;
CurrentSection += 1;
@ -383,11 +410,23 @@ bool CIniFileBase::MoveToSectionNameData(const char * lpSectionName, bool Change
do
{
result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos);
if (result <= 1) { continue; }
if (strlen(CleanLine(Input)) <= 1) { continue; }
if (Input[0] == '[') { break; }
if (result <= 1)
{
continue;
}
if (strlen(CleanLine(Input)) <= 1)
{
continue;
}
if (Input[0] == '[')
{
break;
}
char * Pos = strchr(Input, '=');
if (Pos == nullptr) { continue; }
if (Pos == nullptr)
{
continue;
}
char * Value = &Pos[1];
char * Pos1 = Pos - 1;
@ -442,7 +481,10 @@ const char * CIniFileBase::CleanLine(char * Line)
// Strip any spaces or line feeds from the end of the line
for (int count = (int)strlen(&Line[0]) - 1; count >= 0; count--)
{
if (Line[count] != ' ' && Line[count] != '\r') { break; }
if (Line[count] != ' ' && Line[count] != '\r')
{
break;
}
Line[count] = 0;
}
return Line;
@ -502,7 +544,10 @@ bool CIniFileBase::DeleteSection(const char * lpSectionName)
{
CGuard Guard(m_CS);
if (!m_File.IsOpen()) { return false; }
if (!m_File.IsOpen())
{
return false;
}
SaveCurrentSection();
if (!MoveToSectionNameData(lpSectionName, true))
@ -520,8 +565,14 @@ bool CIniFileBase::DeleteSection(const char * lpSectionName)
do
{
result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos);
if (result <= 1) { continue; }
if (strlen(CleanLine(Input)) <= 1) { continue; }
if (result <= 1)
{
continue;
}
if (strlen(CleanLine(Input)) <= 1)
{
continue;
}
if (Input[0] != '[')
{
@ -540,13 +591,19 @@ bool CIniFileBase::DeleteSection(const char * lpSectionName)
long ReadPos = NextSectionStart;
long WritePos = DeleteSectionStart;
enum { fIS_MvSize = 0x2000 };
enum
{
fIS_MvSize = 0x2000
};
unsigned char Data[fIS_MvSize + 1];
int SizeToRead;
do
{
SizeToRead = end - ReadPos;
if (SizeToRead > fIS_MvSize) { SizeToRead = fIS_MvSize; }
if (SizeToRead > fIS_MvSize)
{
SizeToRead = fIS_MvSize;
}
m_File.Seek(ReadPos, CFileBase::begin);
m_File.Read(Data, SizeToRead);
m_File.Seek(WritePos, CFileBase::begin);
@ -817,7 +874,10 @@ void CIniFileBase::GetKeyValueData(const char * lpSectionName, KeyValueData & Li
strSection = lpSectionName;
}
if (!MoveToSectionNameData(strSection.c_str(), false)) { return; }
if (!MoveToSectionNameData(strSection.c_str(), false))
{
return;
}
int MaxDataSize = 0, DataSize = 0, ReadPos = 0, result;
std::unique_ptr<char> Data;
@ -825,11 +885,23 @@ void CIniFileBase::GetKeyValueData(const char * lpSectionName, KeyValueData & Li
do
{
result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos);
if (result <= 1) { continue; }
if (strlen(CleanLine(Input)) <= 1) { continue; }
if (Input[0] == '[') { break; }
if (result <= 1)
{
continue;
}
if (strlen(CleanLine(Input)) <= 1)
{
continue;
}
if (Input[0] == '[')
{
break;
}
char * Pos = strchr(Input, '=');
if (Pos == nullptr) { continue; }
if (Pos == nullptr)
{
continue;
}
Pos[0] = 0;
List.insert(KeyValueData::value_type(stdstr(Input).Trim(), &Pos[1]));

View File

@ -4,15 +4,15 @@
#include <strings.h>
#endif
#include "Platform.h"
#include "File.h"
#include "CriticalSection.h"
#include <string>
#include <map>
#include <vector>
#include "File.h"
#include "Platform.h"
#include <list>
#include <set>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
class CIniFileBase
{
@ -47,7 +47,10 @@ public:
void SetCustomSort(SortData SortFunction);
void GetVectorOfSections(SectionList & sections);
const std::string &GetFileName() { return m_FileName; }
const std::string & GetFileName()
{
return m_FileName;
}
protected:
void OpenIniFileReadOnly();

View File

@ -1,8 +1,8 @@
#include "Log.h"
#include "path.h"
#include "Platform.h"
#include <stdio.h>
#include "path.h"
#include <stdarg.h>
#include <stdio.h>
CLog::CLog(void) :
m_FlushOnWrite(false),
@ -31,7 +31,10 @@ bool CLog::Open( const char * FileName, LOG_OPEN_MODE mode /* = Log_New */)
}
uint32_t nOpenFlags = CFile::modeReadWrite | CFile::modeCreate;
if (mode == Log_Append) { nOpenFlags |= CFile::modeNoTruncate; }
if (mode == Log_Append)
{
nOpenFlags |= CFile::modeNoTruncate;
}
if (!m_hLogFile.Open(File, nOpenFlags))
{
@ -61,7 +64,10 @@ void CLog::LogF(const char * Message, ...)
void CLog::LogArgs(const char * Message, va_list & args)
{
if (!m_hLogFile.IsOpen()) { return; }
if (!m_hLogFile.IsOpen())
{
return;
}
try
{
@ -82,7 +88,10 @@ void CLog::LogArgs(const char * Message, va_list & args )
void CLog::Log(const char * Message)
{
if (!m_hLogFile.IsOpen()) { return; }
if (!m_hLogFile.IsOpen())
{
return;
}
uint32_t message_len = (uint32_t)strlen(Message);
m_hLogFile.Write(Message, message_len);
if (m_FlushOnWrite)
@ -137,11 +146,17 @@ void CLog::Log( const char * Message )
uint32_t SizeToRead, WritePos = 0;
do
{
enum { fIS_MvSize = 0x5000 };
enum
{
fIS_MvSize = 0x5000
};
unsigned char Data[fIS_MvSize + 1];
SizeToRead = end - ReadPos;
if (SizeToRead > fIS_MvSize) { SizeToRead = fIS_MvSize; }
if (SizeToRead > fIS_MvSize)
{
SizeToRead = fIS_MvSize;
}
m_hLogFile.Seek(ReadPos, CFile::begin);
@ -169,7 +184,10 @@ void CLog::Log( const char * Message )
bool CLog::Empty(void)
{
if (!m_hLogFile.IsOpen()) { return true; }
if (!m_hLogFile.IsOpen())
{
return true;
}
if (m_hLogFile.GetLength() == 0)
{
return true;

View File

@ -1,18 +1,25 @@
#pragma once
#include "File.h"
#include <stdarg.h>
#include <string>
#include "File.h"
class CLog
{
public:
enum LOG_OPEN_MODE
{
Log_New, Log_Append
Log_New,
Log_Append
};
enum { MB = 1024 * 1024 };
enum { MAX_FILE_SIZE = 10 * MB };
enum
{
MB = 1024 * 1024
};
enum
{
MAX_FILE_SIZE = 10 * MB
};
CLog(void);
~CLog(void);
@ -29,11 +36,26 @@ public:
m_MaxFileSize = Size;
m_FileChangeSize = (uint32_t)(Size * 0.1);
}
inline void SetTruncateFile(bool Truncate) { m_TruncateFileLog = Truncate; }
inline void SetFlush(bool Always) { m_FlushOnWrite = Always; }
inline bool IsOpen(void) const { return m_hLogFile.IsOpen(); }
inline bool Flush(void) { return m_hLogFile.Flush(); }
inline const std::string & FileName(void) const { return m_FileName; }
inline void SetTruncateFile(bool Truncate)
{
m_TruncateFileLog = Truncate;
}
inline void SetFlush(bool Always)
{
m_FlushOnWrite = Always;
}
inline bool IsOpen(void) const
{
return m_hLogFile.IsOpen();
}
inline bool Flush(void)
{
return m_hLogFile.Flush();
}
inline const std::string & FileName(void) const
{
return m_FileName;
}
private:
CLog(const CLog &);

View File

@ -1,7 +1,7 @@
#include "Platform.h"
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#ifndef _WIN32
int _vscprintf(const char * format, va_list pargs)
@ -22,10 +22,22 @@ int fesetround(int RoundType)
{
static const unsigned int msRound[4] = {_RC_NEAR, _RC_CHOP, _RC_UP, _RC_DOWN};
int32_t res = _controlfp(msRound[RoundType], _MCW_RC);
if (res == _RC_NEAR) { return FE_TONEAREST; }
if (res == _RC_CHOP) { return FE_TOWARDZERO; }
if (res == _RC_UP) { return FE_UPWARD; }
if (res == _RC_DOWN) { return FE_DOWNWARD; }
if (res == _RC_NEAR)
{
return FE_TONEAREST;
}
if (res == _RC_CHOP)
{
return FE_TOWARDZERO;
}
if (res == _RC_UP)
{
return FE_UPWARD;
}
if (res == _RC_DOWN)
{
return FE_DOWNWARD;
}
return FE_TONEAREST;
}
#endif

View File

@ -16,7 +16,13 @@ int _vscprintf (const char * format, va_list pargs);
// FPU rounding code
#ifdef _WIN32
typedef enum { FE_TONEAREST = 0, FE_TOWARDZERO, FE_UPWARD, FE_DOWNWARD } eRoundType;
typedef enum
{
FE_TONEAREST = 0,
FE_TOWARDZERO,
FE_UPWARD,
FE_DOWNWARD,
} eRoundType;
int fesetround(int RoundType);
#else
#include <fenv.h>

View File

@ -1,7 +1,7 @@
#include "StdString.h"
#include "Platform.h"
#include <malloc.h>
#include <algorithm>
#include <malloc.h>
#ifdef _WIN32
#include <Windows.h>
#endif

View File

@ -2,10 +2,10 @@
class stdstr;
#include <stdarg.h>
#include <vector>
#include <string>
#include <list>
#include <stdarg.h>
#include <string>
#include <vector>
typedef std::vector<stdstr> strvector;

View File

@ -4,7 +4,10 @@
class SyncEvent
{
public:
enum { INFINITE_TIMEOUT = 0xFFFFFFFF };
enum
{
INFINITE_TIMEOUT = 0xFFFFFFFF
};
SyncEvent(bool bManualReset = true);
~SyncEvent(void);

View File

@ -4,9 +4,9 @@
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#include <pthread.h>
#include <sys/syscall.h>
#include <unistd.h>
#endif
CThread::CThread(CTHREAD_START_ROUTINE lpStartAddress) :

View File

@ -14,7 +14,10 @@ public:
bool Start(void * lpThreadParameter);
inline uint32_t ThreadID(void) const { return m_threadID; }
inline uint32_t ThreadID(void) const
{
return m_threadID;
}
bool isRunning(void) const;
void Terminate(void);

View File

@ -1,8 +1,8 @@
#include "Trace.h"
#include "StdString.h"
#include "CriticalSection.h"
#include "Thread.h"
#include "Platform.h"
#include "StdString.h"
#include "Thread.h"
#include <map>
#include <vector>
#ifdef _WIN32
@ -26,7 +26,10 @@ public:
CTraceLog()
{
}
~CTraceLog() { CloseTrace(); }
~CTraceLog()
{
CloseTrace();
}
void TraceMessage(uint32_t module, uint8_t severity, const char * file, int line, const char * function, const char * Message);
@ -142,7 +145,6 @@ void CTraceLog::FlushTrace(void)
{
m_Modules[i]->FlushTrace();
}
}
void CTraceLog::TraceMessage(uint32_t module, uint8_t severity, const char * file, int line, const char * function, const char * Message)
@ -202,7 +204,10 @@ const char * TraceModule(uint32_t module)
CTraceFileLog::CTraceFileLog(const char * FileName, bool FlushFile, CLog::LOG_OPEN_MODE eMode, size_t dwMaxFileSize) :
m_FlushFile(FlushFile)
{
enum { MB = 1024 * 1024 };
enum
{
MB = 1024 * 1024
};
m_hLogFile.SetFlush(false);
m_hLogFile.SetTruncateFile(true);
@ -222,7 +227,10 @@ CTraceFileLog::~CTraceFileLog()
void CTraceFileLog::Write(uint32_t module, uint8_t severity, const char * /*file*/, int /*line*/, const char * function, const char * Message)
{
if (!m_hLogFile.IsOpen()) { return; }
if (!m_hLogFile.IsOpen())
{
return;
}
#ifdef _WIN32
SYSTEMTIME sysTime;

View File

@ -37,9 +37,17 @@ private:
};
#ifdef _WIN32
#define WriteTrace(m, s, format, ...) if(g_ModuleLogLevel[(m)] >= (s)) { WriteTraceFull((m), (s), __FILE__, __LINE__, __FUNCTION__, (format), ## __VA_ARGS__); }
#define WriteTrace(m, s, format, ...) \
if (g_ModuleLogLevel[(m)] >= (s)) \
{ \
WriteTraceFull((m), (s), __FILE__, __LINE__, __FUNCTION__, (format), ##__VA_ARGS__); \
}
#else
#define WriteTrace(m, s, format, ...) if(g_ModuleLogLevel[(m)] >= (s)) { WriteTraceFull((m), (s), __FILE__, __LINE__, __PRETTY_FUNCTION__, (format), ## __VA_ARGS__); }
#define WriteTrace(m, s, format, ...) \
if (g_ModuleLogLevel[(m)] >= (s)) \
{ \
WriteTraceFull((m), (s), __FILE__, __LINE__, __PRETTY_FUNCTION__, (format), ##__VA_ARGS__); \
}
#endif
CTraceModule * TraceAddModule(CTraceModule * TraceModule);

View File

@ -3,6 +3,7 @@
#include "path.h"
#ifdef _WIN32
#include <windows.h>
#include <Tlhelp32.h>
#else
#include <time.h>
@ -17,7 +18,8 @@ void pjutil::Sleep(uint32_t timeout)
struct timespec elapsed, tv;
elapsed.tv_sec = timeout / 1000;
elapsed.tv_nsec = (timeout % 1000) * 1000000;
do {
do
{
errno = 0;
tv.tv_sec = elapsed.tv_sec;
tv.tv_nsec = elapsed.tv_nsec;

View File

@ -41,19 +41,25 @@ documentation and/or software.
#pragma once
#include <string.h>
#include <stdio.h>
#include <string>
#include <functional>
#include "path.h"
#include "StdString.h"
#include "path.h"
#include <functional>
#include <stdio.h>
#include <string.h>
#include <string>
struct MD5Digest
{
MD5Digest() { Reset(); }
MD5Digest()
{
Reset();
}
unsigned char digest[16];
void Reset() { ::memset(digest, 0, sizeof(digest)); }
void Reset()
{
::memset(digest, 0, sizeof(digest));
}
bool IsClear()
{
int isClear = 0;
@ -110,7 +116,6 @@ public:
const char * hex_digest(); // Digest as a 33-byte ascii-hex string
private:
// First, some types:
typedef unsigned int uint4; // Assumes integer is 4 words long
typedef unsigned short int uint2; // Assumes short integer is 2 words long

View File

@ -1,7 +1,7 @@
#include "path.h"
#include "StdString.h"
#include "Trace.h"
#include "TraceModulesCommon.h"
#include "StdString.h"
#ifdef _WIN32
#pragma warning(push)
@ -9,13 +9,14 @@
#pragma warning(disable : 4996) // warning C4091: 'typedef ': ignored on left of 'tagGPFIDL_FLAGS' when no variable is declared
#include <Shlobj.h>
#include <dos.h>
#include <CommDlg.h>
#pragma warning(pop)
#else
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#include "Platform.h"
@ -24,9 +25,17 @@
#undef WriteTrace
#ifdef _WIN32
#define WriteTrace(m, s, format, ...) if (g_ModuleLogLevel != nullptr && g_ModuleLogLevel[(m)] >= (s)) { WriteTraceFull((m), (s), __FILE__, __LINE__, __FUNCTION__, (format), ## __VA_ARGS__); }
#define WriteTrace(m, s, format, ...) \
if (g_ModuleLogLevel != nullptr && g_ModuleLogLevel[(m)] >= (s)) \
{ \
WriteTraceFull((m), (s), __FILE__, __LINE__, __FUNCTION__, (format), ##__VA_ARGS__); \
}
#else
#define WriteTrace(m, s, format, ...) if (g_ModuleLogLevel != nullptr && g_ModuleLogLevel[(m)] >= (s)) { WriteTraceFull((m), (s), __FILE__, __LINE__, __PRETTY_FUNCTION__, (format), ## __VA_ARGS__); }
#define WriteTrace(m, s, format, ...) \
if (g_ModuleLogLevel != nullptr && g_ModuleLogLevel[(m)] >= (s)) \
{ \
WriteTraceFull((m), (s), __FILE__, __LINE__, __PRETTY_FUNCTION__, (format), ##__VA_ARGS__); \
}
#endif
// Constants
@ -249,7 +258,10 @@ CPath::CPath(DIR_CURRENT_DIRECTORY /*sdt*/, const char * NameExten)
// Application's current directory
Init();
CurrentDirectory();
if (NameExten) { SetNameExtension(NameExten); }
if (NameExten)
{
SetNameExtension(NameExten);
}
}
#ifdef _WIN32
@ -258,7 +270,10 @@ CPath::CPath(DIR_MODULE_DIRECTORY /*sdt*/, const char * NameExten)
// The directory where the executable of this app is
Init();
ModuleDirectory();
if (NameExten) { SetNameExtension(NameExten); }
if (NameExten)
{
SetNameExtension(NameExten);
}
}
CPath::CPath(DIR_MODULE_FILE /*sdt*/)
@ -599,7 +614,10 @@ void CPath::SetComponents(const char * lpszDirectory, const char * lpszName, con
memset(buff_fullname, 0, sizeof(buff_fullname));
if (lpszDirectory != nullptr && lpszDirectory[0] != '\0')
{
if (lpszDirectory[0] != DIRECTORY_DELIMITER) { buff_fullname[0] = DIRECTORY_DELIMITER; }
if (lpszDirectory[0] != DIRECTORY_DELIMITER)
{
buff_fullname[0] = DIRECTORY_DELIMITER;
}
strncat(buff_fullname, lpszDirectory, sizeof(buff_fullname) - 1);
std::string::size_type nLength = strlen(buff_fullname);
if (buff_fullname[nLength - 1] != DIRECTORY_DELIMITER && nLength < sizeof(buff_fullname))

View File

@ -1,16 +1,24 @@
#pragma once
#include <string>
#include <stdint.h>
#include <string>
class CPath
{
// Enums
public:
enum DIR_CURRENT_DIRECTORY { CURRENT_DIRECTORY = 1 };
enum DIR_CURRENT_DIRECTORY
{
CURRENT_DIRECTORY = 1
};
#ifdef _WIN32
enum DIR_MODULE_DIRECTORY { MODULE_DIRECTORY = 2 };
enum DIR_MODULE_FILE { MODULE_FILE = 3 };
enum DIR_MODULE_DIRECTORY
{
MODULE_DIRECTORY = 2
};
enum DIR_MODULE_FILE
{
MODULE_FILE = 3
};
#endif
enum
@ -58,7 +66,10 @@ public:
bool operator==(const CPath & rPath) const;
bool operator!=(const CPath & rPath) const;
operator const char *() const;
operator const std::string &() { return m_strPath; }
operator const std::string &()
{
return m_strPath;
}
// Get path components
#ifdef _WIN32
@ -82,7 +93,10 @@ public:
void GetComponents(std::string * pDirectory = nullptr, std::string * pName = nullptr, std::string * pExtension = nullptr) const;
#endif
// Get other state
bool IsEmpty() const { return m_strPath.empty(); }
bool IsEmpty() const
{
return m_strPath.empty();
}
bool IsRelative() const;
// Set path components
@ -104,7 +118,10 @@ public:
void SetComponents(const char * lpszDirectory, const char * lpszName, const char * lpszExtension);
#endif
// Set whole path
void Empty() { m_strPath.erase(); }
void Empty()
{
m_strPath.erase();
}
void CurrentDirectory();
#ifdef _WIN32
void Module();
@ -118,7 +135,10 @@ public:
bool DirectoryExists() const;
// File information
bool IsFile() const { return !IsDirectory(); }
bool IsFile() const
{
return !IsDirectory();
}
bool Exists() const;
#ifdef _WIN32
bool SelectFile(void * hwndOwner, const char * InitialDir, const char * FileFilter, bool FileMustExist);