diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..baf5828 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +[*.{h,cpp,py,json,page,txt}] +indent_style = space +indent_size = 4 + +[*.{xml,css,md,blp,yml}] +indent_style = space +indent_size = 2 diff --git a/.gitignore b/.gitignore index db6d9bf..9978543 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,8 @@ # Directories out/ +out-linux/ +out-windows/ build/ bin/ .vs/ @@ -54,4 +56,7 @@ _nickbuild/ CMakeUserPresets.json # UI Files -*.ui \ No newline at end of file +*.ui + +# Setup Files +inno/*.exe diff --git a/CMakeLists.txt b/CMakeLists.txt index 645f270..16636c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ if(DEFINED ENV{VCPKG_ROOT}) file(TO_CMAKE_PATH $ENV{VCPKG_ROOT} VCPKG_ROOT) if(EXISTS "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake") set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake") + set(USING_VCPKG ON) endif() endif() if(WIN32) @@ -25,6 +26,7 @@ include(CTest) #libnick Setup add_compile_definitions(SQLITE_HAS_CODEC) +add_compile_definitions(UUID_SYSTEM_GENERATOR) if(LINUX) add_compile_definitions(HAVE_USLEEP) endif() @@ -74,8 +76,14 @@ find_package(CURL REQUIRED) find_package(jsoncpp CONFIG REQUIRED) find_package(Intl REQUIRED) find_package(OpenSSL REQUIRED) -find_package(unofficial-maddy CONFIG REQUIRED) -target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost Boost::locale CURL::libcurl JsonCpp::JsonCpp Intl::Intl OpenSSL::SSL OpenSSL::Crypto unofficial::maddy::maddy) +find_package(stduuid CONFIG REQUIRED) +target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost Boost::locale CURL::libcurl JsonCpp::JsonCpp Intl::Intl OpenSSL::SSL OpenSSL::Crypto stduuid) +if(USING_VCPKG) + find_package(unofficial-maddy CONFIG REQUIRED) + target_link_libraries(${PROJECT_NAME} PUBLIC unofficial::maddy::maddy) +else() + target_link_libraries(${PROJECT_NAME} PUBLIC maddy) +endif() if(WIN32) target_link_libraries(${PROJECT_NAME} PUBLIC Advapi32 Dwmapi Gdiplus Shell32) elseif(LINUX) @@ -88,8 +96,7 @@ elseif(LINUX) pkg_check_modules(gobject REQUIRED IMPORTED_TARGET gobject-2.0) pkg_check_modules(gthread REQUIRED IMPORTED_TARGET gthread-2.0) pkg_check_modules(libsecret REQUIRED IMPORTED_TARGET libsecret-1) - find_package(unofficial-libuuid CONFIG REQUIRED) - target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads PkgConfig::glib PkgConfig::gio PkgConfig::gmodule PkgConfig::gobject PkgConfig::gthread PkgConfig::libsecret unofficial::UUID::uuid) + target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads PkgConfig::glib PkgConfig::gio PkgConfig::gmodule PkgConfig::gobject PkgConfig::gthread PkgConfig::libsecret) endif() #libnick Install diff --git a/README.md b/README.md index 004aa9c..e2f45d4 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,12 @@ The following are a list of dependencies used by libnick. - maddy - openssl - Used for sqlcipher, as libnick manually includes and compiles sqlcipher. +- stduuid ### Linux Only The above dependencies must be installed, plus the following for linux systems: - glib - libsecret -- libuuid ## Consuming libnick via vcpkg libnick is available through `vcpkg`. diff --git a/include/helpers/stringhelpers.h b/include/helpers/stringhelpers.h index 5299a66..db0db66 100644 --- a/include/helpers/stringhelpers.h +++ b/include/helpers/stringhelpers.h @@ -3,6 +3,10 @@ #define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING +#ifndef UUID_SYSTEM_GENERATOR +#define UUID_SYSTEM_GENERATOR +#endif + #include #include #include diff --git a/src/helpers/stringhelpers.cpp b/src/helpers/stringhelpers.cpp index 2073a20..f30dab5 100644 --- a/src/helpers/stringhelpers.cpp +++ b/src/helpers/stringhelpers.cpp @@ -8,11 +8,7 @@ #include #include #include -#ifdef _WIN32 -#include -#elif defined(__linux__) -#include -#endif +#include namespace Nickvision { @@ -89,60 +85,7 @@ namespace Nickvision std::string StringHelpers::newGuid() noexcept { - std::array guid; -#ifdef _WIN32 - GUID win; - CoInitializeEx(nullptr, COINIT_MULTITHREADED); - if (CoCreateGuid(&win) != S_OK) - { - return ""; - } - guid = { - (unsigned char)((win.Data1 >> 24) & 0xFF), - (unsigned char)((win.Data1 >> 16) & 0xFF), - (unsigned char)((win.Data1 >> 8) & 0xFF), - (unsigned char)((win.Data1) & 0xff), - - (unsigned char)((win.Data2 >> 8) & 0xFF), - (unsigned char)((win.Data2) & 0xff), - - (unsigned char)((win.Data3 >> 8) & 0xFF), - (unsigned char)((win.Data3) & 0xFF), - - (unsigned char)win.Data4[0], - (unsigned char)win.Data4[1], - (unsigned char)win.Data4[2], - (unsigned char)win.Data4[3], - (unsigned char)win.Data4[4], - (unsigned char)win.Data4[5], - (unsigned char)win.Data4[6], - (unsigned char)win.Data4[7] - }; -#elif defined(__linux__) - uuid_generate(guid.data()); -#endif - std::ostringstream out; - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[0]); - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[1]); - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[2]); - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[3]); - out << "-"; - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[4]); - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[5]); - out << "-"; - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[6]); - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[7]); - out << "-"; - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[8]); - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[9]); - out << "-"; - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[10]); - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[11]); - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[12]); - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[13]); - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[14]); - out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[15]); - return out.str(); + return uuids::to_string(uuids::uuid_system_generator{}()); } bool StringHelpers::isValidUrl(const std::string& s) noexcept diff --git a/tests/stringtests.cpp b/tests/stringtests.cpp index cf4812f..01a2f8d 100644 --- a/tests/stringtests.cpp +++ b/tests/stringtests.cpp @@ -53,6 +53,7 @@ TEST(StringTests, Guid1) std::string s; ASSERT_NO_THROW(s = StringHelpers::newGuid()); ASSERT_FALSE(s.empty()); + ASSERT_TRUE(s.size() == 36); } TEST(StringTests, UrlValidity1)