Commit e299e59d authored by ElenaSubbotina's avatar ElenaSubbotina

fix write compaund files

parent 1e0f4d6f
...@@ -115,7 +115,8 @@ void CompoundFile::copy_stream(std::string streamNameOpen, std::string streamNam ...@@ -115,7 +115,8 @@ void CompoundFile::copy_stream(std::string streamNameOpen, std::string streamNam
POLE::Stream *streamNew = new POLE::Stream(storageOut, streamNameCreate, true, size_stream); POLE::Stream *streamNew = new POLE::Stream(storageOut, streamNameCreate, true, size_stream);
if (!streamNew) return; if (!streamNew) return;
unsigned char* data_stream = new unsigned char[size_stream]; unsigned char* data_stream = new unsigned char[size_stream + 64];
memset(data_stream, 0, size_stream + 64);
if (data_stream) if (data_stream)
{ {
stream->read(data_stream, size_stream); stream->read(data_stream, size_stream);
...@@ -140,16 +141,15 @@ void CompoundFile::copy( int indent, std::string path, POLE::Storage * storageOu ...@@ -140,16 +141,15 @@ void CompoundFile::copy( int indent, std::string path, POLE::Storage * storageOu
for( std::list<std::string>::iterator it = entries.begin(); it != entries.end(); it++ ) for( std::list<std::string>::iterator it = entries.begin(); it != entries.end(); it++ )
{ {
std::string name = *it; std::string fullname = path + *it;
std::string fullname = path + name;
if( storage_->isDirectory( fullname ) ) if ((it->at(0) >= 32) && (storage_->isDirectory( fullname ) ))
{ {
entries_dir.push_back(name); entries_dir.push_back(*it);
} }
else else
{ {
entries_files.push_front(name); entries_files.push_front(*it);
} }
} }
for( std::list<std::string>::iterator it = entries_dir.begin(); it != entries_dir.end(); it++ ) for( std::list<std::string>::iterator it = entries_dir.begin(); it != entries_dir.end(); it++ )
...@@ -158,8 +158,8 @@ void CompoundFile::copy( int indent, std::string path, POLE::Storage * storageOu ...@@ -158,8 +158,8 @@ void CompoundFile::copy( int indent, std::string path, POLE::Storage * storageOu
copy( indent + 1, fullname + "/", storageOut, bWithRoot, bSortFiles ); copy( indent + 1, fullname + "/", storageOut, bWithRoot, bSortFiles );
} }
//if (bSortFiles)
entries_files.sort(); entries_files.sort();
for( std::list<std::string>::iterator it = entries_files.begin(); it != entries_files.end(); it++ ) for( std::list<std::string>::iterator it = entries_files.begin(); it != entries_files.end(); it++ )
{ {
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
*/ */
#include "SheetExt.h" #include "SheetExt.h"
#include <Logic/Biff_structures/FrtHeader.h> #include "../Biff_structures/FrtHeader.h"
namespace XLS namespace XLS
{ {
...@@ -70,31 +70,5 @@ void SheetExt::readFields(CFRecord& record) ...@@ -70,31 +70,5 @@ void SheetExt::readFields(CFRecord& record)
} }
} }
int SheetExt::serialize(std::wostream & stream)
{
if (!sheetExtOptional.bEnabled) return 0;
CP_XML_WRITER(stream)
{
CP_XML_NODE(L"sheetPr")
{
if (!sheetExtOptional.fCondFmtCalc)
CP_XML_ATTR(L"enableFormatConditionsCalculation", false);
if (!sheetExtOptional.fNotPublished)
CP_XML_ATTR(L"published" ,false);
if (sheetExtOptional.color.xclrType.type == XColorType::XCLRRGB)
{
CP_XML_NODE(L"tabColor")
{
CP_XML_ATTR(L"rgb", sheetExtOptional.color.rgb.strARGB);
}
}
}
}
return 0;
}
} // namespace XLS } // namespace XLS
...@@ -32,13 +32,11 @@ ...@@ -32,13 +32,11 @@
#pragma once #pragma once
#include "BiffRecord.h" #include "BiffRecord.h"
#include <Logic/Biff_structures/SheetExtOptional.h> #include "../Biff_structures/SheetExtOptional.h"
namespace XLS namespace XLS
{ {
// Logical representation of SheetExt record in BIFF8
class SheetExt: public BiffRecord class SheetExt: public BiffRecord
{ {
BIFF_RECORD_DEFINE_TYPE_INFO(SheetExt) BIFF_RECORD_DEFINE_TYPE_INFO(SheetExt)
...@@ -48,13 +46,11 @@ public: ...@@ -48,13 +46,11 @@ public:
~SheetExt(); ~SheetExt();
BaseObjectPtr clone(); BaseObjectPtr clone();
void readFields(CFRecord& record); void readFields(CFRecord& record);
static const ElementType type = typeSheetExt; static const ElementType type = typeSheetExt;
int serialize(std::wostream & stream);
//----------------------------- //-----------------------------
_UINT32 cb; _UINT32 cb;
unsigned char icvPlain; unsigned char icvPlain;
......
...@@ -32,8 +32,7 @@ ...@@ -32,8 +32,7 @@
#pragma once #pragma once
#include "BiffStructure.h" #include "BiffStructure.h"
#include <Logic/Biff_structures/CFColor.h> #include "CFColor.h"
//#include <Logic/Biff_structures/BiffString.h>
namespace XLS namespace XLS
{ {
......
...@@ -150,7 +150,14 @@ const bool ChartSheetSubstream::loadContent(BinProcessor& proc) ...@@ -150,7 +150,14 @@ const bool ChartSheetSubstream::loadContent(BinProcessor& proc)
switch(type) switch(type)
{ {
case rt_WriteProtect: proc.optional<WriteProtect>(); break; case rt_WriteProtect: proc.optional<WriteProtect>(); break;
case rt_SheetExt: proc.optional<SheetExt>(); break; case rt_SheetExt:
{
if (proc.optional<SheetExt>())
{
m_SheetExt = elements_.back();
elements_.pop_back();
}
}break;
case rt_WebPub: proc.optional<WebPub>(); break; case rt_WebPub: proc.optional<WebPub>(); break;
case rt_HFPicture: proc.repeated<HFPicture>(0, 0); break; case rt_HFPicture: proc.repeated<HFPicture>(0, 0); break;
......
...@@ -82,6 +82,8 @@ public: ...@@ -82,6 +82,8 @@ public:
BaseObjectPtr m_PivotChartBits; BaseObjectPtr m_PivotChartBits;
BaseObjectPtr m_SBaseRef; BaseObjectPtr m_SBaseRef;
BaseObjectPtr m_CodeName;
BaseObjectPtr m_SheetExt;
private: private:
void recalc(CHARTFORMATS* charts); void recalc(CHARTFORMATS* charts);
......
...@@ -144,9 +144,17 @@ const bool MacroSheetSubstream::loadContent(BinProcessor& proc) ...@@ -144,9 +144,17 @@ const bool MacroSheetSubstream::loadContent(BinProcessor& proc)
proc.repeated<SORT>(0, 2); proc.repeated<SORT>(0, 2);
proc.optional<DxGCol>(); proc.optional<DxGCol>();
proc.optional<PHONETICINFO>(); proc.optional<PHONETICINFO>();
proc.optional<CodeName>(); if (proc.optional<CodeName>())
{
m_CodeName = elements_.back();
elements_.pop_back();
}
proc.repeated<CellWatch>(0, 0); proc.repeated<CellWatch>(0, 0);
proc.optional<SheetExt>(); if (proc.optional<SheetExt>())
{
m_SheetExt = elements_.back();
elements_.pop_back();
}
proc.repeated<FEAT>(0, 0); proc.repeated<FEAT>(0, 0);
proc.repeated<RECORD12>(0, 0); proc.repeated<RECORD12>(0, 0);
proc.mandatory<EOF_T>(); proc.mandatory<EOF_T>();
......
...@@ -54,6 +54,9 @@ public: ...@@ -54,6 +54,9 @@ public:
BaseObjectPtr m_GLOBALS; BaseObjectPtr m_GLOBALS;
BaseObjectPtr m_OBJECTS; BaseObjectPtr m_OBJECTS;
std::vector<BaseObjectPtr> m_arCUSTOMVIEW; std::vector<BaseObjectPtr> m_arCUSTOMVIEW;
BaseObjectPtr m_SheetExt;
BaseObjectPtr m_CodeName;
}; };
......
...@@ -503,7 +503,37 @@ void WorksheetSubstream::LoadHFPicture() ...@@ -503,7 +503,37 @@ void WorksheetSubstream::LoadHFPicture()
} }
} }
int WorksheetSubstream::serialize_format(std::wostream & strm)
{
SheetExt *sheet_ext = dynamic_cast<SheetExt*>(m_SheetExt.get());
CodeName *code_name = dynamic_cast<CodeName*>(m_CodeName.get());
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"sheetPr")
{
if (code_name)
{
CP_XML_ATTR(L"codeName", code_name->value);
}
if ((sheet_ext) && (sheet_ext->sheetExtOptional.bEnabled))
{
if (!sheet_ext->sheetExtOptional.fCondFmtCalc)
CP_XML_ATTR(L"enableFormatConditionsCalculation", false);
if (!sheet_ext->sheetExtOptional.fNotPublished)
CP_XML_ATTR(L"published" ,false);
if (sheet_ext->sheetExtOptional.color.xclrType.type == XColorType::XCLRRGB)
{
CP_XML_NODE(L"tabColor")
{
CP_XML_ATTR(L"rgb", sheet_ext->sheetExtOptional.color.rgb.strARGB);
}
}
}
}
}
return 0;
}
} // namespace XLS } // namespace XLS
...@@ -50,6 +50,7 @@ public: ...@@ -50,6 +50,7 @@ public:
BaseObjectPtr clone(); BaseObjectPtr clone();
virtual const bool loadContent (BinProcessor& proc); virtual const bool loadContent (BinProcessor& proc);
int serialize_format(std::wostream & _stream);
static const ElementType type = typeWorksheetSubstream; static const ElementType type = typeWorksheetSubstream;
......
...@@ -431,11 +431,9 @@ void XlsConverter::convert (XLS::WorksheetSubstream* sheet) ...@@ -431,11 +431,9 @@ void XlsConverter::convert (XLS::WorksheetSubstream* sheet)
{ {
sheet->m_Dimensions->serialize(xlsx_context->current_sheet().dimension()); sheet->m_Dimensions->serialize(xlsx_context->current_sheet().dimension());
} }
if (sheet->m_SheetExt)
{ sheet->serialize_format(xlsx_context->current_sheet().sheetProperties());
sheet->m_SheetExt->serialize(xlsx_context->current_sheet().sheetProperties());
// todooo + GLOBALS->WsBool
}
if (sheet->m_GLOBALS) if (sheet->m_GLOBALS)
{ {
XLS::GLOBALS * globals = dynamic_cast<XLS::GLOBALS *>(sheet->m_GLOBALS.get()); XLS::GLOBALS * globals = dynamic_cast<XLS::GLOBALS *>(sheet->m_GLOBALS.get());
......
...@@ -399,13 +399,13 @@ void Header::save( unsigned char* buffer ) ...@@ -399,13 +399,13 @@ void Header::save( unsigned char* buffer )
{ {
memset( buffer, 0, 0x4c ); memset( buffer, 0, 0x4c );
memcpy( buffer, pole_magic, 8 ); // ole signature memcpy( buffer, pole_magic, 8 ); // ole signature
writeU32( buffer + 8, 0 ); // unknown writeU32( buffer + 8, 0 ); // reserved must be zero
writeU32( buffer + 12, 0 ); // unknown writeU32( buffer + 12, 0 ); // reserved must be zero
writeU32( buffer + 16, 0 ); // unknown writeU32( buffer + 16, 0 ); // reserved must be zero
writeU16( buffer + 24, 0x003e ); // revision ? writeU16( buffer + 24, 0x003e ); // minor version of the format: 33
writeU16( buffer + 26, 3 ); // version ? writeU16( buffer + 26, 3 ); // major version (512 clasters)
writeU16( buffer + 28, 0xfffe ); // unknown writeU16( buffer + 28, 0xfffe ); // indicates Intel byte-ordering
writeU16( buffer + 0x1e, (uint32) b_shift ); writeU16( buffer + 0x1e, (uint32) b_shift ); //size of sectors in power-of-two
writeU16( buffer + 0x20, (uint32) s_shift ); writeU16( buffer + 0x20, (uint32) s_shift );
writeU32( buffer + 0x2c, (uint32) num_bat ); writeU32( buffer + 0x2c, (uint32) num_bat );
writeU32( buffer + 0x30, (uint32) dirent_start ); writeU32( buffer + 0x30, (uint32) dirent_start );
...@@ -415,8 +415,8 @@ void Header::save( unsigned char* buffer ) ...@@ -415,8 +415,8 @@ void Header::save( unsigned char* buffer )
writeU32( buffer + 0x44, (uint32) mbat_start ); writeU32( buffer + 0x44, (uint32) mbat_start );
writeU32( buffer + 0x48, (uint32) num_mbat ); writeU32( buffer + 0x48, (uint32) num_mbat );
for( unsigned int i=0; i<109; i++ ) for( unsigned int i = 0; i < 109; i++ )
writeU32( buffer + 0x4C+i*4, (uint32) bb_blocks[i] ); writeU32( buffer + 0x4C + i * 4, (uint32) bb_blocks[i] );
dirty = false; dirty = false;
} }
...@@ -711,7 +711,7 @@ int64 DirTree::parent( uint64 index ) ...@@ -711,7 +711,7 @@ int64 DirTree::parent( uint64 index )
for( uint64 j=0; j<entryCount(); j++ ) for( uint64 j=0; j<entryCount(); j++ )
{ {
std::vector<uint64> chi = children( j ); std::vector<uint64> chi = children( j );
for( unsigned i=0; i<chi.size();i++ ) for( size_t i=0; i<chi.size();i++ )
if( chi[i] == index ) if( chi[i] == index )
return j; return j;
} }
...@@ -748,7 +748,7 @@ std::string DirTree::fullName( uint64 index ) ...@@ -748,7 +748,7 @@ std::string DirTree::fullName( uint64 index )
// if create is true, a new entry is returned // if create is true, a new entry is returned
DirEntry* DirTree::entry( const std::string& name, bool create, int64 bigBlockSize, StorageIO *const io, int64 streamSize) DirEntry* DirTree::entry( const std::string& name, bool create, int64 bigBlockSize, StorageIO *const io, int64 streamSize)
{ {
if( !name.length() ) return (DirEntry*)0; if( name.empty() ) return (DirEntry*)0;
// quick check for "/" (that's root) // quick check for "/" (that's root)
if( name == "/" ) return entry( 0 ); if( name == "/" ) return entry( 0 );
...@@ -778,23 +778,21 @@ DirEntry* DirTree::entry( const std::string& name, bool create, int64 bigBlockSi ...@@ -778,23 +778,21 @@ DirEntry* DirTree::entry( const std::string& name, bool create, int64 bigBlockSi
{ {
// find among the children of index // find among the children of index
levelsLeft--; levelsLeft--;
uint64 child = 0; uint64 child = 0;
/*
// dima: this block is really inefficient // dima: this block is really inefficient
std::vector<unsigned> chi = children( index ); //std::vector<uint64> chi = children( index );
for( unsigned i = 0; i < chi.size(); i++ ) //for( size_t i = 0; i < chi.size(); i++ )
{ //{
DirEntry* ce = entry( chi[i] ); // DirEntry* ce = entry( chi[i] );
if( ce ) // if( ce )
if( ce->valid && ( ce->name.length()>1 ) ) // if( ce->valid && ( ce->name !="/" ) )
if( ce->name == *it ) { // if( ce->name == *it ) {
child = chi[i]; // child = chi[i];
break; // break;
} // }
} //}
*/
// dima: performance optimisation of the previous // dima: performance optimisation of the previous
uint64 closest = End; uint64 closest = End;
child = find_child( index, *it, closest ); child = find_child( index, *it, closest );
...@@ -804,14 +802,14 @@ DirEntry* DirTree::entry( const std::string& name, bool create, int64 bigBlockSi ...@@ -804,14 +802,14 @@ DirEntry* DirTree::entry( const std::string& name, bool create, int64 bigBlockSi
{ {
index = child; index = child;
} }
else else if( !create || !io->writeable)
{ {
std::vector<uint64> chi = children( index ); std::vector<uint64> chi = children( index );
for( unsigned i = 0; i < chi.size(); i++ ) for( size_t i = 0; i < chi.size(); i++ )
{ {
DirEntry* ce = entry( chi[i] ); DirEntry* ce = entry( chi[i] );
if( ce ) if( ce )
if( ce->valid && ( ce->name.length()>1 ) ) if( ce->valid && ( ce->name !="/" )/*( ce->name.length()>1 )*/ )
if( ce->name == *it ) if( ce->name == *it )
{ {
child = chi[i]; child = chi[i];
...@@ -1502,13 +1500,28 @@ void StorageIO::flush() ...@@ -1502,13 +1500,28 @@ void StorageIO::flush()
void StorageIO::close() void StorageIO::close()
{ {
if( !opened ) return; if( !opened ) return;
if (writeable)
{
file.seekg(0, std::ios::end );
filesize = static_cast<uint64>(file.tellg());
if (filesize % 512 != 0)
{
char padding[512];
memset(padding, 0, 512);
file.write(padding, (filesize / 512 + 1 ) * 512 - filesize);
fileCheck(file);
}
}
file.close(); file.close();
opened = false; opened = false;
std::list<Stream*>::iterator it; std::list<Stream*>::iterator it;
for( it = streams.begin(); it != streams.end(); ++it ) for( it = streams.begin(); it != streams.end(); ++it )
delete *it; delete *it;
streams.clear();
} }
...@@ -1595,8 +1608,7 @@ bool StorageIO::deleteLeaf(DirEntry *entry, const std::string& fullName) ...@@ -1595,8 +1608,7 @@ bool StorageIO::deleteLeaf(DirEntry *entry, const std::string& fullName)
return true; return true;
} }
uint64 StorageIO::loadBigBlocks( std::vector<uint64> blocks, uint64 StorageIO::loadBigBlocks( std::vector<uint64> blocks, unsigned char* data, uint64 maxlen )
unsigned char* data, uint64 maxlen )
{ {
// sentinel // sentinel
if( !data ) return 0; if( !data ) return 0;
...@@ -1624,8 +1636,7 @@ uint64 StorageIO::loadBigBlocks( std::vector<uint64> blocks, ...@@ -1624,8 +1636,7 @@ uint64 StorageIO::loadBigBlocks( std::vector<uint64> blocks,
return bytes; return bytes;
} }
uint64 StorageIO::loadBigBlock( uint64 block, uint64 StorageIO::loadBigBlock( uint64 block, unsigned char* data, uint64 maxlen )
unsigned char* data, uint64 maxlen )
{ {
// sentinel // sentinel
if( !data ) return 0; if( !data ) return 0;
...@@ -1651,7 +1662,7 @@ uint64 StorageIO::saveBigBlocks( std::vector<uint64> blocks, uint64 offset, unsi ...@@ -1651,7 +1662,7 @@ uint64 StorageIO::saveBigBlocks( std::vector<uint64> blocks, uint64 offset, unsi
// write block one by one, seems fast enough // write block one by one, seems fast enough
uint64 bytes = 0; uint64 bytes = 0;
for( unsigned int i=0; (i < blocks.size() ) & ( bytes<len ); i++ ) for( size_t i=0; (i < blocks.size() ) & ( bytes<len ); i++ )
{ {
uint64 block = blocks[i]; uint64 block = blocks[i];
uint64 pos = (bbat->blockSize * ( block+1 ) ) + offset; uint64 pos = (bbat->blockSize * ( block+1 ) ) + offset;
...@@ -1686,8 +1697,7 @@ uint64 StorageIO::saveBigBlock( uint64 block, uint64 offset, unsigned char* data ...@@ -1686,8 +1697,7 @@ uint64 StorageIO::saveBigBlock( uint64 block, uint64 offset, unsigned char* data
} }
// return number of bytes which has been read // return number of bytes which has been read
uint64 StorageIO::loadSmallBlocks( std::vector<uint64> blocks, uint64 StorageIO::loadSmallBlocks( std::vector<uint64> blocks, unsigned char* data, uint64 maxlen )
unsigned char* data, uint64 maxlen )
{ {
// sentinel // sentinel
if( !data ) return 0; if( !data ) return 0;
...@@ -1725,8 +1735,7 @@ uint64 StorageIO::loadSmallBlocks( std::vector<uint64> blocks, ...@@ -1725,8 +1735,7 @@ uint64 StorageIO::loadSmallBlocks( std::vector<uint64> blocks,
return bytes; return bytes;
} }
uint64 StorageIO::loadSmallBlock( uint64 block, uint64 StorageIO::loadSmallBlock( uint64 block, unsigned char* data, uint64 maxlen )
unsigned char* data, uint64 maxlen )
{ {
// sentinel // sentinel
if( !data ) return 0; if( !data ) return 0;
......
...@@ -189,17 +189,17 @@ bool AddFile2Storage(POLE::Storage* storage, std::string inFile, std::string nam ...@@ -189,17 +189,17 @@ bool AddFile2Storage(POLE::Storage* storage, std::string inFile, std::string nam
return true; return true;
} }
void AddDir2Storage(POLE::Storage* storage, std::wstring inDir, std::wstring name, int &nFolders, int &nFiles) void AddDir2Storage(POLE::Storage* storage, std::string inDir, std::string name, int &nFolders, int &nFiles)
{ {
WIN32_FIND_DATA ffd; WIN32_FIND_DATAA ffd;
HANDLE h; HANDLE h;
std::wstring inDirLcl = inDir + "*"; std::string inDirLcl = inDir + "*";
std::wstring outNameLcl = name; std::string outNameLcl = name;
const wchar_t *cInDir = inDirLcl.c_str(); const char *cInDir = inDirLcl.c_str();
h = FindFirstFile(cInDir, &ffd); h = FindFirstFileA(cInDir, &ffd);
if (h == INVALID_HANDLE_VALUE) if (h == INVALID_HANDLE_VALUE)
return; return;
nFolders++; nFolders++;
...@@ -249,7 +249,7 @@ void AddDir2Storage(POLE::Storage* storage, std::wstring inDir, std::wstring nam ...@@ -249,7 +249,7 @@ void AddDir2Storage(POLE::Storage* storage, std::wstring inDir, std::wstring nam
nFiles++; nFiles++;
} }
} }
while (FindNextFile(h, &ffd) != 0); while (FindNextFileA(h, &ffd) != 0);
} }
...@@ -264,7 +264,10 @@ void cmdOpen(std::list<std::string> &entries) ...@@ -264,7 +264,10 @@ void cmdOpen(std::list<std::string> &entries)
storage->close(); storage->close();
std::string ssName = entries.front(); std::string ssName = entries.front();
entries.pop_front(); entries.pop_front();
storage = new POLE::Storage(ssName.c_str());
std::wstring sName(ssName.begin(), ssName.end());
storage = new POLE::Storage(sName.c_str());
bool bWrite = false; bool bWrite = false;
bool bCreate = false; bool bCreate = false;
if (entries.size() > 0) if (entries.size() > 0)
...@@ -313,7 +316,7 @@ void cmdStats(std::list<std::string> &entries) ...@@ -313,7 +316,7 @@ void cmdStats(std::list<std::string> &entries)
{ {
if (storage) if (storage)
{ {
unsigned int nDirs, nUUDirs, nBBs, nUUBBs, nSBs, nUUSBs; unsigned __int64 nDirs, nUUDirs, nBBs, nUUBBs, nSBs, nUUSBs;
storage->GetStats(&nDirs, &nUUDirs, &nBBs, &nUUBBs, &nSBs, &nUUSBs); storage->GetStats(&nDirs, &nUUDirs, &nBBs, &nUUBBs, &nSBs, &nUUSBs);
printf("%d Directory Entries, %d unused.\n", nDirs, nUUDirs); printf("%d Directory Entries, %d unused.\n", nDirs, nUUDirs);
printf("%d Big Blocks, %d unused.\n", nBBs, nUUBBs); printf("%d Big Blocks, %d unused.\n", nBBs, nUUBBs);
...@@ -334,7 +337,7 @@ void cmdVisit(std::list<std::string> &entries) ...@@ -334,7 +337,7 @@ void cmdVisit(std::list<std::string> &entries)
} }
} }
void cmdExtract(std::list<std::wstring> &entries) void cmdExtract(std::list<std::string> &entries)
{ {
if (!storage) if (!storage)
std::cout << "No storage is opened." << std::endl; std::cout << "No storage is opened." << std::endl;
...@@ -342,9 +345,9 @@ void cmdExtract(std::list<std::wstring> &entries) ...@@ -342,9 +345,9 @@ void cmdExtract(std::list<std::wstring> &entries)
std::cout << "You must specify a path in the open storage to be extracted, and a destination file or folder." << std::endl; std::cout << "You must specify a path in the open storage to be extracted, and a destination file or folder." << std::endl;
else else
{ {
std::wstring ssPath = entries.front(); std::string ssPath = entries.front();
entries.pop_front(); entries.pop_front();
std::wstring filePath = entries.front(); std::string filePath = entries.front();
if (storage->isDirectory(ssPath)) if (storage->isDirectory(ssPath))
{ {
if (filePath[filePath.size()-1] != '/') if (filePath[filePath.size()-1] != '/')
...@@ -366,7 +369,7 @@ void cmdExtract(std::list<std::wstring> &entries) ...@@ -366,7 +369,7 @@ void cmdExtract(std::list<std::wstring> &entries)
} }
} }
void cmdAdd(std::list<std::wstring> &entries) void cmdAdd(std::list<std::string> &entries)
{ {
if (!storage) if (!storage)
std::cout << "No storage is opened." << std::endl; std::cout << "No storage is opened." << std::endl;
...@@ -378,9 +381,9 @@ void cmdAdd(std::list<std::wstring> &entries) ...@@ -378,9 +381,9 @@ void cmdAdd(std::list<std::wstring> &entries)
std::cout << "The specified storage node already exists - to save it again, first delete it." << std::endl; std::cout << "The specified storage node already exists - to save it again, first delete it." << std::endl;
else else
{ {
std::wstring ssPath = entries.front(); std::string ssPath = entries.front();
entries.pop_front(); entries.pop_front();
std::wstring filePath = entries.front(); std::string filePath = entries.front();
if (DirectoryExists(filePath.c_str())) if (DirectoryExists(filePath.c_str()))
{ {
if (filePath[filePath.size()-1] != '/') if (filePath[filePath.size()-1] != '/')
...@@ -481,67 +484,77 @@ std::list<std::string> clineParse(std::string inCmd) ...@@ -481,67 +484,77 @@ std::list<std::string> clineParse(std::string inCmd)
return outWords; return outWords;
} }
//int main(int argc, char* argv[]) int main(int argc, char* argv[])
//{ {
// if( argc > 1 ) //if( argc > 1 )
// { //{
// std::cout << "Usage:" << std::endl; // std::cout << "Usage:" << std::endl;
// std::cout << argv[0] << " This takes no arguments - type help in the console window for information. " << std::endl; // std::cout << argv[0] << " This takes no arguments - type help in the console window for information. " << std::endl;
// return 0; // return 0;
// } //}
// std::list<std::string> entries;
// std::string command;
// while (true) entries.push_back("open");
// { entries.push_back(argv[2]);
// std::getline(std::cin, command); entries.push_back("cw");
// std::list<std::string> entries = clineParse(command);
// if (entries.size() == 0) entries.push_back("add");
// continue; entries.push_back("/");
// std::string cmdWord = entries.front(); entries.push_back(argv[1]);
// entries.pop_front(); entries.push_back("close");
// if (cmdWord.compare("open") == 0)
// cmdOpen(entries); std::string command;
// else if (cmdWord.compare("visit") == 0) while (true)
// cmdVisit(entries); {
// else if (cmdWord.compare("extract") == 0) //std::getline(std::cin, command);
// cmdExtract(entries); //std::list<std::string> entries = clineParse(command);
// else if (cmdWord.compare("add") == 0) if (entries.size() == 0)
// cmdAdd(entries); continue;
// else if (cmdWord.compare("delete") == 0) std::string cmdWord = entries.front();
// cmdDelete(entries); entries.pop_front();
// else if (cmdWord.compare("stats") == 0) if (cmdWord.compare("open") == 0)
// cmdStats(entries); cmdOpen(entries);
// else if (cmdWord.compare("close") == 0) else if (cmdWord.compare("visit") == 0)
// cmdClose(entries); cmdVisit(entries);
// else if (cmdWord.compare("quit") == 0) else if (cmdWord.compare("extract") == 0)
// { cmdExtract(entries);
// if (cmdQuit(entries)) else if (cmdWord.compare("add") == 0)
// break; cmdAdd(entries);
// } else if (cmdWord.compare("delete") == 0)
// else cmdDelete(entries);
// cmdHelp(entries); else if (cmdWord.compare("stats") == 0)
// } cmdStats(entries);
//#if 0 else if (cmdWord.compare("close") == 0)
// std::list<std::string>::iterator it; cmdClose(entries);
// for( it = entries.begin(); it != entries.end(); ++it ) else if (cmdWord.compare("quit") == 0)
// std::cout << *it << std::endl; {
// open filename [modifier] (modifier can be r, w, c) if (cmdQuit(entries))
//visit [sspath] break;
//extract sspath fpath }
//add sspath fpath else
//delete sspath cmdHelp(entries);
//close }
// #if 0
// std::string indir = argv[1]; std::list<std::string>::iterator it;
// char* outfile = argv[2]; for( it = entries.begin(); it != entries.end(); ++it )
// if (indir[indir.length()-1] != '\\') std::cout << *it << std::endl;
// indir += "\\"; open filename [modifier] (modifier can be r, w, c)
// POLE::Storage* storage = new POLE::Storage(outfile); visit [sspath]
// storage->open(true, true); extract sspath fpath
// AddDir2Storage(storage, indir, "/"); add sspath fpath
// storage->close(); delete sspath
// storage->open(); close
// visit(0, storage, "/");
// storage->close(); std::string indir = argv[1];
//#endif char* outfile = argv[2];
//} if (indir[indir.length()-1] != '\\')
\ No newline at end of file indir += "\\";
POLE::Storage* storage = new POLE::Storage(outfile);
storage->open(true, true);
AddDir2Storage(storage, indir, "/");
storage->close();
storage->open();
visit(0, storage, "/");
storage->close();
#endif
}
\ No newline at end of file
...@@ -5,22 +5,27 @@ ...@@ -5,22 +5,27 @@
int _tmain(int argc, _TCHAR* argv[]) int _tmain(int argc, _TCHAR* argv[])
{ {
//std::wstring srcFileName = L"D:\\test\\_crypted\\test-password-2016.docx"; std::wstring srcFileName = L"D:\\test\\_crypted\\test-111.docx";
std::wstring dstFileName = srcFileName + L"-mycrypt.docx";
std::wstring dstFileName2 = dstFileName + L".oox";
//std::wstring dstFileName = srcFileName + L".oox"; //std::wstring dstFileName = srcFileName + L".oox";
//std::wstring dstFileName2 = dstFileName + L"-mycrypt.docx"; //std::wstring dstFileName2 = dstFileName + L"-mycrypt.docx";
std::wstring srcFileName = L"D:\\test\\_crypted\\test.docx";
std::wstring dstFileName2 = srcFileName + L"-mycrypt.docx";
std::wstring password = L"password132eqdqdwewedwdwwskskms09elzwewedskjsdnkjsdnjksjsnkcsdncskjdnss"; //std::wstring srcFileName = L"D:\\test\\_crypted\\test.docx";
//std::wstring dstFileName3 = srcFileName + L"-mycrypt1.docx";
std::wstring password = L"574446f1-6aa0-860a-0296-787a87a214bb";
ECMACryptFile crypt_file; ECMACryptFile crypt_file;
bool result, bDataIntegrity; bool result, bDataIntegrity;
//result = crypt_file.DecryptOfficeFile(srcFileName, dstFileName, password, bDataIntegrity); //result = crypt_file.DecryptOfficeFile(srcFileName, dstFileName, password, bDataIntegrity);
//result = crypt_file.EncryptOfficeFile(dstFileName, dstFileName2, password); //result = crypt_file.EncryptOfficeFile(dstFileName, dstFileName2, password);
result = crypt_file.EncryptOfficeFile(srcFileName, dstFileName2, password);
result = crypt_file.EncryptOfficeFile(srcFileName, dstFileName, password);
result = crypt_file.DecryptOfficeFile(dstFileName, dstFileName2, password, bDataIntegrity);
return 0; return 0;
} }
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