Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub workflows for Windows #37

Merged
merged 9 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
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: Check out scrypt
uses: actions/checkout@master
with:
repository: barrysteyn/scrypt-windows
path: scrypt-windows

- name: Add msbuild to PATH
uses: microsoft/[email protected]

- name: Install node
uses: actions/setup-node@master

- 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

- 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
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
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ on:
jobs:
matrix-linux:
uses: ./.github/workflows/build-linux.yml

matrix-windows:
uses: ./.github/workflows/build-windows.yml
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ ui/ui_*.h
*.pro.user

/.qtc_clangd

/cmake-build-*
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -68,22 +69,27 @@ 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)
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
libeay32
scrypt
${SCRYPT_LIBRARY}
ws2_32
)
endif()
Expand Down
2 changes: 1 addition & 1 deletion include/3rdparty/IInputSimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class IKeyboardSimulator
virtual void ModifiedKeyStroke(std::vector<VirtualKeyCode>* modifierKeyCodes, VirtualKeyCode keyCode) = 0;
virtual void ModifiedKeyStroke(VirtualKeyCode modifierKey, std::vector<VirtualKeyCode>* keyCodes) = 0;
virtual void ModifiedKeyStroke(VirtualKeyCode modifierKeyCode, VirtualKeyCode keyCode) = 0;
virtual void TextEntry(LPCTSTR text) = 0;
virtual void TextEntry(LPCWSTR text) = 0;
};

class IMouseSimulator
Expand Down
2 changes: 1 addition & 1 deletion include/3rdparty/InputBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class CInputBuilder

CInputBuilder& AddCharacter(wchar_t character);
CInputBuilder& AddCharacters(std::vector<wchar_t> characters);
CInputBuilder& AddCharacters(LPCTSTR characters);
CInputBuilder& AddCharacters(LPCWSTR characters);


CInputBuilder& AddRelativeMouseMovement(int x, int y);
Expand Down
2 changes: 1 addition & 1 deletion include/3rdparty/KeyboardSimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class CKeyboardSimulator :
void ModifiedKeyStroke(std::vector<VirtualKeyCode>* modifierKeyCodes, VirtualKeyCode keyCode);
void ModifiedKeyStroke(VirtualKeyCode modifierKey, std::vector<VirtualKeyCode>* keyCodes);
void ModifiedKeyStroke(std::vector<VirtualKeyCode>* modifierKeyCodes, std::vector<VirtualKeyCode>* keyCodes);
void TextEntry(LPCTSTR text);
void TextEntry(LPCWSTR text);

};

2 changes: 1 addition & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 "/"
Expand Down
2 changes: 1 addition & 1 deletion include/crypto_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <openssl/hmac.h>
#include <openssl/rand.h>
#ifdef WIN32
#ifdef _WIN32
extern "C" {
#include <crypto/crypto_scrypt.h>
}
Expand Down
42 changes: 22 additions & 20 deletions include/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
#include <string>
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<int>(LogLevel::Count)


#define LOG(level, fmt, ...) CLog::getInstance().Log(level, __FILE__, \
Expand All @@ -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; }
Expand All @@ -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<int>(level)]; }
void setLogSourceFile(LogLevel level, bool on) { m_bLog_src_file[static_cast<int>(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<int>(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<int>(log_level)];}
int getConsoleLogCount(); //sum all levels

static string getDate(); //format: DD.MM.YY
Expand All @@ -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];
Expand Down
3 changes: 1 addition & 2 deletions src/3rdparty/InputBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,9 @@ CInputBuilder& CInputBuilder::AddCharacters(std::vector<wchar_t> 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<wchar_t*> (&wstr[0]);
for(int j = 0; j < count; ++j)
Expand Down
2 changes: 1 addition & 1 deletion src/3rdparty/KeyboardSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
}


void CKeyboardSimulator::TextEntry(LPCTSTR text)
void CKeyboardSimulator::TextEntry(LPCWSTR text)
{
CInputBuilder inputList;
SendSimulatedInput(inputList.AddCharacters(text));
Expand Down
2 changes: 1 addition & 1 deletion src/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/import_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UiSite>();
user.getSites().push_back(new_site);
}
Expand All @@ -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);
Expand Down
24 changes: 7 additions & 17 deletions src/keypress_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <type_traits>
#include <string>
#include <locale>
#include <codecvt>


#if defined(_WIN32)
Expand All @@ -33,11 +35,11 @@ Keypress::~Keypress() {
}

static VirtualKeyCode modifier_keys[] = {
SHIFT,
CONTROL,
MENU,
LWIN,
RWIN
VirtualKeyCode::SHIFT,
VirtualKeyCode::CONTROL,
VirtualKeyCode::MENU,
VirtualKeyCode::LWIN,
VirtualKeyCode::RWIN
};


Expand Down Expand Up @@ -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 <locale>
#include <codecvt>
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> 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());
}


Expand Down
Loading