diff --git a/ChangeLog b/ChangeLog index 5942bb601..dc9307b4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,7 @@ Bug fixes: - #7092 Synergy is running after quit on Linux - #7095 Update account and upgrade links - #7096 The system duplicates hotkeys in setup +- #7100 No configuration available on Windows - #7097 The title "Enterprise" disappeares after clicking on "Preferences" Enhancements: diff --git a/src/lib/base/Path.cpp b/src/lib/base/Path.cpp new file mode 100644 index 000000000..1e0fa3265 --- /dev/null +++ b/src/lib/base/Path.cpp @@ -0,0 +1,52 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2014-2021 Symless Ltd. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "Path.h" + +#if SYSAPI_WIN32 +#include "arch/win32/ArchMiscWindows.h" +#endif + +namespace synergy { + +namespace filesystem { + +#ifdef SYSAPI_WIN32 + +std::wstring path(const String& filePath) +{ + std::wstring result; + + auto lenght = MultiByteToWideChar(CP_UTF8, 0, filePath.c_str(), filePath.length(), NULL, 0); + if (lenght > 0) + { + result.resize(lenght); + MultiByteToWideChar(CP_UTF8, 0, filePath.c_str(), filePath.length(), &result[0], lenght); + } + + return result; +} + +#else +std::string path(const String& filePath) +{ + return filePath; +} +#endif + +} //namespace filesystem + +} //namespace synergy diff --git a/src/lib/base/Path.h b/src/lib/base/Path.h new file mode 100644 index 000000000..ee8d43e6b --- /dev/null +++ b/src/lib/base/Path.h @@ -0,0 +1,37 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2014-2021 Symless Ltd. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef SYNERGY_PATH_H +#define SYNERGY_PATH_H + +#include "String.h" + +namespace synergy { + +namespace filesystem { + +#ifdef SYSAPI_WIN32 + std::wstring path(const String& filePath); +#else + std::string path(const String& filePath); +#endif + + +} //namespace filesystem + +} //namespace synergy + +#endif // SYNERGY_PATH_H diff --git a/src/lib/base/log_outputters.cpp b/src/lib/base/log_outputters.cpp index 514e0fa31..20b904a40 100644 --- a/src/lib/base/log_outputters.cpp +++ b/src/lib/base/log_outputters.cpp @@ -18,6 +18,7 @@ #include "base/log_outputters.h" #include "base/TMethodJob.h" +#include "base/Path.h" #include "arch/Arch.h" #include @@ -259,7 +260,7 @@ FileLogOutputter::write(ELevel level, const char *message) bool moveFile = false; std::ofstream m_handle; - m_handle.open(m_fileName.c_str(), std::fstream::app); + m_handle.open(synergy::filesystem::path(m_fileName), std::fstream::app); if (m_handle.is_open() && m_handle.fail() != true) { m_handle << message << std::endl; diff --git a/src/lib/net/SecureSocket.cpp b/src/lib/net/SecureSocket.cpp index 7676132ad..4cc2a1274 100644 --- a/src/lib/net/SecureSocket.cpp +++ b/src/lib/net/SecureSocket.cpp @@ -23,6 +23,7 @@ #include "mt/Lock.h" #include "arch/XArch.h" #include "base/Log.h" +#include "base/Path.h" #include #include @@ -333,7 +334,7 @@ SecureSocket::loadCertificates(String& filename) return false; } else { - std::ifstream file(filename.c_str()); + std::ifstream file(synergy::filesystem::path(filename)); bool exist = file.good(); file.close(); @@ -706,7 +707,7 @@ SecureSocket::verifyCertFingerprint() // check if this fingerprint exist String fileLine; std::ifstream file; - file.open(trustedServersFilename.c_str()); + file.open(synergy::filesystem::path(trustedServersFilename)); bool isValid = false; if (file.is_open()) { diff --git a/src/lib/synergy/ServerApp.cpp b/src/lib/synergy/ServerApp.cpp index c734d98eb..840e8e213 100644 --- a/src/lib/synergy/ServerApp.cpp +++ b/src/lib/synergy/ServerApp.cpp @@ -39,6 +39,7 @@ #include "base/Log.h" #include "base/TMethodEventJob.h" #include "common/Version.h" +#include "base/Path.h" #if SYSAPI_WIN32 #include "arch/win32/ArchMiscWindows.h" @@ -228,7 +229,7 @@ ServerApp::loadConfig(const String& pathname) try { // load configuration LOG((CLOG_DEBUG "opening configuration \"%s\"", pathname.c_str())); - std::ifstream configStream(pathname.c_str()); + std::ifstream configStream(synergy::filesystem::path(pathname)); if (!configStream.is_open()) { // report failure to open configuration as a debug message // since we try several paths and we expect some to be diff --git a/src/test/unittests/base/PathTests.cpp b/src/test/unittests/base/PathTests.cpp new file mode 100644 index 000000000..0303009e5 --- /dev/null +++ b/src/test/unittests/base/PathTests.cpp @@ -0,0 +1,40 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2014-2021 Symless Ltd. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "base/Path.h" +#include + +#include "test/global/gtest.h" + + +TEST(PathTests, open_file_using_path) +{ + std::string utf8FileName = "тіás.txt"; +#if SYSAPI_WIN32 + //Windows uses UTF-16 for file path and names + std::wstring fileName = L"\x0442\x0456\x00E1\x0073\x002E\x0074\x0078\x0074"; +#else + std::string fileName = utf8FileName; +#endif + + std::fstream file(fileName, std::fstream::out); + file << "test"; + file.close(); + + std::ifstream inFile(synergy::filesystem::path(utf8FileName)); + EXPECT_TRUE(inFile.is_open()); +}