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