SYNERGY-1232 No configuration available on Windows system (#7100)
* SYNERGY-1232 Use UTF-16 for file path on Windows system * SYNERGY-1232 No configuration available on Windows
This commit is contained in:
@ -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:
|
||||
|
||||
52
src/lib/base/Path.cpp
Normal file
52
src/lib/base/Path.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#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
|
||||
37
src/lib/base/Path.h
Normal file
37
src/lib/base/Path.h
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#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
|
||||
@ -18,6 +18,7 @@
|
||||
|
||||
#include "base/log_outputters.h"
|
||||
#include "base/TMethodJob.h"
|
||||
#include "base/Path.h"
|
||||
#include "arch/Arch.h"
|
||||
|
||||
#include <fstream>
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#include "mt/Lock.h"
|
||||
#include "arch/XArch.h"
|
||||
#include "base/Log.h"
|
||||
#include "base/Path.h"
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
@ -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()) {
|
||||
|
||||
@ -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
|
||||
|
||||
40
src/test/unittests/base/PathTests.cpp
Normal file
40
src/test/unittests/base/PathTests.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/Path.h"
|
||||
#include <fstream>
|
||||
|
||||
#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());
|
||||
}
|
||||
Reference in New Issue
Block a user