Merge pull request #4676 from jmarshallnz/dont_set_scraper_on_tvshow_on_nfo
[vuplus_xbmc] / xbmc / AppParamParser.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "AppParamParser.h"
22 #include "GUIInfoManager.h"
23 #include "PlayListPlayer.h"
24 #include "FileItem.h"
25 #include "Application.h"
26 #include "ApplicationMessenger.h"
27 #include "settings/AdvancedSettings.h"
28 #include "utils/log.h"
29 #ifdef TARGET_WINDOWS
30 #include "WIN32Util.h"
31 #endif
32 #ifdef HAS_LIRC
33 #include "input/linux/LIRC.h"
34 #endif
35 #ifndef TARGET_WINDOWS
36 #include "linux/XTimeUtils.h"
37 #endif
38
39 CAppParamParser::CAppParamParser()
40 {
41   m_testmode = false;
42 }
43
44 void CAppParamParser::Parse(const char* argv[], int nArgs)
45 {
46   if (nArgs > 1)
47   {
48     for (int i = 1; i < nArgs; i++)
49     {
50       ParseArg(argv[i]);
51 #ifdef HAS_LIRC
52       if (strnicmp(argv[i], "-l", 2) == 0 || strnicmp(argv[i], "--lircdev", 9) == 0)
53       {
54         // check the next arg with the proper value.
55         int next=i+1;
56         if (next < nArgs)
57         {
58           if ((argv[next][0] != '-' ) && (argv[next][0] == '/' ))
59           {
60             g_RemoteControl.setDeviceName(argv[next]);
61             i++;
62           }
63         }
64       }
65       else if (strnicmp(argv[i], "-n", 2) == 0 || strnicmp(argv[i], "--nolirc", 8) == 0)
66          g_RemoteControl.setUsed(false);
67 #endif
68       if (stricmp(argv[i], "-d") == 0)
69       {
70         if (i + 1 < nArgs)
71         {
72           int sleeptime = atoi(argv[i + 1]);
73           if (sleeptime > 0 && sleeptime < 360)
74             Sleep(sleeptime*1000);
75         }
76         i++;
77       }
78     }
79   }
80   PlayPlaylist();
81 }
82
83 void CAppParamParser::DisplayVersion()
84 {
85   printf("XBMC Media Center %s\n", g_infoManager.GetVersion().c_str());
86   printf("Copyright (C) 2005-2013 Team XBMC - http://xbmc.org\n");
87   exit(0);
88 }
89
90 void CAppParamParser::DisplayHelp()
91 {
92   printf("Usage: xbmc [OPTION]... [FILE]...\n\n");
93   printf("Arguments:\n");
94   printf("  -d <n>\t\tdelay <n> seconds before starting\n");
95   printf("  -fs\t\t\tRuns XBMC in full screen\n");
96   printf("  --standalone\t\tXBMC runs in a stand alone environment without a window \n");
97   printf("\t\t\tmanager and supporting applications. For example, that\n");
98   printf("\t\t\tenables network settings.\n");
99   printf("  -p or --portable\tXBMC will look for configurations in install folder instead of ~/.xbmc\n");
100   printf("  --legacy-res\t\tEnables screen resolutions such as PAL, NTSC, etc.\n");
101 #ifdef HAS_LIRC
102   printf("  -l or --lircdev\tLircDevice to use default is "LIRC_DEVICE" .\n");
103   printf("  -n or --nolirc\tdo not use Lirc, i.e. no remote input.\n");
104 #endif
105   printf("  --debug\t\tEnable debug logging\n");
106   printf("  --version\t\tPrint version information\n");
107   printf("  --test\t\tEnable test mode. [FILE] required.\n");
108   printf("  --settings=<filename>\t\tLoads specified file after advancedsettings.xml replacing any settings specified\n");
109   printf("  \t\t\t\tspecified file must exist in special://xbmc/system/\n");
110   exit(0);
111 }
112
113 void CAppParamParser::EnableDebugMode()
114 {
115   g_advancedSettings.m_logLevel     = LOG_LEVEL_DEBUG;
116   g_advancedSettings.m_logLevelHint = LOG_LEVEL_DEBUG;
117   CLog::SetLogLevel(g_advancedSettings.m_logLevel);
118 }
119
120 void CAppParamParser::ParseArg(const CStdString &arg)
121 {
122   if (arg == "-fs" || arg == "--fullscreen")
123     g_advancedSettings.m_startFullScreen = true;
124   else if (arg == "-h" || arg == "--help")
125     DisplayHelp();
126   else if (arg == "-v" || arg == "--version")
127     DisplayVersion();
128   else if (arg == "--standalone")
129     g_application.SetStandAlone(true);
130   else if (arg == "-p" || arg  == "--portable")
131     g_application.EnablePlatformDirectories(false);
132   else if (arg == "--debug")
133     EnableDebugMode();
134   else if (arg == "--legacy-res")
135     g_application.SetEnableLegacyRes(true);
136   else if (arg == "--test")
137     m_testmode = true;
138   else if (arg.substr(0, 11) == "--settings=")
139     g_advancedSettings.AddSettingsFile(arg.substr(11));
140   else if (arg.length() != 0 && arg[0] != '-')
141   {
142     if (m_testmode)
143       g_application.SetEnableTestMode(true);
144     CFileItemPtr pItem(new CFileItem(arg));
145     pItem->SetPath(arg);
146     m_playlist.Add(pItem);
147   }
148 }
149
150 void CAppParamParser::PlayPlaylist()
151 {
152   if (m_playlist.Size() > 0)
153   {
154     g_playlistPlayer.Add(0, m_playlist);
155     g_playlistPlayer.SetCurrentPlaylist(0);
156   }
157
158   ThreadMessage tMsg = {TMSG_PLAYLISTPLAYER_PLAY, (DWORD) -1};
159   CApplicationMessenger::Get().SendMessage(tMsg, false);
160 }