Merge pull request #5095 from koying/fixdroidappcrash
[vuplus_xbmc] / xbmc / filesystem / DirectoryFactory.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 "DirectoryFactory.h"
27 #include "HDDirectory.h"
28 #include "SpecialProtocolDirectory.h"
29 #include "MultiPathDirectory.h"
30 #include "StackDirectory.h"
31 #include "FileDirectoryFactory.h"
32 #include "PlaylistDirectory.h"
33 #include "MusicDatabaseDirectory.h"
34 #include "MusicSearchDirectory.h"
35 #include "VideoDatabaseDirectory.h"
36 #include "FavouritesDirectory.h"
37 #include "LibraryDirectory.h"
38 #include "AddonsDirectory.h"
39 #include "SourcesDirectory.h"
40 #include "FTPDirectory.h"
41 #include "HTTPDirectory.h"
42 #include "DAVDirectory.h"
43 #include "UDFDirectory.h"
44 #include "Application.h"
45 #include "addons/Addon.h"
46 #include "utils/log.h"
47 #include "network/WakeOnAccess.h"
48
49 #ifdef HAS_FILESYSTEM_SMB
50 #ifdef TARGET_WINDOWS
51 #include "windows/WINSMBDirectory.h"
52 #else
53 #include "SMBDirectory.h"
54 #endif
55 #endif
56 #ifdef HAS_FILESYSTEM_CDDA
57 #include "CDDADirectory.h"
58 #endif
59 #include "PluginDirectory.h"
60 #ifdef HAS_FILESYSTEM
61 #include "ISO9660Directory.h"
62 #ifdef HAS_FILESYSTEM_RTV
63 #include "RTVDirectory.h"
64 #endif
65 #ifdef HAS_FILESYSTEM_DAAP
66 #include "DAAPDirectory.h"
67 #endif
68 #endif
69 #ifdef HAS_UPNP
70 #include "UPnPDirectory.h"
71 #endif
72 #ifdef HAS_FILESYSTEM_SAP
73 #include "SAPDirectory.h"
74 #endif
75 #ifdef HAS_FILESYSTEM_VTP
76 #include "VTPDirectory.h"
77 #endif
78 #ifdef HAS_FILESYSTEM_HTSP
79 #include "HTSPDirectory.h"
80 #endif
81 #ifdef HAS_PVRCLIENTS
82 #include "PVRDirectory.h"
83 #endif
84 #if defined(TARGET_ANDROID)
85 #include "APKDirectory.h"
86 #endif
87 #include "ZipDirectory.h"
88 #ifdef HAS_FILESYSTEM_RAR
89 #include "RarDirectory.h"
90 #endif
91 #include "TuxBoxDirectory.h"
92 #include "HDHomeRunDirectory.h"
93 #include "SlingboxDirectory.h"
94 #include "MythDirectory.h"
95 #include "FileItem.h"
96 #include "URL.h"
97 #include "RSSDirectory.h"
98 #ifdef HAS_ZEROCONF
99 #include "ZeroconfDirectory.h"
100 #endif
101 #ifdef HAS_FILESYSTEM_SFTP
102 #include "SFTPDirectory.h"
103 #endif
104 #ifdef HAS_FILESYSTEM_NFS
105 #include "NFSDirectory.h"
106 #endif
107 #ifdef HAS_FILESYSTEM_AFP
108 #include "AFPDirectory.h"
109 #endif
110 #ifdef HAVE_LIBBLURAY
111 #include "BlurayDirectory.h"
112 #endif
113 #if defined(TARGET_ANDROID)
114 #include "AndroidAppDirectory.h"
115 #endif
116
117 using namespace XFILE;
118
119 /*!
120  \brief Create a IDirectory object of the share type specified in \e strPath .
121  \param strPath Specifies the share type to access, can be a share or share with path.
122  \return IDirectory object to access the directories on the share.
123  \sa IDirectory
124  */
125 IDirectory* CDirectoryFactory::Create(const CStdString& strPath)
126 {
127   CURL url(strPath);
128   if (!CWakeOnAccess::Get().WakeUpHost(url))
129     return NULL;
130
131   CFileItem item(strPath, false);
132   IFileDirectory* pDir=CFileDirectoryFactory::Create(strPath, &item);
133   if (pDir)
134     return pDir;
135
136   CStdString strProtocol = url.GetProtocol();
137
138   if (strProtocol.size() == 0 || strProtocol == "file") return new CHDDirectory();
139   if (strProtocol == "special") return new CSpecialProtocolDirectory();
140   if (strProtocol == "sources") return new CSourcesDirectory();
141   if (strProtocol == "addons") return new CAddonsDirectory();
142 #if defined(HAS_FILESYSTEM_CDDA) && defined(HAS_DVD_DRIVE)
143   if (strProtocol == "cdda") return new CCDDADirectory();
144 #endif
145 #ifdef HAS_FILESYSTEM
146   if (strProtocol == "iso9660") return new CISO9660Directory();
147 #endif
148   if (strProtocol == "udf") return new CUDFDirectory();
149   if (strProtocol == "plugin") return new CPluginDirectory();
150 #if defined(TARGET_ANDROID)
151   if (strProtocol == "apk") return new CAPKDirectory();
152 #endif
153   if (strProtocol == "zip") return new CZipDirectory();
154   if (strProtocol == "rar") 
155   {
156 #ifdef HAS_FILESYSTEM_RAR
157     return new CRarDirectory();
158 #else
159     CLog::Log(LOGWARNING, "%s - Compiled without non-free, rar support is disabled", __FUNCTION__);
160 #endif
161   }
162   if (strProtocol == "multipath") return new CMultiPathDirectory();
163   if (strProtocol == "stack") return new CStackDirectory();
164   if (strProtocol == "playlistmusic") return new CPlaylistDirectory();
165   if (strProtocol == "playlistvideo") return new CPlaylistDirectory();
166   if (strProtocol == "musicdb") return new CMusicDatabaseDirectory();
167   if (strProtocol == "musicsearch") return new CMusicSearchDirectory();
168   if (strProtocol == "videodb") return new CVideoDatabaseDirectory();
169   if (strProtocol == "library") return new CLibraryDirectory();
170   if (strProtocol == "favourites") return new CFavouritesDirectory();
171   if (strProtocol == "filereader")
172     return CDirectoryFactory::Create(url.GetFileName());
173 #if defined(TARGET_ANDROID)
174   if (strProtocol == "androidapp") return new CAndroidAppDirectory();
175 #endif
176
177   if( g_application.getNetwork().IsAvailable(true) )  // true to wait for the network (if possible)
178   {
179     if (strProtocol == "tuxbox") return new CTuxBoxDirectory();
180     if (strProtocol == "ftp" || strProtocol == "ftps") return new CFTPDirectory();
181     if (strProtocol == "http" || strProtocol == "https") return new CHTTPDirectory();
182     if (strProtocol == "dav" || strProtocol == "davs") return new CDAVDirectory();
183 #ifdef HAS_FILESYSTEM_SFTP
184     if (strProtocol == "sftp" || strProtocol == "ssh") return new CSFTPDirectory();
185 #endif
186 #ifdef HAS_FILESYSTEM_SMB
187 #ifdef TARGET_WINDOWS
188     if (strProtocol == "smb") return new CWINSMBDirectory();
189 #else
190     if (strProtocol == "smb") return new CSMBDirectory();
191 #endif
192 #endif
193 #ifdef HAS_FILESYSTEM
194 #ifdef HAS_FILESYSTEM_DAAP
195     if (strProtocol == "daap") return new CDAAPDirectory();
196 #endif
197 #ifdef HAS_FILESYSTEM_RTV
198     if (strProtocol == "rtv") return new CRTVDirectory();
199 #endif
200 #endif
201 #ifdef HAS_UPNP
202     if (strProtocol == "upnp") return new CUPnPDirectory();
203 #endif
204     if (strProtocol == "hdhomerun") return new CHomeRunDirectory();
205     if (strProtocol == "sling") return new CSlingboxDirectory();
206     if (strProtocol == "myth") return new CMythDirectory();
207     if (strProtocol == "cmyth") return new CMythDirectory();
208     if (strProtocol == "rss") return new CRSSDirectory();
209 #ifdef HAS_FILESYSTEM_SAP
210     if (strProtocol == "sap") return new CSAPDirectory();
211 #endif
212 #ifdef HAS_FILESYSTEM_VTP
213     if (strProtocol == "vtp") return new CVTPDirectory();
214 #endif
215 #ifdef HAS_FILESYSTEM_HTSP
216     if (strProtocol == "htsp") return new CHTSPDirectory();
217 #endif
218 #ifdef HAS_PVRCLIENTS
219     if (strProtocol == "pvr") return new CPVRDirectory();
220 #endif
221 #ifdef HAS_ZEROCONF
222     if (strProtocol == "zeroconf") return new CZeroconfDirectory();
223 #endif
224 #ifdef HAS_FILESYSTEM_NFS
225     if (strProtocol == "nfs") return new CNFSDirectory();
226 #endif
227 #ifdef HAS_FILESYSTEM_AFP
228       if (strProtocol == "afp") return new CAFPDirectory();
229 #endif
230 #ifdef HAVE_LIBBLURAY
231       if (strProtocol == "bluray") return new CBlurayDirectory();
232 #endif
233   }
234
235   CLog::Log(LOGWARNING, "%s - Unsupported protocol(%s) in %s", __FUNCTION__, strProtocol.c_str(), url.Get().c_str() );
236   return NULL;
237 }
238