mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +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
|
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;
|
ECMACryptFile crypt_file;
|
||||||
bool result = false, bDataIntegrity = false;
|
bool result = false, bDataIntegrity = false;
|
||||||
|
|
||||||
std::wstring srcFileName = L"D:\\tests\\__53\\test123-1.rtf-my.docx";
|
std::wstring srcFileName = L"D:\\tests\\__63\\test-group-ole.ods-ms.xlsx";
|
||||||
std::wstring dstFileName = srcFileName + L"-mycrypt.docx";
|
std::wstring dstFileName = srcFileName + L"-mycrypt.xlsx";
|
||||||
std::wstring dstFileName2 = dstFileName + L".oox";
|
std::wstring dstFileName2 = dstFileName + L".oox";
|
||||||
|
|
||||||
//std::wstring dstFileName = srcFileName + L".oox";
|
//std::wstring dstFileName = srcFileName + L".oox";
|
||||||
@ -45,19 +45,22 @@ int _tmain(int argc, _TCHAR* argv[])
|
|||||||
//std::wstring dstFileName1 = srcFileName1 + L".oox";
|
//std::wstring dstFileName1 = srcFileName1 + L".oox";
|
||||||
//result = crypt_file.DecryptOfficeFile(srcFileName1, dstFileName1, password, bDataIntegrity);
|
//result = crypt_file.DecryptOfficeFile(srcFileName1, dstFileName1, password, bDataIntegrity);
|
||||||
|
|
||||||
|
|
||||||
result = crypt_file.EncryptOfficeFile(srcFileName, dstFileName, password, L"123456789");
|
result = crypt_file.EncryptOfficeFile(srcFileName, dstFileName, password, L"123456789");
|
||||||
//result = crypt_file.DecryptOfficeFile(dstFileName, dstFileName2, password, bDataIntegrity);
|
//result = crypt_file.DecryptOfficeFile(dstFileName, dstFileName2, password, bDataIntegrity);
|
||||||
|
|
||||||
//std::wstring addit_name = L"11111111111111111111111111111";
|
std::wstring addit_name = L"11111111111111111111111111111";
|
||||||
//
|
|
||||||
//std::string addit_info = crypt_file.ReadAdditional(srcFileName, addit_name);
|
|
||||||
|
|
||||||
//std::wstring temp = NSFile::CFileBinary::CreateTempFileWithUniqueName(L"", L"asd");
|
for (size_t i = 0; i < 100; ++i)
|
||||||
//
|
{
|
||||||
//addit_info += std::string(temp.begin(), temp.end());
|
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();
|
_CrtDumpMemoryLeaks();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -87,12 +87,15 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\Common\OfficeFileFormatChecker.h" />
|
<ClInclude Include="..\..\Common\OfficeFileFormatChecker.h" />
|
||||||
|
<ClInclude Include="..\..\OOXML\Base\unicode_util.h" />
|
||||||
|
<ClInclude Include="..\..\OOXML\Base\Unit.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\Common\3dParty\pole\pole.cpp" />
|
<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="..\..\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" />
|
<ClCompile Include="Test.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -9,6 +9,8 @@
|
|||||||
<ClInclude Include="..\..\Common\OfficeFileFormatChecker.h">
|
<ClInclude Include="..\..\Common\OfficeFileFormatChecker.h">
|
||||||
<Filter>Common</Filter>
|
<Filter>Common</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\OOXML\Base\unicode_util.h" />
|
||||||
|
<ClInclude Include="..\..\OOXML\Base\Unit.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\Common\OfficeFileFormatChecker2.cpp">
|
<ClCompile Include="..\..\Common\OfficeFileFormatChecker2.cpp">
|
||||||
@ -17,12 +19,9 @@
|
|||||||
<ClCompile Include="..\..\Common\3dParty\pole\pole.cpp">
|
<ClCompile Include="..\..\Common\3dParty\pole\pole.cpp">
|
||||||
<Filter>Common</Filter>
|
<Filter>Common</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\Common\DocxFormat\Source\Base\unicode_util.cpp">
|
|
||||||
<Filter>Common</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Test.cpp" />
|
<ClCompile Include="Test.cpp" />
|
||||||
<ClCompile Include="..\..\Common\DocxFormat\Source\Base\Unit.cpp">
|
<ClCompile Include="..\..\OOXML\Base\unicode_util.cpp" />
|
||||||
<Filter>Common</Filter>
|
<ClCompile Include="..\..\OOXML\Base\Unit.cpp" />
|
||||||
</ClCompile>
|
<ClCompile Include="..\..\MsBinaryFile\DocFile\MemoryStream.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</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)
|
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());
|
try
|
||||||
|
|
||||||
if (!pStorage)return false;
|
|
||||||
|
|
||||||
if (!pStorage->open(true, false))
|
|
||||||
{
|
{
|
||||||
|
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;
|
delete pStorage;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
POLE::Stream *pStream = new POLE::Stream(pStorage, addit_name, true, addit_info.size());
|
//POLE::Storage *pStorage = new POLE::Storage(file_name.c_str());
|
||||||
|
//
|
||||||
pStream->write((unsigned char*)addit_info.c_str(), addit_info.size());
|
//if (!pStorage)return false;
|
||||||
pStream->setSize(addit_info.size());
|
|
||||||
|
|
||||||
pStream->flush();
|
//if (!pStorage->open(true, false))
|
||||||
delete pStream;
|
//{
|
||||||
|
// delete pStorage;
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
|
||||||
pStorage->close();
|
//POLE::Stream *pStream = new POLE::Stream(pStorage, addit_name, true, addit_info.size());
|
||||||
delete pStorage;
|
//
|
||||||
|
//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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user