From 235016323527761a9774b6305b7c8a1acdad8879 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sun, 22 Oct 2023 19:15:01 +0300 Subject: [PATCH 1/9] build: add GitHub workflows for Windows - matrix: build against Qt 5 & 6 --- .github/workflows/build-windows.yml | 34 +++++++++++++++++++++++++++++ .github/workflows/build.yml | 3 +++ 2 files changed, 37 insertions(+) create mode 100644 .github/workflows/build-windows.yml diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml new file mode 100644 index 0000000..3986b41 --- /dev/null +++ b/.github/workflows/build-windows.yml @@ -0,0 +1,34 @@ +--- +name: build-windows + +on: + workflow_call: + +jobs: + build-windows: + name: Build against Qt ${{ matrix.qt }} on Windows + runs-on: windows-latest + + strategy: + matrix: + qt: [5.15.*, 6.6.*] + fail-fast: false + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install Qt + uses: jurplel/install-qt-action@v3 + with: + version: ${{ matrix.qt }} + host: windows + target: desktop + dir: ${{ runner.temp }}/qt + setup-python: false + + - name: Configure + run: cmake -B ${{ runner.temp }}/build . + + - name: Build + run: cmake --build ${{ runner.temp }}/build diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 43d3fd3..7330098 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,3 +15,6 @@ on: jobs: matrix-linux: uses: ./.github/workflows/build-linux.yml + + matrix-windows: + uses: ./.github/workflows/build-windows.yml From 3c28afc9b0ad0aad2610f8cc1a331a1a0d1f319a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Sat, 4 Nov 2023 10:46:45 +0100 Subject: [PATCH 2/9] fix keypress_windows: need to use scope for enums --- src/keypress_windows.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/keypress_windows.cpp b/src/keypress_windows.cpp index e84fda1..fe81b83 100644 --- a/src/keypress_windows.cpp +++ b/src/keypress_windows.cpp @@ -33,11 +33,11 @@ Keypress::~Keypress() { } static VirtualKeyCode modifier_keys[] = { - SHIFT, - CONTROL, - MENU, - LWIN, - RWIN + VirtualKeyCode::SHIFT, + VirtualKeyCode::CONTROL, + VirtualKeyCode::MENU, + VirtualKeyCode::LWIN, + VirtualKeyCode::RWIN }; From 9cf1ca64f465b54f72edd2f7df821f8d6aed2fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Sat, 4 Nov 2023 10:53:12 +0100 Subject: [PATCH 3/9] fix keypress_windows: use LPCWSTR (const wchar_t*) instead of LPCTSTR (const char*) fixes this error: D:\a\qMasterPassword\qMasterPassword\src\keypress_windows.cpp(99,5): error C2664: 'void CKeyboardSimulator::TextEntry(LPCTSTR)': cannot convert argument 1 from 'const _Elem *' to 'LPCTSTR' [D:\a\_temp\build\qMasterPassword.vcxproj] --- include/3rdparty/IInputSimulator.h | 2 +- include/3rdparty/InputBuilder.h | 2 +- include/3rdparty/KeyboardSimulator.h | 2 +- src/3rdparty/InputBuilder.cpp | 3 +-- src/3rdparty/KeyboardSimulator.cpp | 2 +- src/keypress_windows.cpp | 14 ++------------ 6 files changed, 7 insertions(+), 18 deletions(-) diff --git a/include/3rdparty/IInputSimulator.h b/include/3rdparty/IInputSimulator.h index fa0b5c0..4093671 100644 --- a/include/3rdparty/IInputSimulator.h +++ b/include/3rdparty/IInputSimulator.h @@ -43,7 +43,7 @@ class IKeyboardSimulator virtual void ModifiedKeyStroke(std::vector* modifierKeyCodes, VirtualKeyCode keyCode) = 0; virtual void ModifiedKeyStroke(VirtualKeyCode modifierKey, std::vector* keyCodes) = 0; virtual void ModifiedKeyStroke(VirtualKeyCode modifierKeyCode, VirtualKeyCode keyCode) = 0; - virtual void TextEntry(LPCTSTR text) = 0; + virtual void TextEntry(LPCWSTR text) = 0; }; class IMouseSimulator diff --git a/include/3rdparty/InputBuilder.h b/include/3rdparty/InputBuilder.h index 1973f14..d42690d 100644 --- a/include/3rdparty/InputBuilder.h +++ b/include/3rdparty/InputBuilder.h @@ -52,7 +52,7 @@ class CInputBuilder CInputBuilder& AddCharacter(wchar_t character); CInputBuilder& AddCharacters(std::vector characters); - CInputBuilder& AddCharacters(LPCTSTR characters); + CInputBuilder& AddCharacters(LPCWSTR characters); CInputBuilder& AddRelativeMouseMovement(int x, int y); diff --git a/include/3rdparty/KeyboardSimulator.h b/include/3rdparty/KeyboardSimulator.h index 5e39ebc..5d9988a 100644 --- a/include/3rdparty/KeyboardSimulator.h +++ b/include/3rdparty/KeyboardSimulator.h @@ -52,7 +52,7 @@ class CKeyboardSimulator : void ModifiedKeyStroke(std::vector* modifierKeyCodes, VirtualKeyCode keyCode); void ModifiedKeyStroke(VirtualKeyCode modifierKey, std::vector* keyCodes); void ModifiedKeyStroke(std::vector* modifierKeyCodes, std::vector* keyCodes); - void TextEntry(LPCTSTR text); + void TextEntry(LPCWSTR text); }; diff --git a/src/3rdparty/InputBuilder.cpp b/src/3rdparty/InputBuilder.cpp index c296fa2..c8b0258 100644 --- a/src/3rdparty/InputBuilder.cpp +++ b/src/3rdparty/InputBuilder.cpp @@ -166,10 +166,9 @@ CInputBuilder& CInputBuilder::AddCharacters(std::vector characters) return *this; } -CInputBuilder& CInputBuilder::AddCharacters(LPCTSTR characters) +CInputBuilder& CInputBuilder::AddCharacters(LPCWSTR wstr) { - LPCWSTR wstr = characters; int count = wcslen(wstr); wchar_t* pwchr = const_cast (&wstr[0]); for(int j = 0; j < count; ++j) diff --git a/src/3rdparty/KeyboardSimulator.cpp b/src/3rdparty/KeyboardSimulator.cpp index dd00b79..32e9d15 100644 --- a/src/3rdparty/KeyboardSimulator.cpp +++ b/src/3rdparty/KeyboardSimulator.cpp @@ -138,7 +138,7 @@ } - void CKeyboardSimulator::TextEntry(LPCTSTR text) + void CKeyboardSimulator::TextEntry(LPCWSTR text) { CInputBuilder inputList; SendSimulatedInput(inputList.AddCharacters(text)); diff --git a/src/keypress_windows.cpp b/src/keypress_windows.cpp index fe81b83..5031c0d 100644 --- a/src/keypress_windows.cpp +++ b/src/keypress_windows.cpp @@ -20,6 +20,8 @@ #include #include +#include +#include #if defined(_WIN32) @@ -82,21 +84,9 @@ void Keypress::type(const char* str) { CKeyboardSimulator* sim = (CKeyboardSimulator*)m_simulator; //we need to convert str from UTF8 to UTF16 - /* - //with c++11: -#include -#include std::wstring_convert> converter; std::wstring wide = converter.from_bytes(str); sim->TextEntry(wide.c_str()); - */ - - //Win32 API - std::string sstr = str; - int size_needed = MultiByteToWideChar(CP_UTF8, 0, &sstr[0], (int)sstr.size(), NULL, 0); - std::wstring wstrTo( size_needed, 0 ); - MultiByteToWideChar(CP_UTF8, 0, &sstr[0], (int)sstr.size(), &wstrTo[0], size_needed); - sim->TextEntry(wstrTo.c_str()); } From f6866487c75cc6eb06c088297e170de8d70e89ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Sat, 4 Nov 2023 11:06:08 +0100 Subject: [PATCH 4/9] CMakeLists: use find_package(OpenSSL REQUIRED) for OpenSSL --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58a0511..266a079 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ set(CMAKE_SKIP_RPATH ON) find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui Widgets LinguistTools) find_package(Qt${QT_VERSION_MAJOR} OPTIONAL_COMPONENTS DBus Test) +find_package(OpenSSL REQUIRED) # exposes ${TS_FILES} add_subdirectory(data/translations) @@ -68,21 +69,21 @@ target_link_libraries(${TARGET} PRIVATE Qt::Core Qt::Gui Qt::Widgets + OpenSSL::Crypto ) +target_include_directories(${TARGET} PRIVATE ${OPENSSL_INCLUDE_DIR}) if(UNIX) target_link_libraries(${TARGET} PRIVATE Qt::DBus X11 Xtst - crypto scrypt ) endif() if(WIN32) target_link_libraries(${TARGET} PRIVATE - libeay32 scrypt ws2_32 ) From 7b8bee8b9c19b65e9881f400926cb59e7f223d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Sat, 4 Nov 2023 11:44:09 +0100 Subject: [PATCH 5/9] ci: add scrypt to windows build --- .github/workflows/build-windows.yml | 26 +++++++++++++++++++++++++- CMakeLists.txt | 3 ++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 3986b41..d8f4ea3 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -18,6 +18,30 @@ jobs: - name: Checkout uses: actions/checkout@v3 + - name: Check out scrypt + uses: actions/checkout@master + with: + repository: barrysteyn/scrypt-windows + path: scrypt-windows + + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@v1.1 + + - name: install node + uses: actions/setup-node@master + + - name: Install node-gpy + shell: powershell + run: | + npm install --global node-gyp@latest + + - name: Build scrypt-windows + run: | + node-gyp configure + node-gyp build + node-gyp install + working-directory: scrypt-windows + - name: Install Qt uses: jurplel/install-qt-action@v3 with: @@ -28,7 +52,7 @@ jobs: setup-python: false - name: Configure - run: cmake -B ${{ runner.temp }}/build . + run: cmake -B ${{ runner.temp }}/build . "-DCMAKE_CXX_FLAGS=-I${{ github.workspace }}/scrypt-windows/scrypt-1.1.6/lib" -DCMAKE_LIBRARY_PATH=${{ github.workspace }}/scrypt-windows/build/Release - name: Build run: cmake --build ${{ runner.temp }}/build diff --git a/CMakeLists.txt b/CMakeLists.txt index 266a079..444b8ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,8 +83,9 @@ if(UNIX) endif() if(WIN32) + find_library(SCRYPT_LIBRARY NAMES scrypt scrypt_lib) target_link_libraries(${TARGET} PRIVATE - scrypt + ${SCRYPT_LIBRARY} ws2_32 ) endif() From 61aa5b7531537c8713a94cac79696e55ae599e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Sat, 4 Nov 2023 13:53:42 +0100 Subject: [PATCH 6/9] fix: use _WIN32 instead of WIN32 _WIN32 is defined by the compiler whereas WIN32 by the SDK. --- include/config.h | 2 +- include/crypto_functions.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/config.h b/include/config.h index cc8c7d1..666990d 100644 --- a/include/config.h +++ b/include/config.h @@ -27,7 +27,7 @@ //most of the defines in here are project/OS specific -#if defined(WIN32) || defined(WIN64) +#if defined(_WIN32) || defined(_WIN64) #define PATH_SEP "\\" #else #define PATH_SEP "/" diff --git a/include/crypto_functions.h b/include/crypto_functions.h index 8b1f3be..4eb5936 100644 --- a/include/crypto_functions.h +++ b/include/crypto_functions.h @@ -23,7 +23,7 @@ #include #include -#ifdef WIN32 +#ifdef _WIN32 extern "C" { #include } From 8d90e04ce3e188dd1aa13e4369a47c06fcc6f7ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Sat, 4 Nov 2023 13:34:33 +0100 Subject: [PATCH 7/9] refactor logging: convert ELOG enum to an enum class & rename ERROR was conflicting with a macro on Windows. --- include/logging.h | 42 ++++++++++++++++--------------- src/crypto.cpp | 2 +- src/exception.cpp | 4 +-- src/import_export.cpp | 6 ++--- src/logging.cpp | 40 ++++++++++++++--------------- src/main.cpp | 8 +++--- src/main_class.cpp | 18 ++++++------- src/main_window.cpp | 30 +++++++++++----------- src/password_generator_widget.cpp | 4 +-- 9 files changed, 78 insertions(+), 76 deletions(-) diff --git a/include/logging.h b/include/logging.h index 678d91c..b74d173 100644 --- a/include/logging.h +++ b/include/logging.h @@ -19,15 +19,17 @@ #include using namespace std; -enum ELOG { - NONE = 0, - ERROR, - WARN, - INFO, - DEBUG +enum class LogLevel { + None = 0, + Error, + Warn, + Info, + Debug, + + Count }; -#define LOG_LEVEL_COUNT 5 +#define LOG_LEVEL_COUNT static_cast(LogLevel::Count) #define LOG(level, fmt, ...) CLog::getInstance().Log(level, __FILE__, \ @@ -49,17 +51,17 @@ class CLog *(m_instance.log = new CLog()); } - static string toStr(ELOG level); - static bool parseLevel(const string& level, ELOG& level_out); + static string toStr(LogLevel level); + static bool parseLevel(const string& level, LogLevel& level_out); - void Log(ELOG level, const char* file, const char* function, int line, + void Log(LogLevel level, const char* file, const char* function, int line, const char* fmt, ...); - ELOG consoleLevel() { return m_console_log; } - ELOG fileLevel() { return m_file_log; } + LogLevel consoleLevel() { return m_console_log; } + LogLevel fileLevel() { return m_file_log; } - void setConsoleLevel(ELOG level) { if (level >= NONE && level <= DEBUG) m_console_log = level; } - void setFileLevel(ELOG level) { if (level >= NONE && level <= DEBUG) m_file_log = level; } + void setConsoleLevel(LogLevel level) { if (level >= LogLevel::None && level <= LogLevel::Debug) m_console_log = level; } + void setFileLevel(LogLevel level) { if (level >= LogLevel::None && level <= LogLevel::Debug) m_file_log = level; } bool logDateTimeFile() { return m_bLog_time_file; } bool logDateTimeConsole() { return m_bLog_time_console; } @@ -68,15 +70,15 @@ class CLog void setLogDateTimeFile(bool on) { m_bLog_time_file = on; } - bool logSourceFile(ELOG level) { return m_bLog_src_file[level]; } - void setLogSourceFile(ELOG level, bool on) { m_bLog_src_file[level] = on; } + bool logSourceFile(LogLevel level) { return m_bLog_src_file[static_cast(level)]; } + void setLogSourceFile(LogLevel level, bool on) { m_bLog_src_file[static_cast(level)] = on; } void setLogSourceFileAll(bool on) { for (int i = 0; i < LOG_LEVEL_COUNT; ++i) m_bLog_src_file[i] = on; } - int getFileLogCount(ELOG log_level) { return m_file_log_count[log_level];} + int getFileLogCount(LogLevel log_level) { return m_file_log_count[static_cast(log_level)];} int getFileLogCount(); //sum all levels - int getConsoleLogCount(ELOG log_level) { return m_console_log_count[log_level];} + int getConsoleLogCount(LogLevel log_level) { return m_console_log_count[static_cast(log_level)];} int getConsoleLogCount(); //sum all levels static string getDate(); //format: DD.MM.YY @@ -89,8 +91,8 @@ class CLog bool m_bLog_time_console; bool m_bLog_src_file[LOG_LEVEL_COUNT]; - ELOG m_console_log; - ELOG m_file_log; + LogLevel m_console_log; + LogLevel m_file_log; int m_file_log_count[LOG_LEVEL_COUNT]; int m_console_log_count[LOG_LEVEL_COUNT]; diff --git a/src/crypto.cpp b/src/crypto.cpp index 6893dfe..75fe2c5 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -59,7 +59,7 @@ void User::setStorePasswordHash(const std::string& password) { unsigned char salt_buffer[salt_length]; int ret = secureRandomBytes(salt_buffer, salt_length); if (ret == 0) { - LOG(WARN, "Unsecure random bytes used for password salt!"); + LOG(LogLevel::Warn, "Unsecure random bytes used for password salt!"); } else if (ret == -1) { throw CryptoException(CryptoException::Type_random_failed); } diff --git a/src/exception.cpp b/src/exception.cpp index 2f9450b..2f62627 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -47,7 +47,7 @@ Exception::~Exception() void Exception::log() { if (!m_bLogged) { - CLog::getInstance().Log(ERROR, m_file, m_func, m_line, "Exception: %s", + CLog::getInstance().Log(LogLevel::Error, m_file, m_func, m_line, "Exception: %s", getErrorStr().c_str()); m_bLogged = true; } @@ -117,7 +117,7 @@ ExceptionString::ExceptionString(EnErrors err, const char* func void ExceptionString::log() { if (!m_bLogged) { - CLog::getInstance().Log(ERROR, m_file, m_func, m_line, "%s", + CLog::getInstance().Log(LogLevel::Error, m_file, m_func, m_line, "%s", m_err_desc.c_str()); m_bLogged = true; } diff --git a/src/import_export.cpp b/src/import_export.cpp index 1a47355..736f61f 100644 --- a/src/import_export.cpp +++ b/src/import_export.cpp @@ -91,12 +91,12 @@ void DataImportExport::importJson(UiUser& user, const QString& file_name) { for (auto& site : user.getSites()) { if (site->site.getName() == site_name_str) { new_site = site; - LOG(DEBUG, "Import: found site %s", site_name_str.c_str()); + LOG(LogLevel::Debug, "Import: found site %s", site_name_str.c_str()); break; } } if (!new_site.get()) { - LOG(DEBUG, "Import: new site %s", site_name_str.c_str()); + LOG(LogLevel::Debug, "Import: new site %s", site_name_str.c_str()); new_site = make_shared(); user.getSites().push_back(new_site); } @@ -115,7 +115,7 @@ void DataImportExport::importJson(UiUser& user, const QString& file_name) { try { new_site->site.setType(password_type_str.toUtf8().constData()); } catch (Exception& e) { - LOG(WARN, "Import: unknown password type %s", + LOG(LogLevel::Warn, "Import: unknown password type %s", password_type_str.toUtf8().constData()); } new_site->site.setName(site_name_str); diff --git a/src/logging.cpp b/src/logging.cpp index a596239..d458252 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -29,32 +29,32 @@ *//*********************************************************************/ -string CLog::toStr(ELOG level) +string CLog::toStr(LogLevel level) { switch (level) { - case ERROR: return ("ERROR"); - case WARN: return ("WARN"); - case INFO: return ("INFO"); - case DEBUG: return ("DEBUG"); - case NONE: + case LogLevel::Error: return ("ERROR"); + case LogLevel::Warn: return ("Warn"); + case LogLevel::Info: return ("Info"); + case LogLevel::Debug: return ("Debug"); + case LogLevel::None: default: return ("UNKNOWN LEVEL"); } } -bool CLog::parseLevel(const string& level, ELOG& level_out) +bool CLog::parseLevel(const string& level, LogLevel& level_out) { string str = toLower(level); - if (str == "error" || str == "e") level_out = ERROR; - else if (str == "warn" || str == "w") level_out = WARN; - else if (str == "info" || str == "i") level_out = INFO; - else if (str == "debug" || str == "d") level_out = DEBUG; - else if (str == "none" || str == "n") level_out = NONE; + if (str == "error" || str == "e") level_out = LogLevel::Error; + else if (str == "warn" || str == "w") level_out = LogLevel::Warn; + else if (str == "info" || str == "i") level_out = LogLevel::Info; + else if (str == "debug" || str == "d") level_out = LogLevel::Debug; + else if (str == "none" || str == "n") level_out = LogLevel::None; else return false; return true; } -void CLog::Log(ELOG level, const char* file, const char* function, int line, +void CLog::Log(LogLevel level, const char* file, const char* function, int line, const char* fmt, ...) { @@ -67,7 +67,7 @@ void CLog::Log(ELOG level, const char* file, const char* function, int line, if (level <= m_file_log) { FILE* pFile = fopen(LOG_FILE, "a+"); if (pFile) { - if (m_bLog_src_file[level] && file) { + if (m_bLog_src_file[static_cast(level)] && file) { /* be more verbose in debug mode */ #ifdef _DEBUG fprintf(pFile, "%s: %s() Line %d: ", file, function, line); @@ -80,12 +80,12 @@ void CLog::Log(ELOG level, const char* file, const char* function, int line, fprintf(pFile, "%s: %s\n", toStr(level).c_str(), buffer); fclose(pFile); } - ++m_file_log_count[level]; + ++m_file_log_count[static_cast(level)]; } if (level <= m_console_log) { - if (level == ERROR) { - if (m_bLog_src_file[level] && file) { + if (level == LogLevel::Error) { + if (m_bLog_src_file[static_cast(level)] && file) { #ifdef _DEBUG fprintf(stderr, "%s: %s() Line %d: ", file, function, line); #else @@ -96,7 +96,7 @@ void CLog::Log(ELOG level, const char* file, const char* function, int line, getTime().c_str()); fprintf(stderr, "%s\n", buffer); } else { - if (m_bLog_src_file[level] && file) { + if (m_bLog_src_file[static_cast(level)] && file) { #ifdef _DEBUG printf("%s: %s() Line %d: ", file, function, line); #else @@ -107,7 +107,7 @@ void CLog::Log(ELOG level, const char* file, const char* function, int line, getTime().c_str()); printf("%s\n", buffer); } - ++m_console_log_count[level]; + ++m_console_log_count[static_cast(level)]; } } @@ -154,7 +154,7 @@ string CLog::getTime() CLog::CLog() : m_bLog_time_file(true), m_bLog_time_console(false) - , m_console_log(INFO), m_file_log(INFO) + , m_console_log(LogLevel::Info), m_file_log(LogLevel::Info) { memset(m_console_log_count, 0, sizeof(m_console_log_count)); memset(m_file_log_count, 0, sizeof(m_file_log_count)); diff --git a/src/main.cpp b/src/main.cpp index 3209eca..33c4e68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,13 +21,13 @@ int main(int argc, char* argv[]) try { #ifdef _DEBUG - CLog::getInstance().setConsoleLevel(DEBUG); + CLog::getInstance().setConsoleLevel(LogLevel::Debug); #else - CLog::getInstance().setConsoleLevel(WARN); + CLog::getInstance().setConsoleLevel(LogLevel::Warn); #endif - CLog::getInstance().setFileLevel(NONE); + CLog::getInstance().setFileLevel(LogLevel::None); CLog::getInstance().setLogSourceFileAll(false); - CLog::getInstance().setLogSourceFile(ERROR, true); + CLog::getInstance().setLogSourceFile(LogLevel::Error, true); Exception::setLogAllExceptions(true); diff --git a/src/main_class.cpp b/src/main_class.cpp index cd423b4..672a67d 100644 --- a/src/main_class.cpp +++ b/src/main_class.cpp @@ -184,12 +184,12 @@ void CMain::loadTranslation() { if (!m_app_trans.load(locale, "translation", "_", src_app_trans_path)) { if (!m_app_trans.load(locale, "translation", "_", app_trans_path)) { if (!locale.name().startsWith("en")) - LOG(WARN, "Failed to load translation %s", locale.name().toUtf8().constData()); + LOG(LogLevel::Warn, "Failed to load translation %s", locale.name().toUtf8().constData()); } else { - LOG(DEBUG, "Using translation from %s", app_trans_path.toUtf8().constData()); + LOG(LogLevel::Debug, "Using translation from %s", app_trans_path.toUtf8().constData()); } } else { - LOG(DEBUG, "Using translation from %s", src_app_trans_path.toUtf8().constData()); + LOG(LogLevel::Debug, "Using translation from %s", src_app_trans_path.toUtf8().constData()); } qApp->installTranslator(&m_app_trans); @@ -204,19 +204,19 @@ int CMain::processArgs() //set console log level string level; if (m_parameters->getSwitch("verbose")) - CLog::getInstance().setConsoleLevel(DEBUG); + CLog::getInstance().setConsoleLevel(LogLevel::Debug); else if (m_parameters->getSwitch("no-log")) - CLog::getInstance().setConsoleLevel(NONE); + CLog::getInstance().setConsoleLevel(LogLevel::None); else if (m_parameters->getParam("log", level)) { - ELOG log_level; + LogLevel log_level; if (CLog::parseLevel(level, log_level)) CLog::getInstance().setConsoleLevel(log_level); } //set file log level if (m_parameters->getSwitch("no-file-log")) - CLog::getInstance().setFileLevel(NONE); + CLog::getInstance().setFileLevel(LogLevel::None); else if (m_parameters->getParam("file-log", level)) { - ELOG log_level; + LogLevel log_level; if (CLog::parseLevel(level, log_level)) CLog::getInstance().setFileLevel(log_level); } @@ -224,7 +224,7 @@ int CMain::processArgs() #ifdef TESTING_SUPPORT string test_file; if (m_parameters->getParam("test", test_file)) { - LOG(DEBUG, "Running tests on file %s", test_file.c_str()); + LOG(LogLevel::Debug, "Running tests on file %s", test_file.c_str()); UnitTests test(test_file); return QTest::qExec(&test); } diff --git a/src/main_window.cpp b/src/main_window.cpp index 17f66bc..ae1b4ee 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -124,11 +124,11 @@ MainWindow::MainWindow(QWidget *parent) : #ifdef Q_OS_LINUX if (!QDBusConnection::sessionBus().isConnected()) { - LOG(WARN, "Cannot connect to the D-Bus session bus.\n" + LOG(LogLevel::Warn, "Cannot connect to the D-Bus session bus.\n" "To start it, run: eval `dbus-launch --auto-syntax`\n"); } else if (!QDBusConnection::sessionBus().registerService( "org.bkueng.qMasterPassword")) { - LOG(WARN, "%s", qPrintable(QDBusConnection::sessionBus().lastError().message())); + LOG(LogLevel::Warn, "%s", qPrintable(QDBusConnection::sessionBus().lastError().message())); } else { DBusAdapter* dbus_adapter = new DBusAdapter(this); QDBusConnection::sessionBus().registerObject("/MainWindow", dbus_adapter, @@ -259,7 +259,7 @@ void MainWindow::loginLogoutClicked() { } void MainWindow::login() { - LOG(DEBUG, "Login"); + LOG(LogLevel::Debug, "Login"); QString user_name = m_ui->cmbUserName->currentText(); QString password = m_ui->txtPassword->text(); auto iter_user = m_users.find(user_name); @@ -325,7 +325,7 @@ void MainWindow::login() { } void MainWindow::logout() { - LOG(DEBUG, "Logout"); + LOG(LogLevel::Debug, "Logout"); m_master_password.logout(); m_current_user = nullptr; m_ui->btnLoginLogout->setText(tr("Login")); @@ -531,7 +531,7 @@ void MainWindow::appAboutToQuit() { saveSettings(); } void MainWindow::saveSettings() { - LOG(DEBUG, "saving settings"); + LOG(LogLevel::Debug, "saving settings"); QSettings settings("qMasterPassword", "qMasterPassword"); settings.setValue("main_window/geometry", saveGeometry()); settings.setValue("main_window/window_state", saveState()); @@ -576,7 +576,7 @@ void MainWindow::readSettings() { m_next_category_id = category; } ++m_next_category_id; - LOG(DEBUG, "next category id: %i", (int )m_next_category_id); + LOG(LogLevel::Debug, "next category id: %i", (int )m_next_category_id); } for (auto iter = m_categories.begin(); iter != m_categories.end(); ++iter) { addCategory(iter.value(), iter.key()); @@ -589,7 +589,7 @@ void MainWindow::readSettings() { stream >> m_users; int selected_index = -1; for (auto& user : m_users) { - LOG(DEBUG, "Read user: %s (%i sites)", + LOG(LogLevel::Debug, "Read user: %s (%i sites)", user.getUserName().toUtf8().constData(), user.getSites().count()); m_ui->cmbUserName->addItem(user.getUserName()); @@ -668,7 +668,7 @@ void MainWindow::selectionChanged(const QItemSelection& selected, } void MainWindow::addCategory(const QString& name, CategoryId id) { - LOG(DEBUG, "Adding Category %s", name.toStdString().c_str()); + LOG(LogLevel::Debug, "Adding Category %s", name.toStdString().c_str()); if (id == -1) id = m_next_category_id++; m_categories[id] = name; @@ -679,7 +679,7 @@ void MainWindow::addCategory(const QString& name, CategoryId id) { } void MainWindow::removeCategory(CategoryId category_id) { const QString& category_name = m_categories[category_id]; - LOG(DEBUG, "Removing Category %s", category_name.toStdString().c_str()); + LOG(LogLevel::Debug, "Removing Category %s", category_name.toStdString().c_str()); m_categories.remove(category_id); //button @@ -739,7 +739,7 @@ void MainWindow::copyPWToClipboardClicked() { copyPWToClipboard(button->site()); } void MainWindow::copyPWToClipboard(const UiSite& site) { - LOG(DEBUG, "copy pw to clipboard"); + LOG(LogLevel::Debug, "copy pw to clipboard"); string password = m_master_password.sitePassword(site.site); int timeout = copyToClipboard(QString::fromUtf8(password.c_str())); QString suffix = ""; @@ -751,7 +751,7 @@ void MainWindow::copyPWToClipboard(const UiSite& site) { void MainWindow::copyUserToClipboard(const UiSite& site) { if (site.user_name.isEmpty()) return; - LOG(DEBUG, "copy login name to clipboard"); + LOG(LogLevel::Debug, "copy login name to clipboard"); int timeout = copyToClipboard(site.user_name); QString suffix = ""; if (timeout > 0) @@ -787,7 +787,7 @@ void MainWindow::clearDataFromClipboardTimer() { } } void MainWindow::clearDataFromClipboard() { - LOG(DEBUG, "Clear data from clipboard"); + LOG(LogLevel::Debug, "Clear data from clipboard"); QClipboard* clipboard = QApplication::clipboard(); QString original_text = clipboard->text(); if (original_text == m_clipboard_data) { @@ -800,7 +800,7 @@ void MainWindow::clearDataFromClipboard() { m_clipboard_time_left = 0; } void MainWindow::showHidePWClicked() { - LOG(DEBUG, "show/hide PW clicked"); + LOG(LogLevel::Debug, "show/hide PW clicked"); UserPushButton* button = dynamic_cast(sender()); if (!button) return; UiSite& site = button->site(); @@ -832,14 +832,14 @@ void MainWindow::activateLogoutTimer() { if (!m_master_password.isLoggedIn() || !m_application_settings.auto_logout_when_hidden) return; - LOG(DEBUG, "Activating Logout Timer (%i min)", + LOG(LogLevel::Debug, "Activating Logout Timer (%i min)", m_application_settings.auto_logout_timeout); m_logout_timer->start(m_application_settings.auto_logout_timeout*60*1000); } void MainWindow::abortLogoutTimer() { if (m_logout_timer->isActive()) { - LOG(DEBUG, "Aborting Logout Timer"); + LOG(LogLevel::Debug, "Aborting Logout Timer"); m_logout_timer->stop(); } } diff --git a/src/password_generator_widget.cpp b/src/password_generator_widget.cpp index 4cc4708..ca26dd7 100644 --- a/src/password_generator_widget.cpp +++ b/src/password_generator_widget.cpp @@ -61,7 +61,7 @@ void PasswordGeneratorWidget::uiChanged() { QString chars; //Note: we assume each template contains only passwords that are in no //other of the templates - LOG(DEBUG, "Number of pw templates: %i", (int)templates.size()); + LOG(LogLevel::Debug, "Number of pw templates: %i", (int)templates.size()); for (int j = 0; j < (int)templates.size(); ++j) { double num = 1; for (int i = 0; i < templates[j].length(); ++i) { @@ -148,7 +148,7 @@ PasswordGeneratorWidget::Method PasswordGeneratorWidget::selectedMethod() { void PasswordGeneratorWidget::getRandomBytes(unsigned char* buffer, int num) { int ret = secureRandomBytes(buffer, num); - if (ret == 0) LOG(WARN, "Used less secure pseudo-random function for random numbers!"); + if (ret == 0) LOG(LogLevel::Warn, "Used less secure pseudo-random function for random numbers!"); else if (ret == -1) { QMessageBox::critical(this, tr("Error"), tr("Failed to get random data")); throw 0; From d91c48ec2a58f6bf6d24d5e2f54fa2b12173b5aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Sat, 4 Nov 2023 14:07:59 +0100 Subject: [PATCH 8/9] .gitignore: ignore cmake-build-* --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 2fd2b1c..c546339 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,5 @@ ui/ui_*.h *.pro.user /.qtc_clangd + +/cmake-build-* \ No newline at end of file From da9be61245e4cfddf09ba1c6c60fce43fa1607f8 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sat, 4 Nov 2023 19:07:40 +0200 Subject: [PATCH 9/9] build: use CXXFLAGS to add flags Setting CMAKE_CXX_FLAGS on the command line overrides the defaults generated by CMake, which leads to compiler warnings and broken code. We want to add flags to the compiler command line, hence setting CXXFLAGS environment variable is the correct approach. - CMakeLists.txt: prepend linker options to address linker warnings - fix some typos - reformat run parts to improve readability --- .github/workflows/build-windows.yml | 16 +++++++++++----- CMakeLists.txt | 4 ++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index d8f4ea3..347dcb3 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -27,20 +27,20 @@ jobs: - name: Add msbuild to PATH uses: microsoft/setup-msbuild@v1.1 - - name: install node + - name: Install node uses: actions/setup-node@master - - name: Install node-gpy + - name: Install node-gyp shell: powershell run: | npm install --global node-gyp@latest - name: Build scrypt-windows + working-directory: scrypt-windows run: | node-gyp configure node-gyp build node-gyp install - working-directory: scrypt-windows - name: Install Qt uses: jurplel/install-qt-action@v3 @@ -52,7 +52,13 @@ jobs: setup-python: false - name: Configure - run: cmake -B ${{ runner.temp }}/build . "-DCMAKE_CXX_FLAGS=-I${{ github.workspace }}/scrypt-windows/scrypt-1.1.6/lib" -DCMAKE_LIBRARY_PATH=${{ github.workspace }}/scrypt-windows/build/Release + env: + CXXFLAGS: -I${{ github.workspace }}/scrypt-windows/scrypt-1.1.6/lib + run: > + cmake -B ${{ runner.temp }}/build + "-DCMAKE_LIBRARY_PATH=${{ github.workspace }}/scrypt-windows/build/Release" + . - name: Build - run: cmake --build ${{ runner.temp }}/build + run: | + cmake --build ${{ runner.temp }}/build diff --git a/CMakeLists.txt b/CMakeLists.txt index 444b8ff..909af8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,10 @@ endif() if(WIN32) find_library(SCRYPT_LIBRARY NAMES scrypt scrypt_lib) + target_link_options(${TARGET} BEFORE PRIVATE + /LTCG /INCREMENTAL:NO + /NODEFAULTLIB:libcmt.lib + ) target_link_libraries(${TARGET} PRIVATE ${SCRYPT_LIBRARY} ws2_32