Merge pull request #5095 from koying/fixdroidappcrash
[vuplus_xbmc] / xbmc / filesystem / FileFactory.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 #if (defined HAVE_CONFIG_H) && (!defined TARGET_WINDOWS)
22   #include "config.h"
23 #endif
24 #include "network/Network.h"
25 #include "system.h"
26 #include "FileFactory.h"
27 #include "HDFile.h"
28 #include "CurlFile.h"
29 #include "HTTPFile.h"
30 #include "DAVFile.h"
31 #include "ShoutcastFile.h"
32 #include "FileReaderFile.h"
33 #ifdef HAS_FILESYSTEM_SMB
34 #ifdef TARGET_WINDOWS
35 #include "windows/WINFileSmb.h"
36 #else
37 #include "SmbFile.h"
38 #endif
39 #endif
40 #ifdef HAS_FILESYSTEM_CDDA
41 #include "CDDAFile.h"
42 #endif
43 #ifdef HAS_FILESYSTEM
44 #include "ISOFile.h"
45 #ifdef HAS_FILESYSTEM_RTV
46 #include "RTVFile.h"
47 #endif
48 #ifdef HAS_FILESYSTEM_DAAP
49 #include "DAAPFile.h"
50 #endif
51 #endif
52 #ifdef HAS_FILESYSTEM_SAP
53 #include "SAPFile.h"
54 #endif
55 #ifdef HAS_FILESYSTEM_VTP
56 #include "VTPFile.h"
57 #endif
58 #ifdef HAS_PVRCLIENTS
59 #include "PVRFile.h"
60 #endif
61 #if defined(TARGET_ANDROID)
62 #include "APKFile.h"
63 #endif
64 #include "ZipFile.h"
65 #ifdef HAS_FILESYSTEM_RAR
66 #include "RarFile.h"
67 #endif
68 #ifdef HAS_FILESYSTEM_SFTP
69 #include "SFTPFile.h"
70 #endif
71 #ifdef HAS_FILESYSTEM_NFS
72 #include "NFSFile.h"
73 #endif
74 #ifdef HAS_FILESYSTEM_AFP
75 #include "AFPFile.h"
76 #endif
77 #if defined(TARGET_ANDROID)
78 #include "AndroidAppFile.h"
79 #endif
80 #ifdef HAS_UPNP
81 #include "UPnPFile.h"
82 #endif
83 #include "PipesManager.h"
84 #include "PipeFile.h"
85 #include "MusicDatabaseFile.h"
86 #include "SpecialProtocolFile.h"
87 #include "MultiPathFile.h"
88 #include "TuxBoxFile.h"
89 #include "UDFFile.h"
90 #include "MythFile.h"
91 #include "HDHomeRunFile.h"
92 #include "SlingboxFile.h"
93 #include "ImageFile.h"
94 #include "Application.h"
95 #include "URL.h"
96 #include "utils/log.h"
97 #include "utils/StringUtils.h"
98 #include "network/WakeOnAccess.h"
99
100 using namespace XFILE;
101
102 CFileFactory::CFileFactory()
103 {
104 }
105
106 CFileFactory::~CFileFactory()
107 {
108 }
109
110 IFile* CFileFactory::CreateLoader(const CStdString& strFileName)
111 {
112   CURL url(strFileName);
113   return CreateLoader(url);
114 }
115
116 IFile* CFileFactory::CreateLoader(const CURL& url)
117 {
118   if (!CWakeOnAccess::Get().WakeUpHost(url))
119     return NULL;
120
121   CStdString strProtocol = url.GetProtocol();
122   StringUtils::ToLower(strProtocol);
123
124 #if defined(TARGET_ANDROID)
125   if (strProtocol == "apk") return new CAPKFile();
126 #endif
127   if (strProtocol == "zip") return new CZipFile();
128   else if (strProtocol == "rar")
129   {
130 #ifdef HAS_FILESYSTEM_RAR
131     return new CRarFile();
132 #else
133     CLog::Log(LOGWARNING, "%s - Compiled without non-free, rar support is disabled", __FUNCTION__);
134 #endif
135   }
136   else if (strProtocol == "musicdb") return new CMusicDatabaseFile();
137   else if (strProtocol == "videodb") return NULL;
138   else if (strProtocol == "special") return new CSpecialProtocolFile();
139   else if (strProtocol == "multipath") return new CMultiPathFile();
140   else if (strProtocol == "image") return new CImageFile();
141   else if (strProtocol == "file" || strProtocol.empty()) return new CHDFile();
142   else if (strProtocol == "filereader") return new CFileReaderFile();
143 #if defined(HAS_FILESYSTEM_CDDA) && defined(HAS_DVD_DRIVE)
144   else if (strProtocol == "cdda") return new CFileCDDA();
145 #endif
146 #ifdef HAS_FILESYSTEM
147   else if (strProtocol == "iso9660") return new CISOFile();
148 #endif
149   else if(strProtocol == "udf") return new CUDFFile();
150 #if defined(TARGET_ANDROID)
151   else if (strProtocol == "androidapp") return new CFileAndroidApp();
152 #endif
153
154   if( g_application.getNetwork().IsAvailable() )
155   {
156     if (strProtocol == "ftp"
157     ||  strProtocol == "ftps"
158     ||  strProtocol == "rss") return new CCurlFile();
159     else if (strProtocol == "http" ||  strProtocol == "https") return new CHTTPFile();
160     else if (strProtocol == "dav" || strProtocol == "davs") return new CDAVFile();
161 #ifdef HAS_FILESYSTEM_SFTP
162     else if (strProtocol == "sftp" || strProtocol == "ssh") return new CSFTPFile();
163 #endif
164     else if (strProtocol == "shout") return new CShoutcastFile();
165     else if (strProtocol == "tuxbox") return new CTuxBoxFile();
166     else if (strProtocol == "hdhomerun") return new CHomeRunFile();
167     else if (strProtocol == "sling") return new CSlingboxFile();
168     else if (strProtocol == "myth") return new CMythFile();
169     else if (strProtocol == "cmyth") return new CMythFile();
170 #ifdef HAS_FILESYSTEM_SMB
171 #ifdef TARGET_WINDOWS
172     else if (strProtocol == "smb") return new CWINFileSMB();
173 #else
174     else if (strProtocol == "smb") return new CSmbFile();
175 #endif
176 #endif
177 #ifdef HAS_FILESYSTEM
178 #ifdef HAS_FILESYSTEM_RTV
179     else if (strProtocol == "rtv") return new CRTVFile();
180 #endif
181 #ifdef HAS_FILESYSTEM_DAAP
182     else if (strProtocol == "daap") return new CDAAPFile();
183 #endif
184 #endif
185 #ifdef HAS_FILESYSTEM_SAP
186     else if (strProtocol == "sap") return new CSAPFile();
187 #endif
188 #ifdef HAS_FILESYSTEM_VTP
189     else if (strProtocol == "vtp") return new CVTPFile();
190 #endif
191 #ifdef HAS_PVRCLIENTS
192     else if (strProtocol == "pvr") return new CPVRFile();
193 #endif
194 #ifdef HAS_FILESYSTEM_NFS
195     else if (strProtocol == "nfs") return new CNFSFile();
196 #endif
197 #ifdef HAS_FILESYSTEM_AFP
198     else if (strProtocol == "afp") return new CAFPFile();
199 #endif
200     else if (strProtocol == "pipe") return new CPipeFile();    
201 #ifdef HAS_UPNP
202     else if (strProtocol == "upnp") return new CUPnPFile();
203 #endif
204   }
205
206   CLog::Log(LOGWARNING, "%s - Unsupported protocol(%s) in %s", __FUNCTION__, strProtocol.c_str(), url.Get().c_str() );
207   return NULL;
208 }