Skip to content

Commit

Permalink
refactor app parameter parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Marshall committed Jun 13, 2011
1 parent 1e703b3 commit b12aab6
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 116 deletions.
6 changes: 6 additions & 0 deletions XBMC-ATV2.xcodeproj/project.pbxproj
Expand Up @@ -13,6 +13,7 @@
1840B797139968DB007C848B /* JSONVariantWriter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1840B794139968DB007C848B /* JSONVariantWriter.cpp */; };
18ACF8E313597B0000B67371 /* RecentlyAddedJob.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 18ACF8E113597B0000B67371 /* RecentlyAddedJob.cpp */; };
4D5D2E131301753F006ABC13 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D5D2E121301753F006ABC13 /* CFNetwork.framework */; };
7C0A7ECD13A5DBF900AFC2BD /* AppParamParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C0A7ECB13A5DBF900AFC2BD /* AppParamParser.cpp */; };
7C99B73F133D372300FC2B16 /* CacheCircular.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C99B73D133D372300FC2B16 /* CacheCircular.cpp */; };
7C99B7AA134072CD00FC2B16 /* GUIDialogPlayEject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C99B7A8134072CD00FC2B16 /* GUIDialogPlayEject.cpp */; };
C807119F135DB842002F601B /* InputOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C807119D135DB842002F601B /* InputOperations.cpp */; };
Expand Down Expand Up @@ -929,6 +930,8 @@
18ACF8E113597B0000B67371 /* RecentlyAddedJob.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RecentlyAddedJob.cpp; sourceTree = "<group>"; };
18ACF8E213597B0000B67371 /* RecentlyAddedJob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RecentlyAddedJob.h; sourceTree = "<group>"; };
4D5D2E121301753F006ABC13 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
7C0A7ECB13A5DBF900AFC2BD /* AppParamParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AppParamParser.cpp; sourceTree = "<group>"; };
7C0A7ECC13A5DBF900AFC2BD /* AppParamParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppParamParser.h; sourceTree = "<group>"; };
7C99B73D133D372300FC2B16 /* CacheCircular.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CacheCircular.cpp; sourceTree = "<group>"; };
7C99B73E133D372300FC2B16 /* CacheCircular.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CacheCircular.h; sourceTree = "<group>"; };
7C99B7A8134072CD00FC2B16 /* GUIDialogPlayEject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GUIDialogPlayEject.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4930,6 +4933,8 @@
F56C76D2131EC153000AD0F6 /* GUISettings.h */,
F56C76D3131EC153000AD0F6 /* AdvancedSettings.cpp */,
F56C76D4131EC153000AD0F6 /* AdvancedSettings.h */,
7C0A7ECB13A5DBF900AFC2BD /* AppParamParser.cpp */,
7C0A7ECC13A5DBF900AFC2BD /* AppParamParser.h */,
F56C76D5131EC153000AD0F6 /* GUIWindowSettings.cpp */,
F56C76D6131EC153000AD0F6 /* GUIWindowSettings.h */,
F56C76D7131EC153000AD0F6 /* GUIWindowSettingsCategory.cpp */,
Expand Down Expand Up @@ -6710,6 +6715,7 @@
18404DFB1396C43B00863BBA /* Slingbox.cpp in Sources */,
1840B796139968DB007C848B /* JSONVariantParser.cpp in Sources */,
1840B797139968DB007C848B /* JSONVariantWriter.cpp in Sources */,
7C0A7ECD13A5DBF900AFC2BD /* AppParamParser.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 6 additions & 0 deletions XBMC-IOS.xcodeproj/project.pbxproj
Expand Up @@ -14,6 +14,7 @@
18ACF8FD13597B5700B67371 /* RecentlyAddedJob.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 18ACF8FB13597B5700B67371 /* RecentlyAddedJob.cpp */; };
3255316612B2D02400837CD2 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3255316512B2D02400837CD2 /* CoreAudio.framework */; };
4D5D2E1E1301758F006ABC13 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D5D2E1D1301758F006ABC13 /* CFNetwork.framework */; };
7C0A7EDE13A5DC2800AFC2BD /* AppParamParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C0A7EDC13A5DC2800AFC2BD /* AppParamParser.cpp */; };
7C99B6E9133D36E200FC2B16 /* CacheCircular.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C99B6E7133D36E200FC2B16 /* CacheCircular.cpp */; };
7C99B7BE1340730000FC2B16 /* GUIDialogPlayEject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C99B7BC1340730000FC2B16 /* GUIDialogPlayEject.cpp */; };
C80711AD135DB85F002F601B /* InputOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C80711AB135DB85F002F601B /* InputOperations.cpp */; };
Expand Down Expand Up @@ -930,6 +931,8 @@
18ACF8FC13597B5700B67371 /* RecentlyAddedJob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RecentlyAddedJob.h; sourceTree = "<group>"; };
3255316512B2D02400837CD2 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; };
4D5D2E1D1301758F006ABC13 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
7C0A7EDC13A5DC2800AFC2BD /* AppParamParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AppParamParser.cpp; sourceTree = "<group>"; };
7C0A7EDD13A5DC2800AFC2BD /* AppParamParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppParamParser.h; sourceTree = "<group>"; };
7C99B6E7133D36E200FC2B16 /* CacheCircular.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CacheCircular.cpp; sourceTree = "<group>"; };
7C99B6E8133D36E200FC2B16 /* CacheCircular.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CacheCircular.h; sourceTree = "<group>"; };
7C99B7BC1340730000FC2B16 /* GUIDialogPlayEject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GUIDialogPlayEject.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5298,6 +5301,8 @@
F56C86BD131F42EB000AD0F6 /* GUISettings.h */,
F56C86BE131F42EB000AD0F6 /* AdvancedSettings.cpp */,
F56C86BF131F42EB000AD0F6 /* AdvancedSettings.h */,
7C0A7EDC13A5DC2800AFC2BD /* AppParamParser.cpp */,
7C0A7EDD13A5DC2800AFC2BD /* AppParamParser.h */,
F56C86C0131F42EB000AD0F6 /* GUIWindowSettings.cpp */,
F56C86C1131F42EB000AD0F6 /* GUIWindowSettings.h */,
F56C86C2131F42EB000AD0F6 /* GUIWindowSettingsCategory.cpp */,
Expand Down Expand Up @@ -6725,6 +6730,7 @@
18404DD61396C3F300863BBA /* Slingbox.cpp in Sources */,
1840B77A1399616D007C848B /* JSONVariantParser.cpp in Sources */,
1840B77B1399616D007C848B /* JSONVariantWriter.cpp in Sources */,
7C0A7EDE13A5DC2800AFC2BD /* AppParamParser.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
8 changes: 8 additions & 0 deletions XBMC.xcodeproj/project.pbxproj
Expand Up @@ -500,6 +500,8 @@
43EA4297136C1D9E002C82A5 /* RenderCapture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F56579AD13060D1E0085ED7F /* RenderCapture.cpp */; };
43EA429B136C1E2F002C82A5 /* xbmcvfsmodule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 189047D11301DEAB00C11012 /* xbmcvfsmodule.cpp */; };
43EA42B0136C2274002C82A5 /* InputOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C807114B135DB5CC002F601B /* InputOperations.cpp */; };
7C0A7EC013A5DBCE00AFC2BD /* AppParamParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C0A7EBE13A5DBCE00AFC2BD /* AppParamParser.cpp */; };
7C0A7EC113A5DBCE00AFC2BD /* AppParamParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C0A7EBE13A5DBCE00AFC2BD /* AppParamParser.cpp */; };
7C2D6AE40F35453E00DD2E85 /* SpecialProtocol.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C2D6AE20F35453E00DD2E85 /* SpecialProtocol.cpp */; };
7C45DBE910F325C400D4BBF3 /* DAVDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C45DBE710F325C400D4BBF3 /* DAVDirectory.cpp */; };
7C45DBEA10F325C400D4BBF3 /* DAVDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C45DBE710F325C400D4BBF3 /* DAVDirectory.cpp */; };
Expand Down Expand Up @@ -2370,6 +2372,8 @@
6E97BDC10DA2B620003A2A89 /* EventServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventServer.h; sourceTree = "<group>"; };
6E97BDC30DA2B620003A2A89 /* Fanart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Fanart.h; sourceTree = "<group>"; };
6E97BDC40DA2B620003A2A89 /* Socket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Socket.h; sourceTree = "<group>"; };
7C0A7EBE13A5DBCE00AFC2BD /* AppParamParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AppParamParser.cpp; sourceTree = "<group>"; };
7C0A7EBF13A5DBCE00AFC2BD /* AppParamParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppParamParser.h; sourceTree = "<group>"; };
7C2D6AE20F35453E00DD2E85 /* SpecialProtocol.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpecialProtocol.cpp; sourceTree = "<group>"; };
7C2D6AE30F35453E00DD2E85 /* SpecialProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpecialProtocol.h; sourceTree = "<group>"; };
7C45DBE710F325C400D4BBF3 /* DAVDirectory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DAVDirectory.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6630,6 +6634,8 @@
18B7C8C312942451009E7A26 /* GUISettings.h */,
18B7C3A612942132009E7A26 /* AdvancedSettings.cpp */,
18B7C3A712942132009E7A26 /* AdvancedSettings.h */,
7C0A7EBE13A5DBCE00AFC2BD /* AppParamParser.cpp */,
7C0A7EBF13A5DBCE00AFC2BD /* AppParamParser.h */,
18B7C39612942114009E7A26 /* GUIWindowSettings.cpp */,
18B7C39712942114009E7A26 /* GUIWindowSettings.h */,
18B7C39812942114009E7A26 /* GUIWindowSettingsCategory.cpp */,
Expand Down Expand Up @@ -8041,6 +8047,7 @@
18404D9E1396C13500863BBA /* Slingbox.cpp in Sources */,
1840B74D13993D8A007C848B /* JSONVariantParser.cpp in Sources */,
1840B75313993DA0007C848B /* JSONVariantWriter.cpp in Sources */,
7C0A7EC013A5DBCE00AFC2BD /* AppParamParser.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -8929,6 +8936,7 @@
18404E701396E05D00863BBA /* Slingbox.cpp in Sources */,
1840B74E13993D8A007C848B /* JSONVariantParser.cpp in Sources */,
1840B75413993DA0007C848B /* JSONVariantWriter.cpp in Sources */,
7C0A7EC113A5DBCE00AFC2BD /* AppParamParser.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 2 additions & 0 deletions project/VS2010Express/XBMC.vcxproj
Expand Up @@ -691,6 +691,7 @@
<ClCompile Include="..\..\xbmc\rendering\RenderSystem.cpp" />
<ClCompile Include="..\..\xbmc\SectionLoader.cpp" />
<ClCompile Include="..\..\xbmc\settings\AdvancedSettings.cpp" />
<ClCompile Include="..\..\xbmc\settings\AppParamParser.cpp" />
<ClCompile Include="..\..\xbmc\settings\GUIDialogContentSettings.cpp" />
<ClCompile Include="..\..\xbmc\settings\GUIDialogLockSettings.cpp" />
<ClCompile Include="..\..\xbmc\settings\GUIDialogProfileSettings.cpp" />
Expand Down Expand Up @@ -1523,6 +1524,7 @@
<ClInclude Include="..\..\xbmc\rendering\RenderSystem.h" />
<ClInclude Include="..\..\xbmc\SectionLoader.h" />
<ClInclude Include="..\..\xbmc\settings\AdvancedSettings.h" />
<ClInclude Include="..\..\xbmc\settings\AppParamParser.h" />
<ClInclude Include="..\..\xbmc\settings\GUIDialogContentSettings.h" />
<ClInclude Include="..\..\xbmc\settings\GUIDialogLockSettings.h" />
<ClInclude Include="..\..\xbmc\settings\GUIDialogProfileSettings.h" />
Expand Down
6 changes: 6 additions & 0 deletions project/VS2010Express/XBMC.vcxproj.filters
Expand Up @@ -2457,6 +2457,9 @@
<ClCompile Include="..\..\xbmc\utils\JSONVariantWriter.cpp">
<Filter>utils</Filter>
</ClCompile>
<ClCompile Include="..\..\xbmc\settings\AppParamParser.cpp">
<Filter>settings</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\xbmc\win32\pch.h">
Expand Down Expand Up @@ -4922,6 +4925,9 @@
<ClInclude Include="..\..\xbmc\utils\JSONVariantWriter.h">
<Filter>utils</Filter>
</ClInclude>
<ClInclude Include="..\..\xbmc\settings\AppParamParser.h">
<Filter>settings</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\xbmc\win32\XBMC.ico">
Expand Down
133 changes: 133 additions & 0 deletions xbmc/settings/AppParamParser.cpp
@@ -0,0 +1,133 @@
/*
* Copyright (C) 2005-2008 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program 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 XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/

#include "AppParamParser.h"
#include "AdvancedSettings.h"
#include "PlayListPlayer.h"
#include "FileItem.h"
#include "Application.h"
#include "log.h"
#ifdef _WIN32
#include "WIN32Util.h"
#endif
#ifdef HAS_LIRC
#include "input/linux/LIRC.h"
#endif

CAppParamParser::CAppParamParser()
{
m_testmode = false;
}

void CAppParamParser::Parse(const char* argv[], int nArgs)
{
if (nArgs > 1)
{
for (int i = 1; i < nArgs; i++)
{
ParseArg(argv[i]);
#ifdef HAS_LIRC
if (strnicmp(argv[i], "-l", 2) == 0 || strnicmp(argv[i], "--lircdev", 9) == 0)
{
// check the next arg with the proper value.
int next=i+1;
if (next < nArgs)
{
if ((argv[next][0] != '-' ) && (argv[next][0] == '/' ))
{
g_RemoteControl.setDeviceName(argv[next]);
i++;
}
}
}
else if (strnicmp(argv[i], "-n", 2) == 0 || strnicmp(argv[i], "--nolirc", 8) == 0)
g_RemoteControl.setUsed(false);
#endif
}
}
PlayPlaylist();
}

void CAppParamParser::DisplayHelp()
{
printf("Usage: xbmc [OPTION]... [FILE]...\n\n");
printf("Arguments:\n");
printf(" -fs\t\t\tRuns XBMC in full screen\n");
printf(" --standalone\t\tXBMC runs in a stand alone environment without a window \n");
printf("\t\t\tmanager and supporting applications. For example, that\n");
printf("\t\t\tenables network settings.\n");
printf(" -p or --portable\tXBMC will look for configurations in install folder instead of ~/.xbmc\n");
printf(" --legacy-res\t\tEnables screen resolutions such as PAL, NTSC, etc.\n");
#ifdef HAS_LIRC
printf(" -l or --lircdev\tLircDevice to use default is "LIRC_DEVICE" .\n");
printf(" -n or --nolirc\tdo not use Lirc, i.e. no remote input.\n");
#endif
printf(" --debug\t\tEnable debug logging\n");
printf(" --test\t\tEnable test mode. [FILE] required.\n");
printf(" --settings=<filename>\t\tLoads specified file after advancedsettings.xml replacing any settings specified\n");
printf(" \t\t\t\tspecified file must exist in special://xbmc/system/\n");
exit(0);
}

void CAppParamParser::EnableDebugMode()
{
g_advancedSettings.m_logLevel = LOG_LEVEL_DEBUG;
g_advancedSettings.m_logLevelHint = LOG_LEVEL_DEBUG;
CLog::SetLogLevel(g_advancedSettings.m_logLevel);
}

void CAppParamParser::ParseArg(const CStdString &arg)
{
if (arg == "-fs" || arg == "--fullscreen")
g_advancedSettings.m_startFullScreen = true;
else if (arg == "-h" || arg == "--help")
DisplayHelp();
else if (arg == "--standalone")
g_application.SetStandAlone(true);
else if (arg == "-p" || arg == "--portable")
g_application.EnablePlatformDirectories(false);
else if (arg == "--debug")
EnableDebugMode();
else if (arg == "--legacy-res")
g_application.SetEnableLegacyRes(true);
else if (arg == "--test")
m_testmode = true;
else if (arg.length() != 0 && arg[0] != '-')
{
if (m_testmode)
g_application.SetEnableTestMode(true);
CFileItemPtr pItem(new CFileItem(arg));
pItem->m_strPath = arg;
m_playlist.Add(pItem);
}
}

void CAppParamParser::PlayPlaylist()
{
if (m_playlist.Size() > 0)
{
g_playlistPlayer.Add(0, m_playlist);
g_playlistPlayer.SetCurrentPlaylist(0);
}

ThreadMessage tMsg = {TMSG_PLAYLISTPLAYER_PLAY, (DWORD) -1};
g_application.getApplicationMessenger().SendMessage(tMsg, false);
}
38 changes: 38 additions & 0 deletions xbmc/settings/AppParamParser.h
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2005-2008 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program 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 XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/

#include "StdString.h"
#include "FileItem.h"

class CAppParamParser
{
public:
CAppParamParser();
void Parse(const char* argv[], int nArgs);

private:
bool m_testmode;
CFileItemList m_playlist;
void ParseArg(const CStdString &arg);
void DisplayHelp();
void EnableDebugMode();
void PlayPlaylist();
};
1 change: 1 addition & 0 deletions xbmc/settings/Makefile
@@ -1,4 +1,5 @@
SRCS=AdvancedSettings.cpp \
AppParamParser.cpp \
GUIDialogContentSettings.cpp \
GUIDialogLockSettings.cpp \
GUIDialogProfileSettings.cpp \
Expand Down

0 comments on commit b12aab6

Please sign in to comment.