lib/common: Replace PathUtilities::basename with barrier::fs equivalent
This commit is contained in:
parent
e7d936b5d7
commit
677612d342
|
@ -24,7 +24,7 @@
|
||||||
#include "barrier/ArgsBase.h"
|
#include "barrier/ArgsBase.h"
|
||||||
#include "base/Log.h"
|
#include "base/Log.h"
|
||||||
#include "base/String.h"
|
#include "base/String.h"
|
||||||
#include "common/PathUtilities.h"
|
#include "io/filesystem.h"
|
||||||
|
|
||||||
#ifdef WINAPI_MSWINDOWS
|
#ifdef WINAPI_MSWINDOWS
|
||||||
#include <VersionHelpers.h>
|
#include <VersionHelpers.h>
|
||||||
|
@ -487,7 +487,13 @@ void
|
||||||
ArgParser::updateCommonArgs(const char* const* argv)
|
ArgParser::updateCommonArgs(const char* const* argv)
|
||||||
{
|
{
|
||||||
argsBase().m_name = ARCH->getHostName();
|
argsBase().m_name = ARCH->getHostName();
|
||||||
argsBase().m_exename = PathUtilities::basename(argv[0]);
|
argsBase().m_exename = parse_exename(argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ArgParser::parse_exename(const char* arg)
|
||||||
|
{
|
||||||
|
// FIXME: we assume UTF-8 encoding, but on Windows this is not correct
|
||||||
|
return barrier::fs::u8path(arg).filename().u8string();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -48,11 +48,14 @@ public:
|
||||||
static String assembleCommand(std::vector<String>& argsArray,
|
static String assembleCommand(std::vector<String>& argsArray,
|
||||||
String ignoreArg = "", int parametersRequired = 0);
|
String ignoreArg = "", int parametersRequired = 0);
|
||||||
|
|
||||||
|
static std::string parse_exename(const char* arg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateCommonArgs(const char* const* argv);
|
void updateCommonArgs(const char* const* argv);
|
||||||
bool checkUnexpectedArgs();
|
bool checkUnexpectedArgs();
|
||||||
|
|
||||||
static ArgsBase& argsBase() { return *m_argsBase; }
|
static ArgsBase& argsBase() { return *m_argsBase; }
|
||||||
|
|
||||||
bool parseMSWindowsArg(ArgsBase& argsBase, const int& argc, const char* const* argv, int& i);
|
bool parseMSWindowsArg(ArgsBase& argsBase, const int& argc, const char* const* argv, int& i);
|
||||||
bool parseCarbonArg(ArgsBase& argsBase, const int& argc, const char* const* argv, int& i);
|
bool parseCarbonArg(ArgsBase& argsBase, const int& argc, const char* const* argv, int& i);
|
||||||
bool parseXWindowsArg(ArgsBase& argsBase, const int& argc, const char* const* argv, int& i);
|
bool parseXWindowsArg(ArgsBase& argsBase, const int& argc, const char* const* argv, int& i);
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
#include "base/TMethodJob.h"
|
#include "base/TMethodJob.h"
|
||||||
#include "base/Log.h"
|
#include "base/Log.h"
|
||||||
#include "common/Version.h"
|
#include "common/Version.h"
|
||||||
#include "common/PathUtilities.h"
|
|
||||||
|
|
||||||
#if WINAPI_MSWINDOWS
|
#if WINAPI_MSWINDOWS
|
||||||
#include "platform/MSWindowsScreen.h"
|
#include "platform/MSWindowsScreen.h"
|
||||||
|
@ -522,7 +521,7 @@ ClientApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc
|
||||||
{
|
{
|
||||||
// general initialization
|
// general initialization
|
||||||
m_serverAddress = new NetworkAddress;
|
m_serverAddress = new NetworkAddress;
|
||||||
args().m_exename = PathUtilities::basename(argv[0]);
|
argsBase().m_exename = ArgParser::parse_exename(argv[0]);
|
||||||
|
|
||||||
// install caller's output filter
|
// install caller's output filter
|
||||||
if (outputter != NULL) {
|
if (outputter != NULL) {
|
||||||
|
|
|
@ -835,7 +835,7 @@ ServerApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc
|
||||||
// general initialization
|
// general initialization
|
||||||
m_barrierAddress = new NetworkAddress;
|
m_barrierAddress = new NetworkAddress;
|
||||||
args().m_config = new Config(m_events);
|
args().m_config = new Config(m_events);
|
||||||
args().m_exename = PathUtilities::basename(argv[0]);
|
args().m_exename = ArgParser::parse_exename(argv[0]);
|
||||||
|
|
||||||
// install caller's output filter
|
// install caller's output filter
|
||||||
if (outputter != NULL) {
|
if (outputter != NULL) {
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
/*
|
|
||||||
* barrier -- mouse and keyboard sharing utility
|
|
||||||
* Copyright (C) 2018 Debauchee Open Source Group
|
|
||||||
*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
These functions cover the vast majority of cases for different paths across
|
|
||||||
windows and unixes. They are not, however, fullproof and probably don't cover
|
|
||||||
fringe cases very well. The library below might be used as an alternative if
|
|
||||||
these implementations prove to be insufficient. As the library's readme states
|
|
||||||
it is simply a temporary band-aid until std::filesystem is integrated (C++17
|
|
||||||
has it in std::experimental) and this class should also be treated as such.
|
|
||||||
|
|
||||||
https://github.com/wjakob/filesystem/
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "PathUtilities.h"
|
|
||||||
|
|
||||||
// keep the default platform delimiter as the first in the list
|
|
||||||
#ifdef _WIN32
|
|
||||||
static const char *Delimiters = "\\/";
|
|
||||||
#else
|
|
||||||
static const char *Delimiters = "/";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const char DefaultDelimiter = Delimiters[0];
|
|
||||||
|
|
||||||
std::string PathUtilities::basename(const std::string& path)
|
|
||||||
{
|
|
||||||
return path.substr(path.find_last_of(Delimiters) + 1);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
* barrier -- mouse and keyboard sharing utility
|
|
||||||
* Copyright (C) 2018 Debauchee Open Source Group
|
|
||||||
*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class PathUtilities
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static std::string basename(const std::string& path);
|
|
||||||
};
|
|
Loading…
Reference in New Issue