Merge remote-tracking branch 'origin/feature/lib_cfcpp3' into develop

fix
This commit is contained in:
Elena.Subbotina
2022-10-31 19:56:31 +03:00
48 changed files with 902 additions and 640 deletions

View File

@ -39,6 +39,7 @@
typedef unsigned __int32 _UINT32;
typedef unsigned __int64 _UINT64;
#elif __linux__
#include "stdint.h"
typedef int16_t _INT16;
typedef int32_t _INT32;
typedef int64_t _INT64;

View File

@ -219,6 +219,8 @@ namespace XmlUtils
catch(...)
{
}
return 0;
}
AVSINLINE static double GetDouble (const std::wstring& string)
{

View File

@ -30,15 +30,19 @@
<ClInclude Include="guid.h" />
<ClInclude Include="header.h" />
<ClInclude Include="idirectoryentry.h" />
<ClInclude Include="RBTree\action.h" />
<ClInclude Include="RBTree\irbnode.h" />
<ClInclude Include="RBTree\rbtree.h" />
<ClInclude Include="RBTree\rbtreeexception.h" />
<ClInclude Include="sector.h" />
<ClInclude Include="sectorcollection.h" />
<ClInclude Include="slist.h" />
<ClInclude Include="stream.h" />
<ClInclude Include="streamrw.h" />
<ClInclude Include="streamview.h" />
<ClInclude Include="Stream\fstream_utils.h" />
<ClInclude Include="Stream\fstream_wrapper.h" />
<ClInclude Include="Stream\stream.h" />
<ClInclude Include="Stream\stream_utils.h" />
<ClInclude Include="svector.h" />
</ItemGroup>
<ItemGroup>
@ -51,9 +55,10 @@
<ClCompile Include="RBTree\rbtree.cpp" />
<ClCompile Include="sector.cpp" />
<ClCompile Include="sectorcollection.cpp" />
<ClCompile Include="stream.cpp" />
<ClCompile Include="streamrw.cpp" />
<ClCompile Include="streamview.cpp" />
<ClCompile Include="Stream\fstream_utils.cpp" />
<ClCompile Include="Stream\stream_utils.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{FA22BAB4-E93E-459D-8A5F-16764FBBED40}</ProjectGuid>

View File

@ -9,13 +9,12 @@
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="RBTree">
<UniqueIdentifier>{2e4c5c99-c3a8-43af-8b70-e1527104287a}</UniqueIdentifier>
</Filter>
<Filter Include="Stream">
<UniqueIdentifier>{2486cb73-0ee3-4336-80d0-0b9b06b62860}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="cfexception.h">
@ -60,9 +59,6 @@
<ClInclude Include="slist.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stream.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="streamrw.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -81,6 +77,21 @@
<ClInclude Include="RBTree\rbtreeexception.h">
<Filter>RBTree</Filter>
</ClInclude>
<ClInclude Include="RBTree\action.h">
<Filter>RBTree</Filter>
</ClInclude>
<ClInclude Include="Stream\fstream_utils.h">
<Filter>Stream</Filter>
</ClInclude>
<ClInclude Include="Stream\fstream_wrapper.h">
<Filter>Stream</Filter>
</ClInclude>
<ClInclude Include="Stream\stream.h">
<Filter>Stream</Filter>
</ClInclude>
<ClInclude Include="Stream\stream_utils.h">
<Filter>Stream</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="cfitem.cpp">
@ -107,9 +118,6 @@
<ClCompile Include="sectorcollection.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="stream.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="streamrw.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -119,5 +127,11 @@
<ClCompile Include="RBTree\rbtree.cpp">
<Filter>RBTree</Filter>
</ClCompile>
<ClCompile Include="Stream\fstream_utils.cpp">
<Filter>Stream</Filter>
</ClCompile>
<ClCompile Include="Stream\stream_utils.cpp">
<Filter>Stream</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,40 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include <functional>
namespace RedBlackTree
{
template <class T>
using Action = std::function<void(T)>;
}

View File

@ -1,7 +1,39 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include <memory>
#include <string>
#include "../../DocxFormat/Source/Base/Types_32.h"
namespace RedBlackTree
@ -36,7 +68,7 @@ public:
virtual void AssignValueTo(PIRBNode other) = 0;
virtual int CompareTo(const PIRBNode& other) const = 0;
virtual _INT32 CompareTo(const PIRBNode& other) const = 0;
virtual std::wstring ToString() const = 0;
};
}

View File

@ -79,7 +79,7 @@ void RBTree::Insert(PIRBNode newNode)
PIRBNode node = getRoot();
while (true)
{
int compResult = newNode->CompareTo(node);
auto compResult = newNode->CompareTo(node);
if (compResult == 0)
{
throw RBTreeDuplicatedItemException(L"RBNode " + newNode->ToString() + L" already exists in tree");
@ -178,7 +178,7 @@ PIRBNode RBTree::LookupNode(PIRBNode pattern)
while (node != nullptr)
{
int compResult = pattern->CompareTo(node);
auto compResult = pattern->CompareTo(node);
if (compResult == 0)
{

View File

@ -1,17 +1,44 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include "irbnode.h"
#include <iterator>
#include <functional>
#include <list>
#include "irbnode.h"
#include "action.h"
namespace RedBlackTree
{
template <class T>
using Action = std::function<void(T)>;
class RBTree
{
public:

View File

@ -1,3 +1,34 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include <exception>

View File

@ -0,0 +1,77 @@
#include "fstream_utils.h"
#include "fstream_wrapper.h"
#include "stream_utils.h"
#include "../../../DesktopEditor/common/File.h"
#include <algorithm>
using namespace CFCPP;
CFCPP::Stream CFCPP::OpenFileStream(const std::wstring & filename, bool bRewrite, bool trunc)
{
BYTE* pUtf8 = nullptr;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(filename.c_str(), filename.length(), pUtf8, lLen, false);
std::string utf8filename((char*)pUtf8, lLen);
delete [] pUtf8;
return OpenFileStream(utf8filename, bRewrite, trunc);
}
CFCPP::Stream CFCPP::OpenFileStream(const std::string & filename, bool bRewrite, bool trunc)
{
CFCPP::Stream st;
// it's not good, but otherwise file doesn't create or if use ios::app, then the seek for writing will be blocked
if (bRewrite)
std::fstream create(filename, std::ios::app | std::ios::out);
if (trunc && bRewrite)
st.reset(new FStreamWrapper(filename, std::ios::binary | std::ios::in | std::ios::out | std::ios::trunc));
else if (bRewrite)
st.reset(new FStreamWrapper(filename, std::ios::binary | std::ios::in | std::ios::out));
else
st.reset(new FStreamWrapper(filename, std::ios::binary | std::ios::in));
return st;
}
_INT64 CFCPP::FileLenght(const std::wstring & filename)
{
auto stream = OpenFileStream(filename);
auto lenght = Length(stream);
stream->close();
return lenght;
}
ULONG64 CFCPP::FileFNVHash(const std::wstring & filename, _INT64 len, _INT64 offset)
{
auto stream = OpenFileStream(filename);
if (!IsOpen(stream))
return 0;
if (len < 0)
len = Length(stream);
stream->seek(offset);
ULONG64 h = 2166136261;
constexpr _INT64 bufLen = 0x2000;
char buffer[bufLen];
while (len > 0)
{
memset(buffer, 0, bufLen);
_INT64 readLen = std::min(bufLen, len);
stream->read(buffer, readLen);
_INT64 i;
for (i = 0; i < readLen; i++)
h = (h * 16777619) ^ buffer[i];
len -= readLen;
}
return h;
}

View File

@ -0,0 +1,44 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include "stream.h"
namespace CFCPP
{
Stream OpenFileStream(const std::wstring & filename, bool bRewrite = false, bool trunc = false);
Stream OpenFileStream(const std::string & filename, bool bRewrite = false, bool trunc = false);
_INT64 FileLenght(const std::wstring & filename);
ULONG64 FileFNVHash(const std::wstring & filename, _INT64 len = -1, _INT64 offset = 0);
}

View File

@ -0,0 +1,69 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include <fstream>
#include "stream.h"
namespace CFCPP
{
class FStreamWrapper : public IStream, public std::fstream
{
public:
FStreamWrapper(std::string filename, std::ios_base::openmode openmode) :
std::fstream(filename, openmode) {}
inline _INT64 tell() override {
return std::fstream::tellg();
}
inline _INT64 seek(_INT64 offset, std::ios_base::seekdir mode = std::ios::beg) override {
std::fstream::seekp(offset, mode);
std::fstream::seekg(offset, mode);
return tell();
}
inline _INT64 read(char* buffer, _INT64 len) override {
std::fstream::read(buffer, len);
return tell();
}
inline void write (const char* buffer, _INT64 len) override {
std::fstream::write(buffer, len);
}
inline void flush() override {
std::fstream::flush();
}
inline void close() override {
std::fstream::close();
}
};
}

View File

@ -0,0 +1,54 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include <memory>
#include <ios>
#include "../../DocxFormat/Source/Base/Types_32.h"
#include "../../../DesktopEditor/common/Types.h"
namespace CFCPP
{
class IStream
{
public:
virtual _INT64 tell() = 0;
virtual _INT64 seek(_INT64 offset, std::ios_base::seekdir mode = std::ios::beg) = 0;
virtual _INT64 read(char* buffer, _INT64 len) = 0;
virtual void write (const char* buffer, _INT64 len) = 0;
virtual void flush() = 0;
virtual void close() = 0;
};
using Stream = std::shared_ptr<IStream>;
}

View File

@ -0,0 +1,58 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "stream_utils.h"
#include "fstream_wrapper.h"
using namespace CFCPP;
_INT64 CFCPP::Length(const CFCPP::Stream& st)
{
if (st.get() == nullptr)
return 0;
auto curPos = st->tell();
st->seek(0, std::ios_base::end);
auto ssize = st->tell();
st->seek(curPos);
return ssize;
}
bool CFCPP::IsOpen(const Stream &st)
{
if (std::dynamic_pointer_cast<FStreamWrapper>(st))
return std::static_pointer_cast<FStreamWrapper>(st)->is_open();
return false;
}

View File

@ -0,0 +1,41 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include "stream.h"
namespace CFCPP
{
bool IsOpen(const Stream& st);
_INT64 Length(const Stream& st);
}

View File

@ -13,6 +13,8 @@ include(../base.pri)
SOURCES += \
RBTree/rbtree.cpp \
Stream/fstream_utils.cpp \
Stream/stream_utils.cpp \
cfitem.cpp \
cfstorage.cpp \
cfstream.cpp \
@ -21,14 +23,17 @@ SOURCES += \
header.cpp \
sector.cpp \
sectorcollection.cpp \
stream.cpp \
streamrw.cpp \
streamview.cpp
HEADERS += \
RBTree/action.h \
RBTree/irbnode.h \
RBTree/rbtree.h \
RBTree/rbtreeexception.h \
Stream/fstream_utils.h \
Stream/fstream_wrapper.h \
Stream/stream_utils.h \
cfexception.h \
cfitem.h \
cfstorage.h \
@ -43,7 +48,7 @@ HEADERS += \
sector.h \
sectorcollection.h \
slist.h \
stream.h \
Stream/stream.h \
streamrw.h \
streamview.h \
svector.h

View File

@ -37,7 +37,7 @@
using namespace CFCPP;
int CFItem::CompareTo(const CFItem &other) const
_INT32 CFItem::CompareTo(const CFItem &other) const
{
return dirEntry.lock()->CompareTo(std::dynamic_pointer_cast<RedBlackTree::IRBNode>(other.dirEntry.lock()));
}
@ -52,7 +52,7 @@ bool CFItem::operator!=(const CFItem &rightItem) const
return CompareTo(rightItem) != 0;
}
int CFItem::GetHashCode() const
_INT32 CFItem::GetHashCode() const
{
return dirEntry.lock()->GetHashCode();
}
@ -71,7 +71,7 @@ std::wstring CFItem::Name() const
return L"";
}
std::streamsize CFItem::size() const
_INT64 CFItem::size() const
{
return dirEntry.lock()->getSize();
}
@ -150,14 +150,14 @@ void CFItem::CheckDisposed() const
}
DataTime::DataTime(unsigned long long time)
DataTime::DataTime(_UINT64 time)
{
memcpy(data, reinterpret_cast<char*>(&time), 8);
}
unsigned long long DataTime::getUINT64()const
_UINT64 DataTime::getUINT64()const
{
unsigned long long timeStamp(0);
_UINT64 timeStamp(0);
memcpy(reinterpret_cast<char*>(&timeStamp), data, 8);
return timeStamp;

View File

@ -30,19 +30,18 @@
*
*/
#pragma once
#include "guid.h"
#include "cfexception.h" // Used by heirs
#include <memory>
#include <string>
#include <ios>
#include "../../DesktopEditor/common/Types.h"
namespace CFCPP
{
struct DataTime
{
DataTime(unsigned long long time);
unsigned long long getUINT64()const;
DataTime(_UINT64 time);
_UINT64 getUINT64()const;
char data[8] = {0,0,0,0,0,0,0,0};
};
@ -52,12 +51,12 @@ class IDirectoryEntry;
class CFItem : public std::enable_shared_from_this<CFItem>
{
public:
int CompareTo(const CFItem& other) const;
_INT32 CompareTo(const CFItem& other) const;
bool operator==(const CFItem &rightItem) const;
bool operator!=(const CFItem &rightItem) const;
int GetHashCode() const;
_INT32 GetHashCode() const;
std::wstring Name() const;
std::streamsize size() const;
_INT64 size() const;
bool IsStorage() const;
bool IsStream() const;
bool ISRoot() const;
@ -68,7 +67,7 @@ public:
_GUID_ getStorageCLSID() const;
void setStorageCLSID(_GUID_ value);
int CompareTo(const CFItem& other);
_INT32 CompareTo(const CFItem& other);
std::wstring ToString() const;
void setDirEntry(const std::weak_ptr<IDirectoryEntry> &newDirEntry);

View File

@ -35,6 +35,7 @@
#include "directoryentry.h"
#include "RBTree/rbtreeexception.h"
#include "RBTree/irbnode.h"
#include "RBTree/rbtree.h"
using namespace CFCPP;
using RedBlackTree::RBTree;
@ -365,7 +366,7 @@ void CFStorage::RenameItem(const std::wstring &oldItemName, const std::wstring &
}
}
std::shared_ptr<RBTree> CFStorage::LoadChildren(int SID)
std::shared_ptr<RBTree> CFStorage::LoadChildren(_INT32 SID)
{
std::shared_ptr<RBTree> childrenTree = compoundFile->GetChildrenTree(SID);

View File

@ -31,10 +31,13 @@
*/
#pragma once
#include "RBTree/rbtree.h"
#include "idirectoryentry.h"
#include "RBTree/action.h"
#include "cfstream.h"
namespace RedBlackTree
{
class RBTree;
}
namespace CFCPP
{
@ -60,10 +63,10 @@ public:
void Delete(const std::wstring& entryName);
void RenameItem(const std::wstring& oldItemName, const std::wstring& newItemName);
std::streamsize size() const {return CFItem::size();}
_INT64 size() const {return CFItem::size();}
private:
std::shared_ptr<RedBlackTree::RBTree> LoadChildren(int SID);
std::shared_ptr<RedBlackTree::RBTree> LoadChildren(_INT32 SID);
private:
std::shared_ptr<RedBlackTree::RBTree> children;

View File

@ -33,6 +33,7 @@
#include "cfexception.h"
#include "idirectoryentry.h"
#include "compoundfile_impl.h"
#include "Stream/stream_utils.h"
using namespace CFCPP;
@ -53,18 +54,18 @@ void CFStream::SetData(const std::vector<BYTE> &data)
compoundFile->WriteData(shared_from_this(), data);
}
void CFStream::Write(const std::vector<BYTE> &data, std::streamsize position)
void CFStream::Write(const std::vector<BYTE> &data, _INT64 position)
{
Write(data, position, 0, data.size());
}
void CFStream::Write(const std::vector<BYTE> &data, std::streamsize position, int offset, int count)
void CFStream::Write(const std::vector<BYTE> &data, _INT64 position, _INT32 offset, _INT32 count)
{
CheckDisposed();
compoundFile->WriteData(shared_from_this(), data, position, offset, count);
}
void CFStream::Write(const char *data, std::streamsize position, int count)
void CFStream::Write(const char *data, _INT64 position, _INT32 count)
{
CheckDisposed();
compoundFile->WriteData(shared_from_this(), data, position, count);
@ -90,13 +91,13 @@ std::vector<BYTE> CFStream::getData() const
return compoundFile->GetData(this);
}
int CFStream::Read(std::vector<BYTE> &buffer, std::streamsize position, int count)
_INT32 CFStream::Read(std::vector<BYTE> &buffer, _INT64 position, _INT32 count)
{
CheckDisposed();
return compoundFile->ReadData(this, position, buffer, 0, count);
}
int CFStream::Read(std::vector<BYTE> &buffer, std::streamsize position, int offset, int count)
_INT32 CFStream::Read(std::vector<BYTE> &buffer, _INT64 position, _INT32 offset, _INT32 count)
{
CheckDisposed();
return compoundFile->ReadData(this, position, buffer, offset, count);
@ -117,7 +118,7 @@ void CFStream::CopyFrom(const Stream &input)
SetData(buffer);
}
void CFStream::Resize(std::streamsize length)
void CFStream::Resize(_INT64 length)
{
compoundFile->SetStreamLength(shared_from_this(), length);
}

View File

@ -31,7 +31,7 @@
*/
#pragma once
#include "stream.h"
#include "Stream/stream.h"
#include "cfitem.h"
#include <vector>
@ -44,20 +44,20 @@ public:
CFStream(CompoundFile_impl* compFile, std::weak_ptr<IDirectoryEntry> dirEntry);
void Append(const std::vector<BYTE>& data);
void Write(const std::vector<BYTE>& data, std::streamsize position);
void Write(const std::vector<BYTE>& data, std::streamsize position, int offset, int count);
void Write(const char *data, std::streamsize position, int count);
void Write(const std::vector<BYTE>& data, _INT64 position);
void Write(const std::vector<BYTE>& data, _INT64 position, _INT32 offset, _INT32 count);
void Write(const char *data, _INT64 position, _INT32 count);
int Read(std::vector<BYTE>& buffer, std::streamsize position, int count);
int Read(std::vector<BYTE>& buffer, std::streamsize position, int offset, int count);
_INT32 Read(std::vector<BYTE>& buffer, _INT64 position, _INT32 count);
_INT32 Read(std::vector<BYTE>& buffer, _INT64 position, _INT32 offset, _INT32 count);
void SetData(const std::vector<BYTE>& data); // set hard
std::vector<BYTE> getData() const;
void CopyFrom(const Stream& input);
void Resize(std::streamsize length);
void Resize(_INT64 length);
std::streamsize size() const
_INT64 size() const
{return CFItem::size();}
};
}

View File

@ -37,7 +37,8 @@
#include <algorithm>
#include <cmath>
#include <array>
#include "Stream/fstream_utils.h"
#include "Stream/stream_utils.h"
#include "sector.h"
//--------------------------------------------------------------------------------
@ -94,20 +95,22 @@ void CompoundFile::Close()
{
_impl->Close();
}
std::vector<BYTE> CompoundFile::GetDataBySID(int sid)
std::vector<BYTE> CompoundFile::GetDataBySID(_INT32 sid)
{
return _impl->GetDataBySID(sid);
}
_GUID_ CompoundFile::getGuidBySID(int sid)
_GUID_ CompoundFile::getGuidBySID(_INT32 sid)
{
return _impl->getGuidBySID(sid);
}
_GUID_ CompoundFile::getGuidForStream(int sid)
_GUID_ CompoundFile::getGuidForStream(_INT32 sid)
{
return _impl->getGuidForStream(sid);
}
//--------------------------------------------------------------------------------
CompoundFile_impl::~CompoundFile_impl()
{
}
CompoundFile_impl::CompoundFile_impl() :
CompoundFile_impl(CFSVersion::Ver_3, CFSConfiguration::Default)
{}
@ -189,9 +192,9 @@ void CompoundFile_impl::Commit(bool releaseMemory)
if (updateMode != CFSUpdateMode::Update)
throw CFInvalidOperation("Cannot commit data in Read-Only update mode");
int sectorSize = GetSectorSize();
_INT32 sectorSize = GetSectorSize();
if (header->majorVersion != (unsigned short)CFSVersion::Ver_3)
if (header->majorVersion != (_UINT16)CFSVersion::Ver_3)
CheckForLockSector();
sourceStream->seek(0, std::ios::beg);
@ -205,7 +208,7 @@ void CompoundFile_impl::Commit(bool releaseMemory)
bool gap = true;
for (int i = 0; i < (int)sectors.largeArraySlices.size(); i++)
for (_INT32 i = 0; i < (int)sectors.largeArraySlices.size(); i++)
{
std::shared_ptr<Sector> sector = sectors[i];
@ -260,7 +263,7 @@ std::shared_ptr<RedBlackTree::RBTree> CompoundFile_impl::CreateNewTree()
return std::shared_ptr<RedBlackTree::RBTree>(new RedBlackTree::RBTree);
}
std::shared_ptr<RedBlackTree::RBTree> CompoundFile_impl::GetChildrenTree(int sid)
std::shared_ptr<RedBlackTree::RBTree> CompoundFile_impl::GetChildrenTree(_INT32 sid)
{
std::shared_ptr<RedBlackTree::RBTree> bst(new RedBlackTree::RBTree());
@ -285,7 +288,7 @@ void CompoundFile_impl::Load(Stream stream)
header->Read(stream);
int countSectors = std::ceil(((double)(Length(stream) - GetSectorSize()) / (double)GetSectorSize()));
_INT32 countSectors = std::ceil(((double)(Length(stream) - GetSectorSize()) / (double)GetSectorSize()));
if (Length(stream) > 0x7FFFFF0)
this->isTransactionLockAllocated = true;
@ -293,7 +296,7 @@ void CompoundFile_impl::Load(Stream stream)
sectors.Clear();
for (int i = 0; i < countSectors; i++)
for (_INT32 i = 0; i < countSectors; i++)
{
sectors.Add({});
}
@ -352,7 +355,7 @@ void CompoundFile_impl::Save(Stream stream)
// todo or not check seekable
CheckForLockSector();
int sectorSize = GetSectorSize();
_INT32 sectorSize = GetSectorSize();
try
{
@ -362,7 +365,7 @@ void CompoundFile_impl::Save(Stream stream)
CommitDirectory();
for (int i = 0; i < sectors.Count(); i++)
for (_INT32 i = 0; i < sectors.Count(); i++)
{
auto sector = sectors[i];
@ -387,15 +390,15 @@ void CompoundFile_impl::Save(Stream stream)
SVector<Sector> CompoundFile_impl::GetFatSectorChain()
{
int N_HEADER_FAT_ENTRY = 109;
_INT32 N_HEADER_FAT_ENTRY = 109;
SVector<Sector> result;
int nextSectorID = Sector::ENDOFCHAIN;
_INT32 nextSectorID = Sector::ENDOFCHAIN;
SVector<Sector> difatSectors = GetDifatSectorChain();
int index = 0;
_INT32 index = 0;
while (index < header->fatSectorsNumber && index < N_HEADER_FAT_ENTRY)
{
@ -417,8 +420,8 @@ SVector<Sector> CompoundFile_impl::GetFatSectorChain()
if (difatSectors.size() > 0)
{
std::unordered_set<int> processedSectors;
std::streamsize stLength = header->fatSectorsNumber > N_HEADER_FAT_ENTRY ?
std::unordered_set<_INT32> processedSectors;
_INT64 stLength = header->fatSectorsNumber > N_HEADER_FAT_ENTRY ?
(header->fatSectorsNumber - N_HEADER_FAT_ENTRY) * 4 : 0;
SList<Sector> zeroQueue;
@ -435,7 +438,7 @@ SVector<Sector> CompoundFile_impl::GetFatSectorChain()
char nextDIFATSectorBuffer[4];
int i = 0;
_INT32 i = 0;
while ((int)result.size() < header->fatSectorsNumber)
{
@ -475,13 +478,13 @@ SVector<Sector> CompoundFile_impl::GetFatSectorChain()
SVector<Sector> CompoundFile_impl::GetDifatSectorChain()
{
int validationCount = 0;
_INT32 validationCount = 0;
SVector<Sector> result;
int nextSectorID = Sector::ENDOFCHAIN;
_INT32 nextSectorID = Sector::ENDOFCHAIN;
std::unordered_set<int> processedSectors;
std::unordered_set<_INT32> processedSectors;
if (header->difatSectorsNumber != 0)
{
@ -501,7 +504,7 @@ SVector<Sector> CompoundFile_impl::GetDifatSectorChain()
while (true)
{
int startPos = GetSectorSize() - 4;
_INT32 startPos = GetSectorSize() - 4;
nextSectorID = *reinterpret_cast<int*>(sector->GetData().data() + startPos);
EnsureUniqueSectorIndex(nextSectorID, processedSectors);
if (nextSectorID == Sector::FREESECT || nextSectorID == Sector::ENDOFCHAIN) break;
@ -533,14 +536,14 @@ SVector<Sector> CompoundFile_impl::GetDifatSectorChain()
return result;
}
SVector<Sector> CompoundFile_impl::GetNormalSectorChain(int sectorID)
SVector<Sector> CompoundFile_impl::GetNormalSectorChain(_INT32 sectorID)
{
SVector<Sector> result;
int nextSectorID = sectorID;
_INT32 nextSectorID = sectorID;
SVector<Sector> fatSectors = GetFatSectorChain();
std::unordered_set<int> processedSectors;
std::unordered_set<_INT32> processedSectors;
SList<Sector> zeroQueue;
StreamView fatStream(fatSectors, GetSectorSize(), fatSectors.size() * GetSectorSize(), zeroQueue, sourceStream);
@ -568,7 +571,7 @@ SVector<Sector> CompoundFile_impl::GetNormalSectorChain(int sectorID)
result.push_back(sector);
fatStream.seek(nextSectorID * 4, std::ios::beg);
int next = fatStream.ReadInt32();
_INT32 next = fatStream.ReadInt32();
EnsureUniqueSectorIndex(next, processedSectors);
nextSectorID = next;
@ -578,13 +581,13 @@ SVector<Sector> CompoundFile_impl::GetNormalSectorChain(int sectorID)
return result;
}
SVector<Sector> CompoundFile_impl::GetMiniSectorChain(int sectorID)
SVector<Sector> CompoundFile_impl::GetMiniSectorChain(_INT32 sectorID)
{
SVector<Sector> result;
if (sectorID != Sector::ENDOFCHAIN)
{
int nextSectorID = sectorID;
_INT32 nextSectorID = sectorID;
SVector<Sector> miniFAT = GetNormalSectorChain(header->firstMiniFATSectorID);
SVector<Sector> miniStream = GetNormalSectorChain(RootEntry()->getStartSetc());
@ -596,7 +599,7 @@ SVector<Sector> CompoundFile_impl::GetMiniSectorChain(int sectorID)
nextSectorID = sectorID;
std::unordered_set<int> processedSectors;
std::unordered_set<_INT32> processedSectors;
while (true)
{
@ -614,7 +617,7 @@ SVector<Sector> CompoundFile_impl::GetMiniSectorChain(int sectorID)
result.push_back(ms);
miniFATView.seek(nextSectorID * 4, std::ios::beg);
int next = miniFATView.ReadInt32();
_INT32 next = miniFATView.ReadInt32();
nextSectorID = next;
EnsureUniqueSectorIndex(nextSectorID, processedSectors);
@ -624,7 +627,7 @@ SVector<Sector> CompoundFile_impl::GetMiniSectorChain(int sectorID)
return result;
}
SVector<Sector> CompoundFile_impl::GetSectorChain(int sectorID, SectorType chainType)
SVector<Sector> CompoundFile_impl::GetSectorChain(_INT32 sectorID, SectorType chainType)
{
switch (chainType)
{
@ -645,7 +648,7 @@ SVector<Sector> CompoundFile_impl::GetSectorChain(int sectorID, SectorType chain
}
}
void CompoundFile_impl::EnsureUniqueSectorIndex(int nextSectorID, std::unordered_set<int>& processedSectors)
void CompoundFile_impl::EnsureUniqueSectorIndex(_INT32 nextSectorID, std::unordered_set<_INT32> & processedSectors)
{
if (processedSectors.find(nextSectorID) != processedSectors.end() && this->isValidationExceptionEnabled)
{
@ -657,7 +660,7 @@ void CompoundFile_impl::EnsureUniqueSectorIndex(int nextSectorID, std::unordered
void CompoundFile_impl::CommitDirectory()
{
const int DIRECTORY_SIZE = 128;
const _INT32 DIRECTORY_SIZE = 128;
auto directorySectors
= GetSectorChain(header->firstDirectorySectorID, SectorType::Normal);
@ -678,7 +681,7 @@ void CompoundFile_impl::CommitDirectory()
de->Write(sv);
}
int delta = directoryEntries.size();
_INT32 delta = directoryEntries.size();
while (delta % (GetSectorSize() / DIRECTORY_SIZE) != 0)
{
@ -803,7 +806,7 @@ void CompoundFile_impl::DoLoadSiblings(std::shared_ptr<RedBlackTree::RBTree> bst
bst->Insert(de);
}
bool CompoundFile_impl::ValidateSibling(int sid)
bool CompoundFile_impl::ValidateSibling(_INT32 sid)
{
if (sid != DirectoryEntry::NOSTREAM)
{
@ -827,7 +830,7 @@ bool CompoundFile_impl::ValidateSibling(int sid)
return false;
}
int stgtype = directoryEntries[sid]->getStgType();
_INT32 stgtype = directoryEntries[sid]->getStgType();
if (false == (stgtype >= 0 && stgtype <= 5))
{
@ -864,7 +867,7 @@ void CompoundFile_impl::LoadDirectories()
Stream dirReader(new StreamView(directoryChain, sectorSize, directoryChain.size() * sectorSize, zeroQueue, sourceStream));
while (dirReader->tell() < (std::streamsize)directoryChain.size() * sectorSize)
while (dirReader->tell() < (_INT64)directoryChain.size() * sectorSize)
{
std::shared_ptr<IDirectoryEntry> de(DirectoryEntry::New(L"", StgType::StgInvalid, directoryEntries));
de->Read(dirReader, getVersion());
@ -876,7 +879,7 @@ void CompoundFile_impl::FreeMiniChain(SVector<Sector> &sectorChain, bool zeroSec
FreeMiniChain(sectorChain,0, zeroSector);
}
void CompoundFile_impl::FreeMiniChain(SVector<Sector> &sectorChain, int nth_sector_to_remove, bool zeroSector)
void CompoundFile_impl::FreeMiniChain(SVector<Sector> &sectorChain, _INT32 nth_sector_to_remove, bool zeroSector)
{
std::vector<char> ZEROED_MINI_SECTOR(Sector::MINISECTOR_SIZE, 0);
@ -893,7 +896,7 @@ void CompoundFile_impl::FreeMiniChain(SVector<Sector> &sectorChain, int nth_sect
if (zeroSector)
{
for (int i = nth_sector_to_remove; i < (int)sectorChain.size(); i++)
for (_INT32 i = nth_sector_to_remove; i < (int)sectorChain.size(); i++)
{
auto& s = sectorChain[i];
@ -905,19 +908,19 @@ void CompoundFile_impl::FreeMiniChain(SVector<Sector> &sectorChain, int nth_sect
}
}
for (int i = nth_sector_to_remove; i < (int)sectorChain.size(); i++)
for (_INT32 i = nth_sector_to_remove; i < (int)sectorChain.size(); i++)
{
int currentId = sectorChain[i]->id;
_INT32 currentId = sectorChain[i]->id;
miniFATView.seek(currentId * 4, std::ios::beg);
const int freesec = Sector::FREESECT;
const _INT32 freesec = Sector::FREESECT;
miniFATView.write(reinterpret_cast<const char*>(&freesec), 4);
}
if (nth_sector_to_remove > 0 && sectorChain.size() > 0)
{
miniFATView.seek(sectorChain[nth_sector_to_remove - 1]->id * 4, std::ios::beg);
const int endofchain = Sector::ENDOFCHAIN;
const _INT32 endofchain = Sector::ENDOFCHAIN;
miniFATView.write(reinterpret_cast<const char*>(&endofchain), 4);
}
@ -932,7 +935,7 @@ void CompoundFile_impl::FreeMiniChain(SVector<Sector> &sectorChain, int nth_sect
}
}
void CompoundFile_impl::FreeChain(SVector<Sector> &sectorChain, int nth_sector_to_remove, bool zeroSector)
void CompoundFile_impl::FreeChain(SVector<Sector> &sectorChain, _INT32 nth_sector_to_remove, bool zeroSector)
{
SVector<Sector> FAT = GetSectorChain(-1, SectorType::FAT);
@ -941,25 +944,25 @@ void CompoundFile_impl::FreeChain(SVector<Sector> &sectorChain, int nth_sector_t
if (zeroSector)
{
for (int i = nth_sector_to_remove; i < (int)sectorChain.size(); i++)
for (_INT32 i = nth_sector_to_remove; i < (int)sectorChain.size(); i++)
{
sectorChain[i]->ZeroData();
}
}
for (int i = nth_sector_to_remove; i < (int)sectorChain.size(); i++)
for (_INT32 i = nth_sector_to_remove; i < (int)sectorChain.size(); i++)
{
int currentId = sectorChain[i]->id;
_INT32 currentId = sectorChain[i]->id;
FATView.seek(currentId * 4, std::ios::beg);
const int freesec = Sector::FREESECT;
const _INT32 freesec = Sector::FREESECT;
FATView.write(reinterpret_cast<const char*>(&freesec), 4);
}
if (nth_sector_to_remove > 0 && sectorChain.size() > 0)
{
FATView.seek(sectorChain[nth_sector_to_remove - 1]->id * 4, std::ios::beg);
const int endofchain = Sector::ENDOFCHAIN;
const _INT32 endofchain = Sector::ENDOFCHAIN;
FATView.write(reinterpret_cast<const char*>(&endofchain), 4);
}
}
@ -998,7 +1001,7 @@ void CompoundFile_impl::AllocateFATSectorChain(SVector<Sector> &sectorChain)
);
for (int i = 0; i < (int)sectorChain.size() - 1; i++)
for (_INT32 i = 0; i < (int)sectorChain.size() - 1; i++)
{
auto sN = sectorChain[i + 1];
@ -1009,7 +1012,7 @@ void CompoundFile_impl::AllocateFATSectorChain(SVector<Sector> &sectorChain)
}
fatStream.seek(sectorChain[sectorChain.size() - 1]->id * 4, std::ios::beg);
const int endofchain = Sector::ENDOFCHAIN;
const _INT32 endofchain = Sector::ENDOFCHAIN;
fatStream.write(reinterpret_cast<const char*>(&endofchain), 4);
AllocateDIFATSectorChain(fatStream.BaseSectorChain());
@ -1029,9 +1032,9 @@ void CompoundFile_impl::AllocateDIFATSectorChain(SVector<Sector> &FATsectorChain
}
}
int nCurrentSectors = sectors.Count();
_INT32 nCurrentSectors = sectors.Count();
int countDIFATSectors = (int)header->difatSectorsNumber;
_INT32 countDIFATSectors = (int)header->difatSectorsNumber;
if ((int)FATsectorChain.size() > HEADER_DIFAT_ENTRIES_COUNT)
{
@ -1069,7 +1072,7 @@ void CompoundFile_impl::AllocateDIFATSectorChain(SVector<Sector> &FATsectorChain
StreamView difatStream(difatSectors, GetSectorSize(), sourceStream);
for (int i = 0; i < (int)FATsectorChain.size(); i++)
for (_INT32 i = 0; i < (int)FATsectorChain.size(); i++)
{
if (i < HEADER_DIFAT_ENTRIES_COUNT)
{
@ -1079,7 +1082,7 @@ void CompoundFile_impl::AllocateDIFATSectorChain(SVector<Sector> &FATsectorChain
{
if (i != HEADER_DIFAT_ENTRIES_COUNT && (i - HEADER_DIFAT_ENTRIES_COUNT) % DIFAT_SECTOR_FAT_ENTRIES_COUNT == 0)
{
int zero = 0;
_INT32 zero = 0;
difatStream.write(reinterpret_cast<const char*>(&zero), sizeof(int));
}
@ -1088,7 +1091,7 @@ void CompoundFile_impl::AllocateDIFATSectorChain(SVector<Sector> &FATsectorChain
}
}
for (int i = 0; i < (int)difatStream.BaseSectorChain().size(); i++)
for (_INT32 i = 0; i < (int)difatStream.BaseSectorChain().size(); i++)
{
if (difatStream.BaseSectorChain()[i]->id == -1)
{
@ -1098,28 +1101,28 @@ void CompoundFile_impl::AllocateDIFATSectorChain(SVector<Sector> &FATsectorChain
}
}
header->difatSectorsNumber = (unsigned int)countDIFATSectors;
header->difatSectorsNumber = (_UINT16)countDIFATSectors;
if (difatStream.BaseSectorChain() != nullptr && difatStream.BaseSectorChain().size() > 0)
{
header->firstDIFATSectorID = difatStream.BaseSectorChain()[0]->id;
header->difatSectorsNumber = (unsigned int)difatStream.BaseSectorChain().size();
header->difatSectorsNumber = (_UINT16)difatStream.BaseSectorChain().size();
for (int i = 0; i < (int)difatStream.BaseSectorChain().size() - 1; i++)
for (_INT32 i = 0; i < (int)difatStream.BaseSectorChain().size() - 1; i++)
{
int ID = difatStream.BaseSectorChain()[i + 1]->id;
_INT32 ID = difatStream.BaseSectorChain()[i + 1]->id;
char* src = reinterpret_cast<char *>(&ID);
char* dst = reinterpret_cast<char *>(difatStream.BaseSectorChain()[i]->GetData().data());
int offsetDst = GetSectorSize() - sizeof(int);
_INT32 offsetDst = GetSectorSize() - sizeof(int);
std::copy_n(src, sizeof(int), dst+offsetDst);
}
auto eoc = Sector::ENDOFCHAIN;
char* src = reinterpret_cast<char*>(&eoc);
char* dst = reinterpret_cast<char *>(difatStream.BaseSectorChain()[difatStream.BaseSectorChain().size() - 1]->GetData().data());
int offsetDst = GetSectorSize() - sizeof(int);
_INT32 offsetDst = GetSectorSize() - sizeof(int);
std::copy_n(src, sizeof(int), dst+offsetDst);
}
else
@ -1130,17 +1133,17 @@ void CompoundFile_impl::AllocateDIFATSectorChain(SVector<Sector> &FATsectorChain
SList<Sector> zeroQueue;
StreamView fatSv(FATsectorChain, GetSectorSize(), header->fatSectorsNumber * GetSectorSize(), zeroQueue, sourceStream);
for (int i = 0; i < (int)header->difatSectorsNumber; i++)
for (_INT32 i = 0; i < (int)header->difatSectorsNumber; i++)
{
fatSv.seek(difatStream.BaseSectorChain()[i]->id * 4, std::ios::beg);
const int difsect = Sector::DIFSECT;
const _INT32 difsect = Sector::DIFSECT;
fatSv.write(reinterpret_cast<const char*>(&difsect), 4);
}
for (int i = 0; i < header->fatSectorsNumber; i++)
for (_INT32 i = 0; i < header->fatSectorsNumber; i++)
{
fatSv.seek(fatSv.BaseSectorChain()[i]->id * 4, std::ios::beg);
const int fatsect = Sector::FATSECT;
const _INT32 fatsect = Sector::FATSECT;
fatSv.write(reinterpret_cast<const char*>(&fatsect), 4);
}
@ -1172,7 +1175,7 @@ void CompoundFile_impl::AllocateMiniSectorChain(SVector<Sector> &sectorChain)
zeroQueue,
sourceStream);
for (int i = 0; i < (int)sectorChain.size(); i++)
for (_INT32 i = 0; i < (int)sectorChain.size(); i++)
{
auto& sector = sectorChain[i];
@ -1185,17 +1188,17 @@ void CompoundFile_impl::AllocateMiniSectorChain(SVector<Sector> &sectorChain)
}
}
for (int i = 0; i < (int)sectorChain.size() - 1; i++)
for (_INT32 i = 0; i < (int)sectorChain.size() - 1; i++)
{
int currentId = sectorChain[i]->id;
int nextId = sectorChain[i + 1]->id;
_INT32 currentId = sectorChain[i]->id;
_INT32 nextId = sectorChain[i + 1]->id;
miniFATView.seek(currentId * 4, std::ios::beg);
miniFATView.write(reinterpret_cast<const char*>(&nextId), 4);
}
miniFATView.seek(sectorChain[sectorChain.size() - 1]->id * SIZE_OF_SID, std::ios::beg);
const int endofchain = Sector::ENDOFCHAIN;
const _INT32 endofchain = Sector::ENDOFCHAIN;
miniFATView.write(reinterpret_cast<const char*>(&endofchain), 4);
AllocateSectorChain(miniStreamView.BaseSectorChain());
@ -1232,7 +1235,7 @@ void CompoundFile_impl::PersistMiniStreamToStream(const SVector<Sector> &miniSec
}
}
int CompoundFile_impl::LowSaturation(int x)
_INT32 CompoundFile_impl::LowSaturation(_INT32 x)
{
return x > 0 ? x : 0;
}
@ -1264,7 +1267,7 @@ SVector<IDirectoryEntry> &CompoundFile_impl::GetDirectories()
return directoryEntries;
}
void CompoundFile_impl::ResetDirectoryEntry(int sid)
void CompoundFile_impl::ResetDirectoryEntry(_INT32 sid)
{
directoryEntries[sid]->SetEntryName(L"");
directoryEntries[sid]->setLeft({});
@ -1280,7 +1283,7 @@ void CompoundFile_impl::ResetDirectoryEntry(int sid)
directoryEntries[sid]->setModifyDate(0);
}
void CompoundFile_impl::InvalidateDirectoryEntry(int sid)
void CompoundFile_impl::InvalidateDirectoryEntry(_INT32 sid)
{
if (sid >= (int)directoryEntries.size())
throw CFException("Invalid SID of the directory entry to remove");
@ -1288,7 +1291,7 @@ void CompoundFile_impl::InvalidateDirectoryEntry(int sid)
ResetDirectoryEntry(sid);
}
void CompoundFile_impl::FreeAssociatedData(int sid)
void CompoundFile_impl::FreeAssociatedData(_INT32 sid)
{
if (directoryEntries[sid]->getSize() > 0)
{
@ -1329,7 +1332,7 @@ void CompoundFile_impl::FreeData(CFStream *stream)
stream->dirEntry.lock()->setSize(0);
}
void CompoundFile_impl::WriteData(std::shared_ptr<CFItem> cfItem, std::streamsize position, const std::vector<BYTE> &buffer)
void CompoundFile_impl::WriteData(std::shared_ptr<CFItem> cfItem, _INT64 position, const std::vector<BYTE> &buffer)
{
WriteData(cfItem, buffer, position, 0, buffer.size());
}
@ -1344,13 +1347,13 @@ void CompoundFile_impl::AppendData(std::shared_ptr<CFItem> cfItem, const std::ve
WriteData(cfItem, cfItem->size(), buffer);
}
void CompoundFile_impl::SetStreamLength(std::shared_ptr<CFItem> cfItem, std::streamsize length)
void CompoundFile_impl::SetStreamLength(std::shared_ptr<CFItem> cfItem, _INT64 length)
{
if (cfItem->size() == length)
return;
SectorType newSectorType = SectorType::Normal;
int newSectorSize = GetSectorSize();
_INT32 newSectorSize = GetSectorSize();
if (length < header->minSizeStandardStream)
{
@ -1359,7 +1362,7 @@ void CompoundFile_impl::SetStreamLength(std::shared_ptr<CFItem> cfItem, std::str
}
SectorType oldSectorType = SectorType::Normal;
int oldSectorSize = GetSectorSize();
_INT32 oldSectorSize = GetSectorSize();
if (cfItem->size() < header->minSizeStandardStream)
{
@ -1368,9 +1371,9 @@ void CompoundFile_impl::SetStreamLength(std::shared_ptr<CFItem> cfItem, std::str
}
std::streamsize oldSize = cfItem->size();
_INT64 oldSize = cfItem->size();
SVector<Sector> sectorChain = GetSectorChain(cfItem->dirEntry.lock()->getStartSetc(), oldSectorType);
std::streamsize delta = length - cfItem->size();
_INT64 delta = length - cfItem->size();
bool transitionToMini = false;
bool transitionToNormal = false;
@ -1414,7 +1417,7 @@ void CompoundFile_impl::SetStreamLength(std::shared_ptr<CFItem> cfItem, std::str
else if (delta < 0)
{
int nSec = (int)std::floor(((double)(std::abs(delta)) / newSectorSize));
_INT32 nSec = (int)std::floor(((double)(std::abs(delta)) / newSectorSize));
if (newSectorSize == Sector::MINISECTOR_SIZE)
FreeMiniChain(sectorChain, nSec, eraseFreeSectors);
@ -1448,11 +1451,11 @@ void CompoundFile_impl::SetStreamLength(std::shared_ptr<CFItem> cfItem, std::str
SVector<Sector> newChain = GetMiniSectorChain(Sector::ENDOFCHAIN);
StreamView destSv(newChain, Sector::MINISECTOR_SIZE, length, freeList, sourceStream);
int cnt = 4096 < length ? 4096 : (int)length;
_INT32 cnt = 4096 < length ? 4096 : (int)length;
std::array<char, 4096> buffer;
buffer.fill(0);
std::streamsize toRead = length;
_INT64 toRead = length;
while (toRead > cnt)
{
@ -1492,11 +1495,11 @@ void CompoundFile_impl::SetStreamLength(std::shared_ptr<CFItem> cfItem, std::str
SVector<Sector> newChain = GetNormalSectorChain(Sector::ENDOFCHAIN);
StreamView destSv(newChain, GetSectorSize(), length, freeList, sourceStream);
int count = 256 < length ? 256 : (int)length;
_INT32 count = 256 < length ? 256 : (int)length;
std::array<char, 256> buf;
buf.fill(0);
std::streamsize toRead = (std::min)(length, cfItem->size());
_INT64 toRead = (std::min)(length, cfItem->size());
while (toRead > count)
{
@ -1536,11 +1539,11 @@ SList<Sector> CompoundFile_impl::FindFreeSectors(SectorType sType)
StreamView fatStream(FatChain, GetSectorSize(), header->fatSectorsNumber * GetSectorSize(), zeroQueue, sourceStream);
int index = 0;
_INT32 index = 0;
while (index < sectors.Count())
{
int id = fatStream.ReadInt32();
_INT32 id = fatStream.ReadInt32();
if (id == Sector::FREESECT)
{
@ -1567,13 +1570,13 @@ SList<Sector> CompoundFile_impl::FindFreeSectors(SectorType sType)
StreamView miniStreamView(miniStream, GetSectorSize(), rootStorage->size(), zeroQueue, sourceStream);
int index = 0;
_INT32 index = 0;
int countMinisectors = (int)(miniStreamView.getLength() / Sector::MINISECTOR_SIZE);
_INT32 countMinisectors = (int)(miniStreamView.getLength() / Sector::MINISECTOR_SIZE);
while (index < countMinisectors)
{
int nextId = miniFATView.ReadInt32();
_INT32 nextId = miniFATView.ReadInt32();
if (nextId == Sector::FREESECT)
{
@ -1631,14 +1634,14 @@ std::vector<BYTE> CompoundFile_impl::GetData(const CFStream *cFStream)
return result;
}
int CompoundFile_impl::ReadData(CFStream *cFStream, std::streamsize position, std::vector<BYTE> &buffer, int count)
_INT32 CompoundFile_impl::ReadData(CFStream *cFStream, _INT64 position, std::vector<BYTE> &buffer, _INT32 count)
{
if (count > (int)buffer.size())
throw std::invalid_argument("count parameter exceeds buffer size");
auto de = cFStream->dirEntry.lock();
count = std::min((std::streamsize)(de->getSize() - position), (std::streamsize)count);
count = std::min((_INT64)(de->getSize() - position), (_INT64)count);
std::shared_ptr<StreamView> sv;
@ -1654,16 +1657,16 @@ int CompoundFile_impl::ReadData(CFStream *cFStream, std::streamsize position, st
sv->seek(position, std::ios::beg);
int result = sv->read(reinterpret_cast<char*>(buffer.data()), count);
_INT32 result = sv->read(reinterpret_cast<char*>(buffer.data()), count);
return result;
}
int CompoundFile_impl::ReadData(CFStream *cFStream, std::streamsize position, std::vector<BYTE> &buffer, int offset, int count)
_INT32 CompoundFile_impl::ReadData(CFStream *cFStream, _INT64 position, std::vector<BYTE> &buffer, _INT32 offset, _INT32 count)
{
auto de = cFStream->dirEntry.lock();
count = std::min((std::streamsize)(buffer.size() - offset), (std::streamsize)count);
count = std::min((_INT64)(buffer.size() - offset), (_INT64)count);
std::shared_ptr<StreamView> sv;
@ -1679,12 +1682,12 @@ int CompoundFile_impl::ReadData(CFStream *cFStream, std::streamsize position, st
sv->seek(position, std::ios::beg);
int result = sv->read(reinterpret_cast<char*>(buffer.data() + offset), count);
_INT32 result = sv->read(reinterpret_cast<char*>(buffer.data() + offset), count);
return result;
}
std::vector<BYTE> CompoundFile_impl::GetDataBySID(int sid)
std::vector<BYTE> CompoundFile_impl::GetDataBySID(_INT32 sid)
{
if (isDisposed)
throw CFDisposedException("Compound File closed: cannot access data");
@ -1717,7 +1720,7 @@ std::vector<BYTE> CompoundFile_impl::GetDataBySID(int sid)
return result;
}
_GUID_ CompoundFile_impl::getGuidBySID(int sid)
_GUID_ CompoundFile_impl::getGuidBySID(_INT32 sid)
{
if (isDisposed)
throw CFDisposedException("Compound File closed: cannot access data");
@ -1727,7 +1730,7 @@ _GUID_ CompoundFile_impl::getGuidBySID(int sid)
return de->getStorageCLSID();
}
_GUID_ CompoundFile_impl::getGuidForStream(int sid)
_GUID_ CompoundFile_impl::getGuidForStream(_INT32 sid)
{
if (isDisposed)
throw CFDisposedException("Compound File closed: cannot access data");
@ -1736,7 +1739,7 @@ _GUID_ CompoundFile_impl::getGuidForStream(int sid)
_GUID_ guid;
for (int i = sid - 1; i >= 0; i--)
for (_INT32 i = sid - 1; i >= 0; i--)
{
if (directoryEntries[i]->getStorageCLSID() != guid && directoryEntries[i]->getStgType() == StgType::StgStorage)
{
@ -1747,7 +1750,7 @@ _GUID_ CompoundFile_impl::getGuidForStream(int sid)
return guid;
}
void CompoundFile_impl::WriteData(std::shared_ptr<CFItem> cfItem, const char* data, std::streamsize position, int count)
void CompoundFile_impl::WriteData(std::shared_ptr<CFItem> cfItem, const char* data, _INT64 position, _INT32 count)
{
if (data == nullptr)
throw CFInvalidOperation("Parameter [data] cannot be null");
@ -1757,13 +1760,13 @@ void CompoundFile_impl::WriteData(std::shared_ptr<CFItem> cfItem, const char* da
if (count == 0) return;
std::streamsize delta = (position + count) - cfItem->size() < 0 ? 0 : (position + count) - cfItem->size();
std::streamsize newLength = cfItem->size() + delta;
_INT64 delta = (position + count) - cfItem->size() < 0 ? 0 : (position + count) - cfItem->size();
_INT64 newLength = cfItem->size() + delta;
SetStreamLength(cfItem, newLength);
SectorType _st = SectorType::Normal;
int _sectorSize = GetSectorSize();
_INT32 _sectorSize = GetSectorSize();
if (cfItem->size() < header->minSizeStandardStream)
{
@ -1784,12 +1787,12 @@ void CompoundFile_impl::WriteData(std::shared_ptr<CFItem> cfItem, const char* da
}
}
void CompoundFile_impl::WriteData(std::shared_ptr<CFItem> cfItem, const std::vector<BYTE> &buffer, std::streamsize position, int offset, int count)
void CompoundFile_impl::WriteData(std::shared_ptr<CFItem> cfItem, const std::vector<BYTE> &buffer, _INT64 position, _INT32 offset, _INT32 count)
{
WriteData(cfItem, reinterpret_cast<const char*>(buffer.data() + offset), position, count);
}
int CompoundFile_impl::GetSectorSize()
_INT32 CompoundFile_impl::GetSectorSize()
{
return 2 << (header->sectorShift - 1);
}
@ -1832,7 +1835,7 @@ void CompoundFile_impl::CheckForLockSector()
StreamView fatStream(GetFatSectorChain(), GetSectorSize(), sourceStream);
fatStream.seek(lockSectorId * 4, std::ios::beg);
const int endOfChain = Sector::ENDOFCHAIN;
const _INT32 endOfChain = Sector::ENDOFCHAIN;
fatStream.write(reinterpret_cast<const char*>(&endOfChain), 4);
isTransactionLockAllocated = true;

View File

@ -32,6 +32,7 @@
#pragma once
#include "cfstorage.h"
#include "idirectoryentry.h"
namespace CFCPP
{
@ -72,9 +73,9 @@ public:
bool IsClosed()const;
void Close();
std::vector<BYTE> GetDataBySID(int sid);
_GUID_ getGuidBySID(int sid);
_GUID_ getGuidForStream(int sid);
std::vector<BYTE> GetDataBySID(_INT32 sid);
_GUID_ getGuidBySID(_INT32 sid);
_GUID_ getGuidForStream(_INT32 sid);
private:
std::shared_ptr<CompoundFile_impl> _impl;

View File

@ -40,6 +40,7 @@
#include "idirectoryentry.h"
#include <mutex>
#include "header.h"
#include "fstream"
namespace CFCPP
{
@ -53,6 +54,7 @@ public:
CompoundFile_impl(const std::wstring &fileName);
CompoundFile_impl(Stream stream);
CompoundFile_impl();
virtual ~CompoundFile_impl();
// Main methods
std::shared_ptr<CFStorage> RootStorage();
@ -67,31 +69,31 @@ public:
bool IsClosed()const;
void Close();
std::vector<BYTE> GetDataBySID(int sid);
_GUID_ getGuidBySID(int sid);
_GUID_ getGuidForStream(int sid);
std::vector<BYTE> GetDataBySID(_INT32 sid);
_GUID_ getGuidBySID(_INT32 sid);
_GUID_ getGuidForStream(_INT32 sid);
// internal methods
static std::shared_ptr<RedBlackTree::RBTree> CreateNewTree();
std::shared_ptr<RedBlackTree::RBTree> GetChildrenTree(int sid);
std::shared_ptr<RedBlackTree::RBTree> GetChildrenTree(_INT32 sid);
SVector<IDirectoryEntry> &GetDirectories();
void ResetDirectoryEntry(int sid);
void InvalidateDirectoryEntry(int sid);
void FreeAssociatedData(int sid);
void ResetDirectoryEntry(_INT32 sid);
void InvalidateDirectoryEntry(_INT32 sid);
void FreeAssociatedData(_INT32 sid);
void FreeData(CFStream* stream);
void WriteData(std::shared_ptr<CFItem> cfItem, const char* data, std::streamsize position, int count);
void WriteData(std::shared_ptr<CFItem> cfItem, const std::vector<BYTE>& buffer, std::streamsize position, int offset, int count);
void WriteData(std::shared_ptr<CFItem> cfItem, std::streamsize position, const std::vector<BYTE>& buffer);
void WriteData(std::shared_ptr<CFItem> cfItem, const char* data, _INT64 position, _INT32 count);
void WriteData(std::shared_ptr<CFItem> cfItem, const std::vector<BYTE>& buffer, _INT64 position, _INT32 offset, _INT32 count);
void WriteData(std::shared_ptr<CFItem> cfItem, _INT64 position, const std::vector<BYTE>& buffer);
void WriteData(std::shared_ptr<CFItem> cfItem, const std::vector<BYTE>& buffer);
void AppendData(std::shared_ptr<CFItem> cfItem, const std::vector<BYTE>& buffer);
void SetStreamLength(std::shared_ptr<CFItem> cfItem, std::streamsize length);
void SetStreamLength(std::shared_ptr<CFItem> cfItem, _INT64 length);
SList<Sector> FindFreeSectors(SectorType sType);
std::vector<BYTE> GetData(const CFStream *cFStream);
int ReadData(CFStream* cFStream, std::streamsize position, std::vector<BYTE>& buffer, int count);
int ReadData(CFStream* cFStream, std::streamsize position, std::vector<BYTE>& buffer, int offset, int count);
_INT32 ReadData(CFStream* cFStream, _INT64 position, std::vector<BYTE>& buffer, _INT32 count);
_INT32 ReadData(CFStream* cFStream, _INT64 position, std::vector<BYTE>& buffer, _INT32 offset, _INT32 count);
protected:
int GetSectorSize();
_INT32 GetSectorSize();
void Dispose(bool disposing);
private:
@ -104,10 +106,10 @@ private:
SVector<Sector> GetFatSectorChain();
SVector<Sector> GetDifatSectorChain();
SVector<Sector> GetNormalSectorChain(int sectorID);
SVector<Sector> GetMiniSectorChain(int sectorID);
SVector<Sector> GetSectorChain(int sectorID, SectorType chainType);
void EnsureUniqueSectorIndex(int nextsectorID, std::unordered_set<int> &processedSectors);
SVector<Sector> GetNormalSectorChain(_INT32 sectorID);
SVector<Sector> GetMiniSectorChain(_INT32 sectorID);
SVector<Sector> GetSectorChain(_INT32 sectorID, SectorType chainType);
void EnsureUniqueSectorIndex(_INT32 nextsectorID, std::unordered_set<_INT32> &processedSectors);
void CommitDirectory();
void Close(bool closeStream);
@ -119,12 +121,12 @@ private:
void NullifyChildNodes(std::shared_ptr<IDirectoryEntry> de);
void LoadSiblings(std::shared_ptr<RedBlackTree::RBTree> bst, std::shared_ptr<IDirectoryEntry> de);
void DoLoadSiblings(std::shared_ptr<RedBlackTree::RBTree> bst, std::shared_ptr<IDirectoryEntry> de);
bool ValidateSibling(int sid);
bool ValidateSibling(_INT32 sid);
void LoadDirectories();
void FreeMiniChain(SVector<Sector>& sectorChain, bool zeroSector);
void FreeMiniChain(SVector<Sector>& sectorChain, int nth_sector_to_remove, bool zeroSector);
void FreeChain(SVector<Sector>& sectorChain, int nth_sector_to_remove, bool zeroSector);
void FreeMiniChain(SVector<Sector>& sectorChain, _INT32 nth_sector_to_remove, bool zeroSector);
void FreeChain(SVector<Sector>& sectorChain, _INT32 nth_sector_to_remove, bool zeroSector);
void FreeChain(SVector<Sector>& sectorChain, bool zeroSector);
void AllocateSectorChain(SVector<Sector>& sectorChain);
@ -132,7 +134,7 @@ private:
void AllocateDIFATSectorChain(SVector<Sector>& FATsectorChain);
void AllocateMiniSectorChain(SVector<Sector>& sectorChain);
void PersistMiniStreamToStream(const SVector<Sector>& miniSectorChain);
static int LowSaturation(int x);
static _INT32 LowSaturation(_INT32 x);
void SetSectorChain(SVector<Sector> sectorChain);
CFSVersion getVersion() const;
@ -143,14 +145,14 @@ public:
Stream sourceStream;
private:
const int HEADER_DIFAT_ENTRIES_COUNT = 109;
int DIFAT_SECTOR_FAT_ENTRIES_COUNT = 127;
int FAT_SECTOR_ENTRIES_COUNT = 128;
const int SIZE_OF_SID = 4;
const _INT32 HEADER_DIFAT_ENTRIES_COUNT = 109;
_INT32 DIFAT_SECTOR_FAT_ENTRIES_COUNT = 127;
_INT32 FAT_SECTOR_ENTRIES_COUNT = 128;
const _INT32 SIZE_OF_SID = 4;
bool sectorRecycle = false;
bool eraseFreeSectors = false;
static constexpr int FLUSHING_QUEUE_SIZE = 6000;
static constexpr int FLUSHING_BUFFER_MAX_SIZE = 1024 * 1024 * 16;
static constexpr _INT32 FLUSHING_QUEUE_SIZE = 6000;
static constexpr _INT32 FLUSHING_BUFFER_MAX_SIZE = 1024 * 1024 * 16;
SectorCollection sectors;
@ -160,14 +162,14 @@ private:
bool closeStream = true;
bool transactionLockAdded = false;
int lockSectorId = -1;
_INT32 lockSectorId = -1;
bool isTransactionLockAllocated = false;
bool isValidationExceptionEnabled = true;
bool isDisposed = false;
CFSUpdateMode updateMode;
SVector<IDirectoryEntry> directoryEntries;
std::list<int> levelSIDs;
std::list<_INT32> levelSIDs;
std::mutex lockObject;
};
}

View File

@ -30,6 +30,7 @@
*
*/
#include "directoryentry.h"
#include <sstream>
#include "cfexception.h"
#include "streamrw.h"
#include <stdexcept>
@ -82,12 +83,12 @@ DirectoryEntry::DirectoryEntry(std::wstring name, StgType stgType) :
}
}
int DirectoryEntry::getSid() const
_INT32 DirectoryEntry::getSid() const
{
return sid;
}
void DirectoryEntry::setSid(int newSid)
void DirectoryEntry::setSid(_INT32 newSid)
{
sid = newSid;
}
@ -97,7 +98,7 @@ std::wstring DirectoryEntry::GetEntryName() const
if (entryName[0] != '\0' && nameLength > 0)
{
wchar_t name[32];
for (int i = 0; i < 32; i++)
for (_INT32 i = 0; i < 32; i++)
{
name[i] = entryName[2*i] + (entryName[2*i+1] << 8);
}
@ -136,11 +137,11 @@ void DirectoryEntry::SetEntryName(const std::wstring &entryName)
this->entryName[i*2+1] = sym / 256;
}
this->nameLength = (unsigned short)entryName.size() * 2 + 2;
this->nameLength = (_UINT16)entryName.size() * 2 + 2;
}
}
int DirectoryEntry::GetHashCode() const
_INT32 DirectoryEntry::GetHashCode() const
{
return (int)fnv_hash(entryName, nameLength);
}
@ -192,8 +193,8 @@ void DirectoryEntry::Read(Stream stream, CFSVersion ver)
if (ver == CFSVersion::Ver_3)
{
size = rw.Read<int>();
rw.Read<INT>();
size = rw.Read<_INT32> ();
rw.Read<_INT32>();
}
else
{
@ -273,7 +274,7 @@ void DirectoryEntry::AssignValueTo(RedBlackTree::PIRBNode other)
d->child = this->child;
}
int DirectoryEntry::CompareTo(const RedBlackTree::PIRBNode &other) const
_INT32 DirectoryEntry::CompareTo(const RedBlackTree::PIRBNode &other) const
{
IDirectoryEntry* otherDir = dynamic_cast<IDirectoryEntry*>(other.get());
@ -293,7 +294,7 @@ int DirectoryEntry::CompareTo(const RedBlackTree::PIRBNode &other) const
std::wstring thisName = GetEntryName();
std::wstring otherName = otherDir->GetEntryName();
for (int z = 0; z < (int)thisName.size(); z++)
for (_INT32 z = 0; z < (int)thisName.size(); z++)
{
char thisChar = toupper(thisName[z]);
char otherChar = toupper(otherName[z]);
@ -309,10 +310,10 @@ int DirectoryEntry::CompareTo(const RedBlackTree::PIRBNode &other) const
}
}
ULONG64 DirectoryEntry::fnv_hash(const char *buffer, int lenght)
_UINT64 DirectoryEntry::fnv_hash(const char *buffer, _INT64 lenght)
{
ULONG64 h = 2166136261;
int i;
_UINT64 h = 2166136261;
_INT64 i;
for (i = 0; i < lenght; i++)
h = (h * 16777619) ^ buffer[i];
@ -341,7 +342,7 @@ std::shared_ptr<IDirectoryEntry> DirectoryEntry::TryNew(std::wstring name, StgTy
if (de != nullptr)
{
for (int i = 0; i < (int)dirRepository.size(); i++)
for (_INT32 i = 0; i < (int)dirRepository.size(); i++)
{
if (dirRepository[i]->getStgType() == StgType::StgInvalid)
{

View File

@ -41,11 +41,11 @@ class DirectoryEntry : public IDirectoryEntry
{
public:
static const int THIS_IS_GREATER = 1;
static const int OTHER_IS_GREATER = -1;
static const _INT32 THIS_IS_GREATER = 1;
static const _INT32 OTHER_IS_GREATER = -1;
static const int NOSTREAM = 0xFFFFFFFF;
static const int ZERO = 0;
static const _INT32 NOSTREAM = 0xFFFFFFFF;
static const _INT32 ZERO = 0;
DirectoryEntry(std::wstring name, StgType stgType, SVector<IDirectoryEntry>& dirRepository);
DirectoryEntry(std::wstring name, StgType stgType);
@ -54,10 +54,10 @@ public:
RedBlackTree::PIRBNode getRight() const override;
void setLeft(RedBlackTree::PIRBNode pNode) override;
void setRight(RedBlackTree::PIRBNode pNode) override;
std::streamsize getSize() const override {return size;}
void setSize(std::streamsize value) override {size = value;}
int getStateBits() const override {return stateBits;}
void setStateBits(int value) override {stateBits = value;}
_INT64 getSize() const override {return size;}
void setSize(_INT64 value) override {size = value;}
_INT32 getStateBits() const override {return stateBits;}
void setStateBits(_INT32 value) override {stateBits = value;}
inline void setColor(RedBlackTree::Color clr) override {stgColor = (StgColor)clr;}
inline RedBlackTree::Color getColor()const override {return (RedBlackTree::Color)stgColor;}
@ -70,31 +70,31 @@ public:
RedBlackTree::PIRBNode Uncle() const override;
void AssignValueTo(RedBlackTree::PIRBNode other) override;
int CompareTo(const RedBlackTree::PIRBNode& other) const override;
_INT32 CompareTo(const RedBlackTree::PIRBNode& other) const override;
std::wstring ToString() const override;
inline int getChild() const override {return child;}
inline void setChild(int value) override {child = value;}
inline _INT32 getChild() const override {return child;}
inline void setChild(_INT32 value) override {child = value;}
inline int getLeftSibling() const override {return leftSibling;}
inline void setLeftSibling(int value) override {leftSibling = value;}
inline int getRightSibling() const override {return rightSibling;}
inline void setRightSibling(int value) override {rightSibling = value;}
inline _INT32 getLeftSibling() const override {return leftSibling;}
inline void setLeftSibling(_INT32 value) override {leftSibling = value;}
inline _INT32 getRightSibling() const override {return rightSibling;}
inline void setRightSibling(_INT32 value) override {rightSibling = value;}
inline UINT64 getCreationDate() const override {return creationDate;}
inline void setCreationDate(const UINT64& value) override {creationDate = value;}
inline UINT64 getModifyDate() const override {return modifyDate;}
inline void setModifyDate(const UINT64& value) override {modifyDate = value;}
int getSid() const override;
void setSid(int newSid) override;
_INT32 getSid() const override;
void setSid(_INT32 newSid) override;
std::wstring GetEntryName() const override;
void SetEntryName(const std::wstring &entryName) override;
inline unsigned short getNameLength() const override {return nameLength;}
inline _UINT16 getNameLength() const override {return nameLength;}
void setStartSetc(int value) override {startSetc = value;};
int getStartSetc() const override {return startSetc;};
void setStartSetc(_INT32 value) override {startSetc = value;};
_INT32 getStartSetc() const override {return startSetc;};
void Read(Stream stream, CFSVersion ver = CFSVersion::Ver_3) override;
void Write(Stream stream) const override;
@ -104,30 +104,30 @@ public:
inline void setStgType(StgType value) override {stgType = value;}
inline _GUID_ getStorageCLSID() const override {return storageCLSID;}
inline void setStorageCLSID(_GUID_ value) override {storageCLSID = value;}
int GetHashCode() const override;
_INT32 GetHashCode() const override;
inline std::wstring Name() const {return GetEntryName();}
public:
UINT64 creationDate = 0;
UINT64 modifyDate = 0;
int startSetc = 0xFFFFFFFE;
LONG64 size = 0;
int leftSibling = NOSTREAM;
int rightSibling = NOSTREAM;
int child = NOSTREAM;
int stateBits = 0;
_UINT64 creationDate = 0;
_UINT64 modifyDate = 0;
_INT32 startSetc = 0xFFFFFFFE;
_INT64 size = 0;
_INT32 leftSibling = NOSTREAM;
_INT32 rightSibling = NOSTREAM;
_INT32 child = NOSTREAM;
_INT32 stateBits = 0;
static std::shared_ptr<IDirectoryEntry> New(std::wstring name, StgType stgType, SVector<IDirectoryEntry>& dirRepository);
static std::shared_ptr<IDirectoryEntry> TryNew(std::wstring name, StgType stgType, SVector<IDirectoryEntry> &dirRepository);
static std::shared_ptr<IDirectoryEntry> Mock(std::wstring name, StgType stgType);
private:
static ULONG64 fnv_hash(const char *buffer, int lenght);
static _UINT64 fnv_hash(const char *buffer, _INT64 lenght);
private:
int sid = -1;
_INT32 sid = -1;
char entryName[64] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned short nameLength = 0;
_UINT16 nameLength = 0;
StgType stgType = StgType::StgInvalid;
StgColor stgColor = StgColor::Red;
SVector<IDirectoryEntry> emptyDir;

View File

@ -31,16 +31,19 @@
*/
#pragma once
#include "../DocxFormat/Source/Base/Types_32.h"
#include "../../DesktopEditor/common/Types.h"
struct _GUID_
{
unsigned int Data1 = 0;
unsigned short Data2 = 0;
unsigned short Data3 = 0;
unsigned long long Data4 = 0;
_UINT32 Data1 = 0;
_UINT16 Data2 = 0;
_UINT16 Data3 = 0;
_UINT64 Data4 = 0;
unsigned char* getData4()
BYTE* getData4()
{
return reinterpret_cast<unsigned char*>(&Data4);
return reinterpret_cast<BYTE*>(&Data4);
}
_GUID_(const _GUID_& o) : Data1(o.Data1), Data2(o.Data2), Data3(o.Data3)

View File

@ -42,7 +42,7 @@ Header::Header() :
}
Header::Header(unsigned short version)
Header::Header(_UINT16 version)
{
switch (version)
{
@ -62,7 +62,7 @@ Header::Header(unsigned short version)
}
for (int i = 0; i < 109; i++)
for (_INT32 i = 0; i < 109; i++)
{
difat[i] = Sector::FREESECT;
}
@ -89,7 +89,7 @@ void Header::Write(CFCPP::Stream &stream) const
rw.Write(firstDIFATSectorID);
rw.Write(difatSectorsNumber);
for (int i : difat)
for (_INT32 i : difat)
{
rw.Write(i);
}
@ -125,9 +125,9 @@ void Header::Read(CFCPP::Stream &stream)
firstDIFATSectorID = rw.Read<decltype(firstDIFATSectorID)>();
difatSectorsNumber = rw.Read<decltype(difatSectorsNumber)>();
for (int i = 0; i < 109; i++)
for (_INT32 i = 0; i < 109; i++)
{
difat[i] = rw.Read<int>();
difat[i] = rw.Read<_INT32>();
}
}

View File

@ -40,7 +40,7 @@ class Header
{
public:
Header();
Header(unsigned short version);
Header(_UINT16 version);
void Write(Stream& stream) const;
void Read(Stream& stream);
@ -51,22 +51,22 @@ private:
public:
BYTE headerSignature[8] = {0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1};
BYTE clsid[16];
USHORT minorVersion = 0x003E;
USHORT majorVersion = 0x0003;
USHORT byteOrder = 0xFFFE;
USHORT sectorShift = 9;
USHORT miniSectorShift = 6;
_UINT16 minorVersion = 0x003E;
_UINT16 majorVersion = 0x0003;
_UINT16 byteOrder = 0xFFFE;
_UINT16 sectorShift = 9;
_UINT16 miniSectorShift = 6;
BYTE unUsed[6] = {0,0,0,0,0,0};
INT directorySectorsNumber = 0;
INT fatSectorsNumber = 0;
INT firstDirectorySectorID = Sector::ENDOFCHAIN;
unsigned int unUsed2 = 0;
unsigned int minSizeStandardStream = 4096;
INT firstMiniFATSectorID = 0xFFFFFFFE;
unsigned int miniFATSectorsNumber = 0;
INT firstDIFATSectorID = Sector::ENDOFCHAIN;
unsigned int difatSectorsNumber = 0;
INT difat[109];
_INT32 directorySectorsNumber = 0;
_INT32 fatSectorsNumber = 0;
_INT32 firstDirectorySectorID = Sector::ENDOFCHAIN;
_UINT32 unUsed2 = 0;
_UINT32 minSizeStandardStream = 4096;
_INT32 firstMiniFATSectorID = 0xFFFFFFFE;
_UINT32 miniFATSectorsNumber = 0;
_INT32 firstDIFATSectorID = Sector::ENDOFCHAIN;
_UINT32 difatSectorsNumber = 0;
_INT32 difat[109];
};
}

View File

@ -32,13 +32,13 @@
#pragma once
#include <map>
#include "stream.h"
#include "Stream/stream.h"
#include "RBTree/irbnode.h"
#include "guid.h"
namespace CFCPP
{
enum StgType : int
enum StgType : _INT32
{
StgInvalid = 0,
StgStorage = 1,
@ -48,13 +48,13 @@ enum StgType : int
StgRoot = 5
};
enum StgColor : int
enum StgColor : _INT32
{
Red = 0,
Black = 1
};
enum CFSVersion : int
enum CFSVersion : _INT32
{
// Sector size 512 - default and very common
Ver_3 = 3,
@ -65,32 +65,32 @@ enum CFSVersion : int
class IDirectoryEntry : public RedBlackTree::IRBNode
{
public:
virtual int getChild() const = 0;
virtual void setChild(int value) = 0;
virtual int getLeftSibling() const = 0;
virtual void setLeftSibling(int value) = 0;
virtual int getRightSibling() const = 0;
virtual void setRightSibling(int value) = 0;
virtual std::streamsize getSize() const = 0;
virtual void setSize(std::streamsize value) = 0;
virtual int getStateBits() const = 0;
virtual void setStateBits(int value) = 0;
virtual _INT32 getChild() const = 0;
virtual void setChild(_INT32 value) = 0;
virtual _INT32 getLeftSibling() const = 0;
virtual void setLeftSibling(_INT32 value) = 0;
virtual _INT32 getRightSibling() const = 0;
virtual void setRightSibling(_INT32 value) = 0;
virtual _INT64 getSize() const = 0;
virtual void setSize(_INT64 value) = 0;
virtual _INT32 getStateBits() const = 0;
virtual void setStateBits(_INT32 value) = 0;
virtual UINT64 getCreationDate() const = 0;
virtual void setCreationDate(const UINT64& value) = 0;
virtual UINT64 getModifyDate() const = 0;
virtual void setModifyDate(const UINT64& value) = 0;
virtual _UINT64 getCreationDate() const = 0;
virtual void setCreationDate(const _UINT64& value) = 0;
virtual _UINT64 getModifyDate() const = 0;
virtual void setModifyDate(const _UINT64& value) = 0;
virtual int getSid() const = 0;
virtual void setSid(int newSid) = 0;
virtual _INT32 getSid() const = 0;
virtual void setSid(_INT32 newSid) = 0;
virtual std::wstring GetEntryName() const = 0;
virtual void SetEntryName(const std::wstring &entryName) = 0;
virtual unsigned short getNameLength() const = 0;
virtual _UINT16 getNameLength() const = 0;
virtual void setStartSetc(int value) = 0;
virtual int getStartSetc() const = 0;
virtual void setStartSetc(_INT32 value) = 0;
virtual _INT32 getStartSetc() const = 0;
virtual void Read(Stream stream, CFSVersion ver = CFSVersion::Ver_3) = 0;
virtual void Write(Stream stream) const = 0;
@ -100,6 +100,6 @@ public:
virtual void setStgType(StgType value) = 0;
virtual _GUID_ getStorageCLSID() const = 0;
virtual void setStorageCLSID(_GUID_ value) = 0;
virtual int GetHashCode() const = 0;
virtual _INT32 GetHashCode() const = 0;
};
}

View File

@ -30,21 +30,23 @@
*
*/
#include "sector.h"
#include "Stream/stream_utils.h"
using namespace CFCPP;
int Sector::MINISECTOR_SIZE = 64;
_INT32 Sector::MINISECTOR_SIZE = 64;
Sector::Sector(int size, const Stream stream) :
Sector::Sector(_INT32 size, const Stream stream) :
size(size),
stream(stream)
{}
Sector::Sector(int size, const std::vector<BYTE>& data) :
Sector::Sector(_INT32 size, const std::vector<BYTE>& data) :
size(size), data(data)
{}
Sector::Sector(int size) :
Sector::Sector(_INT32 size) :
size(size)
{}
@ -110,7 +112,7 @@ std::vector<BYTE> &Sector::GetData()
return data;
}
int Sector::getSize() const
_INT32 Sector::getSize() const
{
return size;
}

View File

@ -15,7 +15,7 @@
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* The _INT32eractive user _INT32erfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
@ -25,7 +25,7 @@
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* Creative Commons Attribution-ShareAlike 4.0 _INT32ernational. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
@ -34,8 +34,7 @@
#include <memory>
#include <vector>
#include <mutex>
#include "stream.h"
#include "../../DesktopEditor/common/Types.h"
#include "Stream/stream.h"
namespace CFCPP
@ -54,9 +53,9 @@ enum SectorType
class Sector
{
public:
Sector(int size, const Stream stream);
Sector(int size, const std::vector<BYTE> &data);
Sector(int size);
Sector(_INT32 size, const Stream stream);
Sector(_INT32 size, const std::vector<BYTE> &data);
Sector(_INT32 size);
bool IsStreamed();
void ZeroData();
@ -67,20 +66,20 @@ public:
std::vector<BYTE> &GetData();
public:
static int MINISECTOR_SIZE;
const static int FREESECT = 0xFFFFFFFF;
const static int ENDOFCHAIN = 0xFFFFFFFE;
const static int FATSECT = 0xFFFFFFFD;
const static int DIFSECT = 0xFFFFFFFC;
static _INT32 MINISECTOR_SIZE;
const static _INT32 FREESECT = 0xFFFFFFFF;
const static _INT32 ENDOFCHAIN = 0xFFFFFFFE;
const static _INT32 FATSECT = 0xFFFFFFFD;
const static _INT32 DIFSECT = 0xFFFFFFFC;
int getSize() const;
_INT32 getSize() const;
SectorType type = Normal;
bool dirtyFlag = false;
int id = -1;
_INT32 id = -1;
private:
int size = 0;
_INT32 size = 0;
Stream stream;
std::vector<BYTE> data;
std::mutex lockObject;

View File

@ -58,8 +58,8 @@ void SectorCollection::Clear()
std::shared_ptr<Sector>& SectorCollection::operator[](size_t index)
{
int itemIndex = index / SLICE_SIZE;
int itemOffset = index % SLICE_SIZE;
_INT32 itemIndex = index / SLICE_SIZE;
_INT32 itemOffset = index % SLICE_SIZE;
return largeArraySlices[itemIndex][itemOffset];
}
@ -73,9 +73,9 @@ void SectorCollection::DoCheckSizeLimitReached()
}
}
int SectorCollection::add(std::shared_ptr<Sector> item)
_INT32 SectorCollection::add(std::shared_ptr<Sector> item)
{
unsigned itemIndex = count / SLICE_SIZE;
_UINT32 itemIndex = count / SLICE_SIZE;
if (itemIndex < largeArraySlices.size())
{

View File

@ -48,19 +48,19 @@ public:
SectorCollection();
void Add(std::shared_ptr<Sector> item);
void Clear();
inline int Count()const {return count;}
inline _INT32 Count()const {return count;}
std::shared_ptr<Sector>& operator[](size_t index);
Event<Ver3SizeLimitReached> OnVer3SizeLimitReached;
private:
void DoCheckSizeLimitReached();
int add(std::shared_ptr<Sector> item);
_INT32 add(std::shared_ptr<Sector> item);
private:
const int MAX_SECTOR_V4_COUNT_LOCK_RANGE = 524287; // 0x7FFFFF00 for Version 4
const int SLICE_SIZE = 4096;
const _INT32 MAX_SECTOR_V4_COUNT_LOCK_RANGE = 524287; // 0x7FFFFF00 for Version 4
const _INT32 SLICE_SIZE = 4096;
bool sizeLimitReached = false;
int count = 0;
_INT32 count = 0;
};
}

View File

@ -1,136 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "stream.h"
#include "../../DesktopEditor/common/File.h"
#include <algorithm>
std::streamsize CFCPP::Length(const CFCPP::Stream& st)
{
if (st.get() == nullptr)
return 0;
auto curPos = st->tell();
st->seek(0, std::ios_base::end);
auto ssize = st->tell();
st->seek(curPos);
return ssize;
}
CFCPP::Stream CFCPP::OpenFileStream(std::wstring filename, bool bRewrite, bool trunc)
{
BYTE* pUtf8 = nullptr;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(filename.c_str(), filename.length(), pUtf8, lLen, false);
std::string utf8filename(pUtf8, pUtf8 + lLen);
delete [] pUtf8;
return OpenFileStream(utf8filename, bRewrite, trunc);
}
CFCPP::Stream CFCPP::OpenFileStream(std::string filename, bool bRewrite, bool trunc)
{
CFCPP::Stream st;
// it's not good, but otherwise file doesn't create or if use ios::app, then the seek for writing will be blocked
if (bRewrite)
std::fstream create(filename, std::ios::app | std::ios::out);
if (trunc && bRewrite)
st.reset(new FStreamWrapper(filename, std::ios::binary | std::ios::in | std::ios::out | std::ios::trunc));
else if (bRewrite)
st.reset(new FStreamWrapper(filename, std::ios::binary | std::ios::in | std::ios::out));
else
st.reset(new FStreamWrapper(filename, std::ios::binary | std::ios::in));
return st;
}
bool CFCPP::IsOpen(const Stream &st)
{
if (std::dynamic_pointer_cast<FStreamWrapper>(st))
return std::static_pointer_cast<FStreamWrapper>(st)->is_open();
return false;
}
std::string CFCPP::CorrectUnixPath(const std::string original)
{
#if !defined(_WIN32) && !defined (_WIN64)
return original;
#else
auto str = original;
std::replace(str.begin(), str.end(), '/', '\\');
return str;
#endif
}
int CFCPP::FileLenght(std::wstring filename)
{
auto stream = OpenFileStream(filename);
auto lenght = Length(stream);
stream->close();
return lenght;
}
ULONG64 CFCPP::FileFNVHash(std::wstring filename, int len, int offset)
{
auto stream = OpenFileStream(filename);
if (!IsOpen(stream))
return 0;
if (len < 0)
len = Length(stream);
stream->seek(offset);
ULONG64 h = 2166136261;
constexpr int bufLen = 0x2000;
char buffer[bufLen];
while (len > 0)
{
memset(buffer, 0, bufLen);
int readLen = std::min(bufLen, len);
stream->read(buffer, readLen);
int i;
for (i = 0; i < readLen; i++)
h = (h * 16777619) ^ buffer[i];
len -= readLen;
}
return h;
}

View File

@ -1,98 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include <sstream>
#include <fstream>
#include <memory>
#include <algorithm>
#include <iosfwd>
#include "../../DesktopEditor/common/Types.h"
namespace CFCPP
{
class IStream
{
public:
virtual std::streamsize tell() = 0;
virtual std::streamsize seek(std::streamsize offset, std::ios_base::seekdir mode = std::ios::beg) = 0;
virtual std::streamsize read(char* buffer, std::streamsize len) = 0;
virtual void write (const char* buffer, std::streamsize len) = 0;
virtual void flush() = 0;
virtual void close() = 0;
};
using Stream = std::shared_ptr<IStream>;
class FStreamWrapper : public IStream, public std::fstream
{
public:
FStreamWrapper(std::string filename, std::ios_base::openmode openmode) :
std::fstream(filename, openmode) {}
inline std::streamsize tell() override {
return std::fstream::tellg();
}
inline std::streamsize seek(std::streamsize offset, std::ios_base::seekdir mode = std::ios::beg) override {
std::fstream::seekp(offset, mode);
std::fstream::seekg(offset, mode);
return tell();
}
inline std::streamsize read(char* buffer, std::streamsize len) override {
std::fstream::read(buffer, len);
return tell();
}
inline void write (const char* buffer, std::streamsize len) override {
std::fstream::write(buffer, len);
}
inline void flush() override {
std::fstream::flush();
}
inline void close() override {
std::fstream::close();
}
};
std::string CorrectUnixPath(const std::string original);
Stream OpenFileStream(std::wstring filename, bool bRewrite = false, bool trunc = false);
Stream OpenFileStream(std::string filename, bool bRewrite = false, bool trunc = false);
bool IsOpen(const Stream& st);
std::streamsize Length(const Stream& st);
int FileLenght(std::wstring filename);
ULONG64 FileFNVHash(std::wstring filename, int len = -1, int offset = 0);
}

View File

@ -30,7 +30,6 @@
*
*/
#include "streamrw.h"
#include <algorithm>
using namespace CFCPP;
@ -40,33 +39,33 @@ StreamRW::StreamRW(CFCPP::Stream stream)
{
}
T_LONG64 StreamRW::Seek(T_LONG64 offset)
_INT64 StreamRW::Seek(_INT64 offset)
{
stream->seek(offset, std::ios::beg);
return stream->tell();
}
T_LONG64 CFCPP::StreamRW::Tell()
_INT64 CFCPP::StreamRW::Tell()
{
return stream->tell();
}
void StreamRW::ReadArray(char *data, int lenght)
void StreamRW::ReadArray(char *data, _INT32 lenght)
{
stream->read(data, lenght);
}
void StreamRW::ReadArray(BYTE* data, int lenght)
void StreamRW::ReadArray(BYTE* data, _INT32 lenght)
{
stream->read(reinterpret_cast<char*>(data), lenght);
}
void StreamRW::WriteArray(const BYTE *arr, int lenght)
void StreamRW::WriteArray(const BYTE *arr, _INT32 lenght)
{
stream->write(reinterpret_cast<const char*>(arr), lenght);
}
void StreamRW::WriteArray(const char *arr, int lenght)
void StreamRW::WriteArray(const char *arr, _INT32 lenght)
{
stream->write(arr, lenght);
}

View File

@ -34,7 +34,7 @@
#include <fstream>
#include <array>
#include <vector>
#include "stream.h"
#include "Stream/stream.h"
namespace CFCPP
@ -45,8 +45,8 @@ public:
StreamRW(Stream stream);
T_LONG64 Seek(T_LONG64 offset);
T_LONG64 Tell();
_INT64 Seek(_INT64 offset);
_INT64 Tell();
template <class T>
T Read()
@ -64,10 +64,10 @@ public:
stream->write(asByteArr, sizeof (T));
}
void ReadArray(char* data, int lenght);
void ReadArray(BYTE* data, int lenght);
void WriteArray(const BYTE *arr, int lenght);
void WriteArray(const char *arr, int lenght);
void ReadArray(char* data, _INT32 lenght);
void ReadArray(BYTE* data, _INT32 lenght);
void WriteArray(const BYTE *arr, _INT32 lenght);
void WriteArray(const char *arr, _INT32 lenght);
inline void Close(){return;}

View File

@ -32,11 +32,11 @@
#include "streamview.h"
#include "cfexception.h"
#include <cmath>
#include <algorithm>
using namespace CFCPP;
StreamView::StreamView(const SVector<Sector> &sectorChain, int sectorSize, Stream stream)
StreamView::StreamView(const SVector<Sector> &sectorChain, _INT32 sectorSize, Stream stream)
: sectorSize(sectorSize),
sectorChain(sectorChain),
stream(stream)
@ -48,7 +48,7 @@ StreamView::StreamView(const SVector<Sector> &sectorChain, int sectorSize, Strea
throw CFException("Sector size must be greater than zero");
}
StreamView::StreamView(const SVector<Sector> &sectorChain, int sectorSize, std::streamsize length,
StreamView::StreamView(const SVector<Sector> &sectorChain, _INT32 sectorSize, _INT64 length,
SList<Sector> &availableSectors, Stream stream, bool isFatStream) :
StreamView(sectorChain, sectorSize, stream)
{
@ -57,26 +57,26 @@ StreamView::StreamView(const SVector<Sector> &sectorChain, int sectorSize, std::
}
std::streamsize StreamView::tell()
_INT64 StreamView::tell()
{
return position;
}
void StreamView::write(const char *buffer, std::streamsize count)
void StreamView::write(const char *buffer, _INT64 count)
{
int byteWritten = 0;
int roundByteWritten = 0;
int offset = 0;
_INT32 byteWritten = 0;
_INT32 roundByteWritten = 0;
_INT32 offset = 0;
if ((position + count) > length)
adjustLength((position + count));
if (sectorChain.empty() == false)
{
int sectorOffset = (int)(position / (std::streamsize)sectorSize);
int sectorShift = (int)(position % sectorSize);
_INT32 sectorOffset = (int)(position / (_INT64)sectorSize);
_INT32 sectorShift = (int)(position % sectorSize);
roundByteWritten = (int)(std::min)(sectorSize - (position % (std::streamsize)sectorSize), count);
roundByteWritten = (int)(std::min)((_INT64)sectorSize - (position % (_INT64)sectorSize), count);
if (sectorOffset < (int)sectorChain.size())
{
@ -124,16 +124,16 @@ void StreamView::close()
stream->close();
}
std::streamsize StreamView::read(char *buffer, std::streamsize len)
_INT64 StreamView::read(char *buffer, _INT64 len)
{
int nRead = 0;
int nToRead = 0;
int offset = 0;
_INT32 nRead = 0;
_INT32 nToRead = 0;
_INT32 offset = 0;
if (sectorChain.empty() == false && sectorChain.size() > 0)
{
int sectorIndex = (int)(position / (std::streamsize)sectorSize);
_INT32 sectorIndex = (int)(position / (_INT64)sectorSize);
nToRead = (std::min)((int)sectorChain[0]->GetData().size() - ((int)position % sectorSize), (int)len);
nToRead = (std::min)((_INT64)sectorChain[0]->GetData().size() - ((_INT64)position % sectorSize), len);
if (sectorIndex < (int)sectorChain.size())
{
@ -177,7 +177,7 @@ std::streamsize StreamView::read(char *buffer, std::streamsize len)
return 0;
}
std::streamsize StreamView::seek(std::streamsize offset, std::ios_base::seekdir mode)
_INT64 StreamView::seek(_INT64 offset, std::ios_base::seekdir mode)
{
switch (mode)
{
@ -199,38 +199,38 @@ std::streamsize StreamView::seek(std::streamsize offset, std::ios_base::seekdir
return position;
}
void StreamView::SetLength(std::streamsize value)
void StreamView::SetLength(_INT64 value)
{
adjustLength(value);
}
int StreamView::ReadInt32()
_INT32 StreamView::ReadInt32()
{
read(reinterpret_cast<char*>(&buf), 4);
return buf;
}
void StreamView::WriteInt32(int val)
void StreamView::WriteInt32(_INT32 val)
{
buf = ((val & 0xFF) << 24) | ((val & 0x00FF) << 16) | ((val & 0x0000FF) << 8) | (val & 0x000000FF);
write(reinterpret_cast<char*>(&buf), 4);
}
void StreamView::adjustLength(std::streamsize value)
void StreamView::adjustLength(_INT64 value)
{
SList<Sector> q;
adjustLength(value, q);
}
void StreamView::adjustLength(std::streamsize value, SList<Sector> &availableSectors)
void StreamView::adjustLength(_INT64 value, SList<Sector> &availableSectors)
{
this->length = value;
std::streamsize delta = value - ((std::streamsize)this->sectorChain.size() * (std::streamsize)sectorSize);
_INT64 delta = value - ((_INT64)this->sectorChain.size() * (_INT64)sectorSize);
if (delta > 0)
{
int numberSector = (int)std::ceil(((double)delta / sectorSize));
_INT32 numberSector = (int)std::ceil(((double)delta / sectorSize));
while (numberSector > 0)
{
@ -258,12 +258,12 @@ void StreamView::adjustLength(std::streamsize value, SList<Sector> &availableSec
}
}
std::streamsize StreamView::getPosition() const
_INT64 StreamView::getPosition() const
{
return position;
}
std::streamsize StreamView::getLength() const
_INT64 StreamView::getLength() const
{
return length;
}

View File

@ -42,41 +42,41 @@ namespace CFCPP
class StreamView : public IStream
{
public:
StreamView(const SVector<Sector> &sectorChain, int sectorSize, Stream stream);
StreamView(const SVector<Sector> &sectorChain, int sectorSize, std::streamsize length,
StreamView(const SVector<Sector> &sectorChain, _INT32 sectorSize, Stream stream);
StreamView(const SVector<Sector> &sectorChain, _INT32 sectorSize, _INT64 length,
SList<Sector> &availableSectors, Stream stream, bool isFatStream = false);
std::streamsize tell() override;
std::streamsize seek(std::streamsize offset, std::ios_base::seekdir mode = std::ios::beg) override;
std::streamsize read(char *buffer, std::streamsize count) override;
void write(const char *buffer, std::streamsize count) override;
_INT64 tell() override;
_INT64 seek(_INT64 offset, std::ios_base::seekdir mode = std::ios::beg) override;
_INT64 read(char *buffer, _INT64 count) override;
void write(const char *buffer, _INT64 count) override;
void flush() override {}
void close() override;
std::streamsize getPosition() const;
void SetLength(std::streamsize value);
std::streamsize getLength() const;
_INT64 getPosition() const;
void SetLength(_INT64 value);
_INT64 getLength() const;
SVector<Sector>& BaseSectorChain();
int ReadInt32();
void WriteInt32(int val);
_INT32 ReadInt32();
void WriteInt32(_INT32 val);
private:
void adjustLength(std::streamsize value);
void adjustLength(std::streamsize value, SList<Sector> &availableSectors);
void adjustLength(_INT64 value);
void adjustLength(_INT64 value, SList<Sector> &availableSectors);
private:
int sectorSize = 0;
std::streamsize length = 0;
_INT32 sectorSize = 0;
_INT64 length = 0;
SVector<Sector> sectorChain;
bool isFatStream = false;
int buf = 0;
_INT32 buf = 0;
Stream stream;
std::streamsize position = 0;
_INT64 position = 0;
SList<Sector> freeSectors;
};
}

View File

@ -6,7 +6,8 @@
#include <gtest/gtest.h>
#include <gmock/gmock-matchers.h>
#include "../../DesktopEditor/common/File.h"
#include "../stream.h"
#include "../Stream/fstream_utils.h"
#include "../Stream/stream_utils.h"
#include "../../DesktopEditor/common/Directory.h"
@ -16,7 +17,7 @@ using namespace CFCPP;
constexpr int _70MBLen = 1024 * 1024 * 70;
const vector<unsigned char> _8ByteData = {0x28, 0xFF, 0x28, 0x1D, 0x4C, 0xFA, 0x00, 0x79};
const vector<BYTE> _8ByteData = {0x28, 0xFF, 0x28, 0x1D, 0x4C, 0xFA, 0x00, 0x79};
const vector<BYTE> _70MBVector(_70MBLen, 0x90);
const wstring testDataPath = L"../../../data/";

View File

@ -11,7 +11,7 @@ CORE_ROOT_DIR = $$PWD/../../..
PWD_ROOT_DIR = $$PWD
include(../../base.pri)
ADD_DEPENDENCY(UnicodeConverter, kernel, cfcpp)
ADD_DEPENDENCY(UnicodeConverter, kernel, CompoundFileLib)
INCLUDEPATH += $$PWD/../

View File

@ -15,24 +15,6 @@ struct CompoundFileTest : testing::Test
{
}
void printDirs()
{
for (const auto& dir : *cf.GetDirectories())
{
if (dir == nullptr)
continue;
wcout << left << setw(3) << dir->getSid()
<< left << setw(6) << (dir->getColor() ? L"Black" : L"Red")
<< left << setw(3) << dir->getLeftSibling()
<< left << setw(3) << dir->getRightSibling()
<< left << setw(3) << dir->getChild()
<< left << dir->GetEntryName()
<< endl;
}
wcout << endl;
}
};

View File

@ -36,7 +36,7 @@ void test_dirEntry_read(const DirectoryEntry& de)
EXPECT_EQ(de.rightSibling, 0xFFFFFFFF);
EXPECT_EQ(de.child, 1);
GUID storageCLSID;
_GUID_ storageCLSID;
storageCLSID.Data1 = 0x64818D10;
storageCLSID.Data2 = 0x4F9B;
storageCLSID.Data3 = 0x11CF;

View File

@ -47,7 +47,7 @@ TEST_F(StreamRWTest, read)
EXPECT_EQ(rw->Seek(0), 0);
EXPECT_EQ(rw->Read<char>(), symbol);
EXPECT_EQ(rw->Read<int>(), integer);
EXPECT_EQ(rw->Read<_INT32> (), integer);
}
TEST_F(StreamRWTest, rw_array)

View File

@ -117,7 +117,7 @@ std::wstring ReadUnicodeLP(POLE::Stream *pStream)
{
}
res = std::wstring(ptr, length);
delete ptr;
delete []ptr;
}
else
res = std::wstring((wchar_t*)Data, length);

View File

@ -149,7 +149,6 @@ namespace NSUnicodeConverter
m[852] = "IBM852";
m[1250] = "windows-1250";
m[950] = "Big5";
m[936] = "GBK";
m[28592] = "ISO-8859-2";