diff --git a/src/path_manager/path_manager.cpp b/src/path_manager/path_manager.cpp index 99f469c..9b7250f 100644 --- a/src/path_manager/path_manager.cpp +++ b/src/path_manager/path_manager.cpp @@ -76,22 +76,34 @@ std::filesystem::path PathManager::GetKnownFolder(REFKNOWNFOLDERID id) { #endif std::string PathManager::GetHome() { - if (const char* home = getenv("HOME")) { - return std::string(home); - } #ifdef _WIN32 char path[MAX_PATH]; if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, path))) return std::string(path); +#else + if (const char* home = getenv("HOME")) { + return std::string(home); + } #endif return {}; } std::filesystem::path PathManager::GetEnvOrDefault(const char* env_var, const std::string& def) { +#ifdef _WIN32 + char* buffer = nullptr; + size_t size = 0; + + if (_dupenv_s(&buffer, &size, env_var) == 0 && buffer != nullptr) { + std::filesystem::path result(buffer); + free(buffer); + return result; + } +#else if (const char* val = getenv(env_var)) { return std::filesystem::path(val); } +#endif return std::filesystem::path(def); } diff --git a/src/screen_capturer/windows/screen_capturer_wgc.cpp b/src/screen_capturer/windows/screen_capturer_wgc.cpp index cc8a893..01416a1 100644 --- a/src/screen_capturer/windows/screen_capturer_wgc.cpp +++ b/src/screen_capturer/windows/screen_capturer_wgc.cpp @@ -14,33 +14,42 @@ namespace crossdesk { static std::vector gs_display_list; -std::string WideToUtf8(const wchar_t* wideStr) { - int size_needed = WideCharToMultiByte(CP_UTF8, 0, wideStr, -1, nullptr, 0, - nullptr, nullptr); +std::string WideToUtf8(const std::wstring& wstr) { + if (wstr.empty()) return {}; + int size_needed = WideCharToMultiByte( + CP_UTF8, 0, wstr.data(), (int)wstr.size(), nullptr, 0, nullptr, nullptr); std::string result(size_needed, 0); - WideCharToMultiByte(CP_UTF8, 0, wideStr, -1, &result[0], size_needed, nullptr, - nullptr); - result.pop_back(); + WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), result.data(), + size_needed, nullptr, nullptr); return result; } +std::string CleanDisplayName(const std::wstring& wide_name) { + std::string name = WideToUtf8(wide_name); + name.erase(std::remove_if(name.begin(), name.end(), + [](unsigned char c) { return !std::isalnum(c); }), + name.end()); + return name; +} + BOOL WINAPI EnumMonitorProc(HMONITOR hmonitor, [[maybe_unused]] HDC hdc, [[maybe_unused]] LPRECT lprc, LPARAM data) { MONITORINFOEX monitor_info_; monitor_info_.cbSize = sizeof(MONITORINFOEX); if (GetMonitorInfo(hmonitor, &monitor_info_)) { + std::string display_name = CleanDisplayName(monitor_info_.szDevice); if (monitor_info_.dwFlags & MONITORINFOF_PRIMARY) { gs_display_list.insert( gs_display_list.begin(), - {(void*)hmonitor, WideToUtf8(monitor_info_.szDevice), + {(void*)hmonitor, display_name, (monitor_info_.dwFlags & MONITORINFOF_PRIMARY) ? true : false, monitor_info_.rcMonitor.left, monitor_info_.rcMonitor.top, monitor_info_.rcMonitor.right, monitor_info_.rcMonitor.bottom}); *(HMONITOR*)data = hmonitor; } else { gs_display_list.push_back(DisplayInfo( - (void*)hmonitor, WideToUtf8(monitor_info_.szDevice), + (void*)hmonitor, display_name, (monitor_info_.dwFlags & MONITORINFOF_PRIMARY) ? true : false, monitor_info_.rcMonitor.left, monitor_info_.rcMonitor.top, monitor_info_.rcMonitor.right, monitor_info_.rcMonitor.bottom)); diff --git a/src/thumbnail/thumbnail.cpp b/src/thumbnail/thumbnail.cpp index adcaa5b..bb6f32c 100644 --- a/src/thumbnail/thumbnail.cpp +++ b/src/thumbnail/thumbnail.cpp @@ -118,13 +118,13 @@ void ScaleNv12ToABGR(char* src, int src_w, int src_h, int dst_w, int dst_h, memset(dst_rgba, 0, dst_w * dst_h * 4); for (int i = 0; i < dst_w * dst_h; ++i) { - dst_rgba[i * 4 + 3] = 0xFF; + dst_rgba[i * 4 + 3] = static_cast(0xFF); } - for (int y = 0; y < fit_h; ++y) { + for (int row = 0; row < fit_h; ++row) { int dst_offset = - ((y + (dst_h - fit_h) / 2) * dst_w + (dst_w - fit_w) / 2) * 4; - memcpy(dst_rgba + dst_offset, abgr.data() + y * fit_w * 4, fit_w * 4); + ((row + (dst_h - fit_h) / 2) * dst_w + (dst_w - fit_w) / 2) * 4; + memcpy(dst_rgba + dst_offset, abgr.data() + row * fit_w * 4, fit_w * 4); } } @@ -172,7 +172,7 @@ int Thumbnail::SaveToThumbnail(const char* yuv420p, int width, int height, memset(rgba_buffer_, 0x00, thumbnail_width_ * thumbnail_height_ * 4); for (int i = 0; i < thumbnail_width_ * thumbnail_height_; ++i) { // Set alpha channel to opaque - rgba_buffer_[i * 4 + 3] = 0xFF; + rgba_buffer_[i * 4 + 3] = static_cast(0xFF); } } @@ -214,7 +214,7 @@ int Thumbnail::LoadThumbnail( return -1; } else { for (int i = 0; i < image_paths.size(); i++) { - size_t pos1 = image_paths[i].string().find('/') + 1; + // size_t pos1 = image_paths[i].string().find('/') + 1; std::string cipher_image_name = image_paths[i].filename().string(); std::string remote_id; std::string cipher_password; @@ -241,7 +241,7 @@ int Thumbnail::LoadThumbnail( AES_decrypt(cipher_password, aes128_key_, aes128_iv_); } else { size_t pos_n = cipher_image_name.find('N'); - size_t pos_at = cipher_image_name.find('@'); + // size_t pos_at = cipher_image_name.find('@'); if (pos_n == std::string::npos) { LOG_ERROR("Invalid filename"); diff --git a/xmake.lua b/xmake.lua index 85ac3e9..6fdce6f 100644 --- a/xmake.lua +++ b/xmake.lua @@ -13,6 +13,7 @@ set_encodings("utf-8") -- set_policy("build.warning", true) -- set_warnings("all", "extra") +-- add_cxxflags("/W4", "/WX") add_defines("UNICODE") if is_mode("debug") then