PIChar ICU fixes
git-svn-id: svn://db.shs.com.ru/pip@95 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -110,27 +110,47 @@ PIChar PIChar::fromUTF8(const char * c) {
|
||||
|
||||
|
||||
bool PIChar::operator ==(const PIChar & o) const {
|
||||
return strcmp(o.toCharPtr(), toCharPtr()) == 0;
|
||||
return ch == o.ch;
|
||||
}
|
||||
|
||||
|
||||
bool PIChar::operator >(const PIChar & o) const {
|
||||
return strcmp(o.toCharPtr(), toCharPtr()) < 0;
|
||||
return
|
||||
#ifdef PIP_ICU
|
||||
u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) > 0;
|
||||
#else
|
||||
strcmp(toCharPtr(), o.toCharPtr()) > 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool PIChar::operator <(const PIChar & o) const {
|
||||
return strcmp(o.toCharPtr(), toCharPtr()) > 0;
|
||||
return
|
||||
#ifdef PIP_ICU
|
||||
u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) < 0;
|
||||
#else
|
||||
strcmp(toCharPtr(), o.toCharPtr()) < 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool PIChar::operator >=(const PIChar & o) const {
|
||||
return strcmp(o.toCharPtr(), toCharPtr()) <= 0;
|
||||
return
|
||||
#ifdef PIP_ICU
|
||||
u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) >= 0;
|
||||
#else
|
||||
strcmp(toCharPtr(), o.toCharPtr()) >= 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool PIChar::operator <=(const PIChar & o) const {
|
||||
return strcmp(o.toCharPtr(), toCharPtr()) >= 0;
|
||||
return
|
||||
#ifdef PIP_ICU
|
||||
u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) <= 0;
|
||||
#else
|
||||
strcmp(toCharPtr(), o.toCharPtr()) <= 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -217,12 +237,26 @@ char PIChar::toConcole1Byte() const {
|
||||
|
||||
|
||||
PIChar PIChar::toUpper() const {
|
||||
#ifdef PIP_ICU
|
||||
UChar c(0);
|
||||
UErrorCode e((UErrorCode)0);
|
||||
u_strToUpper(&c, 1, (const UChar*)(&ch), 1, 0, &e);
|
||||
return PIChar(c);
|
||||
#else
|
||||
return PIChar(toupper(ch));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
PIChar PIChar::toLower() const {
|
||||
#ifdef PIP_ICU
|
||||
UChar c(0);
|
||||
UErrorCode e((UErrorCode)0);
|
||||
u_strToLower(&c, 1, (const UChar*)(&ch), 1, 0, &e);
|
||||
return PIChar(c);
|
||||
#else
|
||||
return PIChar(tolower(ch));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -237,6 +271,18 @@ std::ostream & operator <<(std::ostream & s, const PIChar & v) {
|
||||
PICout operator <<(PICout s, const PIChar & v) {
|
||||
s.space();
|
||||
s.setControl(0, true);
|
||||
#ifdef PIP_ICU
|
||||
UErrorCode e((UErrorCode)0);
|
||||
UConverter * cc = ucnv_open(PICout::isBufferActive() ? __syslocname__ : __sysoemname__, &e);
|
||||
if (cc) {
|
||||
char uc[8];
|
||||
memset(uc, 0, 8);
|
||||
e = (UErrorCode)0;
|
||||
ucnv_fromUChars(cc, uc, 8, (const UChar*)(&v.ch), 1, &e);
|
||||
ucnv_close(cc);
|
||||
s << uc;
|
||||
} else
|
||||
#endif
|
||||
s << v.toCharPtr();
|
||||
s.restoreControl();
|
||||
return s;
|
||||
|
||||
@@ -35,6 +35,7 @@ class PIP_EXPORT PIChar
|
||||
friend class PIString;
|
||||
friend PIByteArray & operator <<(PIByteArray & s, const PIChar & v);
|
||||
friend PIByteArray & operator >>(PIByteArray & s, PIChar & v);
|
||||
friend PICout operator <<(PICout s, const PIChar & v);
|
||||
public:
|
||||
//! Contructs ascii symbol
|
||||
PIChar(const char c) {ch = c; ch &= 0xFF;}
|
||||
|
||||
@@ -149,6 +149,7 @@ PIDir & PIDir::cleanPath() {
|
||||
PIString PIDir::relative(const PIString & path) const {
|
||||
PIDir td(path);
|
||||
PIStringList dl(absolutePath().split(separator)), pl(td.absolutePath().split(separator)), rl;
|
||||
//piCout << pl << "rel to" << dl;
|
||||
while (!dl.isEmpty() && !pl.isEmpty()) {
|
||||
if (dl.front() != pl.front()) break;
|
||||
dl.pop_front();
|
||||
|
||||
@@ -54,9 +54,12 @@ bool PIFileTransfer::send(PIVector<PIFile::FileInfo> entries) {
|
||||
PIVector<PIFile::FileInfo> fls = d.allEntries();
|
||||
scanning = false;
|
||||
d.up();
|
||||
for (int j=0; j<fls.size(); j++) {
|
||||
//piCout << "files rel to" << d.absolutePath();
|
||||
for (int j = 0; j < fls.size(); j++) {
|
||||
allEntries << PFTFileInfo(fls[j]);
|
||||
allEntries.back().dest_path = d.relative(fls[j].path);
|
||||
//piCout << " abs path" << fls[j].path;
|
||||
//piCout << " rel path" << allEntries.back().dest_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,15 +104,15 @@ bool PIFileTransfer::sendFiles(const PIVector<PFTFileInfo> &files) {
|
||||
|
||||
|
||||
void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) {
|
||||
// piCout << "processFile" << id << files_.size();
|
||||
//piCout << "processFile" << id << files_.size();
|
||||
PFTFileInfo fi = files_[id-1];
|
||||
bytes_file_all = fi.size;
|
||||
bytes_file_cur = start;
|
||||
cur_file_string = fi.dest_path;
|
||||
PIString path = dir.absolutePath() + dir.separator + fi.dest_path;
|
||||
// piCout << "receive" << path << fi.size << data.size();
|
||||
//piCout << "receive" << path << fi.size << data.size();
|
||||
if (fi.isDir()) {
|
||||
// piCoutObj << "make dir" << fi.entry.path;
|
||||
//piCoutObj << "make dir" << fi.entry.path;
|
||||
if (!PIDir::make(path)) {
|
||||
cur_file_string = "ERROR! while create directory " + path;
|
||||
piCoutObj << cur_file_string;
|
||||
@@ -119,7 +122,9 @@ void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) {
|
||||
}
|
||||
if (fi.isFile()) {
|
||||
if (work_file.path() != path || !work_file.isOpened()) {
|
||||
//piCout << "file close";
|
||||
work_file.close();
|
||||
//piCout << "new file" << path << work_file.path() << work_file.isOpened();
|
||||
if (!work_file.open(path, PIIODevice::ReadWrite)) {
|
||||
cur_file_string = "ERROR! while open file " + path;
|
||||
piCoutObj << cur_file_string;
|
||||
@@ -128,17 +133,17 @@ void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) {
|
||||
}
|
||||
PIFile::applyFileInfo(path, fi);
|
||||
if (work_file.size() > fi.size) {
|
||||
// piCoutObj << "error size" << work_file.size() << fi.size;
|
||||
//piCoutObj << "error size" << work_file.size() << fi.size;
|
||||
work_file.clear();
|
||||
work_file.resize(fi.size);
|
||||
// piCoutObj << "correct size" << work_file.size() << fi.size;
|
||||
//piCoutObj << "correct size" << work_file.size() << fi.size;
|
||||
}
|
||||
}
|
||||
// piCoutObj << "write file" << path << work_file.path() << work_file.size() << fi.entry.size << work_file.pos() << fi.fstart << fi.fsize;
|
||||
//piCoutObj << "write file" << path << work_file.path() << work_file.size() << fi.entry.size << work_file.pos() << fi.fstart << fi.fsize;
|
||||
if (work_file.size() < (llong)start) {
|
||||
// piCoutObj << "error pos size" << work_file.pos() << fi.fstart;
|
||||
//piCoutObj << "error pos size" << work_file.pos() << fi.fstart;
|
||||
work_file.resize(start);
|
||||
// piCoutObj << "correct pos size" << work_file.pos() << fi.fstart;
|
||||
//piCoutObj << "correct pos size" << work_file.pos() << fi.fstart;
|
||||
}
|
||||
if (work_file.size() > fi.size) {
|
||||
piCoutObj << "****** error size" << work_file.size() << fi.size;
|
||||
@@ -146,7 +151,7 @@ void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) {
|
||||
work_file.resize(fi.size);
|
||||
piCoutObj << "****** correct size" << work_file.size() << fi.size;
|
||||
}
|
||||
// if (fi.fstart != work_file.pos()) piCoutObj << "error pos" << work_file.pos() << fi.fstart;
|
||||
//if (fi.fstart != work_file.pos()) piCoutObj << "error pos" << work_file.pos() << fi.fstart;
|
||||
work_file.seek(start);
|
||||
int rs = work_file.write(data.data(), data.size());
|
||||
if (rs != data.size_s()) {
|
||||
@@ -160,8 +165,8 @@ void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) {
|
||||
|
||||
|
||||
PIByteArray PIFileTransfer::buildPacket(Part p) {
|
||||
// piCoutObj << "Step" << pftheader.step;
|
||||
// piCoutObj << "session id" << pftheader.session_id;
|
||||
//piCoutObj << "Step" << pftheader.step;
|
||||
//piCoutObj << "session id" << pftheader.session_id;
|
||||
PIByteArray ba;
|
||||
switch(pftheader.step) {
|
||||
case pft_None:
|
||||
@@ -285,6 +290,7 @@ void PIFileTransfer::receive_finished(bool ok) {
|
||||
} else resume();
|
||||
}
|
||||
if (pftheader.step == pft_Data) {
|
||||
//piCout << "file close";
|
||||
work_file.close();
|
||||
started_ = false;
|
||||
receiveFilesFinished(ok);
|
||||
@@ -293,6 +299,7 @@ void PIFileTransfer::receive_finished(bool ok) {
|
||||
|
||||
|
||||
void PIFileTransfer::send_finished(bool ok) {
|
||||
//piCout << "file close";
|
||||
work_file.close();
|
||||
started_ = false;
|
||||
}
|
||||
|
||||
@@ -358,6 +358,7 @@ void Daemon::fmActionRequest(bool remote_tile, FileManager::Action type, PIVaria
|
||||
case FileManager::Copy:
|
||||
if (remote_tile) {
|
||||
PIByteArray ba;
|
||||
//piCout << fm.selectedRemote();
|
||||
ba << int(CopyFiles) << fm.selectedRemote();
|
||||
r->ft.setDirectory(fm.localDir());
|
||||
send(conn_name, ba);
|
||||
@@ -515,7 +516,7 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
ba >> dir;
|
||||
r->dir_my.cd(dir);
|
||||
r->ft.setDirectory(r->dir_my);
|
||||
piCout << "store to" << r->dir_my.absolutePath();
|
||||
//piCout << "store to" << r->dir_my.absolutePath();
|
||||
piCout << "cd to" << dir << ", abs =" << r->dir_my.absolutePath();
|
||||
sendDirToRemote(r);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user