Skip to content

Commit

Permalink
fixed tools download url
Browse files Browse the repository at this point in the history
renamed headers and sources for consistency
switched from namespaces to classes
sllightly improved the tar header parsing (using 64-bit fseek function)
moved the zip extraction logic into a separate class to make it compatible with the tar class
moved the tools download logic into a separate class
  • Loading branch information
paolo-projects committed Feb 9, 2022
1 parent 440be2d commit f9aaa78
Show file tree
Hide file tree
Showing 35 changed files with 1,349 additions and 801 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
CMakeSettings.json
/testing
/LIBS
/debug.log
/debug.log
/test.tar
/test.zip
/testtar
128 changes: 103 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,17 @@ if(ZLIB_FOUND)
message (STATUS "ZLib found, version ${ZLIB_VERSION_STRING}")
endif()

include_directories(${ZLIB_INCLUDE_DIRS})

find_package(CURL REQUIRED)

if(CURL_FOUND)
message (STATUS "Curl found, version ${CURL_VERSION_STRING}")
endif()

include_directories(${CURL_INCLUDE_DIRS})

#find_package(LibArchive REQUIRED)

#if(LibArchive_FOUND)
# message (STATUS "LibArchive found, version ${LibArchive_VERSION}")
#endif()

#include_directories(${LibArchive_INCLUDE_DIRS})

find_package(LibZip REQUIRED)

include_directories(${ZLIB_INCLUDE_DIRS})
include_directories(${CURL_INCLUDE_DIRS})
include_directories(${LIBZIP_INCLUDE_DIRS})

if(LIBZIP_FOUND)
Expand All @@ -51,13 +42,16 @@ include_directories ("${PROJECT_SOURCE_DIR}/include")
set (SOURCE_FILES src/unlocker.cpp /
src/versionparser.cpp /
src/buildsparser.cpp /
src/archiveutils.cpp /
src/netutils.cpp /
src/debugutils.cpp /
src/installinfoutils.cpp /
src/servicestoputils.cpp /
src/patchutils.cpp /
src/tar.cpp )
src/archive.cpp /
src/network.cpp /
src/debug.cpp /
src/installinfo.cpp /
src/winservices.cpp /
src/patcher.cpp /
src/tar.cpp /
src/main.cpp /
src/ziparchive.cpp /
src/toolsdownloader.cpp)

IF (MSVC)
IF (UNLOCKER_STATIC_LIBS_WIN)
Expand All @@ -68,13 +62,15 @@ IF (MSVC)
ENDIF()
ENDIF (MSVC)

add_executable(Unlocker ${SOURCE_FILES} )
add_executable(Unlocker ${SOURCE_FILES})

# Support skipping file offsets when tar contains files larger than ~2 Gig
target_compile_definitions(Unlocker PUBLIC _FILE_OFFSET_BITS=64)

set_target_properties(Unlocker PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ON)

target_link_libraries (Unlocker ${ZLIB_LIBRARIES})
target_link_libraries (Unlocker ${CURL_LIBRARIES})
#target_link_libraries (Unlocker ${LibArchive_LIBRARIES})
target_link_libraries (Unlocker ${LIBZIP_LIBRARY})

if(WIN32)
Expand All @@ -95,14 +91,96 @@ IF (MSVC)
ENDIF()
ENDIF(MSVC)

# Main test

set (TEST_SOURCES tests/test_patch.cpp /
src/debugutils.cpp /
src/patchutils.cpp /
src/tar.cpp )
src/debug.cpp /
src/patcher.cpp /
src/network.cpp /
src/versionparser.cpp /
src/buildsparser.cpp /
src/archive.cpp /
src/installinfo.cpp /
src/winservices.cpp /
src/tar.cpp /
src/unlocker.cpp /
src/ziparchive.cpp /
src/toolsdownloader.cpp)

add_executable( TestPatch ${TEST_SOURCES} "include/unlocker.h")

add_executable( TestPatch ${TEST_SOURCES} )
target_compile_definitions(TestPatch PUBLIC _FILE_OFFSET_BITS=64)

include_directories(TestPatch ${ZLIB_INCLUDE_DIRS})
include_directories(TestPatch ${CURL_INCLUDE_DIRS})
include_directories(TestPatch ${LIBZIP_INCLUDE_DIRS})
target_link_libraries (TestPatch ${ZLIB_LIBRARIES})
target_link_libraries (TestPatch ${CURL_LIBRARIES})
target_link_libraries (TestPatch ${LIBZIP_LIBRARY})

if(WIN32)
target_link_libraries (TestPatch ws2_32 Wldap32)
endif()

set_target_properties( TestPatch PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ON)

enable_testing()
add_test(NAME TestPatchTest COMMAND TestPatch "${PROJECT_SOURCE_DIR}")
add_test(NAME TestPatchTest COMMAND TestPatch "${PROJECT_SOURCE_DIR}")

# Tar test

set (TESTTAR_SOURCES tests/test_tar.cpp /
src/debug.cpp /
src/patcher.cpp /
src/versionparser.cpp /
src/buildsparser.cpp /
src/archive.cpp /
src/installinfo.cpp /
src/winservices.cpp /
src/tar.cpp /
src/ziparchive.cpp /
src/toolsdownloader.cpp)

add_executable( TestTar ${TESTTAR_SOURCES} "include/unlocker.h")

target_compile_definitions(TestTar PUBLIC _FILE_OFFSET_BITS=64)

include_directories(TestTar ${ZLIB_INCLUDE_DIRS})
include_directories(TestTar ${CURL_INCLUDE_DIRS})
include_directories(TestTar ${LIBZIP_INCLUDE_DIRS})
target_link_libraries (TestTar ${ZLIB_LIBRARIES})
target_link_libraries (TestTar ${LIBZIP_LIBRARY})

set_target_properties( TestTar PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ON)

enable_testing()
add_test(NAME TestTarTest COMMAND TestTar "${PROJECT_SOURCE_DIR}")

# Zip test

set (TESTZIP_SOURCES tests/test_zip.cpp /
src/debug.cpp /
src/patcher.cpp /
src/versionparser.cpp /
src/buildsparser.cpp /
src/archive.cpp /
src/installinfo.cpp /
src/winservices.cpp /
src/tar.cpp /
src/ziparchive.cpp /
src/toolsdownloader.cpp)

add_executable( TestZip ${TESTZIP_SOURCES} "include/unlocker.h")

target_compile_definitions(TestZip PUBLIC _FILE_OFFSET_BITS=64)

include_directories(TestZip ${ZLIB_INCLUDE_DIRS})
include_directories(TestZip ${CURL_INCLUDE_DIRS})
include_directories(TestZip ${LIBZIP_INCLUDE_DIRS})
target_link_libraries (TestZip ${ZLIB_LIBRARIES})
target_link_libraries (TestZip ${LIBZIP_LIBRARY})

set_target_properties( TestZip PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ON)

enable_testing()
add_test(NAME TestZipTest COMMAND TestZip "${PROJECT_SOURCE_DIR}")
22 changes: 22 additions & 0 deletions include/archive.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef ARCHIVEUTILS_H
#define ARCHIVEUTILS_H

#include "filesystem.hpp"
#ifdef __linux__
#include <cstring>
#endif

#include "ziparchive.h"
#include "tar.h"
#include "debug.h"
#include <errno.h>

class Archive
{
public:
static bool extractZip(fs::path from, std::string filename, fs::path to);
static bool extractTar(fs::path from, std::string filename, fs::path to);
static void Archive::extractionProgress(float progress);
};

#endif // ARCHIVEUTILS_H
31 changes: 0 additions & 31 deletions include/archiveutils.h

This file was deleted.

4 changes: 2 additions & 2 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

// Program options
#define PROG_VERSION "v1.1.3"
#define PROG_VERSION "v1.1.4"

// Install - Default option
#define INSTALL_OPTION "--install"
Expand All @@ -34,7 +34,7 @@
#define FUSION_DEF_PRE15_TOOLS_NAME "com.vmware.fusion.tools.darwinPre15.zip.tar"
#define FUSION_DEF_PRE15_TOOLS_ZIP "com.vmware.fusion.tools.darwinPre15.zip"

#define FUSION_DEF_CORE_LOC "/core/com.vmware.fusion.zip.tar"
#define FUSION_DEF_CORE_LOC "/x86/core/com.vmware.fusion.zip.tar"
#define FUSION_DEF_CORE_NAME "com.vmware.fusion.zip.tar"
#define FUSION_DEF_CORE_NAME_ZIP "com.vmware.fusion.zip"

Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions include/installinfoutils.h → include/installinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
#define INSTALLINFOUTILS_H

#include <string>
#include <stdexcept>

#include "config.h"

class VMWareInfoException : public std::runtime_error
{
public:
VMWareInfoException(const char* message) : std::runtime_error(message) {}
VMWareInfoException(const std::string& message) : std::runtime_error(message) {}
};

class VMWareInfoRetriever
{
public:
Expand Down
23 changes: 0 additions & 23 deletions include/netutils.h

This file was deleted.

47 changes: 47 additions & 0 deletions include/network.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef NETUTILS_H
#define NETUTILS_H

#include <curl/curl.h>
#include <fstream>
#include <sstream>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <chrono>
#include <functional>

#define CURL_DEBUG false

class NetworkException : public std::runtime_error
{
public:
NetworkException(const char* message, CURLcode code) : std::runtime_error(message), code(code) {}
NetworkException(const std::string& message, CURLcode code) : std::runtime_error(message), code(code) {}
CURLcode getCode() const { return code; }
private:
CURLcode code;
};

struct NetworkProgress {
double mBytesDownloadedLastTime = 0.0;
long long lastProgressUpdateTime = 0;
};

class Network
{
public:
Network();
~Network();
void curlDownload(const std::string& url, const std::string& fileName);
std::string curlGet(const std::string& url);
private:
static constexpr double mBytesProgressUpdateDelta = 0.1; // 0.1 MB
static constexpr long long updatePeriodMs = 200; // update every 100ms

NetworkProgress networkProgress = {};
static size_t write_data_file(char* ptr, size_t size, size_t nmemb, void* stream);
static int progress_callback(void* clientp, double dltotal, double dlnow, double ultotal, double ulnow);
};

#endif // NETUTILS_H
Loading

0 comments on commit f9aaa78

Please sign in to comment.