summaryrefslogtreecommitdiff
path: root/libs/fsScan/src/File.cc
diff options
context:
space:
mode:
authorgeronimo <geronimo013@gmx.de>2012-07-25 06:38:28 +0200
committergeronimo <geronimo013@gmx.de>2012-07-25 06:38:28 +0200
commit774e09eef2d7761814e6f19fb462eb0fdc74f2d7 (patch)
treeca0c4e06afdb99139c7953a8dd5576a3bcd15e23 /libs/fsScan/src/File.cc
parentab7186c6c116629983dc506c4b53794026518455 (diff)
downloadcmp-774e09eef2d7761814e6f19fb462eb0fdc74f2d7.tar.gz
cmp-774e09eef2d7761814e6f19fb462eb0fdc74f2d7.tar.bz2
worked out different file class and improved media handling
Diffstat (limited to 'libs/fsScan/src/File.cc')
-rw-r--r--libs/fsScan/src/File.cc101
1 files changed, 68 insertions, 33 deletions
diff --git a/libs/fsScan/src/File.cc b/libs/fsScan/src/File.cc
index c88fd7c..477c5c8 100644
--- a/libs/fsScan/src/File.cc
+++ b/libs/fsScan/src/File.cc
@@ -1,25 +1,25 @@
/**
* ======================== legal notice ======================
- *
+ *
* File: File.cc
- * Created: 21. Juli 2012, 12:41
+ * Created: 21. Juli 2012, 12
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libfsScan: mediatypes and filesystem scanning
- *
+ *
* CMP - compound media player
- *
+ *
* is a client/server mediaplayer intended to play any media from any workstation
* without the need to export or mount shares. cmps is an easy to use backend
* with a (ready to use) HTML-interface. Additionally the backend supports
* authentication via HTTP-digest authorization.
* cmpc is a client with vdr-like osd-menues.
- *
+ *
* Copyright (c) 2012 Reinhard Mantey, some rights reserved!
* published under Creative Commons by-sa
* For details see http://creativecommons.org/licenses/by-sa/3.0/
- *
+ *
* The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
- *
+ *
* --------------------------------------------------------------
*/
#include <File.h>
@@ -39,7 +39,18 @@ cFile::cFile(const char *Path)
: rep(NULL)
{
if (!fs) fs = new cFileSystem();
- rep = fs->representationOfFile(Path);
+ if (!Path) {
+ Path = getcwd(NULL, 0);
+ rep = fs->representationOfFile(Path);
+ free((char *) Path);
+ }
+ else rep = fs->representationOfFile(Path);
+}
+
+cFile::cFile(const cFile &other)
+ : rep(other.rep)
+{
+ if (!fs) fs = new cFileSystem();
}
cFile::cFile(const cFile& Parent, const char* RelativePath)
@@ -59,88 +70,112 @@ cFile::~cFile()
{
}
-char *cFile::AbsolutePath(void) const
+cFile &cFile::operator =(const cFile &other)
{
- cStringBuilder *sb = rep->internalPath();
- char *rv = NULL;
+ rep = other.rep;
+ return *this;
+}
- if (sb) {
- rv = sb->toString();
- delete sb;
- }
- return rv;
+const char *cFile::AbsolutePath(void) const
+{
+ if (rep) return rep->Path();
+ return NULL;
}
bool cFile::Exists(void) const
{
- return rep->exists;
+ if (rep) return rep->exists;
+ return false;
}
bool cFile::IsDirectory(void) const
{
- return (rep->mode & S_IFMT) == S_IFDIR;
+ if (rep) return (rep->mode & S_IFMT) == S_IFDIR;
+ return false;
}
bool cFile::IsFile(void) const
{
- return (rep->mode & S_IFMT) == S_IFREG;
+ if (rep) return (rep->mode & S_IFMT) == S_IFREG;
+ return false;
}
bool cFile::IsSymbolic(void) const
{
- return (rep->mode & S_IFMT) == S_IFLNK;
+ if (rep) return (rep->mode & S_IFMT) == S_IFLNK;
+ return false;
}
bool cFile::CanRead(void) const
{
- return rep->mode & ReadMask;
+ if (rep) return rep->mode & ReadMask;
+ return false;
}
bool cFile::CanWrite(void) const
{
- return rep->mode & WriteMask;
+ if (rep) return rep->mode & WriteMask;
+ return false;
}
bool cFile::CanExecute(void) const
{
- return rep->mode & ExecMask;
+ if (rep) return rep->mode & ExecMask;
+ return false;
}
off64_t cFile::Size(void) const
{
- return rep->size;
+ if (rep) return rep->size;
+ return 0;
}
ulong cFile::LastModified(void) const
{
- return rep->lastModified;
+ if (rep) return rep->lastModified;
+ return 0;
}
cFile *cFile::Parent(void) const
{
- return new cFile(rep->getParent());
+ if (rep) return new cFile(rep->getParent());
+ return NULL;
}
const char *cFile::Name(void) const
{
- return rep->name;
+ if (rep) return rep->name;
+ return NULL;
}
void cFile::Cleanup(void)
{
- if (fs) delete fs;
+ if (fs) {
+ delete fs;
+ fs = NULL;
+ }
}
-void cFile::VisitFiles(int (*cb)(cFile *, const char *))
+void cFile::VisitFiles(int (*cb)(void *, cFile *, const char *), void *opaque)
{
+ if (!Exists() || !IsDirectory()) return;
struct dirent entryBuffer, *pE;
- char * path = AbsolutePath();
- DIR *dir = opendir(path);
+ DIR *dir = opendir(AbsolutePath());
while (!readdir_r(dir, &entryBuffer, &pE) && pE) {
if (*(pE->d_name) == '.') continue; // don't bother with hidden stuff
- cb(this, pE->d_name);
+ cb(opaque, this, pE->d_name);
}
closedir(dir);
- free(path);
+}
+
+char *cFile::toURI() const
+{
+ if (rep) return rep->toURI();
+ return NULL;
+}
+
+void cFile::SetVirtualRoot(bool isRoot)
+{
+ if (rep) ((cFileRepresentation *)rep)->SetVirtualRoot(isRoot);
}