From 774e09eef2d7761814e6f19fb462eb0fdc74f2d7 Mon Sep 17 00:00:00 2001 From: geronimo Date: Wed, 25 Jul 2012 06:38:28 +0200 Subject: worked out different file class and improved media handling --- libs/fsScan/src/File.cc | 101 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 68 insertions(+), 33 deletions(-) (limited to 'libs/fsScan/src/File.cc') 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: Geronimo * 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 @@ -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); } -- cgit v1.2.3