2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "AppParamParser.h"
11 #include "CompileInfo.h"
13 #include "ServiceBroker.h"
14 #include "application/AppParams.h"
15 #include "utils/StringUtils.h"
16 #include "utils/SystemInfo.h"
17 #include "utils/log.h"
26 constexpr const char* versionText
=
27 R
"""({0} Media Center {1}
28 Copyright (C) {2} Team {0} - http://kodi.tv
31 constexpr const char* helpText
=
32 R
"""(Usage: {0} [OPTION]... [FILE]...
35 -fs Runs {1} in full screen
36 --standalone {1} runs in a stand alone environment without a window
37 manager and supporting applications. For example, that
38 enables network settings.
39 -p or --portable {1} will look for configurations in install folder instead of ~/.{0}
40 --debug Enable debug logging
41 --version Print version information
42 --test Enable test mode. [FILE] required.
43 --settings=<filename> Loads specified file after advancedsettings.xml replacing any settings specified
44 specified file must exist in special://xbmc/system/
49 CAppParamParser::CAppParamParser() : m_params(std::make_shared
<CAppParams
>())
53 void CAppParamParser::Parse(const char* const* argv
, int nArgs
)
55 std::vector
<std::string
> args
;
58 for (int i
= 0; i
< nArgs
; i
++)
60 args
.emplace_back(argv
[i
]);
67 // testmode is only valid if at least one item to play was given
68 if (m_params
->GetPlaylist().IsEmpty())
69 m_params
->SetTestMode(false);
72 // Record raw paramerters
73 m_params
->SetRawArgs(std::move(args
));
76 void CAppParamParser::DisplayVersion()
78 std::cout
<< StringUtils::Format(versionText
, CSysInfo::GetAppName(), CSysInfo::GetVersion(),
79 CCompileInfo::GetCopyrightYears());
83 void CAppParamParser::DisplayHelp()
85 std::string lcAppName
= CSysInfo::GetAppName();
86 StringUtils::ToLower(lcAppName
);
88 std::cout
<< StringUtils::Format(helpText
, lcAppName
, CSysInfo::GetAppName());
91 void CAppParamParser::ParseArg(const std::string
&arg
)
93 if (arg
== "-fs" || arg
== "--fullscreen")
94 m_params
->SetStartFullScreen(true);
95 else if (arg
== "-h" || arg
== "--help")
100 else if (arg
== "-v" || arg
== "--version")
102 else if (arg
== "--standalone")
103 m_params
->SetStandAlone(true);
104 else if (arg
== "-p" || arg
== "--portable")
105 m_params
->SetPlatformDirectories(false);
106 else if (arg
== "--debug")
107 m_params
->SetLogLevel(LOG_LEVEL_DEBUG
);
108 else if (arg
== "--test")
109 m_params
->SetTestMode(true);
110 else if (arg
.substr(0, 11) == "--settings=")
111 m_params
->SetSettingsFile(arg
.substr(11));
112 else if (arg
.length() != 0 && arg
[0] != '-')
114 const CFileItemPtr item
= std::make_shared
<CFileItem
>(arg
);
116 m_params
->GetPlaylist().Add(item
);