This allow compile check event for CONNECT and use EVENT as CONNECT target, also raise event now is simple execute EVENT function.
89 lines
2.4 KiB
C++
89 lines
2.4 KiB
C++
/*
|
|
PIP - Platform Independent Primitives
|
|
Directory
|
|
Copyright (C) 2013 Ivan Pelipenko peri4ko@gmail.com
|
|
|
|
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 3 of the License, 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef PIDIR_H
|
|
#define PIDIR_H
|
|
|
|
#include "pifile.h"
|
|
#include "pistring.h"
|
|
#ifndef WINDOWS
|
|
#include <sys/dir.h>
|
|
#include <sys/stat.h>
|
|
|
|
class PIDir
|
|
{
|
|
public:
|
|
PIDir();
|
|
PIDir(const PIString & dir);
|
|
~PIDir() {close();}
|
|
|
|
struct DirEntry {
|
|
DirEntry() {;}
|
|
DirEntry(const PIString & name_, const int & mode_, const int & size_) {
|
|
name = name_; mode = mode_; size = size_;}
|
|
|
|
PIString name;
|
|
int mode;
|
|
int size;
|
|
|
|
bool isDir() const {return (mode & S_IFDIR);}
|
|
bool isFile() const {return (mode & S_IFREG);}
|
|
bool isSymbolicLink() const {return (mode & S_IFLNK);}
|
|
bool isBlockDevice() const {return (mode & S_IFBLK);}
|
|
bool isCharacterDevice() const {return (mode & S_IFCHR);}
|
|
bool isSocket() const {return (mode & S_IFSOCK);}
|
|
};
|
|
|
|
const bool isExists() {return (dir_ != 0);}
|
|
const bool isAbsolute() {if (path_.size() == 0) return false; return (path_[0] == separator);}
|
|
PIString path() {return PIString(path_);}
|
|
PIDir & cleanPath();
|
|
PIDir cleanedPath() {PIDir d(path_); d.cleanPath(); return d;}
|
|
PIString absolutePath();
|
|
bool mkDir(bool withParents = true);
|
|
PIVector<DirEntry> entries();
|
|
|
|
PIDir & cd(const PIString & path);
|
|
PIDir & up() {return cd("..");}
|
|
|
|
bool operator ==(const PIDir & d) const;
|
|
|
|
static const PIChar separator;
|
|
|
|
static PIDir current();
|
|
static PIDir home();
|
|
static PIDir temporary();
|
|
static bool mkDir(const PIString & path, bool withParents = true);
|
|
static bool rmDir(const PIString & path);
|
|
static bool isExists(const PIString & path) {return PIDir(path).isExists();}
|
|
//static bool rmDir(const PIString & path);
|
|
|
|
private:
|
|
bool open();
|
|
bool close();
|
|
|
|
PIString path_;
|
|
|
|
DIR * dir_;
|
|
|
|
};
|
|
|
|
#endif
|
|
#endif // PIDIR_H
|