Commit 405a155e authored by Ivan.Shulga's avatar Ivan.Shulga Committed by Alexander Trofimov

linux build

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@58488 954022d7-b5bf-4e40-9824-e11837661b57
parent ad3bad45
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.1.1, 2014-09-22T17:52:31. --> <!-- Written by QtCreator 3.1.1, 2014-09-24T19:29:36. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>
......
...@@ -150,6 +150,47 @@ static bool stringWStringToUtf16 (const std::wstring& aSrc, std::vector<UTF16> & ...@@ -150,6 +150,47 @@ static bool stringWStringToUtf16 (const std::wstring& aSrc, std::vector<UTF16> &
return true; return true;
#endif #endif
} }
static std::wstring stringUtf8ToWString (const std::string& aSrc)
{
#ifdef _WIN32
//#error "You don't need to convert std::wstring to utf16 on Windows"
return false;
#else
uint32_t nLength = aSrc.length();
UTF32 *pStrUtf32 = new UTF32 [nLength];
memset ((void *) pStrUtf32, 0, sizeof (UTF32) * (nLength));
UTF8 *pStrUtf8 = (UTF8 *) &aSrc[0];
// this values will be modificated
const UTF8 *pStrUtf8_Conv = pStrUtf8;
UTF32 *pStrUtf32_Conv = pStrUtf32;
ConversionResult eUnicodeConversionResult =
ConvertUTF8toUTF32 (&pStrUtf8_Conv,
&pStrUtf8[nLength]
, &pStrUtf32_Conv
, &pStrUtf32 [nLength]
, strictConversion);
if (conversionOK != eUnicodeConversionResult)
{
delete [] pStrUtf32;
return L"";
}
std::wstring wsEntryName ((wchar_t *) pStrUtf32);
delete [] pStrUtf32;
return wsEntryName;
#endif
}
#endif // _WIN32 #endif // _WIN32
// When using VC, turn off browser references // When using VC, turn off browser references
...@@ -431,6 +472,7 @@ inline const Type& SSMAX(const Type& arg1, const Type& arg2) ...@@ -431,6 +472,7 @@ inline const Type& SSMAX(const Type& arg1, const Type& arg2)
typedef wchar_t OLECHAR; typedef wchar_t OLECHAR;
typedef const TCHAR* LPCTSTR; typedef const TCHAR* LPCTSTR;
typedef TCHAR* LPTSTR;
#endif // #ifndef _WIN32 #endif // #ifndef _WIN32
......
...@@ -90,6 +90,7 @@ private: ...@@ -90,6 +90,7 @@ private:
return sResult; return sResult;
#else #else
return stringUtf8ToWString (sLine);
#endif #endif
} }
......
#include "Directory.h" #include "Directory.h"
#include "../../Base/ASCString.h" #include "../../Base/ASCString.h"
//#include <shlobj.h>
#include <unistd.h>
#include <sys/stat.h>
#include <dirent.h>
#ifndef MAX_PATH
#define MAX_PATH 512
#endif
namespace FileSystem { namespace FileSystem {
// recursively make directories by path
// returns true if dir was created
static bool _mkdir (const char *dir) {
char tmp[MAX_PATH];
char *p = NULL;
size_t len;
bool res = true;
snprintf(tmp, sizeof(tmp),"%s",dir);
len = strlen(tmp);
if(tmp[len - 1] == '/')
tmp[len - 1] = 0;
for(p = tmp + 1; *p; p++)
if(*p == '/') {
*p = 0;
res = (0 == mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH));
*p = '/';
if (!res)
break;
}
if (res)
res = (0 == mkdir(tmp, S_IRWXU));
return res;
}
// FIXME: not thread safe (from win32 code, but there are no memory leaks)
LPCTSTR Directory::GetCurrentDirectory() { LPCTSTR Directory::GetCurrentDirectory() {
static const int bufferSize = MAX_PATH; char spc_current_dir [MAX_PATH];
LPTSTR directory = new TCHAR[bufferSize]; static CString wspc_current_dir;
DWORD lenght = ::GetCurrentDirectory(bufferSize, directory); getcwd (spc_current_dir, MAX_PATH);
if (lenght == 0) { std::string sDir;
delete[] directory; sDir = spc_current_dir;
directory = NULL; wspc_current_dir = stringUtf8ToWString (sDir);
}
return directory; return wspc_current_dir.c_str();
} }
String Directory::GetCurrentDirectoryS() { String Directory::GetCurrentDirectoryS() {
LPCTSTR directory = GetCurrentDirectory(); std::string sDir;
if (directory == NULL) char * pc_current_dir = getcwd(NULL, 0);
if (NULL != pc_current_dir)
{
sDir = pc_current_dir;
free (pc_current_dir);
}
else
return String(); return String();
return String(directory); return stringUtf8ToWString (sDir);
} }
bool Directory::CreateDirectory(LPCTSTR path) { bool Directory::CreateDirectory(LPCTSTR path) {
bool directoryCreated = false; bool directoryCreated = false;
if (::CreateDirectory(path, NULL) == TRUE)
std::wstring wsPath = path;
std::string sPathUtf8 = stringWstingToUtf8String (wsPath);
// read/write/search permissions for owner and group, and with read/search permissions for others
if (0 == mkdir (sPathUtf8.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))
directoryCreated = true; directoryCreated = true;
return directoryCreated; return directoryCreated;
} }
bool Directory::CreateDirectory(const String& path) { bool Directory::CreateDirectory(const String& path) {
...@@ -35,45 +82,83 @@ namespace FileSystem { ...@@ -35,45 +82,83 @@ namespace FileSystem {
} }
bool Directory::CreateDirectories(LPCTSTR path) bool Directory::CreateDirectories(LPCTSTR path)
{ {
int codeResult = ERROR_SUCCESS; auto func = [] () { };
func(); // now call the function
codeResult = SHCreateDirectory(NULL, path);
bool created = false; std::wstring pathWstring;
if (codeResult == ERROR_SUCCESS) pathWstring = path;
created = true; std::string pathUtf8 = stringWstingToUtf8String (pathWstring);
return _mkdir (pathUtf8.c_str());
return created;
} }
StringArray Directory::GetFilesInDirectory(LPCTSTR path, const bool& andSubdirectories) { // recursive directory scanning routine
size_t pathLength = 0; bool listdir (const char* dirname, const bool recursive, std::vector<std::string>& files)
StringCchLength(path, MAX_PATH, &pathLength); {
++pathLength; DIR* d_fh;
size_t pathToFilesLength = pathLength + 3; struct dirent* entry;
LPTSTR pathToFiles = new TCHAR[pathToFilesLength]; std::string longest_name;
while ( (d_fh = opendir(dirname)) == NULL)
{
// Couldn't open directory
return false;
}
while ((entry=readdir(d_fh)) != NULL) {
// Don't descend up the tree or include the current directory
if(strncmp(entry->d_name, "..", 2) != 0 &&
strncmp(entry->d_name, ".", 1) != 0)
{
// If it's a directory recurse into it
if (entry->d_type == DT_DIR)
{
if (recursive)
{
// Prepend the current directory and recurse
longest_name = dirname;
longest_name += "/";
longest_name += entry->d_name;
if (!listdir(longest_name.c_str(), recursive, files))
return false;
}
}
else
{
// it's a file
std::string sFileName;
sFileName = dirname;
sFileName += "/";
sFileName += entry->d_name;
files.push_back(sFileName);
}
}
}
closedir(d_fh);
StringCchCopy(pathToFiles, pathLength, path); return true;
StringCchCat(pathToFiles, pathToFilesLength, TEXT("\\*")); }
WIN32_FIND_DATA findData;
HANDLE findResult = FindFirstFile(pathToFiles, &findData);
delete[] pathToFiles;
if (findResult == INVALID_HANDLE_VALUE) StringArray Directory::GetFilesInDirectory(LPCTSTR path, const bool& andSubdirectories)
return StringArray(); {
std::wstring path_wstring = path;
std::string path_utf8 = stringWstingToUtf8String(path_wstring);
StringArray files; std::vector<std::string> files;
do { listdir (path_utf8.c_str(), andSubdirectories, files);
if (andSubdirectories || !(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
String file = findData.cFileName;
files.insert(files.end(), file);
}
} while (FindNextFile(findResult, &findData));
FindClose(findResult); StringArray files_wstring;
std::for_each (std::begin(files), std::end(files), [&] (std::string file)
{
std::wstring file_wstring = stringUtf8ToWString (file);
files_wstring.push_back (file_wstring);
});
return files; return files_wstring;
} }
StringArray Directory::GetFilesInDirectory(const String& path, const bool& andSubdirectories) { StringArray Directory::GetFilesInDirectory(const String& path, const bool& andSubdirectories) {
LPCTSTR pathW = path.c_str(); LPCTSTR pathW = path.c_str();
...@@ -81,29 +166,12 @@ namespace FileSystem { ...@@ -81,29 +166,12 @@ namespace FileSystem {
} }
int Directory::GetFilesCount(const CString& path, const bool& recursive) { int Directory::GetFilesCount(const CString& path, const bool& recursive) {
CString pathMask = path + _T("\\*");
std::string path_utf8 = stringWstingToUtf8String(path.c_str());
WIN32_FIND_DATA findData;
HANDLE findResult = FindFirstFile(pathMask, &findData); std::vector<std::string> files;
listdir (path_utf8.c_str(), recursive, files);
int filesCount = 0;
do { return files.size();
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
if (!recursive)
continue;
if ((CString) findData.cFileName == _T("."))
continue;
if ((CString) findData.cFileName == _T(".."))
continue;
CString innerPath = path + _T('\\') + (CString) findData.cFileName;
filesCount += GetFilesCount(innerPath, recursive);
}
else
++filesCount;
} while (FindNextFile(findResult, &findData));
FindClose(findResult);
return filesCount;
} }
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace FileSystem { namespace FileSystem {
bool File::Exists(LPCTSTR path) { bool File::Exists(LPCTSTR path) {
#ifdef _WIN32
WIN32_FIND_DATA findData; WIN32_FIND_DATA findData;
ZeroMemory(&findData, sizeof(findData)); ZeroMemory(&findData, sizeof(findData));
...@@ -13,6 +14,11 @@ namespace FileSystem { ...@@ -13,6 +14,11 @@ namespace FileSystem {
FindClose(handle); FindClose(handle);
return fileExists; return fileExists;
#else
std::wstring path_wstring;
std::wstring path_string;
return (-1 == access (fname, F_OK));
#endif
} }
bool File::Exists(const String& path) { bool File::Exists(const String& path) {
return Exists(path.c_str()); return Exists(path.c_str());
...@@ -24,4 +30,4 @@ namespace FileSystem { ...@@ -24,4 +30,4 @@ namespace FileSystem {
void File::Create(const String& path) { void File::Create(const String& path) {
Create(path.c_str()); Create(path.c_str());
} }
} }
\ No newline at end of file
...@@ -37,6 +37,11 @@ typedef wchar_t WCHAR; ...@@ -37,6 +37,11 @@ typedef wchar_t WCHAR;
#include <inttypes.h> #include <inttypes.h>
typedef int64_t T_LONG64; typedef int64_t T_LONG64;
typedef uint64_t T_ULONG64; typedef uint64_t T_ULONG64;
typedef T_LONG64 __int64;
typedef T_ULONG64 ULONG64;
typedef T_LONG64 LONG64;
typedef T_ULONG64 UINT64;
#else #else
#if (!defined (_MAC) && (!defined(MIDL_PASS) || defined(__midl)) && (!defined(_M_IX86) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64))) #if (!defined (_MAC) && (!defined(MIDL_PASS) || defined(__midl)) && (!defined(_M_IX86) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64)))
...@@ -83,28 +88,12 @@ typedef long HRESULT; ...@@ -83,28 +88,12 @@ typedef long HRESULT;
#define min(a,b) (((a) < (b)) ? (a) : (b)) #define min(a,b) (((a) < (b)) ? (a) : (b))
#endif #endif
#define ADDREFINTERFACE(pinterface)\ #ifndef RGB
{\ typedef int RGB;
if (pinterface!=NULL)\ #define RGB(r,g,b) ((r)<<16|(g)<<8|(b))
{\ #endif
pinterface->AddRef();\
}\
}
#define RELEASEINTERFACE(pinterface)\
{\
if (pinterface!=NULL)\
{\
pinterface->Release();\
pinterface=NULL;\
}\
}
#define QUERYINTERFACE(pinterface, pinterface_res, iid)\
{\
if (pinterface!=NULL)\
pinterface->QueryInterface(iid, (void**)&pinterface_res);\
else\
pinterface_res=NULL;\
}
#define RELEASEMEM(pobject)\ #define RELEASEMEM(pobject)\
{\ {\
if (pobject!=NULL)\ if (pobject!=NULL)\
...@@ -129,6 +118,30 @@ typedef long HRESULT; ...@@ -129,6 +118,30 @@ typedef long HRESULT;
pobject=NULL;\ pobject=NULL;\
}\ }\
} }
#ifdef _WIN32
#define ADDREFINTERFACE(pinterface)\
{\
if (pinterface!=NULL)\
{\
pinterface->AddRef();\
}\
}
#define RELEASEINTERFACE(pinterface)\
{\
if (pinterface!=NULL)\
{\
pinterface->Release();\
pinterface=NULL;\
}\
}
#define QUERYINTERFACE(pinterface, pinterface_res, iid)\
{\
if (pinterface!=NULL)\
pinterface->QueryInterface(iid, (void**)&pinterface_res);\
else\
pinterface_res=NULL;\
}
#define RELEASEHEAP(pmem)\ #define RELEASEHEAP(pmem)\
{\ {\
if (pmem!=NULL)\ if (pmem!=NULL)\
...@@ -153,6 +166,7 @@ typedef long HRESULT; ...@@ -153,6 +166,7 @@ typedef long HRESULT;
pstring=NULL;\ pstring=NULL;\
}\ }\
} }
#define RELEASEHANDLE(phandle)\ #define RELEASEHANDLE(phandle)\
{\ {\
if (phandle!=NULL)\ if (phandle!=NULL)\
...@@ -162,4 +176,6 @@ typedef long HRESULT; ...@@ -162,4 +176,6 @@ typedef long HRESULT;
}\ }\
} }
#endif // _WIN32
#endif //_BUILD_TYPES_CROSSPLATFORM_H_ #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