Skip to content

Commit

Permalink
Rename ArchiveFactory to Facade7z
Browse files Browse the repository at this point in the history
  • Loading branch information
thebrandre committed Feb 18, 2024
1 parent c053279 commit c7def98
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ target_sources(7zip-examples
"main.cpp"
"InMemoryArchiveUpdateCallback.h"
"InMemoryArchiveUpdateCallback.cpp"
"ArchiveFactory.h"
"ArchiveFactory.cpp"
"Facade7z.h"
"Facade7z.cpp"
"ArchiveProperties.h"
"ArchiveProperties.cpp"
"ExportGUID.cpp"
Expand Down
20 changes: 10 additions & 10 deletions ArchiveFactory.cpp → Facade7z.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ArchiveFactory.h"
#include "Facade7z.h"
#include "ExportGUID.h"
#include <boost/nowide/convert.hpp>
#include <fmt/format.h>
Expand Down Expand Up @@ -39,7 +39,7 @@ static auto getArchiveClassIdFromFormatId(unsigned f_formatId) -> const GUID*
}


ArchiveFactory::ArchiveFactory()
Facade7z::Facade7z()
{
Handle7zipDLL = LoadLibraryW(L"7zip.dll");
if (!Handle7zipDLL)
Expand Down Expand Up @@ -81,12 +81,12 @@ ArchiveFactory::ArchiveFactory()
}
}

ArchiveFactory::~ArchiveFactory()
Facade7z::~Facade7z()
{
FreeLibrary(Handle7zipDLL);
}

auto ArchiveFactory::createInArchive(unsigned FormatId) const -> IInArchive*
auto Facade7z::createInArchive(unsigned FormatId) const -> IInArchive*
{
const auto ArchiveClassGuid = ::getArchiveClassIdFromFormatId(FormatId);
if (ArchiveClassGuid == nullptr)
Expand All @@ -99,7 +99,7 @@ auto ArchiveFactory::createInArchive(unsigned FormatId) const -> IInArchive*
return static_cast<IInArchive*>(Archive);
}

auto ArchiveFactory::createOutArchive(unsigned FormatId) const -> IOutArchive*
auto Facade7z::createOutArchive(unsigned FormatId) const -> IOutArchive*
{
const auto ArchiveClassGuid = ::getArchiveClassIdFromFormatId(FormatId);
if (ArchiveClassGuid == nullptr)
Expand All @@ -112,7 +112,7 @@ auto ArchiveFactory::createOutArchive(unsigned FormatId) const -> IOutArchive*
return static_cast<IOutArchive*>(Archive);
}

auto ArchiveFactory::createHasher(std::string_view Name) const -> IHasher*
auto Facade7z::createHasher(std::string_view Name) const -> IHasher*
{
CMyComPtr<IHashers> Hashers{};
if (Functions.GetHashers(&Hashers) != S_OK) [[unlikely]]
Expand Down Expand Up @@ -145,7 +145,7 @@ auto ArchiveFactory::createHasher(std::string_view Name) const -> IHasher*
return Hasher;
}

auto ArchiveFactory::getFileExtensionFromFormatId(unsigned FormatId) -> const char*
auto Facade7z::getFileExtensionFromFormatId(unsigned FormatId) -> const char*
{
switch (FormatId)
{
Expand All @@ -170,20 +170,20 @@ auto ArchiveFactory::getFileExtensionFromFormatId(unsigned FormatId) -> const ch
}
}

unsigned ArchiveFactory::getNumberOfFormats() const
unsigned Facade7z::getNumberOfFormats() const
{
UInt32 NumberOfFormats{};
if (Functions.GetNumberOfFormats(&NumberOfFormats) != S_OK) [[unlikely]]
throw ArchiveException("GetNumberOfFormats failed!");
return NumberOfFormats;
}

std::uint32_t ArchiveFactory::getMajorVersion() const
std::uint32_t Facade7z::getMajorVersion() const
{
return Version >> 16;
}

std::uint32_t ArchiveFactory::getMinorVersion() const
std::uint32_t Facade7z::getMinorVersion() const
{
return Version & 0xFFFFu;
}
14 changes: 7 additions & 7 deletions ArchiveFactory.h → Facade7z.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

#include "ArchiveProperties.h"

class ArchiveFactory{
class Facade7z{
public:

ArchiveFactory();
ArchiveFactory(const ArchiveFactory&) = delete;
ArchiveFactory(ArchiveFactory&&) noexcept = delete;
ArchiveFactory& operator=(const ArchiveFactory&) = delete;
ArchiveFactory& operator=(ArchiveFactory&&) noexcept = delete;
~ArchiveFactory();
Facade7z();
Facade7z(const Facade7z&) = delete;
Facade7z(Facade7z&&) noexcept = delete;
Facade7z& operator=(const Facade7z&) = delete;
Facade7z& operator=(Facade7z&&) noexcept = delete;
~Facade7z();

auto createInArchive(unsigned FormatId = 7) const -> IInArchive*;
auto createOutArchive(unsigned FormatId = 7) const -> IOutArchive*;
Expand Down
12 changes: 6 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <cassert>
#include <ranges>

#include "ArchiveFactory.h"
#include "Facade7z.h"
#include "ArchiveProperties.h"
#include <Shlwapi.h>
#include <7zip/ICoder.h>
Expand Down Expand Up @@ -42,7 +42,7 @@ std::string getFileName(IInArchive* Archive, UInt32 Index)
}


void extractStuff(ArchiveFactory& Factory)
void extractStuff(Facade7z& Factory)
{
const unsigned ArchiveFormatId = 0x07;
//std::filesystem::path TestArchive("./Archive-Password2.7z");
Expand Down Expand Up @@ -83,7 +83,7 @@ void extractStuff(ArchiveFactory& Factory)
Archive->Extract(&ItemIndex, 1, false, ExtractCallback);
}

void compressStuff(ArchiveFactory& Factory)
void compressStuff(Facade7z& Factory)
{
const unsigned ArchiveFormatId = 0x07;
CMyComPtr<IOutArchive> OutArchive = Factory.createOutArchive(ArchiveFormatId);
Expand Down Expand Up @@ -111,7 +111,7 @@ void compressStuff(ArchiveFactory& Factory)
{
for (const int GeneratedArchiveIndex : std::views::iota(1, 100))
{
const std::filesystem::path Candidate = std::filesystem::current_path() / fmt::format("generatedArchive_{}.{}", GeneratedArchiveIndex, ArchiveFactory::getFileExtensionFromFormatId(ArchiveFormatId));
const std::filesystem::path Candidate = std::filesystem::current_path() / fmt::format("generatedArchive_{}.{}", GeneratedArchiveIndex, Facade7z::getFileExtensionFromFormatId(ArchiveFormatId));
if (!std::filesystem::exists(Candidate))
return Candidate;
}
Expand All @@ -122,7 +122,7 @@ void compressStuff(ArchiveFactory& Factory)
OutFile.write(reinterpret_cast<const char*>(Buffer.data()), Buffer.size());
}

void hashStuff(ArchiveFactory& Factory)
void hashStuff(Facade7z& Factory)
{
CMyComPtr<IHasher> Hasher = Factory.createHasher("SHA256");
Hasher->Init();
Expand All @@ -137,7 +137,7 @@ void hashStuff(ArchiveFactory& Factory)
int main()
{
fmt::print("Running in directory {}.\n", std::filesystem::current_path());
ArchiveFactory Factory;
Facade7z Factory;
fmt::print("7zip DLL version {}.{}.\n", Factory.getMajorVersion(), Factory.getMinorVersion());
fmt::print("Number of supported formats {}.\n", Factory.getNumberOfFormats());
extractStuff(Factory);
Expand Down

0 comments on commit c7def98

Please sign in to comment.