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"?>
<!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>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
......
......@@ -150,6 +150,47 @@ static bool stringWStringToUtf16 (const std::wstring& aSrc, std::vector<UTF16> &
return true;
#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
// When using VC, turn off browser references
......@@ -431,6 +472,7 @@ inline const Type& SSMAX(const Type& arg1, const Type& arg2)
typedef wchar_t OLECHAR;
typedef const TCHAR* LPCTSTR;
typedef TCHAR* LPTSTR;
#endif // #ifndef _WIN32
......
......@@ -90,6 +90,7 @@ private:
return sResult;
#else
return stringUtf8ToWString (sLine);
#endif
}
......
#include "Directory.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 {
// 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() {
static const int bufferSize = MAX_PATH;
LPTSTR directory = new TCHAR[bufferSize];
char spc_current_dir [MAX_PATH];
static CString wspc_current_dir;
DWORD lenght = ::GetCurrentDirectory(bufferSize, directory);
if (lenght == 0) {
delete[] directory;
directory = NULL;
}
getcwd (spc_current_dir, MAX_PATH);
std::string sDir;
sDir = spc_current_dir;
wspc_current_dir = stringUtf8ToWString (sDir);
return directory;
return wspc_current_dir.c_str();
}
String Directory::GetCurrentDirectoryS() {
LPCTSTR directory = GetCurrentDirectory();
if (directory == NULL)
std::string sDir;
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(directory);
return stringUtf8ToWString (sDir);
}
bool Directory::CreateDirectory(LPCTSTR path) {
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;
return directoryCreated;
}
bool Directory::CreateDirectory(const String& path) {
......@@ -35,45 +82,83 @@ namespace FileSystem {
}
bool Directory::CreateDirectories(LPCTSTR path)
{
int codeResult = ERROR_SUCCESS;
codeResult = SHCreateDirectory(NULL, path);
auto func = [] () { };
func(); // now call the function
bool created = false;
if (codeResult == ERROR_SUCCESS)
created = true;
return created;
std::wstring pathWstring;
pathWstring = path;
std::string pathUtf8 = stringWstingToUtf8String (pathWstring);
return _mkdir (pathUtf8.c_str());
}
StringArray Directory::GetFilesInDirectory(LPCTSTR path, const bool& andSubdirectories) {
size_t pathLength = 0;
StringCchLength(path, MAX_PATH, &pathLength);
++pathLength;
size_t pathToFilesLength = pathLength + 3;
LPTSTR pathToFiles = new TCHAR[pathToFilesLength];
// recursive directory scanning routine
bool listdir (const char* dirname, const bool recursive, std::vector<std::string>& files)
{
DIR* d_fh;
struct dirent* entry;
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);
StringCchCat(pathToFiles, pathToFilesLength, TEXT("\\*"));
return true;
}
WIN32_FIND_DATA findData;
HANDLE findResult = FindFirstFile(pathToFiles, &findData);
delete[] pathToFiles;
if (findResult == INVALID_HANDLE_VALUE)
return StringArray();
StringArray Directory::GetFilesInDirectory(LPCTSTR path, const bool& andSubdirectories)
{
std::wstring path_wstring = path;
std::string path_utf8 = stringWstingToUtf8String(path_wstring);
StringArray files;
do {
if (andSubdirectories || !(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
String file = findData.cFileName;
files.insert(files.end(), file);
}
} while (FindNextFile(findResult, &findData));
std::vector<std::string> files;
listdir (path_utf8.c_str(), andSubdirectories, files);
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) {
LPCTSTR pathW = path.c_str();
......@@ -81,29 +166,12 @@ namespace FileSystem {
}
int Directory::GetFilesCount(const CString& path, const bool& recursive) {
CString pathMask = path + _T("\\*");
WIN32_FIND_DATA findData;
HANDLE findResult = FindFirstFile(pathMask, &findData);
int filesCount = 0;
do {
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;
std::string path_utf8 = stringWstingToUtf8String(path.c_str());
std::vector<std::string> files;
listdir (path_utf8.c_str(), recursive, files);
return files.size();
}
}
......@@ -2,6 +2,7 @@
namespace FileSystem {
bool File::Exists(LPCTSTR path) {
#ifdef _WIN32
WIN32_FIND_DATA findData;
ZeroMemory(&findData, sizeof(findData));
......@@ -13,6 +14,11 @@ namespace FileSystem {
FindClose(handle);
return fileExists;
#else
std::wstring path_wstring;
std::wstring path_string;
return (-1 == access (fname, F_OK));
#endif
}
bool File::Exists(const String& path) {
return Exists(path.c_str());
......@@ -24,4 +30,4 @@ namespace FileSystem {
void File::Create(const String& path) {
Create(path.c_str());
}
}
\ No newline at end of file
}
......@@ -37,6 +37,11 @@ typedef wchar_t WCHAR;
#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)))
......@@ -83,28 +88,12 @@ typedef long HRESULT;
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#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;\
}
#ifndef RGB
typedef int RGB;
#define RGB(r,g,b) ((r)<<16|(g)<<8|(b))
#endif
#define RELEASEMEM(pobject)\
{\
if (pobject!=NULL)\
......@@ -129,6 +118,30 @@ typedef long HRESULT;
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)\
{\
if (pmem!=NULL)\
......@@ -153,6 +166,7 @@ typedef long HRESULT;
pstring=NULL;\
}\
}
#define RELEASEHANDLE(phandle)\
{\
if (phandle!=NULL)\
......@@ -162,4 +176,6 @@ typedef long HRESULT;
}\
}
#endif // _WIN32
#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