Commit a0b93fd1 authored by Oleg Korshul's avatar Oleg Korshul

.

parent 96cea25b
/*
/*
* (c) Copyright Ascensio System SIA 2010-2016
*
* This program is a free software product. You can redistribute it and/or
......@@ -439,32 +439,7 @@ namespace NSDirectory
}
static std::wstring CreateTempFileWithUniqueName (const std::wstring & strFolderPathRoot, std::wstring Prefix)
{
#if defined(_WIN32) || defined (_WIN64)
wchar_t pBuffer [MAX_PATH+1];
memset (pBuffer, 0, sizeof (wchar_t) * (MAX_PATH+1));
/*unRet = */GetTempFileNameW( strFolderPathRoot.c_str(), Prefix.c_str(), 0,pBuffer);
return std::wstring(pBuffer);
#else
char pcRes[MAX_PATH];
if (NULL == pcRes) return _T("");
Prefix = strFolderPathRoot + FILE_SEPARATOR_STR + Prefix + _T("_XXXXXX");
std::wstring w_str = Prefix.c_str();
std::string a_str = stringWstingToUtf8String(w_str);
memcpy(pcRes, a_str.c_str(), a_str.length());
pcRes[a_str.length()] = '\0';
int res = mkstemp( pcRes);
if (-1 != res)
close(res);
std::string sRes = pcRes;
return stringUtf8ToWString (sRes);
#endif
return NSFile::CFileBinary::CreateTempFileWithUniqueName(strFolderPathRoot, Prefix);
}
static std::wstring CreateDirectoryWithUniqueName (const std::wstring & strFolderPathRoot)
{
......@@ -494,97 +469,33 @@ namespace NSDirectory
}
return pcTemplate;
#else
std::string pcTemplate = stringWstingToUtf8String (strFolderPathRoot) + "/ascXXXXXX";
std::string pcTemplate = U_TO_UTF8(strFolderPathRoot) + "/ascXXXXXX";
char *pcRes = mkdtemp(const_cast <char *> (pcTemplate.c_str()));
if (NULL == pcRes)
return _T("");
return L"";
std::string sRes = pcRes;
return stringUtf8ToWString (sRes);
return NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sRes.c_str(), (LONG)sRes.length());
#endif
}
static std::wstring GetTempPath()
{
#if defined(_WIN32) || defined (_WIN64)
wchar_t pBuffer [MAX_PATH+1];
memset (pBuffer, 0, sizeof (wchar_t) * (MAX_PATH+1));
::GetTempPathW (MAX_PATH, pBuffer);
std::wstring res;
res += std::wstring(pBuffer);
int nSeparator1Pos = res.rfind(L"/");
if (-1 == nSeparator1Pos)
{
nSeparator1Pos = res.rfind(L"\\");
}
if (-1 == nSeparator1Pos)
return L"";
return res.substr (0, nSeparator1Pos);
#else
char *folder = getenv ("TEMP");
if (NULL == folder)
folder = getenv ("TMP");
if (NULL == folder)
folder = getenv ("TMPDIR");
if (NULL == folder)
folder = "/tmp";
return stringUtf8ToWString(folder);
#endif
return NSFile::CFileBinary::GetTempPath();
}
static int GetFilesCount(const std::wstring& path, const bool& recursive)
{
CArray<std::wstring> arrFiles = NSDirectory::GetFiles(path, recursive);
#if defined(_WIN32) || defined (_WIN64)
std::wstring pathMask = path + L"\\*";
int filesCount = 0;
WIN32_FIND_DATAW findData;
HANDLE findResult = FindFirstFileW(pathMask.c_str(), &findData);
do {
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
if (!recursive)
continue;
if ((std::wstring) findData.cFileName == L".")
continue;
if ((std::wstring) findData.cFileName == L"..")
continue;
std::wstring innerPath = path + L'\\' + (std::wstring) findData.cFileName;
filesCount += GetFilesCount(innerPath, recursive);
}
else
++filesCount;
} while (FindNextFileW(findResult, &findData));
FindClose(findResult);
return filesCount;
#else
std::string path_utf8 = stringWstingToUtf8String(path.c_str());
std::vector<std::string> files;
listdir (path_utf8.c_str(), recursive, files);
return files.size()+1;
return arrFiles.GetCount();
#endif
return arrFiles.GetCount() + 1;
// ???
}
#if !defined(_WIN32) && !defined (_WIN64)
static bool PathIsDirectory(const std::wstring& pathName)
{
struct stat s;
std::string sPathNameUtf8 = stringWstingToUtf8String (pathName);
if (stat(sPathNameUtf8.c_str(), &s) == 0)
{
if (s.st_mode & S_IFDIR)return true;
else return false;
}
return false;
return Exists(pathName);
}
#endif
}
......
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