Commit 78779482 authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

XlsFile2

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63584 954022d7-b5bf-4e40-9824-e11837661b57
parent f6e08db4
......@@ -201,40 +201,43 @@ const std::string bin2str(const char* buf, const size_t nbuf)
}
const std::wstring guid2bstr(const GUID guid)
{
LPOLESTR guid_str;
if(S_OK != StringFromIID(guid, &guid_str))
{
// The only case is E_OUTOFMEMORY, so just throw anything
throw;// EXCEPT::LE::WhatIsTheFuck("StringFromIID failed.", "guid2bstr");
}
std::wstring guid_ret = guid_str;
CoTaskMemFree(guid_str);
const std::wstring guid2bstr(const _GUID_ guid)
{
//todooooo
//LPOLESTR guid_str;
//if(S_OK != StringFromIID(guid, &guid_str))
//{
// // The only case is E_OUTOFMEMORY, so just throw anything
// throw;// EXCEPT::LE::WhatIsTheFuck("StringFromIID failed.", "guid2bstr");
//}
std::wstring guid_ret;// = guid_str;
//CoTaskMemFree(guid_str);
return guid_ret;
}
const std::string guid2str(const GUID guid)
const std::string guid2str(const _GUID_ guid)
{
std::wstring s = guid2bstr(guid);
return std::string(s.begin(),s.end());
}
const bool bstr2guid(const std::wstring & guid_str, GUID& guid)
const bool bstr2guid(const std::wstring & guid_str, _GUID_& guid)
{
HRESULT res = IIDFromString((LPWSTR)(guid_str.c_str()), &guid);
if(S_OK != res)
{
switch(res)
{
case E_INVALIDARG:
return false;
case E_OUTOFMEMORY:
throw;// EXCEPT::LE::WhatIsTheFuck("IIDFromString failed.", "bstr2guid");
}
}
//todoooo
//HRESULT res = IIDFromString((LPWSTR)(guid_str.c_str()), &guid);
//if(S_OK != res)
//{
// switch(res)
// {
// case E_INVALIDARG:
// return false;
// case E_OUTOFMEMORY:
// throw;// EXCEPT::LE::WhatIsTheFuck("IIDFromString failed.", "bstr2guid");
// }
//}
return true;
}
......
#pragma once
#include "guiddef.h"
#include "../../../Common/DocxFormat/Source/Base/Types_32.h"
typedef struct
{
_UINT32 Data1;
_UINT16 Data2;
_UINT16 Data3;
unsigned char Data4[ 8 ];
} _GUID_;
namespace XLS
{
......@@ -26,9 +34,9 @@ namespace STR
const std::wstring int2wstr(const int val, const int radix = 10);
const std::wstring double2str(const double val);
const std::string bin2str(const char* buf, const size_t nbuf);
const std::wstring guid2bstr(const GUID guid);
const std::string guid2str(const GUID guid);
const bool bstr2guid(const std::wstring & guid_str, GUID& guid);
const std::wstring guid2bstr(const _GUID_ guid);
const std::string guid2str(const _GUID_ guid);
const bool bstr2guid(const std::wstring & guid_str, _GUID_& guid);
const std::wstring int2hex_wstr(const int val, const size_t size_of = 4);
const std::wstring wchar_t2hex_str(const wchar_t val);
const std::wstring escapeUrlW(const std::wstring& str);
......
......@@ -110,26 +110,26 @@ public:
CFRecord& operator>>(unsigned char& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(unsigned short& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(unsigned int& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(long& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(double& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(GUID& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(unsigned int& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(long& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(double& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(_GUID_& val) { loadAnyData(val); return *this; };
//CFRecord& operator>>(unsigned int& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(short& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(char& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(short& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(char& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(bool& val);
CFRecord& operator>>(std::wstring & val);
CFRecord& operator<<(unsigned char& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(unsigned short& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(unsigned int& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(long& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(double& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(GUID& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(unsigned int& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(long& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(double& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(_GUID_& val) { storeAnyData(val); return *this; };
//CFRecord& operator<<(unsigned int& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(short& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(char& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(wchar_t& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(short& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(char& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(wchar_t& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(bool& val);
CFRecord& operator<<(std::wstring & val);
......
......@@ -11,20 +11,20 @@
namespace XLS
{;
CFStream::CFStream(IStream* stream)
: stream_(stream)
CFStream::CFStream(POLE::Stream* stream)
{
if(NULL == stream)
{
throw;// EXCEPT::RT::CompoundFileFormatError("Wrong IStream pointer (NULL)");
}
stream_ = stream;
}
CFStream::~CFStream()
{
stream_->Commit(0);
stream_->Release();
if (stream_) delete stream_;
stream_ = NULL;
}
......@@ -35,17 +35,11 @@ void CFStream::read(void* buf, const size_t size)
{
throw;// EXCEPT::RT::CompoundFileFormatError("Wrong buffer pointer (NULL)");
}
ULONG num_read = 0;
HRESULT hres = stream_->Read(buf, size, &num_read);
if(FAILED(hres))
{
std::wstringstream str;
str << L"Impossible to read " << size << L" unsigned chars from \"" << getStreamName() << L"\" stream";
throw;// EXCEPT::RT::CompoundFileFormatError(str.str(), hres);
}
POLE::uint64 num_read = stream_->read((unsigned char*)buf, size);
if(num_read < size)
{
throw;// EXCEPT::RT::EndOfStreamReached(getStreamName(), num_read, size);
throw;// EXCEPT::RT::EndOfStreamReached(stream_->fullName(), num_read, size);
}
// Tipa successful
}
......@@ -58,12 +52,11 @@ void CFStream::write(const void* buf, const size_t size)
{
throw;// EXCEPT::RT::CompoundFileFormatError("Wrong buffer pointer (NULL)");
}
ULONG num_written = 0;
HRESULT hres = stream_->Write(buf, size, &num_written);
if(FAILED(hres))
POLE::uint64 num_written = stream_->write((unsigned char*)buf, size);
if(num_written != size)
{
std::wstringstream str;
str << L"Impossible to write " << size << L" unsigned chars to \"" << getStreamName() << L"\" stream";
//std::wstringstream str;
//str << L"Impossible to write " << size << L" unsigned chars to \"" << stream_->fullName() << L"\" stream";
throw;// EXCEPT::RT::CompoundFileFormatError(str.str(), hres);
}
if(num_written < size)
......@@ -86,71 +79,39 @@ const bool CFStream::isEOF() const
// Stream pointer
const unsigned long CFStream::getStreamPointer() const
{
LARGE_INTEGER null_ptr;
null_ptr.QuadPart = 0;
ULARGE_INTEGER seek_ptr;
stream_->Seek(null_ptr, STREAM_SEEK_CUR, &seek_ptr);
return seek_ptr.QuadPart;
POLE::uint64 pos = stream_->tell();
return pos;
}
void CFStream::seekFromCurForward(const size_t offset)
{
LARGE_INTEGER seek_ptr;
seek_ptr.QuadPart = offset;
stream_->Seek(seek_ptr, STREAM_SEEK_CUR, NULL);
POLE::uint64 pos = offset + stream_->tell();
stream_->seek(pos);
}
void CFStream::seekFromBegin(const unsigned long offset)
{
LARGE_INTEGER seek_ptr;
seek_ptr.QuadPart = offset;
HRESULT result = stream_->Seek(seek_ptr, STREAM_SEEK_SET, NULL);
POLE::uint64 pos = offset;
stream_->seek(pos);
}
void CFStream::seekToEnd()
{
LARGE_INTEGER seek_ptr;
seek_ptr.QuadPart = 0;
HRESULT result = stream_->Seek(seek_ptr, STREAM_SEEK_END, NULL);
stream_->seek(stream_->size());
}
// Stream current size
const unsigned long CFStream::getStreamSize() const
{
STATSTG info;
stream_->Stat(&info, STATFLAG_DEFAULT);
return info.cbSize.QuadPart;
return stream_->size();
}
// Stream name
//const std::string CFStream::getStreamName() const
//{
// STATSTG info;
// HRESULT hres = stream_->Stat(&info, STATFLAG_DEFAULT);
// if(FAILED(hres))
// {
// Log::warning("Can't obtain the name of the Compound File stream");
// return "";
// }
// return static_cast<char*>(std::wstring (info.pwcsName));
//}
const std::wstring CFStream::getStreamName() const
{
STATSTG info;
HRESULT hres = stream_->Stat(&info, STATFLAG_DEFAULT);
if(FAILED(hres))
{
Log::warning("Can't obtain the name of the Compound File stream");
return L"";
}
return std::wstring (info.pwcsName);
}
void CFStream::writeAndApplyDelayedItems(void* buf, const size_t size, const ReceiverItems& receiver_items_from_record, const SourceItems& source_items_from_record)
{
appendDelayedItems(receiver_items_from_record, source_items_from_record);
......
#pragma once
#include "objidl.h"
#include "../../../Common/3dParty/pole/pole.h"
#include "CFRecordType.h"
#include "BinSmartPointers.h"
......@@ -12,7 +13,7 @@ namespace XLS
class CFStream
{
public:
CFStream(IStream* stream);
CFStream(POLE::Stream* stream);
~CFStream();
template<class Type>
......@@ -64,14 +65,11 @@ public:
void appendDelayedItems(const ReceiverItems& receiver_items_from_record, const SourceItems& source_items_from_record);
void applyDelayedItems();
private:
// Stream name
const std::wstring getStreamName() const;
private:
IStream* stream_;
CFStream::ReceiverItems receiver_items;
CFStream::SourceItems source_items;
POLE::Stream * stream_;
CFStream::ReceiverItems receiver_items;
CFStream::SourceItems source_items;
};
} // namespace XLS
......
......@@ -10,120 +10,94 @@ namespace XLS
CompoundFile::~CompoundFile()
{
storage_->Commit(0);
streams.clear();
storage_->Release();
if (storage_)delete storage_;
storage_ = NULL;
}
CompoundFile::CompoundFile(const std::wstring & file_path, const ReadWriteMode mode)
: rwMode(mode)
{
HRESULT hres = S_OK;
unsigned int grfMode = 0;
storage_ = new POLE::Storage(file_path.c_str());
if (storage_ == NULL) return;
switch(rwMode)
{
{
case cf_ReadMode:
hres = StgIsStorageFile(file_path.c_str());
switch(hres)
{
case S_FALSE:
throw;// EXCEPT::RT::CompoundFileFormatError("The specified file \"" + std::string(static_cast<char*>(file_path)) + "\" is not a valid Compound File.", hres);;
case STG_E_FILENOTFOUND:
throw;// EXCEPT::RT::CompoundFileFormatError("Not found the path \"" + std::string(static_cast<char*>(file_path)) + "\"", hres);;
}
grfMode = STGM_READ | STGM_DIRECT | STGM_SHARE_DENY_WRITE;
if(FAILED( hres = StgOpenStorage(file_path.c_str(), NULL, grfMode, NULL, 0, &storage_)))
{
throw;// EXCEPT::RT::CompoundFileFormatError("Error opening \"" + std::string(static_cast<char*>(file_path)) + "\"", hres);
}
break;
{
if (storage_->open(false, false) == false)
throw;
}break;
case cf_WriteMode:
grfMode = STGM_CREATE | STGM_READWRITE | STGM_SIMPLE | STGM_SHARE_EXCLUSIVE;
if(FAILED( hres = StgCreateStorageEx(file_path.c_str(), grfMode, STGFMT_STORAGE, 0, NULL, NULL,
IID_IStorage, reinterpret_cast<void**>(&storage_))))
{
throw;// EXCEPT::RT::CompoundFileFormatError("Error creating \"" + std::string(static_cast<char*>(file_path)) + "\"", hres);
}
break;
{
if (storage_->open(true, true) == false)
throw;
}break;
}
/*
IEnumSTATSTG* storageInfo = NULL;
if(FAILED(hres = storage_->EnumElements(0, 0, 0, &storageInfo)))
{
throw 1;
}
Log::info("The Compound File contains the following streams:");
STATSTG elem;
while(S_OK == storageInfo->Next(1, &elem, 0))
{
Log::info(std::string("name: \"") + static_cast<char*>(std::wstring (elem.pwcsName)) + "\" type: " + STR::int2str(elem.type) + " size: " +
STR::int2hex_wstr(elem.cbSize.HighPart) + STR::int2hex_wstr(elem.cbSize.LowPart));
}
*/
}
// Opens "Workbook" stream and returns the only reference
CFStreamPtr CompoundFile::getWorkbookStream()
{
return getNamedStream(L"Workbook");
return getNamedStream("Workbook");
}
// Creates "Workbook" stream and returns the only reference
CFStreamPtr CompoundFile::createWorkbookStream()
{
return createNamedStream(L"Workbook");
return createNamedStream("Workbook");
}
// Opens "SummaryInformation" stream and returns the only reference
CFStreamPtr CompoundFile::getSummaryInformationStream()
{
return getNamedStream(L"\005SummaryInformation");
return getNamedStream("\005SummaryInformation");
}
// Creates "SummaryInformation" stream and returns the only reference
CFStreamPtr CompoundFile::createSummaryInformationStream()
{
return createNamedStream(L"\005SummaryInformation");
return createNamedStream("\005SummaryInformation");
}
// Closes "SummaryInformation" stream
void CompoundFile::closeSummaryInformationStream()
{
return closeNamedStream(L"\005SummaryInformation");
return closeNamedStream("\005SummaryInformation");
}
// Opens "SummaryInformation" stream and returns the only reference
CFStreamPtr CompoundFile::getDocumentSummaryInformationStream()
{
return getNamedStream(L"\005DocumentSummaryInformation");
return getNamedStream("\005DocumentSummaryInformation");
}
// Creates "SummaryInformation" stream and returns the only reference
CFStreamPtr CompoundFile::createDocumentSummaryInformationStream()
{
return createNamedStream(L"\005DocumentSummaryInformation");
return createNamedStream("\005DocumentSummaryInformation");
}
// Closes "SummaryInformation" stream
void CompoundFile::closeDocumentSummaryInformationStream()
{
closeNamedStream(L"\005DocumentSummaryInformation");
closeNamedStream("\005DocumentSummaryInformation");
}
CFStreamPtr CompoundFile::getNamedStream(const std::wstring& name)
CFStreamPtr CompoundFile::getNamedStream(const std::string& name)
{
if(!streams[name])
{
......@@ -133,7 +107,7 @@ CFStreamPtr CompoundFile::getNamedStream(const std::wstring& name)
}
CFStreamPtr CompoundFile::createNamedStream(const std::wstring& name)
CFStreamPtr CompoundFile::createNamedStream(const std::string& name)
{
if(!streams[name])
{
......@@ -143,18 +117,17 @@ CFStreamPtr CompoundFile::createNamedStream(const std::wstring& name)
}
void CompoundFile::closeNamedStream(const std::wstring& name)
void CompoundFile::closeNamedStream(const std::string& name)
{
streams[name].reset();
}
// Opens a stream in the storage (shall be called not more than once per stream)
IStream* CompoundFile::openStream(const std::wstring & stream_name)
POLE::Stream* CompoundFile::openStream(const std::string & stream_name)
{
IStream* pStream = NULL;
HRESULT hres = storage_->OpenStream(stream_name.c_str(), NULL, STGM_READ | STGM_DIRECT | STGM_SHARE_EXCLUSIVE, NULL, &pStream );
if(FAILED(hres))
POLE::Stream* pStream = new POLE::Stream(storage_, stream_name);
if(pStream == NULL)
{
throw;// EXCEPT::RT::CompoundFileFormatError(std::string("Error opening \"") + static_cast<char*>(stream_name) + "\" stream", hres);
}
......@@ -163,11 +136,10 @@ IStream* CompoundFile::openStream(const std::wstring & stream_name)
// Creates a new stream in the storage
IStream* CompoundFile::createStream(const std::wstring & stream_name)
POLE::Stream* CompoundFile::createStream(const std::string & stream_name)
{
IStream* pStream = NULL;
HRESULT hres = storage_->CreateStream(stream_name.c_str(), STGM_READWRITE | STGM_SHARE_EXCLUSIVE, NULL, NULL, &pStream);
if(FAILED(hres))
POLE::Stream* pStream = new POLE::Stream(storage_, stream_name, true);
if(pStream == NULL)
{
throw;// EXCEPT::RT::CompoundFileFormatError(std::string("Error creating \"") + static_cast<char*>(stream_name) + "\" stream", hres);
}
......
#pragma once
#include "objidl.h"
#include "../../../Common/3dParty/pole/pole.h"
#include "BinSmartPointers.h"
#include <map>
......@@ -27,24 +28,24 @@ public:
CFStreamPtr getSummaryInformationStream();
CFStreamPtr createSummaryInformationStream();
void closeSummaryInformationStream();
void closeSummaryInformationStream();
CFStreamPtr getDocumentSummaryInformationStream();
CFStreamPtr createDocumentSummaryInformationStream();
void closeDocumentSummaryInformationStream();
void closeDocumentSummaryInformationStream();
private:
IStream* openStream (const std::wstring & stream_name); // Opens a stream in the storage (shall be called not more than once per stream)
IStream* createStream (const std::wstring & stream_name); // Creates a new stream in the storage
POLE::Stream* openStream (const std::string & stream_name); // Opens a stream in the storage (shall be called not more than once per stream)
POLE::Stream* createStream (const std::string & stream_name); // Creates a new stream in the storage
CFStreamPtr getNamedStream (const std::wstring& name);
CFStreamPtr createNamedStream (const std::wstring& name);
void closeNamedStream (const std::wstring& name);
CFStreamPtr getNamedStream (const std::string& name);
CFStreamPtr createNamedStream (const std::string& name);
void closeNamedStream (const std::string& name);
private:
std::map<std::wstring, CFStreamPtr> streams;
IStorage* storage_;
ReadWriteMode rwMode;
std::map<std::string, CFStreamPtr> streams;
POLE::Storage *storage_;
ReadWriteMode rwMode;
};
} // namespace XLS
......
......@@ -327,6 +327,14 @@
RelativePath="..\XlsFormat\Binary\CompoundFile.h"
>
</File>
<File
RelativePath="..\..\..\Common\3dParty\pole\pole.cpp"
>
</File>
<File
RelativePath="..\..\..\Common\3dParty\pole\pole.h"
>
</File>
</Filter>
<Filter
Name="Logic"
......
......@@ -283,14 +283,6 @@
RelativePath="..\..\..\Common\DocxFormat\Source\SystemUtility\FileSystem\Directory.cpp"
>
</File>
<File
RelativePath="..\..\..\Common\3dParty\pole\pole.cpp"
>
</File>
<File
RelativePath="..\..\..\Common\3dParty\pole\pole.h"
>
</File>
<File
RelativePath="..\common\simple_xml_writer.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