Commit a7dd77a4 authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

.....

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@61937 954022d7-b5bf-4e40-9824-e11837661b57
parent 6cab330f
#ifndef _ASCVARIANT_H_
#define _ASCVARIANT_H_
#include "Types.h"
#include "../../Common/DocxFormat/Source/Base/ASCString.h" // TODO: move ASCString to DecktopEditor/commmon directory
// VARIANT
#ifndef _WIN32
// 0 == FALSE, -1 == TRUE
typedef short VARIANT_BOOL;
#define VARIANT_TRUE ((VARIANT_BOOL)-1)
#define VARIANT_FALSE ((VARIANT_BOOL)0)
enum VARENUM
{ VT_EMPTY = 0,
VT_NULL = 1,
VT_I2 = 2,
VT_I4 = 3,
VT_R4 = 4,
VT_R8 = 5,
VT_CY = 6,
VT_DATE = 7,
VT_BSTR = 8,
VT_DISPATCH = 9,
VT_ERROR = 10,
VT_BOOL = 11,
VT_VARIANT = 12,
VT_UNKNOWN = 13,
VT_DECIMAL = 14,
VT_I1 = 16,
VT_UI1 = 17,
VT_UI2 = 18,
VT_UI4 = 19,
VT_I8 = 20,
VT_UI8 = 21,
VT_INT = 22,
VT_UINT = 23,
VT_VOID = 24,
VT_HRESULT = 25,
VT_PTR = 26,
VT_SAFEARRAY = 27,
VT_CARRAY = 28,
VT_USERDEFINED = 29,
VT_LPSTR = 30,
VT_LPWSTR = 31,
VT_RECORD = 36,
VT_INT_PTR = 37,
VT_UINT_PTR = 38,
VT_FILETIME = 64,
VT_BLOB = 65,
VT_STREAM = 66,
VT_STORAGE = 67,
VT_STREAMED_OBJECT = 68,
VT_STORED_OBJECT = 69,
VT_BLOB_OBJECT = 70,
VT_CF = 71,
VT_CLSID = 72,
VT_VERSIONED_STREAM = 73,
VT_BSTR_BLOB = 0xfff,
VT_VECTOR = 0x1000,
VT_ARRAY = 0x2000,
VT_BYREF = 0x4000,
VT_RESERVED = 0x8000,
VT_ILLEGAL = 0xffff,
VT_ILLEGALMASKED = 0xfff,
VT_TYPEMASK = 0xfff
} ;
typedef VARIANT_BOOL _VARIANT_BOOL;
typedef unsigned short VARTYPE;
struct VARIANT
{
VARTYPE vt;
LONG64 llVal;//LONGLONG llVal;
LONG lVal;
BYTE bVal;
SHORT iVal;
FLOAT fltVal;
BSTR bstrVal;
VARIANT_BOOL boolVal;
double dblVal;
};
/*
struct tagVARIANT
{
union
{
struct __tagVARIANT
{
VARTYPE vt;
WORD wReserved1;
WORD wReserved2;
WORD wReserved3;
union
{
LONGLONG llVal;
LONG lVal;
BYTE bVal;
SHORT iVal;
FLOAT fltVal;
DOUBLE dblVal;
VARIANT_BOOL boolVal;
_VARIANT_BOOL bool;
SCODE scode;
CY cyVal;
DATE date;
BSTR bstrVal;
IUnknown *punkVal;
IDispatch *pdispVal;
SAFEARRAY *parray;
BYTE *pbVal;
SHORT *piVal;
LONG *plVal;
LONGLONG *pllVal;
FLOAT *pfltVal;
DOUBLE *pdblVal;
VARIANT_BOOL *pboolVal;
_VARIANT_BOOL *pbool;
SCODE *pscode;
CY *pcyVal;
DATE *pdate;
BSTR *pbstrVal;
IUnknown **ppunkVal;
IDispatch **ppdispVal;
SAFEARRAY **pparray;
VARIANT *pvarVal;
PVOID byref;
CHAR cVal;
USHORT uiVal;
ULONG ulVal;
ULONGLONG ullVal;
INT intVal;
UINT uintVal;
DECIMAL *pdecVal;
CHAR *pcVal;
USHORT *puiVal;
ULONG *pulVal;
ULONGLONG *pullVal;
INT *pintVal;
UINT *puintVal;
struct __tagBRECORD
{
PVOID pvRecord;
IRecordInfo *pRecInfo;
} __VARIANT_NAME_4;
} __VARIANT_NAME_3;
} __VARIANT_NAME_2;
DECIMAL decVal;
} __VARIANT_NAME_1;
} ;
*/
typedef VARIANT *LPVARIANT;
typedef VARIANT VARIANTARG;
typedef VARIANT *LPVARIANTARG;
#endif // #ifndef _WIN32
#endif //_ASCVARIANT_H_
#ifndef _GRAPHICS_ARRAY_H
#define _GRAPHICS_ARRAY_H
#include "Types.h"
#include <string.h>
#if 0 //__APPLE__
#include <vector>
template <class T>
class CArray
{
public:
// Construction/destruction
CArray()
{ }
~CArray()
{ }
CArray(const CArray<T>& src)
{
int nSrcSize = src.GetCount();
if (0 != nSrcSize)
{
for (int i = 0; i < nSrcSize; i++)
Add(src[i]);
}
}
CArray<T>& operator=(const CArray<T>& src)
{
int nSrcSize = src.GetCount();
RemoveAll();
for (int i = 0; i < nSrcSize; i++)
Add(src[i]);
return *this;
}
// Operations
int GetSize() const
{
return (int)m_aT.size();
}
int GetCount() const
{
return (int)m_aT.size();
}
INT SetCount(int nAllocSize)
{
RemoveAll();
for (int i = 0; i < nAllocSize; i++)
Add();
return TRUE;
}
INT Add()
{
T element;
m_aT.push_back(element);
return TRUE;
}
INT Add(const T& t)
{
m_aT.push_back(t);
return TRUE;
}
INT RemoveAt(int nIndex)
{
m_aT.erase(m_aT.begin() + nIndex);
return TRUE;
}
INT RemoveAt(int nIndex, int nCount)
{
m_aT.erase(m_aT.begin() + nIndex, m_aT.begin() + nIndex + nCount);
return TRUE;
}
void RemoveAll()
{
m_aT.clear();
}
const T& operator[] (int nIndex) const
{
if (nIndex < 0 || nIndex >= (int)m_aT.size())
{
return m_aT[0]; // exeption
}
return m_aT[nIndex];
}
T& operator[] (int nIndex)
{
if (nIndex < 0 || nIndex >= (int)m_aT.size())
{
return m_aT[0]; // exeption
}
return m_aT[nIndex];
}
private:
std::vector<T> m_aT;
};
#else
#include <stdlib.h>
#ifdef _IOS
#include <new>
#endif
template <class T>
class CArray
{
public:
// Construction/destruction
CArray() : m_aT(NULL), m_nSize(0), m_nAllocSize(0)
{ }
~CArray()
{
RemoveAll();
if (m_aT)
::free(m_aT);
}
CArray(const CArray<T>& src) : m_aT(NULL), m_nSize(0), m_nAllocSize(0)
{
int nSrcSize = src.GetCount();
if (0 != nSrcSize)
{
m_aT = (T*)::calloc(nSrcSize, sizeof(T));
if (m_aT != NULL)
{
m_nAllocSize = nSrcSize;
for (int i = 0; i < nSrcSize; i++)
::new(m_aT + i) T(src.m_aT[i]);
m_nSize = nSrcSize;
}
}
}
CArray<T>& operator=(const CArray<T>& src)
{
RemoveAll();
int nSrcSize = src.GetCount();
if (0 != nSrcSize)
{
m_aT = (T*)::calloc(nSrcSize, sizeof(T));
if (m_aT != NULL)
{
m_nAllocSize = nSrcSize;
for (int i = 0; i < nSrcSize; i++)
::new(m_aT + i) T(src.m_aT[i]);
m_nSize = nSrcSize;
}
}
return *this;
}
// Operations
int GetSize() const
{
return m_nSize;
}
int GetCount() const
{
return m_nSize;
}
INT SetCount(int nAllocSize)
{
RemoveAll();
if (nAllocSize != m_nAllocSize)
{
int nNewAllocSize = nAllocSize;
m_aT = (T*)::calloc(nNewAllocSize, sizeof(T));
for (int i = 0; i < nNewAllocSize; i++)
::new(m_aT + i) T;
if (NULL == m_aT)
return FALSE;
m_nAllocSize = nNewAllocSize;
m_nSize = nNewAllocSize;
}
return TRUE;
}
INT Add()
{
if (m_nSize == m_nAllocSize)
{
int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2);
T* newT = (T*)::calloc(nNewAllocSize, sizeof(T));
//T* newT = (T*)malloc(nNewAllocSize * sizeof(T));
if (NULL == newT)
return FALSE;
m_nAllocSize = nNewAllocSize;
// без операторов копирования и деструкторов
MoveElements(newT, m_aT, m_nSize);
if (NULL != m_aT)
::free(m_aT);
m_aT = newT;
}
::new(m_aT + m_nSize) T;
m_nSize++;
return TRUE;
}
INT Add(const T& t)
{
if (FALSE == Add())
return FALSE;
m_aT[m_nSize - 1] = t;
return TRUE;
}
INT RemoveAt(int nIndex, int nCount = 1)
{
if (nIndex < 0 || nIndex >= m_nSize || nCount < 1)
return FALSE;
if ((nIndex + nCount) > m_nSize)
nCount = m_nSize - nIndex;
// вызываем деструкторы
for (int i = 0; i < nCount; ++i)
m_aT[nIndex + i].~T();
int nNewCount = nIndex + nCount;
int nMoveCount = m_nSize - nNewCount;
if (nNewCount != m_nSize)
{
MoveElements(m_aT + nIndex, m_aT + nNewCount, nMoveCount);
}
m_nSize -= nCount;
return TRUE;
}
void RemoveAll()
{
if (m_aT != NULL)
{
// вызываем деструкторы
for (int i = 0; i < m_nSize; i++)
m_aT[i].~T();
::free(m_aT);
m_aT = NULL;
}
m_nSize = 0;
m_nAllocSize = 0;
}
const T& operator[] (int nIndex) const
{
if (nIndex < 0 || nIndex >= m_nSize)
{
return m_aT[0]; // exeption
}
return m_aT[nIndex];
}
T& operator[] (int nIndex)
{
if (nIndex < 0 || nIndex >= m_nSize)
{
return m_aT[0]; // exeption
}
return m_aT[nIndex];
}
T* GetData() const
{
return m_aT;
}
private:
T* m_aT;
int m_nSize;
int m_nAllocSize;
private:
void MoveElements(T* dst, T* src, int nCount)
{
if (0 >= nCount)
return;
#ifdef WIN32
memmove_s((void*)dst, nCount * sizeof(T), (void*)src, nCount * sizeof(T));
#else
memmove((void*)dst, (void*)src, nCount * sizeof(T));
#endif
}
};
#endif
#endif // !defined(_GRAPHICS_ARRAY_H)
#ifndef _BUILD_BASE64_CROSSPLATFORM_DEFINE
#define _BUILD_BASE64_CROSSPLATFORM_DEFINE
#include <stdio.h>
#include <limits.h>
#include "Types.h"
namespace NSBase64
{
const int B64_BASE64_FLAG_NONE = 0;
const int B64_BASE64_FLAG_NOPAD = 1;
const int B64_BASE64_FLAG_NOCRLF = 2;
#define _BASE64_INT_MAX 2147483647
inline int Base64EncodeGetRequiredLength(int nSrcLen, DWORD dwFlags = B64_BASE64_FLAG_NONE)
{
T_LONG64 nSrcLen4 = static_cast<T_LONG64>(nSrcLen)*4;
if (nSrcLen4 > INT_MAX)
return -1;
int nRet = static_cast<int>(nSrcLen4/3);
if ((dwFlags & B64_BASE64_FLAG_NOPAD) == 0)
nRet += nSrcLen % 3;
int nCRLFs = nRet / 76 + 1;
int nOnLastLine = nRet % 76;
if (nOnLastLine)
{
if (nOnLastLine % 4)
nRet += 4-(nOnLastLine % 4);
}
nCRLFs *= 2;
if ((dwFlags & B64_BASE64_FLAG_NOCRLF) == 0)
nRet += nCRLFs;
return nRet;
}
inline int Base64DecodeGetRequiredLength(int nSrcLen)
{
return nSrcLen;
}
inline INT Base64Encode(const BYTE *pbSrcData, int nSrcLen, BYTE* szDest, int *pnDestLen, DWORD dwFlags = B64_BASE64_FLAG_NONE)
{
static const char s_chBase64EncodingTable[64] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };
if (!pbSrcData || !szDest || !pnDestLen)
return FALSE;
if (*pnDestLen < Base64EncodeGetRequiredLength(nSrcLen, dwFlags))
return FALSE;
int nWritten( 0 );
int nLen1( (nSrcLen/3)*4 );
int nLen2( nLen1/76 );
int nLen3( 19 );
for (int i=0; i<=nLen2; i++)
{
if (i==nLen2)
nLen3 = (nLen1%76)/4;
for (int j=0; j<nLen3; j++)
{
UINT dwCurr(0);
for (int n=0; n<3; n++)
{
dwCurr |= *pbSrcData++;
dwCurr <<= 8;
}
for (int k=0; k<4; k++)
{
BYTE b = (BYTE)(dwCurr>>26);
*szDest++ = s_chBase64EncodingTable[b];
dwCurr <<= 6;
}
}
nWritten+= nLen3*4;
if ((dwFlags & B64_BASE64_FLAG_NOCRLF)==0)
{
*szDest++ = '\r';
*szDest++ = '\n';
nWritten+= 2;
}
}
if (nWritten && (dwFlags & B64_BASE64_FLAG_NOCRLF)==0)
{
szDest-= 2;
nWritten -= 2;
}
nLen2 = (nSrcLen%3) ? (nSrcLen%3 + 1) : 0;
if (nLen2)
{
UINT dwCurr(0);
for (int n=0; n<3; n++)
{
if (n<(nSrcLen%3))
dwCurr |= *pbSrcData++;
dwCurr <<= 8;
}
for (int k=0; k<nLen2; k++)
{
BYTE b = (BYTE)(dwCurr>>26);
*szDest++ = s_chBase64EncodingTable[b];
dwCurr <<= 6;
}
nWritten+= nLen2;
if ((dwFlags & B64_BASE64_FLAG_NOPAD)==0)
{
nLen3 = nLen2 ? 4-nLen2 : 0;
for (int j=0; j<nLen3; j++)
{
*szDest++ = '=';
}
nWritten+= nLen3;
}
}
*pnDestLen = nWritten;
return TRUE;
}
inline int DecodeBase64Char(unsigned int ch)
{
// returns -1 if the character is invalid
// or should be skipped
// otherwise, returns the 6-bit code for the character
// from the encoding table
if (ch >= 'A' && ch <= 'Z')
return ch - 'A' + 0; // 0 range starts at 'A'
if (ch >= 'a' && ch <= 'z')
return ch - 'a' + 26; // 26 range starts at 'a'
if (ch >= '0' && ch <= '9')
return ch - '0' + 52; // 52 range starts at '0'
if (ch == '+')
return 62;
if (ch == '/')
return 63;
return -1;
}
inline INT Base64Decode(const char* szSrc, int nSrcLen, BYTE *pbDest, int *pnDestLen)
{
// walk the source buffer
// each four character sequence is converted to 3 bytes
// CRLFs and =, and any characters not in the encoding table
// are skiped
if (szSrc == NULL || pnDestLen == NULL)
return FALSE;
const char* szSrcEnd = szSrc + nSrcLen;
int nWritten = 0;
INT bOverflow = (pbDest == NULL) ? TRUE : FALSE;
while (szSrc < szSrcEnd &&(*szSrc) != 0)
{
DWORD dwCurr = 0;
int i;
int nBits = 0;
for (i=0; i<4; i++)
{
if (szSrc >= szSrcEnd)
break;
int nCh = DecodeBase64Char(*szSrc);
szSrc++;
if (nCh == -1)
{
// skip this char
i--;
continue;
}
dwCurr <<= 6;
dwCurr |= nCh;
nBits += 6;
}
if(!bOverflow && nWritten + (nBits/8) > (*pnDestLen))
bOverflow = TRUE;
// dwCurr has the 3 bytes to write to the output buffer
// left to right
dwCurr <<= 24-nBits;
for (i=0; i<nBits/8; i++)
{
if(!bOverflow)
{
*pbDest = (BYTE) ((dwCurr & 0x00ff0000) >> 16);
pbDest++;
}
dwCurr <<= 8;
nWritten++;
}
}
*pnDestLen = nWritten;
if(bOverflow)
{
// if (pbDest != NULL) ATLASSERT(FALSE);
return FALSE;
}
return TRUE;
}
}
#endif//_BUILD_BASE64_CROSSPLATFORM_DEFINE
\ No newline at end of file
#ifndef _BUILD_DIRECTORY_CROSSPLATFORM_H_
#define _BUILD_DIRECTORY_CROSSPLATFORM_H_
#include <stdio.h>
#include <string>
#include "Array.h"
#include "File.h"
#ifdef WIN32
#include "windows.h"
#include "windef.h"
#elif LINUX
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#elif MAC
#endif
namespace NSDirectory
{
#ifdef _IOS
void GetFiles2_ios(std::wstring strDirectory, CArray<std::wstring>& oArray, bool bIsRecursion);
#endif
static void GetFiles2(std::wstring strDirectory, CArray<std::wstring>& oArray, bool bIsRecursion = false)
{
#ifdef WIN32
WIN32_FIND_DATAW oFD;
std::wstring sSpec = strDirectory + L"\\*.*";
HANDLE hRes = FindFirstFileW( sSpec.c_str(), &oFD );
if( INVALID_HANDLE_VALUE == hRes )
return;
do
{
sSpec = oFD.cFileName;
if (sSpec != L"." && sSpec != L"..")
{
sSpec = strDirectory + L"\\" + sSpec;
if( !( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
{
oArray.Add(sSpec);
}
else if (bIsRecursion)
{
GetFiles2(sSpec, oArray, bIsRecursion);
}
}
} while( FindNextFileW( hRes, &oFD ) );
FindClose( hRes );
#endif
#ifdef LINUX
BYTE* pUtf8 = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
DIR *dp;
struct dirent *dirp;
if((dp = opendir((char*)pUtf8)) != NULL)
{
while ((dirp = readdir(dp)) != NULL)
{
if(DT_REG == dirp->d_type)
{
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
oArray.Add(strDirectory + L"/" + sName);
}
if (bIsRecursion && DT_DIR == dirp->d_type)
{
if(dirp->d_name[0] != '.')
{
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
GetFiles2(strDirectory + L"/" + sName, oArray, bIsRecursion);
}
}
}
closedir(dp);
}
delete [] pUtf8;
#endif
#ifdef MAC
#endif
#if 0
// нормально работает и линукс версия
#ifdef _IOS
return GetFiles2_ios(strDirectory, oArray, bIsRecursion);
#endif
#endif
}
static CArray<std::wstring> GetFiles(std::wstring strDirectory, bool bIsRecursion = false)
{
CArray<std::wstring> oArray;
GetFiles2(strDirectory, oArray, bIsRecursion);
return oArray;
}
static CArray<std::wstring> GetDirectories(std::wstring strDirectory)
{
CArray<std::wstring> oArray;
#ifdef WIN32
WIN32_FIND_DATAW oFD;
std::wstring sSpec = strDirectory + L"\\*";
HANDLE hRes = FindFirstFileW( sSpec.c_str(), &oFD );
if( INVALID_HANDLE_VALUE == hRes )
return oArray;
do
{
sSpec = oFD.cFileName;
if (sSpec != L"." && sSpec != L"..")
{
sSpec = strDirectory + L"\\" + sSpec;
if( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
{
oArray.Add(sSpec);
}
}
} while( FindNextFileW( hRes, &oFD ) );
FindClose( hRes );
#elif LINUX
BYTE* pUtf8 = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
DIR *dp;
struct dirent *dirp;
if((dp = opendir((char*)pUtf8)) != NULL)
{
while ((dirp = readdir(dp)) != NULL)
{
if(DT_DIR == dirp->d_type)
{
if(dirp->d_name[0] != '.')
{
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
oArray.Add(strDirectory + L"/" + sName);
}
}
}
closedir(dp);
}
delete [] pUtf8;
#elif MAC
#endif
return oArray;
}
static bool Exists(const std::wstring& strDirectory)
{
#ifdef WIN32
DWORD dwAttrib = ::GetFileAttributesW(strDirectory.c_str());
return (dwAttrib != INVALID_FILE_ATTRIBUTES && 0 != (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
#elif LINUX
BYTE* pUtf8 = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
struct stat st;
bool bRes = (0 == stat((char*)pUtf8, &st)) && S_ISDIR(st.st_mode);
delete [] pUtf8;
return bRes;
#elif MAC
return true;
#endif
}
static bool CreateDirectory(const std::wstring& strDirectory)
{
if (Exists(strDirectory) == true) return true;
#ifdef WIN32
return FALSE != ::CreateDirectoryW(strDirectory.c_str(), NULL);
#elif LINUX
BYTE* pUtf8 = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
struct stat st;
int nRes = 0;
if (stat((char*)pUtf8, &st) == -1) {
nRes = mkdir((char*)pUtf8, S_IRWXU | S_IRWXG | S_IRWXO);
}
delete [] pUtf8;
return 0 == nRes;
#elif MAC
return false;
#endif
}
static void DeleteDirectory(const std::wstring& strDirectory)
{
CArray<std::wstring> aFiles = GetFiles(strDirectory);
for(int i = 0; i < aFiles.GetCount(); ++i)
{
NSFile::CFileBinary::Remove(aFiles[i]);
}
CArray<std::wstring> aDirectories = GetDirectories(strDirectory);
for(int i = 0; i < aDirectories.GetCount(); ++i)
{
DeleteDirectory(aDirectories[i]);
}
#ifdef WIN32
RemoveDirectoryW(strDirectory.c_str());
#elif LINUX
BYTE* pUtf8 = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
rmdir((char*)pUtf8);
delete [] pUtf8;
#elif MAC
#endif
}
}
#endif //_BUILD_DIRECTORY_CROSSPLATFORM_H_
This diff is collapsed.
#ifndef _BUILD_PATH_CROSSPLATFORM_H_
#define _BUILD_PATH_CROSSPLATFORM_H_
#include <string>
#include <string.h>
#include "File.h"
#ifdef WIN32
#include <tchar.h>
#elif LINUX
#include <libgen.h>
#elif MAC
#endif
namespace NSSystemPath
{
static std::wstring GetDirectoryName(const std::wstring& strFileName)
{
std::wstring sRes;
#ifdef WIN32
TCHAR tDrive[256];
TCHAR tFolder[256];
_tsplitpath( strFileName.c_str(), tDrive, tFolder, NULL, NULL );
sRes.append(tDrive);
sRes.append(tFolder);
#elif LINUX
BYTE* pUtf8 = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strFileName.c_str(), strFileName.length(), pUtf8, lLen, false);
char* pDirName = dirname((char*)pUtf8);
sRes = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)pDirName, strlen(pDirName));
delete [] pUtf8;
#elif MAC
#endif
return sRes;
}
static std::wstring GetFileName(const std::wstring& strFileName)
{
std::wstring sRes;
#ifdef WIN32
TCHAR tFilename[256];
TCHAR tExt[256];
_tsplitpath( strFileName.c_str(), NULL, NULL, tFilename, tExt );
sRes.append(tFilename);
sRes.append(tExt);
return sRes;
#elif LINUX
BYTE* pUtf8 = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strFileName.c_str(), strFileName.length(), pUtf8, lLen, false);
char* pBaseName = basename((char*)pUtf8);
sRes = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)pBaseName, strlen(pBaseName));
delete [] pUtf8;
#elif MAC
#endif
return sRes;
}
static std::wstring Combine(const std::wstring& strLeft, const std::wstring& strRight)
{
std::wstring sRes;
bool bLeftSlash = false;
bool bRightSlash = false;
if(strLeft.length() > 0)
{
wchar_t cLeft = strLeft[strLeft.length() - 1];
bLeftSlash = ('/' == cLeft) || ('\\' == cLeft);
}
if(strRight.length() > 0)
{
wchar_t cRight = strRight[0];
bRightSlash = ('/' == cRight) || ('\\' == cRight);
}
if(bLeftSlash && bRightSlash)
{
sRes = strLeft + strRight.substr(1);
}
else if(!bLeftSlash && !bRightSlash)
sRes = strLeft + L"/" + strRight;
else
sRes = strLeft + strRight;
return sRes;
}
}
#endif //_BUILD_PATH_CROSSPLATFORM_H_
#ifndef _BUILD_TYPES_CROSSPLATFORM_H_
#define _BUILD_TYPES_CROSSPLATFORM_H_
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
typedef unsigned long DWORD;
#ifndef _IOS
typedef int BOOL;
#else
#ifndef _XCODE
#define BOOL int
#endif
#endif
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef float REAL, FLOAT, *PFLOAT;
typedef char CHAR;
typedef short SHORT;
typedef unsigned short USHORT;
typedef long LONG;
typedef int INT;
typedef unsigned int UINT, *PUINT;
typedef wchar_t WCHAR;
#ifdef _LINUX_QT
#include <inttypes.h>
typedef int64_t T_LONG64;
typedef uint64_t T_ULONG64;
typedef T_LONG64 __int64;
typedef T_ULONG64 ULONG64;
typedef T_LONG64 LONG64;
typedef T_ULONG64 UINT64;
#else
#if (!defined (_MAC) && (!defined(MIDL_PASS) || defined(__midl)) && (!defined(_M_IX86) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64)))
typedef __int64 T_LONG64;
typedef unsigned __int64 T_ULONG64;
#else
#if defined(_MAC) && defined(_MAC_INT_64)
typedef __int64 T_LONG64;
typedef unsigned __int64 T_ULONG64;
#else
typedef double T_LONG64;
typedef double T_ULONG64;
#endif //_MAC and int64
#endif
#endif
#ifndef VOID
typedef void VOID, *LPVOID;
#endif
#ifndef FLT_EPSILON
#define FLT_EPSILON 1.192092896e-07F /* smallest such that 1.0+FLT_EPSILON != 1.0 */
#endif
typedef unsigned long ULONG, ARGB;
typedef long HRESULT;
#ifdef WIN32
#include "winerror.h"
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#else
#ifndef S_OK
#define S_OK ((HRESULT)0x00000000L)
#define S_FALSE ((HRESULT)0x00000001L)
#endif
#endif
#ifndef RGB
typedef int RGB;
#define RGB(r,g,b) ((r)<<16|(g)<<8|(b))
#endif
#define RELEASEMEM(pobject)\
{\
if (pobject!=NULL)\
{\
free(pobject);\
pobject=NULL;\
}\
}
#define RELEASEOBJECT(pobject)\
{\
if (pobject!=NULL)\
{\
delete pobject;\
pobject=NULL;\
}\
}
#define RELEASEARRAYOBJECTS(pobject)\
{\
if (pobject!=NULL)\
{\
delete []pobject;\
pobject=NULL;\
}\
}
#define ADDREFINTERFACE(pinterface)\
{\
if (pinterface!=NULL)\
{\
pinterface->AddRef();\
}\
}
#define RELEASEINTERFACE(pinterface)\
{\
if (pinterface!=NULL)\
{\
pinterface->Release();\
pinterface=NULL;\
}\
}
#endif //_BUILD_TYPES_CROSSPLATFORM_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment