PIDir windows drives support

git-svn-id: svn://db.shs.com.ru/pip@55 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-04-01 06:41:33 +00:00
parent 071fc76ea3
commit d60e7fad2a
8 changed files with 111 additions and 55 deletions

View File

@@ -26,7 +26,7 @@
#include "piscreentypes.h"
#include "pistring.h"
class PIScreenDrawer
class PIP_EXPORT PIScreenDrawer
{
friend class PIScreen;
PIScreenDrawer(PIVector<PIVector<PIScreenTypes::Cell> > & c): cells(c) {}

View File

@@ -28,7 +28,7 @@
class PIScreenDrawer;
class PIScreenTile: public PIObject {
class PIP_EXPORT PIScreenTile: public PIObject {
friend class PIScreen;
PIOBJECT_SUBCLASS(PIScreenTile, PIObject)
public:

View File

@@ -26,7 +26,7 @@
#include "piscreentile.h"
class TileSimple: public PIScreenTile {
class PIP_EXPORT TileSimple: public PIScreenTile {
public:
TileSimple(const PIString & n = PIString());
typedef PIPair<PIString, PIScreenTypes::CellFormat> Row;
@@ -40,7 +40,7 @@ protected:
class TileList: public PIScreenTile {
class PIP_EXPORT TileList: public PIScreenTile {
public:
TileList(const PIString & n = PIString());
enum SelectionMode {
@@ -68,7 +68,7 @@ protected:
class TileButton: public PIScreenTile {
class PIP_EXPORT TileButton: public PIScreenTile {
public:
TileButton(const PIString & n = PIString());
enum EventType {
@@ -85,7 +85,7 @@ protected:
class TileButtons: public PIScreenTile {
class PIP_EXPORT TileButtons: public PIScreenTile {
public:
TileButtons(const PIString & n = PIString());
enum EventType {
@@ -103,7 +103,7 @@ protected:
class TileCheck: public PIScreenTile {
class PIP_EXPORT TileCheck: public PIScreenTile {
public:
TileCheck(const PIString & n = PIString());
enum EventType {
@@ -121,7 +121,7 @@ protected:
class TileProgress: public PIScreenTile {
class PIP_EXPORT TileProgress: public PIScreenTile {
public:
TileProgress(const PIString & n = PIString());
PIScreenTypes::CellFormat format;
@@ -137,7 +137,7 @@ protected:
class TilePICout: public TileList {
class PIP_EXPORT TilePICout: public TileList {
public:
TilePICout(const PIString & n = PIString());
PIScreenTypes::CellFormat format;

View File

@@ -54,14 +54,12 @@ const PIChar PIDir::separator = '/';
PIDir::PIDir(const PIString & dir) {
path_ = dir;
cleanPath();
setDir(dir);
}
PIDir::PIDir(const PIFile & file) {
path_ = file.path();
cleanPath();
setDir(file.path());
if (isExists()) return;
int pos = path_.findLast(separator);
path_.cutRight(path_.size_s() - pos);
@@ -75,18 +73,42 @@ bool PIDir::operator ==(const PIDir & d) const {
bool PIDir::isAbsolute() const {
if (path_.isEmpty()) return false;
#ifdef WINDOWS
/*#ifdef WINDOWS
if (path_.size_s() < 2) return false;
return (path_.mid(1, 2).contains(":"));
#else
return (path_[0] == separator);
#endif*/
return (path_[0] == separator);
}
PIString PIDir::path() const {
#ifdef WINDOWS
if (path_.startsWith(separator)) {
if (path_.length() == 1)
return separator;
else
return path_.mid(1);
} else
#endif
return path_;
}
PIString PIDir::absolutePath() const {
if (isAbsolute()) return path_;
return PIDir(PIDir::current().path_ + separator + path_).path_;
if (isAbsolute()) {
#ifdef WINDOWS
if (path_.startsWith(separator)) {
if (path_.length() == 1)
return separator;
else
return path_.mid(1);
} else
#endif
return path_;
}
return PIDir(PIDir::current().path() + separator + path_).path();
}
@@ -96,13 +118,10 @@ PIDir & PIDir::cleanPath() {
path_ = ".";
return *this;
}
path_.replaceAll(PIString(separator) + PIString(separator), PIString(separator));
PIString sep = PIString(separator);
path_.replaceAll(sep + sep, sep);
bool is_abs = isAbsolute();
PIStringList l = PIString(p).split(separator);
#ifdef WINDOWS
PIString letter;
if (is_abs) letter = l.take_front();
#endif
l.removeAll(".");
l.removeAll("");
for (int i = 0; i < l.size_s() - 1; ++i) {
@@ -120,12 +139,8 @@ PIDir & PIDir::cleanPath() {
break;
}
path_ = l.join(separator);
if (is_abs) {
if (is_abs)
path_.prepend(separator);
#ifdef WINDOWS
path_.prepend(letter);
#endif
}
if (path_.isEmpty()) path_ = ".";
return *this;
}
@@ -149,6 +164,11 @@ PIString PIDir::relative(const PIString & path) const {
PIDir & PIDir::setDir(const PIString & path) {
path_ = path;
#ifdef WINDOWS
if (path_.length() > 2)
if (path_.mid(1, 2).contains(":"))
path_.prepend(separator);
#endif
cleanPath();
return *this;
}
@@ -167,7 +187,7 @@ bool PIDir::make(bool withParents) {
PIString tp;
bool is_abs = isAbsolute();
if (withParents) {
PIStringList l = d.path_.split(separator);
PIStringList l = d.path().split(separator);
for (int i = l.size_s() - 1; i >= 0; --i) {
if (i > 1) tp = PIStringList(l).remove(i, l.size_s() - i).join(separator);
else {
@@ -187,7 +207,7 @@ bool PIDir::make(bool withParents) {
}
return true;
} else
if (makeDir(d.path_)) return true;
if (makeDir(d.path())) return true;
return false;
}
@@ -201,15 +221,41 @@ PIVector<PIFile::FileInfo> PIDir::entries() {
else if (!dp.endsWith(separator)) dp += separator;
//piCout << "entries from" << p;
#ifdef WINDOWS
if (dp == separator) {
char letters[1024];
PIFile::FileInfo fi;
DWORD ll = GetLogicalDriveStrings(1023, letters);
PIString clet;
for (int i = 0; i < ll; ++i) {
if (letters[i] == '\0') {
clet.resize(2);
fi.path = clet;
fi.flags = PIFile::FileInfo::Dir;
l << fi;
clet.clear();
} else
clet += PIChar(letters[i]);
}
} else {
WIN32_FIND_DATA fd; memset(&fd, 0, sizeof(fd));
p += "\\*";
void * hf = FindFirstFile((LPCTSTR)(p.data()), &fd);
if (!hf) return l;
bool hdd = false;
do {
l << PIFile::fileInfo(dp + PIString(fd.cFileName));
PIString fn(fd.cFileName);
if (fn == "..") hdd = true;
l << PIFile::fileInfo(dp + fn);
memset(&fd, 0, sizeof(fd));
} while (FindNextFile(hf, &fd) != 0);
FindClose(hf);
if (!hdd) {
PIFile::FileInfo fi;
fi.path = "..";
fi.flags = PIFile::FileInfo::Dir | PIFile::FileInfo::DotDot;
l.push_front(fi);
}
}
#else
dirent ** list;
int cnt = scandir(
@@ -260,6 +306,7 @@ PIDir PIDir::current() {
if (GetCurrentDirectory(1024, (LPTSTR)rc) == 0) return PIString();
PIString ret(rc);
ret.replaceAll("\\", PIDir::separator);
ret.prepend(separator);
return PIDir(ret);
#else
if (getcwd(rc, 1024) == 0) return PIString();
@@ -280,6 +327,7 @@ PIDir PIDir::home() {
PIString s(rc);
s.replaceAll("\\", PIDir::separator);
delete[] rc;
s.prepend(separator);
return PIDir(s);
#else
rc = getenv("HOME");
@@ -302,6 +350,7 @@ PIDir PIDir::temporary() {
PIString s(rc);
s.replaceAll("\\", PIDir::separator);
delete[] rc;
s.prepend(separator);
return PIDir(s);
#else
rc = tmpnam(0);

View File

@@ -38,7 +38,7 @@ public:
//! Returns if this directory is exists
bool isExists() const {return PIDir::isExists(path_);}
bool isExists() const {return PIDir::isExists(path());}
//! Returns if path of this directory is absolute
bool isAbsolute() const;
@@ -48,7 +48,7 @@ public:
//! Returns path of this directory
const PIString & path() const {return path_;}
PIString path() const;
//! Returns absolute path of this directory
PIString absolutePath() const;
@@ -60,7 +60,7 @@ public:
PIDir & cleanPath();
//! Returns %PIDir with simplified path of this directory
PIDir cleanedPath() const {PIDir d(path_); d.cleanPath(); return d;}
PIDir cleanedPath() const {PIDir d(path()); d.cleanPath(); return d;}
//! Returns relative to this directory path "path"
PIString relative(const PIString & path) const;
@@ -69,13 +69,14 @@ public:
PIDir & setDir(const PIString & path);
//! Set this directory path as current for application
bool setCurrent() {return PIDir::setCurrent(path_);}
bool setCurrent() {return PIDir::setCurrent(path());}
/** \brief Returns this directory content
* \details Scan this directory and returns all directories
* and files in one list, sorted alphabetically. This list
* contains also "." and ".." members.
* contains also "." and ".." members. There are absolute
* pathes in returned list.
* \attention This function doesn`t scan content of inner
* directories! */
PIVector<PIFile::FileInfo> entries();
@@ -83,13 +84,14 @@ public:
/** \brief Returns all this directory content
* \details Scan this directory recursively and returns all
* directories and files in one list, sorted alphabetically.
* This list doesn`t contains "." and ".." members.
* Files placed after directories in this list */
* This list doesn`t contains "." and ".." members. There
* are absolute pathes in returned list, and
* files placed after directories in this list */
PIVector<PIFile::FileInfo> allEntries();
bool make(bool withParents = true);
bool remove() {return PIDir::remove(path_);}
bool rename(const PIString & new_name) {if (!PIDir::rename(path_, new_name)) return false; path_ = new_name; return true;}
bool remove() {return PIDir::remove(path());}
bool rename(const PIString & new_name) {if (!PIDir::rename(path(), new_name)) return false; setDir(new_name); return true;}
PIDir & cd(const PIString & path);
PIDir & up() {return cd("..");}
@@ -107,7 +109,7 @@ public:
static bool remove(const PIString & path) {return removeDir(path);}
static bool rename(const PIString & path, const PIString & new_name) {return PIDir::renameDir(path, new_name);}
static bool setCurrent(const PIString & path);
static bool setCurrent(const PIDir & dir) {return setCurrent(dir.path_);}
static bool setCurrent(const PIDir & dir) {return setCurrent(dir.path());}
private:
static bool makeDir(const PIString & path);

View File

@@ -48,7 +48,7 @@ public:
typedef PIFlags<FileInfo::Flag> Flags;
struct Permissions {
Permissions(uchar r = 0): raw(r) {}
Permissions(bool r, bool w, bool e): raw(0) {read = w; write = w; exec = e;}
Permissions(bool r, bool w, bool e): raw(0) {read = r; write = w; exec = e;}
PIString toString() const {return PIString(read ? "r" : "-") + PIString(write ? "w" : "-") + PIString(exec ? "x" : "-");}
operator int() const {return raw;}
Permissions & operator =(int v) {raw = v; return *this;}

View File

@@ -122,7 +122,10 @@ PIString PIPeer::PeerInfo::fastestAddress() const {
}
PIPeer::PIPeer(const PIString & name_): PIObject() {
destroyed = false;
setName(name_);
self_info.name = name_;
self_info.dist = 0;
@@ -131,15 +134,16 @@ PIPeer::PIPeer(const PIString & name_): PIObject() {
srand(uint(PISystemTime::current(true).toMicroseconds()));
//id_ = self_info.name + "_" + PIString::fromNumber(rand());
CONNECTU(&timer, tickEvent, this, timerEvent);
prev_ifaces = PIEthernet::interfaces();
initNetwork();
sendSelfInfo();
prev_ifaces = PIEthernet::interfaces();
timer.addDelimiter(5);
timer.start(1000);
}
PIPeer::~PIPeer() {
destroyed = true;
timer.stop();
diag_s.stop();
diag_d.stop();
@@ -148,10 +152,10 @@ PIPeer::~PIPeer() {
i->stopThreadedRead();
piForeach (PIEthernet * i, eths_bcast)
i->stopThreadedRead();
eth_send.close();
eth_lo.stopThreadedRead();
sendSelfRemove();
destroyMBcasts();
eth_send.close();
}
@@ -170,7 +174,6 @@ void PIPeer::timerEvent(void * data, int delim) {
void PIPeer::initEths(PIStringList al) {
PIEthernet * ce;
PIEthernet::InterfaceList il = PIEthernet::interfaces();
const PIEthernet::Interface * cint = 0;
piForeachC (PIString & a, al) {
ce = new PIEthernet();
@@ -183,7 +186,7 @@ void PIPeer::initEths(PIStringList al) {
ce->setReadAddress(a, p);
if (ce->open()) {
eths_traffic << ce;
cint = il.getByAddress(a);
cint = prev_ifaces.getByAddress(a);
self_info.addresses << PeerInfo::Address(ce->path(), cint == 0 ? "255.255.255.0" : cint->netmask);
CONNECTU(ce, threadedReadEvent, this, dataRead);
ce->startThreadedRead();
@@ -204,7 +207,6 @@ void PIPeer::initEths(PIStringList al) {
void PIPeer::initMBcasts(PIStringList al) {
destroyMBcasts();
PIEthernet * ce;
PIEthernet::InterfaceList il = PIEthernet::interfaces();
const PIEthernet::Interface * cint;
PIString nm;
al << _PIPEER_MULTICAST_IP;
@@ -227,7 +229,7 @@ void PIPeer::initMBcasts(PIStringList al) {
ce->setDebug(false);
ce->setName("__S__PIPeer_bcast_eth_" + a);
ce->setParameters(PIEthernet::Broadcast);
cint = il.getByAddress(a);
cint = prev_ifaces.getByAddress(a);
nm = (cint == 0) ? "255.255.255.0" : cint->netmask;
ce->setSendAddress(PIEthernet::getBroadcast(a, nm), _PIPEER_BROADCAST_PORT);
ce->setReadAddress(a, _PIPEER_BROADCAST_PORT);
@@ -240,7 +242,7 @@ void PIPeer::initMBcasts(PIStringList al) {
eth_lo.setDebug(false);
eth_lo.setName("__S__PIPeer_eth_loopback");
eth_lo.setParameters(0);
cint = il.getByAddress("127.0.0.1");
cint = prev_ifaces.getByAddress("127.0.0.1");
for (int p = _PIPEER_LOOPBACK_PORT_S; p <= _PIPEER_LOOPBACK_PORT_E; ++p) {
eth_lo.setReadAddress("127.0.0.1", p);
if (eth_lo.open()) {
@@ -345,6 +347,7 @@ void PIPeer::dtReceived(const PIString & from, const PIByteArray & data) {
bool PIPeer::dataRead(uchar * readed, int size) {
if (destroyed) return true;
if (size < 16) return true;
PIByteArray ba(readed, size), sba, pba;
int type, cnt;
@@ -444,6 +447,7 @@ bool PIPeer::dataRead(uchar * readed, int size) {
bool PIPeer::mbcastRead(uchar * data, int size) {
if (destroyed) return true;
if (size < 8) return true;
int type, dist;
PIByteArray ba(data, size);

View File

@@ -192,6 +192,7 @@ private:
PIMap<PIString, PIVector<PeerInfo * > > addresses_map; // map {"to" = list of nearest peers}
PIMap<PIString, PIPair<int, PISystemTime> > removed;
PIDiagnostics diag_s, diag_d;
bool destroyed;
//PIString id_;
};