Commit 1d55b122 authored by ElenaSubbotina's avatar ElenaSubbotina

.

parent ac959e32
......@@ -65,9 +65,7 @@ namespace NSShapeImageGen
static bool _CopyFile(std::wstring strExists, std::wstring strNew, LPVOID lpFunc, LPVOID lpData)
{
//::DeleteFile(strNew);
//return ::CopyFileEx(strExists, strNew, lpFunc, lpData, false, 0);
return CDirectory::CopyFile (strExists, strNew, lpFunc, lpData);
return CDirectory::CopyFile (strExists, strNew);
}
enum ImageType
......@@ -369,7 +367,7 @@ namespace NSShapeImageGen
oInfo.m_eType = itJPG;
OOX::CPath pathSaveItem = m_strDstMedia + FILE_SEPARATOR_STR + oInfo.GetPath2();
CDirectory::CopyFile(strFileSrc, pathSaveItem.GetPath(), NULL, NULL);
CDirectory::CopyFile(strFileSrc, pathSaveItem.GetPath());
return true;
}
......@@ -382,7 +380,7 @@ namespace NSShapeImageGen
oInfo.m_eType = itPNG;
OOX::CPath pathSaveItem = m_strDstMedia + FILE_SEPARATOR_STR + oInfo.GetPath2();
CDirectory::CopyFile(strFileSrc, pathSaveItem.GetPath(), NULL, NULL);
CDirectory::CopyFile(strFileSrc, pathSaveItem.GetPath());
return true;
}
......@@ -408,7 +406,7 @@ namespace NSShapeImageGen
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)
......@@ -524,14 +522,14 @@ namespace NSShapeImageGen
if(bOle)
{
std::wstring sCopyOlePath = strSaveItemWE + L".bin";
CDirectory::CopyFile(strOleFile, sCopyOlePath, NULL, NULL);
CDirectory::CopyFile(strOleFile, sCopyOlePath);
}
if (bVector)
{
//copy source vector image
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);
if (oMetafile.LoadFromFile(strFileName.c_str()))
......
......@@ -38,8 +38,6 @@
#include "../Base/unicode_util.h"
#include "../Base/Types_32.h"
//по аналогии с /DesktopEditor/common/File.h только для CString
#ifndef COINIT_MULTITHREADED
#define COINIT_MULTITHREADED 0 //for win64 .... oO
#endif
......@@ -47,669 +45,463 @@
class CFile
{
private:
HRESULT _Open(const std::wstring& strFileName, bool bOpen = false, bool bCreate = false, bool bReadWrite = false)
{
HRESULT hRes = S_OK;
CloseFile();
HRESULT _Open(const std::wstring& strFileName, bool bOpen = false, bool bCreate = false, bool bReadWrite = false)
{
HRESULT hRes = S_OK;
CloseFile();
#if defined(_WIN32) || defined(_WIN32_WCE) ||defined(_WIN64)
wchar_t* pModeOpen;
wchar_t* pModeCreate;
if(bReadWrite)
{
pModeOpen = L"rb+";
pModeCreate = L"wb+";
}
else
{
pModeOpen = L"rb";
pModeCreate = L"wb";
}
if(NULL == m_pFile && bOpen)
m_pFile = _wfopen(strFileName.c_str(), pModeOpen);
if(NULL == m_pFile && bCreate)
m_pFile = _wfopen(strFileName.c_str(), pModeCreate);
wchar_t* pModeOpen;
wchar_t* pModeCreate;
if(bReadWrite)
{
pModeOpen = L"rb+";
pModeCreate = L"wb+";
}
else
{
pModeOpen = L"rb";
pModeCreate = L"wb";
}
if(NULL == m_pFile && bOpen)
m_pFile = _wfopen(strFileName.c_str(), pModeOpen);
if(NULL == m_pFile && bCreate)
m_pFile = _wfopen(strFileName.c_str(), pModeCreate);
#else
BYTE* pUtf8 = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strFileName.c_str(), strFileName.length(), pUtf8, lLen, false);
char* pModeOpen;
char* pModeCreate;
if(bReadWrite)
{
pModeOpen = "rb+";
pModeCreate = "wb+";
}
else
{
pModeOpen = "rb";
pModeCreate = "wb";
}
if(NULL == m_pFile && bOpen)
m_pFile = fopen((char*)pUtf8, pModeOpen);
if(NULL == m_pFile && bCreate)
m_pFile = fopen((char*)pUtf8, pModeCreate);
RELEASEARRAYOBJECTS(pUtf8);
BYTE* pUtf8 = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strFileName.c_str(), strFileName.length(), pUtf8, lLen, false);
char* pModeOpen;
char* pModeCreate;
if(bReadWrite)
{
pModeOpen = "rb+";
pModeCreate = "wb+";
}
else
{
pModeOpen = "rb";
pModeCreate = "wb";
}
if(NULL == m_pFile && bOpen)
m_pFile = fopen((char*)pUtf8, pModeOpen);
if(NULL == m_pFile && bCreate)
m_pFile = fopen((char*)pUtf8, pModeCreate);
RELEASEARRAYOBJECTS(pUtf8);
#endif
if (NULL == m_pFile)
if (NULL == m_pFile)
return S_FALSE;
fseek(m_pFile, 0, SEEK_END);
m_lFileSize = ftell(m_pFile);
fseek(m_pFile, 0, SEEK_SET);
fseek(m_pFile, 0, SEEK_END);
m_lFileSize = ftell(m_pFile);
fseek(m_pFile, 0, SEEK_SET);
m_lFilePosition = 0;
m_lFilePosition = 0;
if (0 < strFileName.length())
{
if (((wchar_t)'/') == strFileName[strFileName.length() - 1])
m_lFileSize = 0x7FFFFFFF;
}
if (0 < strFileName.length())
{
if (((wchar_t)'/') == strFileName[strFileName.length() - 1])
m_lFileSize = 0x7FFFFFFF;
}
unsigned int err = 0x7FFFFFFF;
unsigned int cur = (unsigned int)m_lFileSize;
if (err == cur)
{
CloseFile();
return S_FALSE;
}
unsigned int err = 0x7FFFFFFF;
unsigned int cur = (unsigned int)m_lFileSize;
if (err == cur)
{
CloseFile();
return S_FALSE;
}
return hRes;
}
return hRes;
}
public:
CFile()
{
m_pFile = NULL;
m_lFilePosition = 0;
m_lFileSize = 0;
}
virtual ~CFile()
{
CloseFile();
}
HRESULT OpenOrCreate(std::wstring strFileName, bool bOnlyOpen = false, bool bReadWrite = false)
{
return _Open(strFileName, true, true, true);
}
virtual HRESULT OpenFile(std::wstring FileName)
{
return _Open(FileName, true, false, false);
}
virtual HRESULT OpenFileRW(std::wstring FileName)
{
return _Open(FileName, true, false, true);
}
HRESULT ReadFile(BYTE* pData, DWORD nBytesToRead)
{
if (!m_pFile)
return S_FALSE;
SetPosition(m_lFilePosition);
DWORD dwSizeRead = (DWORD)fread((void*)pData, 1, nBytesToRead, m_pFile);
m_lFilePosition += dwSizeRead;
return S_OK;
}
HRESULT ReadFile2(BYTE* pData, DWORD nBytesToRead)
{
HRESULT hRes = ReadFile(pData, nBytesToRead);
//reverse bytes
for (size_t index = 0; index < nBytesToRead / 2; ++index)
{
BYTE temp = pData[index];
pData[index] = pData[nBytesToRead - index - 1];
pData[nBytesToRead - index - 1] = temp;
}
return S_OK;
}
HRESULT ReadFile3(void* pData, DWORD nBytesToRead)
{
return ReadFile((BYTE*)pData, nBytesToRead);
}
HRESULT WriteFile(void* pData, DWORD nBytesToWrite)
{
if (!m_pFile)
return S_FALSE;
size_t nCountWrite = fwrite((void*)pData, 1, nBytesToWrite, m_pFile);
m_lFilePosition += nBytesToWrite;
return S_OK;
}
HRESULT WriteFile2(void* pData, DWORD nBytesToWrite)
{
if (!m_pFile)
return S_FALSE;
BYTE* mem = new BYTE[nBytesToWrite];
memcpy(mem, pData, nBytesToWrite);
for (size_t index = 0; index < nBytesToWrite / 2; ++index)
{
BYTE temp = mem[index];
mem[index] = mem[nBytesToWrite - index - 1];
mem[nBytesToWrite - index - 1] = temp;
}
return WriteFile(mem, nBytesToWrite);
}
HRESULT CreateFile(std::wstring strFileName)
{
return _Open(strFileName, false, true, true);
}
HRESULT SetPosition( ULONG64 nPos )
{
if (m_pFile && nPos <= (ULONG)m_lFileSize)
{
m_lFilePosition = (long)nPos;
fseek(m_pFile, m_lFilePosition, SEEK_SET);
return S_OK;
}
else
{
return !m_pFile ? S_FALSE : S_OK;
}
}
LONG64 GetPosition()
{
return m_lFilePosition;
}
HRESULT SkipBytes(ULONG64 nCount)
{
return SetPosition(m_lFilePosition + nCount);
}
HRESULT CloseFile()
{
m_lFilePosition = 0;
m_lFileSize = 0;
if (m_pFile != NULL)
{
fclose(m_pFile);
m_pFile = NULL;
}
return S_OK;
}
ULONG64 GetFileSize()
{
return m_lFileSize;
}
HRESULT WriteReserved(DWORD dwCount)
{
BYTE* buf = new BYTE[dwCount];
memset(buf, 0, (size_t)dwCount);
HRESULT hr = WriteFile(buf, dwCount);
RELEASEARRAYOBJECTS(buf);
return hr;
}
HRESULT WriteReserved2(DWORD dwCount)
{
BYTE* buf = new BYTE[dwCount];
memset(buf, 0xFF, (size_t)dwCount);
HRESULT hr = WriteFile(buf, dwCount);
RELEASEARRAYOBJECTS(buf);
return hr;
}
HRESULT WriteReservedTo(DWORD dwPoint)
{
if ((DWORD)m_lFilePosition >= dwPoint)
return S_OK;
DWORD dwCount = dwPoint - (DWORD)m_lFilePosition;
BYTE* buf = new BYTE[dwCount];
memset(buf, 0, (size_t)dwCount);
HRESULT hr = WriteFile(buf, dwCount);
RELEASEARRAYOBJECTS(buf);
return hr;
}
HRESULT SkipReservedTo(DWORD dwPoint)
{
if ((DWORD)m_lFilePosition >= dwPoint)
return S_OK;
DWORD dwCount = dwPoint - (DWORD)m_lFilePosition;
return SkipBytes(dwCount);
}
LONG GetProgress()
{
if (0 >= m_lFileSize)
return -1;
double dVal = (double)(100 * m_lFilePosition);
LONG lProgress = (LONG)(dVal / m_lFileSize);
return lProgress;
}
void WriteStringUTF8(const std::wstring& strXml)
{
BYTE* pData = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strXml.c_str(), (LONG)strXml.length(), pData, lLen, false);
WriteFile(pData, lLen);
RELEASEARRAYOBJECTS(pData);
}
protected:
FILE* m_pFile;
CFile()
{
m_pFile = NULL;
m_lFilePosition = 0;
m_lFileSize = 0;
}
long m_lFilePosition;
long m_lFileSize;
};
namespace StreamUtils
{
static BYTE ReadBYTE(POLE::Stream* pStream)
{
if (pStream == NULL) return 0;
BYTE lMem = 0;
ULONG lReadByte = 0;
lReadByte = (ULONG)pStream->read(&lMem, 1);
if (lReadByte < 1)
{
lMem = 0;
}
return lMem;
}
static WORD ReadWORD(POLE::Stream* pStream)
{
if (pStream == NULL) return 0;
WORD lWord = 0;
BYTE pMem[2];
ULONG lReadByte = 0;
lReadByte = (ULONG)pStream->read(pMem, 2);
if (lReadByte == 2)
{
lWord = ((pMem[1] << 8) | pMem[0]);
}
return lWord;
}
static DWORD ReadDWORD(POLE::Stream* pStream)
{
if (pStream == NULL) return 0;
DWORD lDWord = 0;
BYTE pMem[4];
ULONG lReadByte = 0;
lReadByte = (ULONG)pStream->read(pMem, 4);
//#if defined(_DEBUG) && (defined(_WIN32) || defined(_WIN64))
// ATLASSERT(4 == lReadByte);
//#endif
if (lReadByte == 4)
{
lDWord = ((pMem[3] << 24) | (pMem[2] << 16) | (pMem[1] << 8) | pMem[0]);
}
return 0xFFFFFFFF & lDWord;
}
static SHORT ReadSHORT(POLE::Stream* pStream)
{
return (short)ReadWORD(pStream);
}
static LONG ReadLONG(POLE::Stream* pStream)
{
return (_INT32)ReadDWORD(pStream);
}
static FLOAT ReadFLOAT( POLE::Stream* pStream)
{
if (pStream == NULL) return 0;
FLOAT Value = 0.0f;
pStream->read ((unsigned char*) &Value, sizeof (FLOAT));
return Value;
}
static std::string ReadStringA(POLE::Stream* pStream, LONG lLen)
{
if (pStream == NULL) return ("");
char* pData = new char[lLen + 1];
ULONG lReadByte = 0;
lReadByte = (ULONG)pStream->read((unsigned char*)pData, lLen);
pData[lLen] = 0;
std::string str(pData);
delete[] pData;
return str;
}
static std::wstring ReadStringW(POLE::Stream* pStream, LONG lLen)
{
if (pStream == NULL) return _T("");
unsigned char* pData = new unsigned char[2 * (lLen + 1)];
memset (pData, 0, 2 * (lLen + 1));
ULONG lReadByte = 0;
lReadByte = (ULONG)pStream->read(pData, 2 * lLen);
if (sizeof(wchar_t) == 4)
{
ConversionResult eUnicodeConversionResult;
UTF32 *pStrUtf32 = new UTF32 [lLen + 1];
pStrUtf32[lLen] = 0 ;
virtual ~CFile()
{
CloseFile();
}
HRESULT OpenOrCreate(std::wstring strFileName, bool bOnlyOpen = false, bool bReadWrite = false)
{
return _Open(strFileName, true, true, true);
}
virtual HRESULT OpenFile(std::wstring FileName)
{
return _Open(FileName, true, false, false);
}
virtual HRESULT OpenFileRW(std::wstring FileName)
{
return _Open(FileName, true, false, true);
}
const UTF16 *pStrUtf16_Conv = (const UTF16 *) pData;
UTF32 *pStrUtf32_Conv = pStrUtf32;
HRESULT ReadFile(BYTE* pData, DWORD nBytesToRead)
{
if (!m_pFile)
return S_FALSE;
eUnicodeConversionResult = ConvertUTF16toUTF32 ( &pStrUtf16_Conv
, &pStrUtf16_Conv[lLen]
, &pStrUtf32_Conv
, &pStrUtf32 [lLen]
, strictConversion);
SetPosition(m_lFilePosition);
DWORD dwSizeRead = (DWORD)fread((void*)pData, 1, nBytesToRead, m_pFile);
m_lFilePosition += dwSizeRead;
return S_OK;
}
if (conversionOK != eUnicodeConversionResult)
{
delete [] pStrUtf32;
return _T("");
}
std::wstring res((wchar_t*)pStrUtf32, lLen);
if (pStrUtf32) delete [] pStrUtf32;
return res;
HRESULT ReadFile2(BYTE* pData, DWORD nBytesToRead)
{
HRESULT hRes = ReadFile(pData, nBytesToRead);
//reverse bytes
for (size_t index = 0; index < nBytesToRead / 2; ++index)
{
BYTE temp = pData[index];
pData[index] = pData[nBytesToRead - index - 1];
pData[nBytesToRead - index - 1] = temp;
}
else
{
std::wstring str((wchar_t*)pData);
delete[] pData;
return str;
}
}
static std::string ConvertCStringWToCStringA(std::wstring& strW)
{
std::string str_a(strW.begin(), strW.end());
return str_a;
}
static void StreamSeek(long lOffset, POLE::Stream* pStream)
{
if (pStream == NULL) return;
pStream->seek(lOffset);
}
static void StreamPosition(long& lPosition, POLE::Stream* pStream)
{
if (pStream == NULL) return ;
lPosition = (LONG)pStream->tell();
}
static void StreamSkip(long lCount, POLE::Stream* pStream)
{
if (pStream == NULL) return;
pStream->seek(pStream->tell() + lCount);
}
static void StreamSkipBack(long lCount, POLE::Stream* pStream)
{
if (pStream == NULL) return;
pStream->seek(pStream->tell()-lCount);
}
}
return S_OK;
}
HRESULT ReadFile3(void* pData, DWORD nBytesToRead)
{
return ReadFile((BYTE*)pData, nBytesToRead);
}
#if defined(_WIN32) || defined(_WIN64)
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)
HRESULT WriteFile(void* pData, DWORD nBytesToWrite)
{
::DeleteFile (strFileName.c_str());
return true;
if (!m_pFile)
return S_FALSE;
size_t nCountWrite = fwrite((void*)pData, 1, nBytesToWrite, m_pFile);
m_lFilePosition += nBytesToWrite;
return S_OK;
}
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)
{
int nLength = (int)strXml.length();
std::string saStr; saStr.reserve(nLength*3 + 1);
#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;
HRESULT WriteFile2(void* pData, DWORD nBytesToWrite)
{
if (!m_pFile)
return S_FALSE;
// set end string
pWStr[nLength] = 0;
BYTE* mem = new BYTE[nBytesToWrite];
memcpy(mem, pData, nBytesToWrite);
// Encoding ASCII to Unicode
MultiByteToWideChar(CP_ACP, 0, strXml, nLength, pWStr, nLength);
for (size_t index = 0; index < nBytesToWrite / 2; ++index)
{
BYTE temp = mem[index];
mem[index] = mem[nBytesToWrite - index - 1];
mem[nBytesToWrite - index - 1] = temp;
}
int nLengthW = (int)wcslen(pWStr);
return WriteFile(mem, nBytesToWrite);
}
// Encoding Unicode to UTF-8
WideCharToMultiByte(CP_UTF8, 0, pWStr, nLengthW + 1, saStr.GetBuffer(nLengthW*3 + 1), nLengthW*3, NULL, NULL);
saStr.ReleaseBuffer();
HRESULT CreateFile(std::wstring strFileName)
{
return _Open(strFileName, false, true, true);
}
HRESULT SetPosition( ULONG64 nPos )
{
if (m_pFile && nPos <= (ULONG)m_lFileSize)
{
m_lFilePosition = (long)nPos;
fseek(m_pFile, m_lFilePosition, SEEK_SET);
return S_OK;
}
else
{
return !m_pFile ? S_FALSE : S_OK;
}
}
LONG64 GetPosition()
{
return m_lFilePosition;
}
HRESULT SkipBytes(ULONG64 nCount)
{
return SetPosition(m_lFilePosition + nCount);
}
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();
}
}
HRESULT CloseFile()
{
m_lFilePosition = 0;
m_lFileSize = 0;
#else
if (m_pFile != NULL)
{
fclose(m_pFile);
m_pFile = NULL;
}
return S_OK;
}
#include <iostream>
#include <fstream> // instream
#include <unistd.h> // unlink
ULONG64 GetFileSize()
{
return m_lFileSize;
}
#include "../../../../DesktopEditor/common/Types.h"
#include "../../../../DesktopEditor/common/File.h"
HRESULT WriteReserved(DWORD dwCount)
{
BYTE* buf = new BYTE[dwCount];
memset(buf, 0, (size_t)dwCount);
HRESULT hr = WriteFile(buf, dwCount);
RELEASEARRAYOBJECTS(buf);
return hr;
}
HRESULT WriteReserved2(DWORD dwCount)
{
BYTE* buf = new BYTE[dwCount];
memset(buf, 0xFF, (size_t)dwCount);
HRESULT hr = WriteFile(buf, dwCount);
RELEASEARRAYOBJECTS(buf);
return hr;
}
HRESULT WriteReservedTo(DWORD dwPoint)
{
if ((DWORD)m_lFilePosition >= dwPoint)
return S_OK;
DWORD dwCount = dwPoint - (DWORD)m_lFilePosition;
BYTE* buf = new BYTE[dwCount];
memset(buf, 0, (size_t)dwCount);
HRESULT hr = WriteFile(buf, dwCount);
RELEASEARRAYOBJECTS(buf);
return hr;
}
HRESULT SkipReservedTo(DWORD dwPoint)
{
if ((DWORD)m_lFilePosition >= dwPoint)
return S_OK;
namespace CDirectory
DWORD dwCount = dwPoint - (DWORD)m_lFilePosition;
return SkipBytes(dwCount);
}
LONG GetProgress()
{
if (0 >= m_lFileSize)
return -1;
double dVal = (double)(100 * m_lFilePosition);
LONG lProgress = (LONG)(dVal / m_lFileSize);
return lProgress;
}
void WriteStringUTF8(const std::wstring& strXml)
{
BYTE* pData = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strXml.c_str(), (LONG)strXml.length(), pData, lLen, false);
WriteFile(pData, lLen);
RELEASEARRAYOBJECTS(pData);
}
protected:
FILE* m_pFile;
long m_lFilePosition;
long m_lFileSize;
};
namespace StreamUtils
{
static BYTE ReadBYTE(POLE::Stream* pStream)
{
if (pStream == NULL) return 0;
static void SaveToFile(std::wstring strFileName, std::wstring strXml)
BYTE lMem = 0;
ULONG lReadByte = 0;
lReadByte = (ULONG)pStream->read(&lMem, 1);
if (lReadByte < 1)
{
lMem = 0;
}
return lMem;
}
static WORD ReadWORD(POLE::Stream* pStream)
{
std::string aContentUtf8 = stringWstingToUtf8String (strXml);
std::string aFileNameUtf8 = stringWstingToUtf8String (strFileName);
if (pStream == NULL) return 0;
FILE *pFile = fopen(aFileNameUtf8.c_str(), "wb");
WORD lWord = 0;
BYTE pMem[2];
ULONG lReadByte = 0;
if (NULL == pFile)
lReadByte = (ULONG)pStream->read(pMem, 2);
if (lReadByte == 2)
{
throw std::exception();
lWord = ((pMem[1] << 8) | pMem[0]);
}
fwrite (aContentUtf8.c_str() , sizeof(char), aContentUtf8.size(), pFile);
fclose (pFile);
return lWord;
}
static bool DeleteFile (std::wstring strFileName)
static DWORD ReadDWORD(POLE::Stream* pStream)
{
std::string aFileNameUtf8 = stringWstingToUtf8String (strFileName);
return 0 == unlink (aFileNameUtf8.c_str());
if (pStream == NULL) return 0;
DWORD lDWord = 0;
BYTE pMem[4];
ULONG lReadByte = 0;
lReadByte = (ULONG)pStream->read(pMem, 4);
//#if defined(_DEBUG) && (defined(_WIN32) || defined(_WIN64))
// ATLASSERT(4 == lReadByte);
//#endif
if (lReadByte == 4)
{
lDWord = ((pMem[3] << 24) | (pMem[2] << 16) | (pMem[1] << 8) | pMem[0]);
}
return 0xFFFFFFFF & lDWord;
}
static std::wstring ToString(DWORD val)
static SHORT ReadSHORT(POLE::Stream* pStream)
{
return std::to_wstring(val);
return (short)ReadWORD(pStream);
}
static LONG ReadLONG(POLE::Stream* pStream)
{
return (_INT32)ReadDWORD(pStream);
}
static FLOAT ReadFLOAT( POLE::Stream* pStream)
{
if (pStream == NULL) return 0;
FLOAT Value = 0.0f;
pStream->read ((unsigned char*) &Value, sizeof (FLOAT));
return Value;
}
static std::string ReadStringA(POLE::Stream* pStream, LONG lLen)
{
if (pStream == NULL) return ("");
char* pData = new char[lLen + 1];
ULONG lReadByte = 0;
lReadByte = (ULONG)pStream->read((unsigned char*)pData, lLen);
pData[lLen] = 0;
std::string str(pData);
static bool CopyFile (std::wstring strExists, std::wstring strNew, LPVOID lpFunc = NULL, LPVOID lpData = NULL)
delete[] pData;
return str;
}
static std::wstring ReadStringW(POLE::Stream* pStream, LONG lLen)
{
bool bRes = true;
try
if (pStream == NULL) return _T("");
unsigned char* pData = new unsigned char[2 * (lLen + 1)];
memset (pData, 0, 2 * (lLen + 1));
ULONG lReadByte = 0;
lReadByte = (ULONG)pStream->read(pData, 2 * lLen);
if (sizeof(wchar_t) == 4)
{
std::string stdstrFrom = stringWstingToUtf8String(strExists);
std::string stdstrTo = stringWstingToUtf8String(strNew);
std::ifstream src (stdstrFrom.c_str(), std::ios::binary);
std::ofstream dst (stdstrTo.c_str(), std::ios::binary);
ConversionResult eUnicodeConversionResult;
UTF32 *pStrUtf32 = new UTF32 [lLen + 1];
pStrUtf32[lLen] = 0 ;
dst << src.rdbuf();
const UTF16 *pStrUtf16_Conv = (const UTF16 *) pData;
UTF32 *pStrUtf32_Conv = pStrUtf32;
eUnicodeConversionResult = ConvertUTF16toUTF32 ( &pStrUtf16_Conv
, &pStrUtf16_Conv[lLen]
, &pStrUtf32_Conv
, &pStrUtf32 [lLen]
, strictConversion);
if (conversionOK != eUnicodeConversionResult)
{
delete [] pStrUtf32;
return _T("");
}
std::wstring res((wchar_t*)pStrUtf32, lLen);
if (pStrUtf32) delete [] pStrUtf32;
return res;
}
catch (...)
else
{
bRes = false;
std::wstring str((wchar_t*)pData);
delete[] pData;
return str;
}
return bRes;
}
static std::string ConvertCStringWToCStringA(std::wstring& strW)
{
std::string str_a(strW.begin(), strW.end());
return str_a;
}
static void StreamSeek(long lOffset, POLE::Stream* pStream)
{
if (pStream == NULL) return;
pStream->seek(lOffset);
}
static void StreamPosition(long& lPosition, POLE::Stream* pStream)
{
if (pStream == NULL) return ;
lPosition = (LONG)pStream->tell();
}
static void StreamSkip(long lCount, POLE::Stream* pStream)
{
if (pStream == NULL) return;
pStream->seek(pStream->tell() + lCount);
}
static void StreamSkipBack(long lCount, POLE::Stream* pStream)
{
if (pStream == NULL) return;
pStream->seek(pStream->tell()-lCount);
}
}
#endif
namespace CDirectory
{
static void SaveToFile(std::wstring strFileName, std::wstring strXml)
{
NSFile::CFileBinary file;
file.CreateFileW(strFileName);
file.WriteStringUTF8(strXml);
file.CloseFile();
}
static bool DeleteFile (std::wstring strFileName)
{
return NSFile::CFileBinary::Remove(strFileName);
}
static std::wstring ToString(DWORD val)
{
return std::to_wstring(val);
}
static bool CopyFile (std::wstring strExists, std::wstring strNew)
{
return NSFile::CFileBinary::Copy(strExists, strNew);
}
static void WriteValueToNode(std::wstring strName, DWORD value, XmlUtils::CXmlWriter* pWriter)
{
pWriter->WriteNodeBegin(strName);
pWriter->WriteString(CDirectory::ToString(value));
pWriter->WriteNodeEnd(strName);
}
static void WriteValueToNode(std::wstring strName, LONG value, XmlUtils::CXmlWriter* pWriter)
{
pWriter->WriteNodeBegin(strName);
std::wstring strLONG = std::to_wstring(value);
std::wstring strLONG = std::to_wstring(value);
pWriter->WriteString(strLONG);
pWriter->WriteString(strLONG);
pWriter->WriteNodeEnd(strName);
}
static void WriteValueToNode(std::wstring strName, std::wstring value, XmlUtils::CXmlWriter* pWriter)
......@@ -747,7 +539,6 @@ namespace CDirectory
return (LONG)(FixedPointToDouble(point) * base);
}
static std::wstring BYTEArrayToString(BYTE* arr, size_t nCount)
{
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