aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Kortstiege <vdrfan@xbmc.org>2014-05-30 15:57:25 +0200
committerMatthias Kortstiege <vdrfan@xbmc.org>2014-06-07 00:52:06 +0200
commit856d88d87f27370e8471963790db4e4e7c4ba910 (patch)
treecba3e823997a416b3b540448faa6a16b561b1f0f
parent95ff639a8345e5ea8051386cd8b1ebbb394f6b7a (diff)
added: CPosixDirectory implementation
-rw-r--r--XBMC.xcodeproj/project.pbxproj18
-rw-r--r--xbmc/filesystem/DirectoryFactory.cpp7
-rw-r--r--xbmc/filesystem/Makefile.in1
-rw-r--r--xbmc/filesystem/posix/PosixDirectory.cpp130
-rw-r--r--xbmc/filesystem/posix/PosixDirectory.h37
5 files changed, 193 insertions, 0 deletions
diff --git a/XBMC.xcodeproj/project.pbxproj b/XBMC.xcodeproj/project.pbxproj
index 5e32a357a4..1cd74c9233 100644
--- a/XBMC.xcodeproj/project.pbxproj
+++ b/XBMC.xcodeproj/project.pbxproj
@@ -288,6 +288,9 @@
7C99B7951340723F00FC2B16 /* GUIDialogPlayEject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C99B7931340723F00FC2B16 /* GUIDialogPlayEject.cpp */; };
7CAA20511079C8160096DE39 /* BaseRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CAA204F1079C8160096DE39 /* BaseRenderer.cpp */; };
7CAA25351085963B0096DE39 /* PasswordManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CAA25331085963B0096DE39 /* PasswordManager.cpp */; };
+ 7CAA469019427AED00008885 /* PosixDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CAA468E19427AED00008885 /* PosixDirectory.cpp */; };
+ 7CAA469119427AED00008885 /* PosixDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CAA468E19427AED00008885 /* PosixDirectory.cpp */; };
+ 7CAA469219427AED00008885 /* PosixDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CAA468E19427AED00008885 /* PosixDirectory.cpp */; };
7CBEBB8412912BA400431822 /* fstrcmp.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CBEBB8212912BA300431822 /* fstrcmp.c */; };
7CC30DB116291A5C003E7579 /* MusicThumbLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC30DAF16291A5C003E7579 /* MusicThumbLoader.cpp */; };
7CC30DC016291C2C003E7579 /* VideoThumbLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC30DBE16291C2C003E7579 /* VideoThumbLoader.cpp */; };
@@ -4229,6 +4232,8 @@
7CAA25341085963B0096DE39 /* PasswordManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PasswordManager.h; sourceTree = "<group>"; };
7CAA25371085971C0096DE39 /* MusicArtistInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MusicArtistInfo.h; sourceTree = "<group>"; };
7CAA25381085971C0096DE39 /* ScraperUrl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScraperUrl.h; sourceTree = "<group>"; };
+ 7CAA468E19427AED00008885 /* PosixDirectory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PosixDirectory.cpp; sourceTree = "<group>"; };
+ 7CAA468F19427AED00008885 /* PosixDirectory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PosixDirectory.h; sourceTree = "<group>"; };
7CBEBB8212912BA300431822 /* fstrcmp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fstrcmp.c; sourceTree = "<group>"; };
7CC30DAF16291A5C003E7579 /* MusicThumbLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MusicThumbLoader.cpp; sourceTree = "<group>"; };
7CC30DB016291A5C003E7579 /* MusicThumbLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MusicThumbLoader.h; sourceTree = "<group>"; };
@@ -7456,6 +7461,15 @@
name = osx;
sourceTree = "<group>";
};
+ 7CAA468D19427AED00008885 /* posix */ = {
+ isa = PBXGroup;
+ children = (
+ 7CAA468E19427AED00008885 /* PosixDirectory.cpp */,
+ 7CAA468F19427AED00008885 /* PosixDirectory.h */,
+ );
+ path = posix;
+ sourceTree = "<group>";
+ };
7CCD9F52192753E30074CF51 /* Source */ = {
isa = PBXGroup;
children = (
@@ -9252,6 +9266,7 @@
E38E17430D25F9FA00618676 /* PlaylistFileDirectory.h */,
E38E17440D25F9FA00618676 /* PluginDirectory.cpp */,
E38E17450D25F9FA00618676 /* PluginDirectory.h */,
+ 7CAA468D19427AED00008885 /* posix */,
C8482905156CFF24005A996F /* PVRDirectory.cpp */,
C8482906156CFF24005A996F /* PVRDirectory.h */,
C8482907156CFF24005A996F /* PVRFile.cpp */,
@@ -11870,6 +11885,7 @@
7CCDACB019275D1F0074CF51 /* NptStdcEnvironment.cpp in Sources */,
7CCDACC119275D790074CF51 /* NptAppleAutoreleasePool.mm in Sources */,
7CCDACCA19275D790074CF51 /* NptAppleLogConfig.mm in Sources */,
+ 7CAA469019427AED00008885 /* PosixDirectory.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -13067,6 +13083,7 @@
7CCDACB219275D1F0074CF51 /* NptStdcEnvironment.cpp in Sources */,
7CCDACC319275D790074CF51 /* NptAppleAutoreleasePool.mm in Sources */,
7CCDACCC19275D790074CF51 /* NptAppleLogConfig.mm in Sources */,
+ 7CAA469219427AED00008885 /* PosixDirectory.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -14266,6 +14283,7 @@
7CCDACB119275D1F0074CF51 /* NptStdcEnvironment.cpp in Sources */,
7CCDACC219275D790074CF51 /* NptAppleAutoreleasePool.mm in Sources */,
7CCDACCB19275D790074CF51 /* NptAppleLogConfig.mm in Sources */,
+ 7CAA469119427AED00008885 /* PosixDirectory.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/xbmc/filesystem/DirectoryFactory.cpp b/xbmc/filesystem/DirectoryFactory.cpp
index 260d53c728..dc39a9388e 100644
--- a/xbmc/filesystem/DirectoryFactory.cpp
+++ b/xbmc/filesystem/DirectoryFactory.cpp
@@ -46,6 +46,9 @@
#include "utils/log.h"
#include "network/WakeOnAccess.h"
+#ifdef TARGET_POSIX
+#include "posix/PosixDirectory.h"
+#endif
#ifdef HAS_FILESYSTEM_SMB
#ifdef TARGET_WINDOWS
#include "windows/WINSMBDirectory.h"
@@ -135,7 +138,11 @@ IDirectory* CDirectoryFactory::Create(const CStdString& strPath)
CStdString strProtocol = url.GetProtocol();
+#ifdef TARGET_POSIX
+ if (strProtocol.size() == 0 || strProtocol == "file") return new CPosixDirectory();
+#else
if (strProtocol.size() == 0 || strProtocol == "file") return new CHDDirectory();
+#endif
if (strProtocol == "special") return new CSpecialProtocolDirectory();
if (strProtocol == "sources") return new CSourcesDirectory();
if (strProtocol == "addons") return new CAddonsDirectory();
diff --git a/xbmc/filesystem/Makefile.in b/xbmc/filesystem/Makefile.in
index 623bbb8c64..725951e8db 100644
--- a/xbmc/filesystem/Makefile.in
+++ b/xbmc/filesystem/Makefile.in
@@ -57,6 +57,7 @@ SRCS += PlaylistFileDirectory.cpp
SRCS += PipeFile.cpp
SRCS += PipesManager.cpp
SRCS += PluginDirectory.cpp
+SRCS += posix/PosixDirectory.cpp
SRCS += PVRFile.cpp
SRCS += PVRDirectory.cpp
SRCS += RSSDirectory.cpp
diff --git a/xbmc/filesystem/posix/PosixDirectory.cpp b/xbmc/filesystem/posix/PosixDirectory.cpp
new file mode 100644
index 0000000000..e60c6f9a1a
--- /dev/null
+++ b/xbmc/filesystem/posix/PosixDirectory.cpp
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2014 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, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#if defined(TARGET_POSIX)
+
+#include "PosixDirectory.h"
+#include "utils/StringUtils.h"
+#include "utils/URIUtils.h"
+#include "FileItem.h"
+
+#include <dirent.h>
+#include <sys/stat.h>
+
+using namespace std;
+using namespace XFILE;
+
+CPosixDirectory::CPosixDirectory(void)
+{}
+
+CPosixDirectory::~CPosixDirectory(void)
+{}
+
+bool CPosixDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
+{
+ const char* root = strPath;
+ struct dirent* entry;
+ DIR *dir = opendir(root);
+
+ if (!dir)
+ return false;
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
+ continue;
+
+ CFileItemPtr pItem(new CFileItem(entry->d_name));
+ std::string itemPath(URIUtils::AddFileToFolder(root, entry->d_name));
+
+ bool bStat = false;
+ struct stat buffer;
+
+ // Unix-based readdir implementations may return an incorrect dirent.d_ino value that
+ // is not equal to the (correct) stat() obtained one. In this case the file type
+ // could not be determined and the value of dirent.d_type is set to DT_UNKNOWN.
+ // In order to get a correct value we have to incur the cost of calling stat.
+ if (entry->d_type == DT_UNKNOWN || entry->d_type == DT_LNK)
+ {
+ if (stat(itemPath.c_str(), &buffer) == 0)
+ bStat = true;
+ }
+
+ if (entry->d_type == DT_DIR || (bStat && buffer.st_mode & S_IFDIR))
+ {
+ pItem->m_bIsFolder = true;
+ URIUtils::AddSlashAtEnd(itemPath);
+ }
+ else
+ {
+ pItem->m_bIsFolder = false;
+ }
+
+ if (StringUtils::StartsWith(entry->d_name, "."))
+ pItem->SetProperty("file:hidden", true);
+
+ pItem->SetPath(itemPath);
+
+ if (!(m_flags & DIR_FLAG_NO_FILE_INFO))
+ {
+ if (bStat || stat(pItem->GetPath(), &buffer) == 0)
+ {
+ FILETIME fileTime, localTime;
+ TimeTToFileTime(buffer.st_mtime, &fileTime);
+ FileTimeToLocalFileTime(&fileTime, &localTime);
+ pItem->m_dateTime = localTime;
+
+ if (!pItem->m_bIsFolder)
+ pItem->m_dwSize = buffer.st_size;
+ }
+ }
+ items.Add(pItem);
+ }
+ closedir(dir);
+ return true;
+}
+
+bool CPosixDirectory::Create(const char* strPath)
+{
+ if (!strPath || !*strPath)
+ return false;
+
+ return (mkdir(strPath, 0755) == 0 || errno == EEXIST);
+}
+
+bool CPosixDirectory::Remove(const char* strPath)
+{
+ if (!strPath || !*strPath)
+ return false;
+
+ return (rmdir(strPath) == 0);
+}
+
+bool CPosixDirectory::Exists(const char* strPath)
+{
+ if (!strPath || !*strPath)
+ return false;
+
+ struct stat buffer;
+ if (stat(strPath, &buffer) != 0)
+ return false;
+ return S_ISDIR(buffer.st_mode) ? true : false;
+}
+#endif
diff --git a/xbmc/filesystem/posix/PosixDirectory.h b/xbmc/filesystem/posix/PosixDirectory.h
new file mode 100644
index 0000000000..a3fd01eb8f
--- /dev/null
+++ b/xbmc/filesystem/posix/PosixDirectory.h
@@ -0,0 +1,37 @@
+#pragma once
+/*
+ * Copyright (C) 2014 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, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "filesystem/IDirectory.h"
+
+namespace XFILE
+{
+
+class CPosixDirectory : public IDirectory
+{
+public:
+ CPosixDirectory(void);
+ virtual ~CPosixDirectory(void);
+ virtual bool GetDirectory(const CStdString& strPath, CFileItemList &items);
+ virtual bool Create(const char* strPath);
+ virtual bool Exists(const char* strPath);
+ virtual bool Remove(const char* strPath);
+};
+}