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 "FileItemList.h"
14 #include "ServiceBroker.h"
15 #include "application/AppParams.h"
16 #include "utils/StringUtils.h"
17 #include "utils/SystemInfo.h"
18 #include "utils/log.h"
27 constexpr const char* versionText
=
28 R
"""({0} Media Center {1}
29 Copyright (C) {2} Team {0} - http://kodi.tv
32 constexpr const char* helpText
=
33 R
"""(Usage: {0} [OPTION]... [FILE]...
36 -fs Runs {1} in full screen
37 --standalone {1} runs in a stand alone environment without a window
38 manager and supporting applications. For example, that
39 enables network settings.
40 -p or --portable {1} will look for configurations in install folder instead of ~/.{0}
41 --debug Enable debug logging
42 --version Print version information
43 --test Enable test mode. [FILE] required.
44 --settings=<filename> Loads specified file after advancedsettings.xml replacing any settings specified
45 specified file must exist in special://xbmc/system/
50 CAppParamParser::CAppParamParser() : m_params(std::make_shared
<CAppParams
>())
54 void CAppParamParser::Parse(const char* const* argv
, int nArgs
)
56 std::vector
<std::string
> args
;
59 for (int i
= 0; i
< nArgs
; i
++)
61 args
.emplace_back(argv
[i
]);
68 // testmode is only valid if at least one item to play was given
69 if (m_params
->GetPlaylist().IsEmpty())
70 m_params
->SetTestMode(false);
73 // Record raw paramerters
74 m_params
->SetRawArgs(std::move(args
));
77 void CAppParamParser::DisplayVersion()
79 std::cout
<< StringUtils::Format(versionText
, CSysInfo::GetAppName(), CSysInfo::GetVersion(),
80 CCompileInfo::GetCopyrightYears());
84 void CAppParamParser::DisplayHelp()
86 std::string lcAppName
= CSysInfo::GetAppName();
87 StringUtils::ToLower(lcAppName
);
89 std::cout
<< StringUtils::Format(helpText
, lcAppName
, CSysInfo::GetAppName());
92 void CAppParamParser::ParseArg(const std::string
&arg
)
94 if (arg
== "-fs" || arg
== "--fullscreen")
95 m_params
->SetStartFullScreen(true);
96 else if (arg
== "-h" || arg
== "--help")
101 else if (arg
== "-v" || arg
== "--version")
103 else if (arg
== "--standalone")
104 m_params
->SetStandAlone(true);
105 else if (arg
== "-p" || arg
== "--portable")
106 m_params
->SetPlatformDirectories(false);
107 else if (arg
== "--debug")
108 m_params
->SetLogLevel(LOG_LEVEL_DEBUG
);
109 else if (arg
== "--test")
110 m_params
->SetTestMode(true);
111 else if (arg
.substr(0, 11) == "--settings=")
112 m_params
->SetSettingsFile(arg
.substr(11));
113 else if (arg
.length() != 0 && arg
[0] != '-')
115 const CFileItemPtr item
= std::make_shared
<CFileItem
>(arg
);
117 m_params
->GetPlaylist().Add(item
);