mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
fix bug #51001
This commit is contained in:
@ -103,7 +103,7 @@ std::shared_ptr<CFStream> CFStorage::GetStream(const std::wstring& streamName)
|
||||
}
|
||||
else
|
||||
{
|
||||
throw CFItemNotFound(L"Cannot find item [" + streamName + L"] within the current storage");
|
||||
return std::shared_ptr<CFStream>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -31,8 +31,8 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
ECMACryptFile crypt_file;
|
||||
bool result = false, bDataIntegrity = false;
|
||||
|
||||
std::wstring srcFileName = L"D:\\tests\\__53\\test123-1.rtf-my.docx";
|
||||
std::wstring dstFileName = srcFileName + L"-mycrypt.docx";
|
||||
std::wstring srcFileName = L"D:\\tests\\__63\\test-group-ole.ods-ms.xlsx";
|
||||
std::wstring dstFileName = srcFileName + L"-mycrypt.xlsx";
|
||||
std::wstring dstFileName2 = dstFileName + L".oox";
|
||||
|
||||
//std::wstring dstFileName = srcFileName + L".oox";
|
||||
@ -45,19 +45,22 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
//std::wstring dstFileName1 = srcFileName1 + L".oox";
|
||||
//result = crypt_file.DecryptOfficeFile(srcFileName1, dstFileName1, password, bDataIntegrity);
|
||||
|
||||
|
||||
result = crypt_file.EncryptOfficeFile(srcFileName, dstFileName, password, L"123456789");
|
||||
//result = crypt_file.DecryptOfficeFile(dstFileName, dstFileName2, password, bDataIntegrity);
|
||||
|
||||
//std::wstring addit_name = L"11111111111111111111111111111";
|
||||
//
|
||||
//std::string addit_info = crypt_file.ReadAdditional(srcFileName, addit_name);
|
||||
std::wstring addit_name = L"11111111111111111111111111111";
|
||||
|
||||
//std::wstring temp = NSFile::CFileBinary::CreateTempFileWithUniqueName(L"", L"asd");
|
||||
//
|
||||
//addit_info += std::string(temp.begin(), temp.end());
|
||||
for (size_t i = 0; i < 100; ++i)
|
||||
{
|
||||
std::string addit_info = crypt_file.ReadAdditional(dstFileName, addit_name);
|
||||
|
||||
//crypt_file.WriteAdditional(srcFileName, addit_name, addit_info);
|
||||
|
||||
std::wstring temp = NSFile::CFileBinary::CreateTempFileWithUniqueName(L"", L"asd");
|
||||
//
|
||||
addit_info += std::string(temp.begin(), temp.end());
|
||||
|
||||
crypt_file.WriteAdditional(dstFileName, addit_name, addit_info);
|
||||
}
|
||||
_CrtDumpMemoryLeaks();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -87,12 +87,15 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\Common\OfficeFileFormatChecker.h" />
|
||||
<ClInclude Include="..\..\OOXML\Base\unicode_util.h" />
|
||||
<ClInclude Include="..\..\OOXML\Base\Unit.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\Common\3dParty\pole\pole.cpp" />
|
||||
<ClCompile Include="..\..\Common\DocxFormat\Source\Base\unicode_util.cpp" />
|
||||
<ClCompile Include="..\..\Common\DocxFormat\Source\Base\Unit.cpp" />
|
||||
<ClCompile Include="..\..\Common\OfficeFileFormatChecker2.cpp" />
|
||||
<ClCompile Include="..\..\MsBinaryFile\DocFile\MemoryStream.cpp" />
|
||||
<ClCompile Include="..\..\OOXML\Base\unicode_util.cpp" />
|
||||
<ClCompile Include="..\..\OOXML\Base\Unit.cpp" />
|
||||
<ClCompile Include="Test.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
<ClInclude Include="..\..\Common\OfficeFileFormatChecker.h">
|
||||
<Filter>Common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\OOXML\Base\unicode_util.h" />
|
||||
<ClInclude Include="..\..\OOXML\Base\Unit.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\Common\OfficeFileFormatChecker2.cpp">
|
||||
@ -17,12 +19,9 @@
|
||||
<ClCompile Include="..\..\Common\3dParty\pole\pole.cpp">
|
||||
<Filter>Common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Common\DocxFormat\Source\Base\unicode_util.cpp">
|
||||
<Filter>Common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Test.cpp" />
|
||||
<ClCompile Include="..\..\Common\DocxFormat\Source\Base\Unit.cpp">
|
||||
<Filter>Common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\OOXML\Base\unicode_util.cpp" />
|
||||
<ClCompile Include="..\..\OOXML\Base\Unit.cpp" />
|
||||
<ClCompile Include="..\..\MsBinaryFile\DocFile\MemoryStream.cpp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@ -1143,26 +1143,49 @@ std::string ECMACryptFile::ReadAdditional(const std::wstring &file_name, const s
|
||||
}
|
||||
bool ECMACryptFile::WriteAdditional(const std::wstring &file_name, const std::wstring &addit_name, const std::string &addit_info)
|
||||
{
|
||||
POLE::Storage *pStorage = new POLE::Storage(file_name.c_str());
|
||||
|
||||
if (!pStorage)return false;
|
||||
|
||||
if (!pStorage->open(true, false))
|
||||
try
|
||||
{
|
||||
CFCPP::CompoundFile *pStorage = new CFCPP::CompoundFile(file_name, CFCPP::Update);
|
||||
if (!pStorage)return false;
|
||||
|
||||
std::shared_ptr<CFCPP::CFStream> pAddit = pStorage->RootStorage()->GetStream(addit_name);
|
||||
|
||||
if (!pAddit)
|
||||
{
|
||||
pAddit = pStorage->RootStorage()->AddStream(addit_name);
|
||||
}
|
||||
|
||||
pAddit->Write(addit_info.c_str(), 0, addit_info.size());
|
||||
|
||||
pStorage->Save(file_name);
|
||||
pStorage->Close();
|
||||
delete pStorage;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
POLE::Stream *pStream = new POLE::Stream(pStorage, addit_name, true, addit_info.size());
|
||||
|
||||
pStream->write((unsigned char*)addit_info.c_str(), addit_info.size());
|
||||
pStream->setSize(addit_info.size());
|
||||
//POLE::Storage *pStorage = new POLE::Storage(file_name.c_str());
|
||||
//
|
||||
//if (!pStorage)return false;
|
||||
|
||||
pStream->flush();
|
||||
delete pStream;
|
||||
//if (!pStorage->open(true, false))
|
||||
//{
|
||||
// delete pStorage;
|
||||
// return false;
|
||||
//}
|
||||
|
||||
pStorage->close();
|
||||
delete pStorage;
|
||||
//POLE::Stream *pStream = new POLE::Stream(pStorage, addit_name, true, addit_info.size());
|
||||
//
|
||||
//pStream->write((unsigned char*)addit_info.c_str(), addit_info.size());
|
||||
//pStream->setSize(addit_info.size());
|
||||
|
||||
//pStream->flush();
|
||||
//delete pStream;
|
||||
|
||||
//pStorage->close();
|
||||
//delete pStorage;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user