Commit 1d55b122 authored by ElenaSubbotina's avatar ElenaSubbotina

.

parent ac959e32
...@@ -65,9 +65,7 @@ namespace NSShapeImageGen ...@@ -65,9 +65,7 @@ namespace NSShapeImageGen
static bool _CopyFile(std::wstring strExists, std::wstring strNew, LPVOID lpFunc, LPVOID lpData) static bool _CopyFile(std::wstring strExists, std::wstring strNew, LPVOID lpFunc, LPVOID lpData)
{ {
//::DeleteFile(strNew); return CDirectory::CopyFile (strExists, strNew);
//return ::CopyFileEx(strExists, strNew, lpFunc, lpData, false, 0);
return CDirectory::CopyFile (strExists, strNew, lpFunc, lpData);
} }
enum ImageType enum ImageType
...@@ -369,7 +367,7 @@ namespace NSShapeImageGen ...@@ -369,7 +367,7 @@ namespace NSShapeImageGen
oInfo.m_eType = itJPG; oInfo.m_eType = itJPG;
OOX::CPath pathSaveItem = m_strDstMedia + FILE_SEPARATOR_STR + oInfo.GetPath2(); OOX::CPath pathSaveItem = m_strDstMedia + FILE_SEPARATOR_STR + oInfo.GetPath2();
CDirectory::CopyFile(strFileSrc, pathSaveItem.GetPath(), NULL, NULL); CDirectory::CopyFile(strFileSrc, pathSaveItem.GetPath());
return true; return true;
} }
...@@ -382,7 +380,7 @@ namespace NSShapeImageGen ...@@ -382,7 +380,7 @@ namespace NSShapeImageGen
oInfo.m_eType = itPNG; oInfo.m_eType = itPNG;
OOX::CPath pathSaveItem = m_strDstMedia + FILE_SEPARATOR_STR + oInfo.GetPath2(); OOX::CPath pathSaveItem = m_strDstMedia + FILE_SEPARATOR_STR + oInfo.GetPath2();
CDirectory::CopyFile(strFileSrc, pathSaveItem.GetPath(), NULL, NULL); CDirectory::CopyFile(strFileSrc, pathSaveItem.GetPath());
return true; return true;
} }
...@@ -408,7 +406,7 @@ namespace NSShapeImageGen ...@@ -408,7 +406,7 @@ namespace NSShapeImageGen
strSaveItem = m_strDstMedia + FILE_SEPARATOR_STR + strSaveItem + pathOriginal.GetExtention(); strSaveItem = m_strDstMedia + FILE_SEPARATOR_STR + strSaveItem + pathOriginal.GetExtention();
CDirectory::CopyFile(strFileSrc, strSaveItem, NULL, NULL); CDirectory::CopyFile(strFileSrc, strSaveItem);
} }
} }
void SaveImage(CBgraFrame& oBgraFrame, CImageInfo& oInfo, LONG __width, LONG __height) void SaveImage(CBgraFrame& oBgraFrame, CImageInfo& oInfo, LONG __width, LONG __height)
...@@ -524,14 +522,14 @@ namespace NSShapeImageGen ...@@ -524,14 +522,14 @@ namespace NSShapeImageGen
if(bOle) if(bOle)
{ {
std::wstring sCopyOlePath = strSaveItemWE + L".bin"; std::wstring sCopyOlePath = strSaveItemWE + L".bin";
CDirectory::CopyFile(strOleFile, sCopyOlePath, NULL, NULL); CDirectory::CopyFile(strOleFile, sCopyOlePath);
} }
if (bVector) if (bVector)
{ {
//copy source vector image //copy source vector image
OOX::CPath pathSaveItem = strSaveDir + oInfo.GetPath2(); OOX::CPath pathSaveItem = strSaveDir + oInfo.GetPath2();
CDirectory::CopyFile(strFileName, pathSaveItem.GetPath(), NULL, NULL); CDirectory::CopyFile(strFileName, pathSaveItem.GetPath());
::MetaFile::CMetaFile oMetafile(m_pFontManager->m_pApplication); ::MetaFile::CMetaFile oMetafile(m_pFontManager->m_pApplication);
if (oMetafile.LoadFromFile(strFileName.c_str())) if (oMetafile.LoadFromFile(strFileName.c_str()))
......
...@@ -38,8 +38,6 @@ ...@@ -38,8 +38,6 @@
#include "../Base/unicode_util.h" #include "../Base/unicode_util.h"
#include "../Base/Types_32.h" #include "../Base/Types_32.h"
//по аналогии с /DesktopEditor/common/File.h только для CString
#ifndef COINIT_MULTITHREADED #ifndef COINIT_MULTITHREADED
#define COINIT_MULTITHREADED 0 //for win64 .... oO #define COINIT_MULTITHREADED 0 //for win64 .... oO
#endif #endif
...@@ -307,6 +305,7 @@ protected: ...@@ -307,6 +305,7 @@ protected:
long m_lFilePosition; long m_lFilePosition;
long m_lFileSize; long m_lFileSize;
}; };
namespace StreamUtils namespace StreamUtils
{ {
static BYTE ReadBYTE(POLE::Stream* pStream) static BYTE ReadBYTE(POLE::Stream* pStream)
...@@ -347,9 +346,9 @@ namespace StreamUtils ...@@ -347,9 +346,9 @@ namespace StreamUtils
ULONG lReadByte = 0; ULONG lReadByte = 0;
lReadByte = (ULONG)pStream->read(pMem, 4); lReadByte = (ULONG)pStream->read(pMem, 4);
//#if defined(_DEBUG) && (defined(_WIN32) || defined(_WIN64)) //#if defined(_DEBUG) && (defined(_WIN32) || defined(_WIN64))
// ATLASSERT(4 == lReadByte); // ATLASSERT(4 == lReadByte);
//#endif //#endif
if (lReadByte == 4) if (lReadByte == 4)
{ {
...@@ -465,244 +464,37 @@ namespace StreamUtils ...@@ -465,244 +464,37 @@ namespace StreamUtils
} }
} }
#if defined(_WIN32) || defined(_WIN64)
namespace CDirectory namespace CDirectory
{ {
static std::wstring GetFolderName(std::wstring strFolderPath)
{
int n1 = (int)strFolderPath.rfind('\\');
if (-1 == n1)
return _T("");
return strFolderPath.substr(n1 + 1);
}
static std::wstring GetFolderPath(std::wstring strFolderPath)
{
int n1 = (int)strFolderPath.rfind('\\');
if (-1 == n1)
return _T("");
return strFolderPath.substr(0, n1);
}
static bool OpenFile(std::wstring strFolderPath, std::wstring strFileName, CFile* pFile)
{
std::wstring strFile = strFolderPath + FILE_SEPARATOR_STR + strFileName;
return (S_OK == pFile->OpenFile(strFile));
}
static bool CreateFile(std::wstring strFolderPath, std::wstring strFileName, CFile* pFile)
{
std::wstring strFile = strFolderPath + FILE_SEPARATOR_STR + strFileName;
return (S_OK == pFile->CreateFile(strFile));
}
static bool CreateDirectory(std::wstring strFolderPathRoot, std::wstring strFolderName)
{
std::wstring strFolder = strFolderPathRoot + FILE_SEPARATOR_STR + strFolderName;
return (bool)CreateDirectory(strFolder, NULL);
}
static bool CreateDirectory(std::wstring strFolderPath)
{
return (bool)CreateDirectory(strFolderPath, NULL);
}
static bool DeleteFile (std::wstring strFileName)
{
::DeleteFile (strFileName.c_str());
return true;
}
static bool MoveFile(std::wstring strExists, std::wstring strNew, LPVOID lpFunc, LPVOID lpData)
{
#if (_WIN32_WINNT >= 0x0500) && !defined (_WIN64)
return (bool)MoveFileWithProgress(strExists.c_str(), strNew.c_str(), (LPPROGRESS_ROUTINE)lpFunc, lpData, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
#else
return (bool)MoveFileEx(strExists.c_str(), strNew.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
#endif
}
static bool CopyFile(std::wstring strExists, std::wstring strNew, LPVOID lpFunc, LPVOID lpData)
{
DeleteFile(strNew);
//#if (_WIN32_WINNT >= 0x0500) && !defined (_WIN64)
// return (bool)CopyFile(strExists.c_str(), strNew.c_str(), true);
//#else
return (bool)CopyFileEx(strExists.c_str(), strNew.c_str(), (LPPROGRESS_ROUTINE)lpFunc, lpData, FALSE, 0);
//#endif
}
static std::wstring GetUnder(std::wstring strFolderPathRoot, std::wstring strFolderName)
{
std::wstring strFolder = strFolderPathRoot + L"\\" + strFolderName;
return strFolder;
}
static std::wstring GetFileName(std::wstring strFullName)
{
size_t nStart = strFullName.rfind(L"\\");
std::wstring strName = strFullName.substr(nStart + 1);
return strName;
}
static std::wstring BYTEArrayToString2(USHORT* arr, size_t nCount)
{
std::wstring str;
for (size_t index = 0; index < nCount; ++index)
{
if ('\0' != (char)(arr[index]))
str += (char)(arr[index]);
}
if (str.length() == 0)
str = _T("0");
return str;
}
static std::wstring ToString(DWORD val)
{
return std::to_wstring(val);
}
static std::wstring ToString(UINT64 val, bool bInit)
{
std::wstring strCoarse = ToString((DWORD)(val >> 32));
if (_T("0") != strCoarse)
{
return strCoarse + ToString((DWORD)val);
}
return ToString((DWORD)val);
}
static UINT64 GetUINT64(std::wstring strVal)
{
UINT64 nRet = 0;
int nLen = (int)strVal.length();
while (nLen > 0)
{
int nDig = XmlUtils::GetDigit(strVal[0]);
nRet *= 10;
nRet += nDig;
strVal.erase(0);
--nLen;
}
return nRet;
}
static UINT GetUINT(std::wstring strVal)
{
return (UINT)GetUINT64(strVal);
}
static void SaveToFile(std::wstring strFileName, std::wstring strXml) static void SaveToFile(std::wstring strFileName, std::wstring strXml)
{ {
int nLength = (int)strXml.length(); NSFile::CFileBinary file;
file.CreateFileW(strFileName);
std::string saStr; saStr.reserve(nLength*3 + 1); file.WriteStringUTF8(strXml);
file.CloseFile();
#ifdef UNICODE
// Encoding Unicode to UTF-8
WideCharToMultiByte(CP_UTF8, 0, strXml.c_str(), nLength + 1, (LPSTR)saStr.c_str(), nLength * 3, NULL, NULL);
#else
wchar_t* pWStr = new wchar_t[nLength + 1];
if (!pWStr)
return;
// set end string
pWStr[nLength] = 0;
// Encoding ASCII to Unicode
MultiByteToWideChar(CP_ACP, 0, strXml, nLength, pWStr, nLength);
int nLengthW = (int)wcslen(pWStr);
// Encoding Unicode to UTF-8
WideCharToMultiByte(CP_UTF8, 0, pWStr, nLengthW + 1, saStr.GetBuffer(nLengthW*3 + 1), nLengthW*3, NULL, NULL);
saStr.ReleaseBuffer();
delete[] pWStr;
#endif
CFile oFile;
oFile.CreateFile(strFileName);
oFile.WriteFile((void*)saStr.c_str(), (DWORD)saStr.length());
oFile.CloseFile();
}
static void SaveToFile2(std::wstring strFileName, std::string strVal)
{
CFile oFile;
HRESULT hr = oFile.OpenFileRW(strFileName);
if (S_OK != hr)
oFile.CreateFile(strFileName);
oFile.SkipBytes(oFile.GetFileSize());
oFile.WriteFile((void*)strVal.c_str(), (DWORD)strVal.length());
oFile.CloseFile();
} }
}
#else
#include <iostream>
#include <fstream> // instream
#include <unistd.h> // unlink
#include "../../../../DesktopEditor/common/Types.h"
#include "../../../../DesktopEditor/common/File.h"
namespace CDirectory
{
static void SaveToFile(std::wstring strFileName, std::wstring strXml)
{
std::string aContentUtf8 = stringWstingToUtf8String (strXml);
std::string aFileNameUtf8 = stringWstingToUtf8String (strFileName);
FILE *pFile = fopen(aFileNameUtf8.c_str(), "wb");
if (NULL == pFile)
{
throw std::exception();
}
fwrite (aContentUtf8.c_str() , sizeof(char), aContentUtf8.size(), pFile);
fclose (pFile);
}
static bool DeleteFile (std::wstring strFileName) static bool DeleteFile (std::wstring strFileName)
{ {
std::string aFileNameUtf8 = stringWstingToUtf8String (strFileName); return NSFile::CFileBinary::Remove(strFileName);
return 0 == unlink (aFileNameUtf8.c_str());
} }
static std::wstring ToString(DWORD val) static std::wstring ToString(DWORD val)
{ {
return std::to_wstring(val); return std::to_wstring(val);
} }
static bool CopyFile (std::wstring strExists, std::wstring strNew, LPVOID lpFunc = NULL, LPVOID lpData = NULL) static bool CopyFile (std::wstring strExists, std::wstring strNew)
{
bool bRes = true;
try
{ {
std::string stdstrFrom = stringWstingToUtf8String(strExists); return NSFile::CFileBinary::Copy(strExists, strNew);
std::string stdstrTo = stringWstingToUtf8String(strNew);
std::ifstream src (stdstrFrom.c_str(), std::ios::binary);
std::ofstream dst (stdstrTo.c_str(), std::ios::binary);
dst << src.rdbuf();
} }
catch (...)
{
bRes = false;
}
return bRes;
}
}
#endif
namespace CDirectory
{
static void WriteValueToNode(std::wstring strName, DWORD value, XmlUtils::CXmlWriter* pWriter) static void WriteValueToNode(std::wstring strName, DWORD value, XmlUtils::CXmlWriter* pWriter)
{ {
pWriter->WriteNodeBegin(strName); pWriter->WriteNodeBegin(strName);
pWriter->WriteString(CDirectory::ToString(value)); pWriter->WriteString(CDirectory::ToString(value));
pWriter->WriteNodeEnd(strName); pWriter->WriteNodeEnd(strName);
} }
static void WriteValueToNode(std::wstring strName, LONG value, XmlUtils::CXmlWriter* pWriter) static void WriteValueToNode(std::wstring strName, LONG value, XmlUtils::CXmlWriter* pWriter)
{ {
pWriter->WriteNodeBegin(strName); pWriter->WriteNodeBegin(strName);
...@@ -747,7 +539,6 @@ namespace CDirectory ...@@ -747,7 +539,6 @@ namespace CDirectory
return (LONG)(FixedPointToDouble(point) * base); return (LONG)(FixedPointToDouble(point) * base);
} }
static std::wstring BYTEArrayToString(BYTE* arr, size_t nCount) static std::wstring BYTEArrayToString(BYTE* arr, size_t nCount)
{ {
std::wstring str; std::wstring str;
......
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