diff --git a/Common/cppcf/cfitem.cpp b/Common/cppcf/cfitem.cpp new file mode 100644 index 0000000000..5b7bf388e5 --- /dev/null +++ b/Common/cppcf/cfitem.cpp @@ -0,0 +1,8 @@ +#include "cfitem.h" + +using namespace CFCPP; + +CFItem::CFItem() +{ + +} diff --git a/Common/cppcf/cfitem.h b/Common/cppcf/cfitem.h new file mode 100644 index 0000000000..6ef195756d --- /dev/null +++ b/Common/cppcf/cfitem.h @@ -0,0 +1,20 @@ +#pragma once +#include "compoundfile.h" + +namespace CFCPP +{ +class CFItem +{ +public: + CFItem(); + +protected: + void CheckDisposed() + { + if (compoudFile.SizeFile() == 0) + } + +public: + CompoundFile compoudFile; +}; +} diff --git a/Common/cppcf/compoundfile.cpp b/Common/cppcf/compoundfile.cpp new file mode 100644 index 0000000000..f39ab64610 --- /dev/null +++ b/Common/cppcf/compoundfile.cpp @@ -0,0 +1,8 @@ +#include "compoundfile.h" + +using namespace CFCPP; + +CompoundFile::CompoundFile() +{ + +} diff --git a/Common/cppcf/compoundfile.h b/Common/cppcf/compoundfile.h new file mode 100644 index 0000000000..5aa6450dfe --- /dev/null +++ b/Common/cppcf/compoundfile.h @@ -0,0 +1,23 @@ +#pragma once + +namespace CFCPP +{ +enum CFSConfiguration +{ + + Default = 1, + SectorRecycle = 2, + EraseFreeSectors = 4, + NoValidationException = 8, + LeaveOpen = 16, +}; + +class CompoundFile +{ +public: + CompoundFile(); + +public: + CFSConfiguration configuration = Default; +}; +} diff --git a/Common/cppcf/header.cpp b/Common/cppcf/header.cpp new file mode 100644 index 0000000000..8410d9a6f5 --- /dev/null +++ b/Common/cppcf/header.cpp @@ -0,0 +1,9 @@ +#include "header.h" + + +using namespace CFCPP; + +Header::Header() +{ + +} diff --git a/Common/cppcf/header.h b/Common/cppcf/header.h new file mode 100644 index 0000000000..d0f9bbb16f --- /dev/null +++ b/Common/cppcf/header.h @@ -0,0 +1,28 @@ +#pragma once + + +#include "sector.h" +#include + +namespace CFCPP +{ +class Header +{ +public: + Header(); + +public: + std::array headerSignature = {0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1}; + std::array clsid; + USHORT minorVersion = 0x003E; + USHORT majorVersion = 0x0003; + USHORT byteOrder = 0xFFFE; + USHORT sectorShift = 9; + USHORT miniSectorShift = 6; + std::array unused; + int directorySectorsNumber; + int fatSectorsNumber; + int firstDirectorySectorID; +}; + +} diff --git a/Common/cppcf/sector.cpp b/Common/cppcf/sector.cpp new file mode 100644 index 0000000000..1464a0aa5f --- /dev/null +++ b/Common/cppcf/sector.cpp @@ -0,0 +1,99 @@ +#include "sector.h" + +using namespace CFCPP; + +int Sector::MINISECTOR_SIZE = 64; + +Sector::Sector(int size, std::unique_ptr stream) : + size(size), stream(std::move(stream)) +{} + +Sector::Sector(int size, const std::vector& data) : + size(size), data(data) +{} + +Sector::Sector(int size) : + size(size) +{} + + +bool Sector::IsStreamed() +{ + if (stream == nullptr || size == MINISECTOR_SIZE) + return false; + + auto currentPossition = stream->tellg(); + + stream->seekg(std::ios_base::end); + auto endPossition = stream->tellg(); + stream->seekg(std::ios_base::beg); + auto begPossition = stream->tellg(); + auto streamSize = endPossition - begPossition; + + stream->seekg(currentPossition, std::ios_base::beg); + + return (this->id * size) + size < streamSize; +} + +void Sector::ZeroData() +{ + std::fill(data.begin(), data.end(), 0); + dirtyFlag = true; +} + +void Sector::InitFATData() +{ + std::fill(data.begin(), data.end(), 0xff); + dirtyFlag = true; +} + +void Sector::ReleaseData() +{ + data.clear(); +} + +void Sector::Dispose(bool disposing) +{ + try + { + if (!_disposed) + { + std::lock_guard lock(lockObject); + if (disposing) + { + // Call from user code... + + + } + + data.clear(); + dirtyFlag = false; + id = ENDOFCHAIN; + size = 0; + + } + } + catch(...) + {} + _disposed = true; +} + +std::vector Sector::GetData() +{ + if (data.empty()) + { + data = std::vector(size, 0); + if (IsStreamed()) + { + stream->seekg(size + id * size, std::ios_base::beg); + stream->read(reinterpret_cast(data.data()), size); + } + } + // copy + return data; +} + +int Sector::getSize() const +{ + return size; +} diff --git a/Common/cppcf/sector.h b/Common/cppcf/sector.h new file mode 100644 index 0000000000..5c541b83d4 --- /dev/null +++ b/Common/cppcf/sector.h @@ -0,0 +1,56 @@ +#pragma once + +#include +#include +#include +#include "../../DesktopEditor/common/Types.h" +#include +#include + +namespace CFCPP +{ +enum SectorType +{ + Normal, + Mini, + FAT, + DIFAT, + RangeLockSector, + Directory +}; + +class Sector +{ +public: + Sector(int size, std::unique_ptr stream); + Sector(int size, const std::vector &data); + Sector(int size); + + bool IsStreamed(); + void ZeroData(); + void InitFATData(); + void ReleaseData(); + + virtual void Dispose(bool disposing=false); + +public: + static int MINISECTOR_SIZE; + const int FREESECT = 0xFFFFFFFF; + const int ENDOFCHAIN = 0xFFFFFFFE; + const int FATSECT = 0xFFFFFFFD; + const int DIFSECT = 0xFFFFFFFC; + + int getSize() const; + +private: + bool dirtyFlag = false; + int size = 0; + std::unique_ptr stream; + SectorType type; + int id = -1; + std::vector data; + std::mutex lockObject; + bool _disposed;//false +}; + +}