From: <arn...@us...> - 2006-03-08 22:45:29
|
Revision: 587 Author: arnetheduck Date: 2006-03-08 14:45:13 -0800 (Wed, 08 Mar 2006) ViewCVS: http://svn.sourceforge.net/dcplusplus/?rev=587&view=rev Log Message: ----------- mem bug fixed, a few other minor things Modified Paths: -------------- dcplusplus/trunk/client/BufferedSocket.cpp dcplusplus/trunk/client/QueueManager.cpp dcplusplus/trunk/client/Util.cpp dcplusplus/trunk/client/Util.h dcplusplus/trunk/windows/ExListViewCtrl.h dcplusplus/trunk/windows/PublicHubsFrm.cpp Modified: dcplusplus/trunk/client/BufferedSocket.cpp =================================================================== --- dcplusplus/trunk/client/BufferedSocket.cpp 2006-02-27 00:04:48 UTC (rev 586) +++ dcplusplus/trunk/client/BufferedSocket.cpp 2006-03-08 22:45:13 UTC (rev 587) @@ -180,6 +180,7 @@ string::size_type pos = 0; AutoArray<u_int8_t> buffer (BufSize); size_t in; + l = line; // decompress all input data and store in l. while (left) { in = BufSize; @@ -200,7 +201,7 @@ l.erase (0, pos + 1 /* seperator char */); } // store remainder - line += l; + line = l; break; } Modified: dcplusplus/trunk/client/QueueManager.cpp =================================================================== --- dcplusplus/trunk/client/QueueManager.cpp 2006-02-27 00:04:48 UTC (rev 586) +++ dcplusplus/trunk/client/QueueManager.cpp 2006-03-08 22:45:13 UTC (rev 587) @@ -1048,13 +1048,13 @@ void QueueManager::removeSource(User::Ptr& aUser, int reason) throw() { string x; - StringList removeList; + string removeRunning; { Lock l(cs); QueueItem* qi = NULL; while( (qi = userQueue.getNext(aUser, QueueItem::PAUSED)) != NULL) { if(qi->isSet(QueueItem::FLAG_USER_LIST)) { - removeList.push_back(qi->getTarget()); + remove(qi->getTarget()); } else { userQueue.remove(qi, aUser); qi->removeSource(aUser, reason); @@ -1066,7 +1066,7 @@ qi = userQueue.getRunning(aUser); if(qi != NULL) { if(qi->isSet(QueueItem::FLAG_USER_LIST)) { - removeList.push_back(qi->getTarget()); + removeRunning = qi->getTarget(); } else { userQueue.setWaiting(qi); userQueue.remove(qi, aUser); @@ -1081,8 +1081,8 @@ if(!x.empty()) { DownloadManager::getInstance()->abortDownload(x); } - for(StringIter i = removeList.begin(); i != removeList.end(); ++i) { - remove(*i); + if(!removeRunning.empty()) { + remove(removeRunning); } } Modified: dcplusplus/trunk/client/Util.cpp =================================================================== --- dcplusplus/trunk/client/Util.cpp 2006-02-27 00:04:48 UTC (rev 586) +++ dcplusplus/trunk/client/Util.cpp 2006-03-08 22:45:13 UTC (rev 587) @@ -393,6 +393,24 @@ return buf; } +double Util::toBytes(TCHAR* aSize) { + double bytes = _tstof(aSize); + + if (_tcsstr(aSize, CTSTRING(PIB))) { + return bytes * 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0; + } else if (_tcsstr(aSize, CTSTRING(TiB))) { + return bytes * 1024.0 * 1024.0 * 1024.0 * 1024.0; + } else if (_tcsstr(aSize, CTSTRING(GiB))) { + return bytes * 1024.0 * 1024.0 * 1024.0; + } else if (_tcsstr(aSize, CTSTRING(MiB))) { + return bytes * 1024.0 * 1024.0; + } else if (_tcsstr(aSize, CTSTRING(KiB))) { + return bytes * 1024.0; + } else { + return bytes; + } +} + string Util::formatExactSize(int64_t aBytes) { #ifdef _WIN32 TCHAR buf[64]; Modified: dcplusplus/trunk/client/Util.h =================================================================== --- dcplusplus/trunk/client/Util.h 2006-02-27 00:04:48 UTC (rev 586) +++ dcplusplus/trunk/client/Util.h 2006-03-08 22:45:13 UTC (rev 587) @@ -272,6 +272,8 @@ static string formatBytes(const string& aString) { return formatBytes(toInt64(aString)); } + + static double toBytes(TCHAR* aSize); static string toDOS(const string& tmp); Modified: dcplusplus/trunk/windows/ExListViewCtrl.h =================================================================== --- dcplusplus/trunk/windows/ExListViewCtrl.h 2006-02-27 00:04:48 UTC (rev 586) +++ dcplusplus/trunk/windows/ExListViewCtrl.h 2006-03-08 22:45:13 UTC (rev 587) @@ -40,7 +40,8 @@ SORT_STRING, SORT_STRING_NOCASE, SORT_INT, - SORT_FLOAT + SORT_FLOAT, + SORT_BYTES }; typedef ListViewArrows<ExListViewCtrl> arrowBase; @@ -143,7 +144,11 @@ p->GetItemText(na, p->sortColumn, buf, 128); p->GetItemText(nb, p->sortColumn, buf2, 128); result = compare(_tstof(buf), _tstof(buf2)); - } + } else if(result == SORT_BYTES) { + p->GetItemText(na, p->sortColumn, buf, 128); + p->GetItemText(nb, p->sortColumn, buf2, 128); + result = compare(Util::toBytes(buf), Util::toBytes(buf2)); + } if(!p->ascending) result = -result; return result; Modified: dcplusplus/trunk/windows/PublicHubsFrm.cpp =================================================================== --- dcplusplus/trunk/windows/PublicHubsFrm.cpp 2006-02-27 00:04:48 UTC (rev 586) +++ dcplusplus/trunk/windows/PublicHubsFrm.cpp 2006-03-08 22:45:13 UTC (rev 587) @@ -167,8 +167,10 @@ // BAH, sorting on bytes will break of course...oh well...later... if(l->iSubItem == COLUMN_USERS || l->iSubItem == COLUMN_MINSLOTS ||l->iSubItem == COLUMN_MAXHUBS || l->iSubItem == COLUMN_MAXUSERS) { ctrlHubs.setSort(l->iSubItem, ExListViewCtrl::SORT_INT); - } else if(l->iSubItem == COLUMN_SHARED || l->iSubItem == COLUMN_MINSHARE || l->iSubItem == COLUMN_RELIABILITY) { - ctrlHubs.setSort(l->iSubItem, ExListViewCtrl::SORT_FLOAT); + } else if(l->iSubItem == COLUMN_RELIABILITY) { + ctrlHubs.setSort(l->iSubItem, ExListViewCtrl::SORT_FLOAT); + } else if (l->iSubItem == COLUMN_SHARED || l->iSubItem == COLUMN_MINSHARE){ + ctrlHubs.setSort(l->iSubItem, ExListViewCtrl::SORT_BYTES); } else { ctrlHubs.setSort(l->iSubItem, ExListViewCtrl::SORT_STRING_NOCASE); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <arn...@us...> - 2006-03-18 19:41:11
|
Revision: 593 Author: arnetheduck Date: 2006-03-18 11:40:59 -0800 (Sat, 18 Mar 2006) ViewCVS: http://svn.sourceforge.net/dcplusplus/?rev=593&view=rev Log Message: ----------- More stuff before release Modified Paths: -------------- dcplusplus/trunk/client/Client.h dcplusplus/trunk/client/ClientManager.cpp dcplusplus/trunk/client/File.h dcplusplus/trunk/client/version.h Modified: dcplusplus/trunk/client/Client.h =================================================================== --- dcplusplus/trunk/client/Client.h 2006-03-18 19:34:20 UTC (rev 592) +++ dcplusplus/trunk/client/Client.h 2006-03-18 19:40:59 UTC (rev 593) @@ -107,7 +107,7 @@ short getPort() const { return port; } const string& getAddress() const { return address; } - const string& getIp() const { return (!socket || socket->getIp().empty()) ? getAddress() : socket->getIp(); } + const string& getIp() const { return ip; } string getIpPort() const { return getIp() + ':' + Util::toString(port); } string getLocalIp() const; @@ -192,6 +192,7 @@ string hubUrl; string address; + string ip; u_int16_t port; char separator; bool secure; @@ -200,7 +201,7 @@ // BufferedSocketListener virtual void on(Connecting) throw() { fire(ClientListener::Connecting(), this); } - virtual void on(Connected) throw() { updateActivity(); fire(ClientListener::Connected(), this); } + virtual void on(Connected) throw() { updateActivity(); ip = socket->getIp(); fire(ClientListener::Connected(), this); } }; #endif // !defined(CLIENT_H) Modified: dcplusplus/trunk/client/ClientManager.cpp =================================================================== --- dcplusplus/trunk/client/ClientManager.cpp 2006-03-18 19:34:20 UTC (rev 592) +++ dcplusplus/trunk/client/ClientManager.cpp 2006-03-18 19:40:59 UTC (rev 593) @@ -427,7 +427,7 @@ string& client = *it; for(Client::Iter j = clients.begin(); j != clients.end(); ++j) { Client* c = *j; - if(c->isConnected() && c->getIpPort() == client) { + if(c->isConnected() && c->getHubUrl() == client) { c->search(aSizeMode, aSize, aFileType, aString, aToken); } } Modified: dcplusplus/trunk/client/File.h =================================================================== --- dcplusplus/trunk/client/File.h 2006-03-18 19:34:20 UTC (rev 592) +++ dcplusplus/trunk/client/File.h 2006-03-18 19:40:59 UTC (rev 593) @@ -287,7 +287,7 @@ virtual size_t read(void* buf, size_t& len) throw(FileException) { ssize_t x = ::read(h, buf, len); if(x == -1) - throw("Read error"); + throw FileException("Read error"); len = x; return (size_t)x; } Modified: dcplusplus/trunk/client/version.h =================================================================== --- dcplusplus/trunk/client/version.h 2006-03-18 19:34:20 UTC (rev 592) +++ dcplusplus/trunk/client/version.h 2006-03-18 19:40:59 UTC (rev 593) @@ -17,8 +17,8 @@ */ #define APPNAME "DC++" -#define VERSIONSTRING "0.6875" -#define VERSIONFLOAT 0.6875 +#define VERSIONSTRING "0.688" +#define VERSIONFLOAT 0.688 /* Update the .rc file as well... */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <arn...@us...> - 2006-06-17 23:26:45
|
Revision: 618 Author: arnetheduck Date: 2006-06-17 16:26:36 -0700 (Sat, 17 Jun 2006) ViewCVS: http://svn.sourceforge.net/dcplusplus/?rev=618&view=rev Log Message: ----------- Spring cleaning Modified Paths: -------------- dcplusplus/trunk/client/NmdcHub.cpp dcplusplus/trunk/client/NmdcHub.h dcplusplus/trunk/windows/CommandDlg.cpp Modified: dcplusplus/trunk/client/NmdcHub.cpp =================================================================== --- dcplusplus/trunk/client/NmdcHub.cpp 2006-06-17 22:24:01 UTC (rev 617) +++ dcplusplus/trunk/client/NmdcHub.cpp 2006-06-17 23:26:36 UTC (rev 618) @@ -192,8 +192,22 @@ } } string line = fromAcp(aLine); - // @todo Decrypt who the message is from... - fire(ClientListener::StatusMessage(), this, unescape(fromAcp(aLine))); + if(line[0] != '<') { + fire(ClientListener::StatusMessage(), this, unescape(line)); + return; + } + string::size_type i = line.find('>', 2); + if(i == string::npos) { + fire(ClientListener::StatusMessage(), this, unescape(line)); + return; + } + string nick = line.substr(1, i-1); + OnlineUser* ou = findUser(nick); + if(ou) { + fire(ClientListener::Message(), this, *ou, unescape(line.substr(i+1))); + } else { + fire(ClientListener::StatusMessage(), this, unescape(line)); + } return; } @@ -282,7 +296,7 @@ return; int type = Util::toInt(param.substr(i, j-i)) - 1; i = j + 1; - param = param.substr(i); + string terms = param.substr(i); if(param.size() > 0) { if(seeker.compare(0, 4, "Hub:") == 0) { @@ -351,7 +365,7 @@ if(j == string::npos) return; - u.getIdentity().setEmail(unescape(param.substr(i, j-i)); + u.getIdentity().setEmail(unescape(param.substr(i, j-i))); i = j + 1; j = param.find('$', i); @@ -366,9 +380,9 @@ fire(ClientListener::UserUpdated(), this, u); } else if(cmd == "$Quit") { if(!param.empty()) { - string nick = param; + const string& nick = param; OnlineUser* u = findUser(nick); - if(u == NULL) + if(!u) return; fire(ClientListener::UserRemoved(), this, *u); @@ -394,7 +408,7 @@ return; } string port = param.substr(j+1); - ConnectionManager::getInstance()->nmdcConnect(server, (short)Util::toInt(port), getMyNick(), getHubUrl()); + ConnectionManager::getInstance()->nmdcConnect(server, (unsigned short)Util::toInt(port), getMyNick(), getHubUrl()); } else if(cmd == "$RevConnectToMe") { if(state != STATE_CONNECTED) { return; @@ -466,10 +480,10 @@ j = param.find('$'); if(j == string::npos) return; - string name = param.substr(i, j-i); + string name = unescape(param.substr(i, j-i)); i = j+1; - string command = param.substr(i, param.length() - i); - fire(ClientListener::UserCommand(), this, type, ctx, unescape(name), unescape(command)); + string command = unescape(param.substr(i, param.length() - i)); + fire(ClientListener::UserCommand(), this, type, ctx, name, command); } } else if(cmd == "$Lock") { if(state != STATE_LOCK) { @@ -557,7 +571,7 @@ OnlineUser* u = findUser(it->substr(0, j)); - if(u == NULL) + if(!u) continue; u->getIdentity().setIp(it->substr(j+1)); @@ -666,7 +680,7 @@ } else if(cmd == "$BadPass") { fire(ClientListener::BadPassword(), this); } else if(cmd == "$ZOn") { - socket->setMode (BufferedSocket::MODE_ZPIPE); + socket->setMode(BufferedSocket::MODE_ZPIPE); } else { dcassert(cmd[0] == '$'); dcdebug("NmdcHub::onLine Unknown command %s\n", aLine.c_str()); @@ -731,9 +745,9 @@ string uMin = (SETTING(MIN_UPLOAD_SPEED) == 0) ? Util::emptyString : tmp5 + Util::toString(SETTING(MIN_UPLOAD_SPEED)); string myInfoA = - "$MyINFO $ALL " + toAcp(getCurrentNick()) + " " + toAcp(NmdcHub::validateMessage(getCurrentDescription(), false)) + + "$MyINFO $ALL " + toAcp(getCurrentNick()) + " " + toAcp(escape(getCurrentDescription())) + tmp1 + VERSIONSTRING + tmp2 + modeChar + tmp3 + getCounts() + tmp4 + Util::toString(SETTING(SLOTS)) + uMin + - ">$ $" + SETTING(UPLOAD_SPEED) + "\x01$" + toAcp(NmdcHub::validateMessage(SETTING(EMAIL), false)) + '$'; + ">$ $" + SETTING(UPLOAD_SPEED) + "\x01$" + toAcp(escape(SETTING(EMAIL))) + '$'; string myInfoB = ShareManager::getInstance()->getShareSizeString() + "$|"; if(lastMyInfoA != myInfoA || alwaysSend || (lastMyInfoB != myInfoB && lastUpdate + 15*60*1000 < GET_TICK()) ){ @@ -755,7 +769,7 @@ AutoArray<char> buf((char*)NULL); char c1 = (aSizeType == SearchManager::SIZE_DONTCARE) ? 'F' : 'T'; char c2 = (aSizeType == SearchManager::SIZE_ATLEAST) ? 'F' : 'T'; - string tmp = NmdcHub::validateMessage(toAcp((aFileType == SearchManager::TYPE_TTH) ? "TTH:" + aString : aString), false); + string tmp = toAcp(escape((aFileType == SearchManager::TYPE_TTH) ? "TTH:" + aString : aString)); string::size_type i; while((i = tmp.find(' ')) != string::npos) { tmp[i] = '$'; @@ -772,7 +786,7 @@ send(buf, chars); } -string NmdcHub::validateMessage(string tmp, bool reverse, bool checkNewLines) { +string NmdcHub::validateMessage(string tmp, bool reverse) { string::size_type i = 0; if(reverse) { @@ -790,6 +804,8 @@ tmp.replace(i, 5, "&"); i++; } +#if 0 +/// @todo move this to a better place if(checkNewLines) { // Check all '<' and '[' after newlines... i = 0; @@ -803,6 +819,7 @@ i++; } } +#endif } else { i = 0; while( (i = tmp.find("&", i)) != string::npos) { @@ -836,12 +853,13 @@ void NmdcHub::privateMessage(const OnlineUser& aUser, const string& aMessage) { checkstate(); - send("$To: " + toAcp(aUser.getIdentity().getNick()) + " From: " + toAcp(getMyNick()) + " $" + toAcp(NmdcHub::validateMessage("<" + getMyNick() + "> " + aMessage, false)) + "|"); + send("$To: " + toAcp(aUser.getIdentity().getNick()) + " From: " + toAcp(getMyNick()) + " $" + toAcp(escape("<" + getMyNick() + "> " + aMessage)) + "|"); // Emulate a returning message... Lock l(cs); - NickIter i = users.find(getMyNick()); - if(i != users.end()) - fire(ClientListener::PrivateMessage(), this, *i->second, aUser, *i->second, aMessage); + OnlineUser* ou = findUser(getMyNick()); + if(ou) { + fire(ClientListener::PrivateMessage(), this, *ou, aUser, *ou, aMessage); + } } // TimerManagerListener Modified: dcplusplus/trunk/client/NmdcHub.h =================================================================== --- dcplusplus/trunk/client/NmdcHub.h 2006-06-17 22:24:01 UTC (rev 617) +++ dcplusplus/trunk/client/NmdcHub.h 2006-06-17 23:26:36 UTC (rev 618) @@ -52,12 +52,12 @@ virtual size_t getUserCount() const { Lock l(cs); return users.size(); } virtual int64_t getAvailable() const; - virtual string escape(string const& str) const; - virtual string unescape(const string& str) const; + virtual string escape(string const& str) const { return validateMessage(str, false); } + static string unescape(const string& str) { return validateMessage(str, true); } virtual void send(const AdcCommand&) { dcassert(0); } - static string validateMessage(string tmp, bool reverse, bool checkNewLines); + static string validateMessage(string tmp, bool reverse); GETSET(int, supportFlags, SupportFlags); private: Modified: dcplusplus/trunk/windows/CommandDlg.cpp =================================================================== --- dcplusplus/trunk/windows/CommandDlg.cpp 2006-06-17 22:24:01 UTC (rev 617) +++ dcplusplus/trunk/windows/CommandDlg.cpp 2006-06-17 23:26:36 UTC (rev 618) @@ -84,7 +84,7 @@ dcassert(i != string::npos); tstring to = command.substr(5, i-5); string::size_type cmd_pos = command.find(_T('>'), 5) + 2; - tstring cmd = Text::toT(NmdcHub::validateMessage(Text::fromT(command.substr(cmd_pos, command.length()-cmd_pos-1)), true, false)); + tstring cmd = Text::toT(NmdcHub::validateMessage(Text::fromT(command.substr(cmd_pos, command.length()-cmd_pos-1)), true)); ctrlPM.SetCheck(BST_CHECKED); ctrlNick.SetWindowText(to.c_str()); ctrlCommand.SetWindowText(cmd.c_str()); @@ -94,7 +94,7 @@ { // Looks like a chat thing... string::size_type cmd_pos = command.find(_T('>')) + 2; - tstring cmd = Text::toT(NmdcHub::validateMessage(Text::fromT(command.substr(cmd_pos, command.length()-cmd_pos-1)), true, false)); + tstring cmd = Text::toT(NmdcHub::validateMessage(Text::fromT(command.substr(cmd_pos, command.length()-cmd_pos-1)), true)); ctrlChat.SetCheck(BST_CHECKED); ctrlCommand.SetWindowText(cmd.c_str()); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <arn...@us...> - 2006-07-23 12:21:26
|
Revision: 642 Author: arnetheduck Date: 2006-07-23 05:21:17 -0700 (Sun, 23 Jul 2006) ViewCVS: http://svn.sourceforge.net/dcplusplus/?rev=642&view=rev Log Message: ----------- wait fix Modified Paths: -------------- dcplusplus/trunk/client/ConnectionManager.cpp dcplusplus/trunk/client/Socket.cpp Modified: dcplusplus/trunk/client/ConnectionManager.cpp =================================================================== --- dcplusplus/trunk/client/ConnectionManager.cpp 2006-07-23 09:31:25 UTC (rev 641) +++ dcplusplus/trunk/client/ConnectionManager.cpp 2006-07-23 12:21:17 UTC (rev 642) @@ -264,7 +264,7 @@ int ConnectionManager::Server::run() throw() { try { while(!die) { - if(sock.wait(POLL_TIMEOUT, Socket::WAIT_CONNECT) == Socket::WAIT_CONNECT) { + if(sock.wait(POLL_TIMEOUT, Socket::WAIT_READ) == Socket::WAIT_READ) { ConnectionManager::getInstance()->accept(sock, secure); } } Modified: dcplusplus/trunk/client/Socket.cpp =================================================================== --- dcplusplus/trunk/client/Socket.cpp 2006-07-23 09:31:25 UTC (rev 641) +++ dcplusplus/trunk/client/Socket.cpp 2006-07-23 12:21:17 UTC (rev 642) @@ -437,14 +437,14 @@ if(waitFor & WAIT_CONNECT) { dcassert(!(waitFor & WAIT_READ) && !(waitFor & WAIT_WRITE)); - FD_ZERO(&rfd); + FD_ZERO(&wfd); FD_ZERO(&efd); - FD_SET(sock, &rfd); + FD_SET(sock, &wfd); FD_SET(sock, &efd); - check(select((int)(sock+1), &rfd, 0, &efd, &tv)); + check(select((int)(sock+1), 0, &wfd, &efd, &tv)); - if(FD_ISSET(sock, &rfd)) { + if(FD_ISSET(sock, &wfd)) { return WAIT_CONNECT; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <arn...@us...> - 2006-10-08 20:45:52
|
Revision: 667 http://svn.sourceforge.net/dcplusplus/?rev=667&view=rev Author: arnetheduck Date: 2006-10-08 13:45:44 -0700 (Sun, 08 Oct 2006) Log Message: ----------- sharemanager fix Modified Paths: -------------- dcplusplus/trunk/client/ShareManager.cpp dcplusplus/trunk/client/ShareManager.h Modified: dcplusplus/trunk/client/ShareManager.cpp =================================================================== --- dcplusplus/trunk/client/ShareManager.cpp 2006-10-08 19:59:43 UTC (rev 666) +++ dcplusplus/trunk/client/ShareManager.cpp 2006-10-08 20:45:44 UTC (rev 667) @@ -43,7 +43,7 @@ #include <limits> -ShareManager::ShareManager() : hits(0), xmlListLen(0), bzXmlListLen(0), bzXmlFile(0), +ShareManager::ShareManager() : hits(0), xmlListLen(0), bzXmlListLen(0), xmlDirty(true), refreshDirs(false), update(false), initial(true), listN(0), refreshing(0), lastXmlUpdate(0), lastFullUpdate(GET_TICK()), bloom(1<<20) { @@ -344,7 +344,7 @@ SimpleXMLReader(&loader).fromXML(txt); for(Directory::MapIter i = directories.begin(); i != directories.end(); ++i) { - addTree(i->second); + addTree(*i->second); } return true; @@ -406,7 +406,7 @@ { Lock l(cs); - addTree(dp); + addTree(*dp); directories[d] = dp; virtualMap.push_back(make_pair(vName, d)); @@ -414,33 +414,33 @@ } } -void ShareManager::removeDirectory(const string& aDirectory, bool duringRefresh) { - Lock l(cs); - +void ShareManager::removeDirectory(const string& aDirectory) { string d(aDirectory); if(d[d.length() - 1] != PATH_SEPARATOR) d += PATH_SEPARATOR; - Directory::MapIter i = directories.find(d); - if(i != directories.end()) { - delete i->second; - directories.erase(i); - } + { + Lock l(cs); - for(StringPairIter j = virtualMap.begin(); j != virtualMap.end(); ++j) { - if(Util::stricmp(j->second.c_str(), d.c_str()) == 0) { - virtualMap.erase(j); - break; + Directory::MapIter i = directories.find(d); + if(i != directories.end()) { + delete i->second; + directories.erase(i); } - } - if(!duringRefresh) - HashManager::getInstance()->stopHashing(d); + for(StringPairIter j = virtualMap.begin(); j != virtualMap.end(); ++j) { + if(Util::stricmp(j->second.c_str(), d.c_str()) == 0) { + virtualMap.erase(j); + break; + } + } - buildIndex(); + rebuildIndices(); + setDirty(); + } - setDirty(); + HashManager::getInstance()->stopHashing(d); } void ShareManager::renameDirectory(const string& oName, const string& nName) throw(ShareException) { @@ -692,6 +692,7 @@ continue; } try { + //@todo race condition - if hashmanager finishes hashing before buildtree is done... if(HashManager::getInstance()->checkTTH(fileName, size, i->getLastWriteTime())) lastFileIter = dir->files.insert(lastFileIter, Directory::File(name, size, dir, HashManager::getInstance()->getTTH(fileName, size))); } catch(const HashException&) { @@ -703,58 +704,49 @@ return dir; } -void ShareManager::addTree(Directory* dir) { - bloom.add(Text::toLower(dir->getName())); +void ShareManager::addTree(Directory& dir) { + bloom.add(Text::toLower(dir.getName())); - for(Directory::MapIter i = dir->directories.begin(); i != dir->directories.end(); ++i) { - Directory* d = i->second; - addTree(d); + for(Directory::MapIter i = dir.directories.begin(); i != dir.directories.end(); ++i) { + addTree(*i->second); } - for(Directory::File::Iter i = dir->files.begin(); i != dir->files.end(); ) { + for(Directory::File::Iter i = dir.files.begin(); i != dir.files.end(); ) { addFile(dir, i++); } } -void ShareManager::buildIndex(const Directory& dir) { - for(Directory::Map::const_iterator i = dir.directories.begin(); i != dir.directories.end(); ++i) { - buildIndex(*i->second); - } - for(Directory::File::Set::const_iterator i = dir.files.begin(); i != dir.files.end(); ++i) { - tthIndex.insert(make_pair(i->getTTH(), i)); - } -} - -void ShareManager::buildIndex() { +void ShareManager::rebuildIndices() { tthIndex.clear(); + bloom.clear(); + for(Directory::Map::const_iterator i = directories.begin(); i != directories.end(); ++i) { - buildIndex(*i->second); + addTree(*i->second); } } -void ShareManager::addFile(Directory* dir, Directory::File::Iter i) { +void ShareManager::addFile(Directory& dir, Directory::File::Iter i) { const Directory::File& f = *i; HashFileIter j = tthIndex.find(f.getTTH()); if(j == tthIndex.end()) { - dir->size+=f.getSize(); + dir.size+=f.getSize(); } else { if(!SETTING(LIST_DUPES)) { - LogManager::getInstance()->message(STRING(DUPLICATE_FILE_NOT_SHARED) + dir->getFullName() + f.getName() + " (" + STRING(SIZE) + ": " + Util::toString(f.getSize()) + " " + STRING(B) + ") " + STRING(DUPLICATE_MATCH) + j->second->getParent()->getFullName() + j->second->getName() ); - dir->files.erase(i); + LogManager::getInstance()->message(STRING(DUPLICATE_FILE_NOT_SHARED) + dir.getFullName() + f.getName() + " (" + STRING(SIZE) + ": " + Util::toString(f.getSize()) + " " + STRING(B) + ") " + STRING(DUPLICATE_MATCH) + j->second->getParent()->getFullName() + j->second->getName() ); + dir.files.erase(i); return; } } - dir->addType(getType(f.getName())); + dir.addType(getType(f.getName())); tthIndex.insert(make_pair(f.getTTH(), i)); bloom.add(Text::toLower(f.getName())); } void ShareManager::refresh(bool dirs /* = false */, bool aUpdate /* = true */, bool block /* = false */) throw(ThreadException, ShareException) { - if(Thread::safeInc(refreshing) > 1) { - Thread::safeDec(refreshing); + if(Thread::safeExchange(refreshing, 1) == 1) { LogManager::getInstance()->message(STRING(FILE_LIST_REFRRESH_IN_PROGRESS)); return; } @@ -792,36 +784,30 @@ } for(StringPairIter i = dirs.begin(); i != dirs.end(); ++i) { - Directory* dp = buildTree(i->second, NULL); + Directory* dp = buildTree(i->second, 0); dp->setName(i->first); newDirs.insert(make_pair(i->second, dp)); } { Lock l(cs); - StringPairList dirs = virtualMap; - for(StringPairIter i = dirs.begin(); i != dirs.end(); ++i) { - removeDirectory(i->second, true); + for(Directory::MapIter i = directories.begin(); i != directories.end(); ++i) { + delete i->second; } - bloom.clear(); + directories = newDirs; - virtualMap = dirs; - - for(Directory::MapIter i = newDirs.begin(); i != newDirs.end(); ++i) { - addTree(i->second); - directories.insert(*i); - } + rebuildIndices(); } refreshDirs = false; } } - Thread::safeDec(refreshing); LogManager::getInstance()->message(STRING(FILE_LIST_REFRESH_FINISHED)); if(update) { ClientManager::getInstance()->infoUpdated(); } + refreshing = 0; return 0; } @@ -946,30 +932,6 @@ } #define LITERAL(n) n, sizeof(n)-1 -void ShareManager::Directory::toNmdc(string& nmdc, string& indent, string& tmp2) { - tmp2.clear(); - nmdc.append(indent); - nmdc.append(Text::utf8ToAcp(name, tmp2)); - nmdc.append(LITERAL("\r\n")); - - indent += '\t'; - for(MapIter i = directories.begin(); i != directories.end(); ++i) { - i->second->toNmdc(nmdc, indent, tmp2); - } - - Directory::File::Iter j = files.begin(); - for(Directory::File::Iter i = files.begin(); i != files.end(); ++i) { - const Directory::File& f = *i; - nmdc.append(indent); - tmp2.clear(); - nmdc.append(Text::utf8ToAcp(f.getName(), tmp2)); - nmdc.append(LITERAL("|")); - nmdc.append(Util::toString(f.getSize())); - nmdc.append(LITERAL("\r\n")); - } - indent.erase(indent.length()-1); -} - void ShareManager::Directory::toXml(OutputStream& xmlFile, string& indent, string& tmp2, bool fullList) { xmlFile.write(indent); xmlFile.write(LITERAL("<Directory Name=\"")); @@ -1357,6 +1319,20 @@ } } +int64_t ShareManager::Directory::getSize() { + int64_t tmp = size; + for(MapIter i = directories.begin(); i != directories.end(); ++i) + tmp+=i->second->getSize(); + return tmp; +} + +size_t ShareManager::Directory::countFiles() { + size_t tmp = files.size(); + for(MapIter i = directories.begin(); i != directories.end(); ++i) + tmp+=i->second->countFiles(); + return tmp; +} + ShareManager::Directory* ShareManager::getDirectory(const string& fname) { for(Directory::MapIter mi = directories.begin(); mi != directories.end(); ++mi) { if(Util::strnicmp(fname, mi->first, mi->first.length()) == 0) { @@ -1413,7 +1389,7 @@ string name = Util::getFileName(fname); int64_t size = File::getSize(fname); Directory::File::Iter it = d->files.insert(Directory::File(name, size, d, root)).first; - addFile(d, it); + addFile(*d, it); } setDirty(); } Modified: dcplusplus/trunk/client/ShareManager.h =================================================================== --- dcplusplus/trunk/client/ShareManager.h 2006-10-08 19:59:43 UTC (rev 666) +++ dcplusplus/trunk/client/ShareManager.h 2006-10-08 20:45:44 UTC (rev 667) @@ -55,7 +55,7 @@ * @param aName Virtual name */ void addDirectory(const string& aDirectory, const string & aName) throw(ShareException); - void removeDirectory(const string& aName, bool duringRefresh = false); + void removeDirectory(const string& aName); void renameDirectory(const string& oName, const string& nName) throw(ShareException); string toVirtual(const TTHValue& tth) throw(ShareException); string toReal(const string& virtualFile) throw(ShareException); @@ -168,24 +168,12 @@ string getADCPath() const throw(); string getFullName() const throw(); - int64_t getSize() { - int64_t tmp = size; - for(MapIter i = directories.begin(); i != directories.end(); ++i) - tmp+=i->second->getSize(); - return tmp; - } + int64_t getSize(); + size_t countFiles(); - size_t countFiles() { - size_t tmp = files.size(); - for(MapIter i = directories.begin(); i != directories.end(); ++i) - tmp+=i->second->countFiles(); - return tmp; - } - void search(SearchResult::List& aResults, StringSearch::List& aStrings, int aSearchType, int64_t aSize, int aFileType, Client* aClient, StringList::size_type maxResults) throw(); void search(SearchResult::List& aResults, AdcSearch& aStrings, StringList::size_type maxResults) throw(); - void toNmdc(string& nmdc, string& indent, string& tmp2); void toXml(OutputStream& xmlFile, string& indent, string& tmp2, bool fullList); void filesToXml(OutputStream& xmlFile, string& indent, string& tmp2); @@ -286,12 +274,11 @@ bool checkFile(const string& virtualFile, string& realFile, Directory::File::Iter& it); Directory* buildTree(const string& aName, Directory* aParent); - - void buildIndex(); - void buildIndex(const Directory& dir); - void addTree(Directory* aDirectory); - void addFile(Directory* dir, Directory::File::Iter i); + void rebuildIndices(); + + void addTree(Directory& aDirectory); + void addFile(Directory& dir, Directory::File::Iter i); void generateXmlList(); bool loadCache(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <arn...@us...> - 2007-05-14 08:32:20
|
Revision: 738 http://dcplusplus.svn.sourceforge.net/dcplusplus/?rev=738&view=rev Author: arnetheduck Date: 2007-05-14 01:32:18 -0700 (Mon, 14 May 2007) Log Message: ----------- text fixes Modified Paths: -------------- dcplusplus/trunk/client/Text.cpp dcplusplus/trunk/client/Text.h This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <arn...@us...> - 2006-10-07 21:51:35
|
Revision: 665 http://svn.sourceforge.net/dcplusplus/?rev=665&view=rev Author: arnetheduck Date: 2006-10-07 14:51:27 -0700 (Sat, 07 Oct 2006) Log Message: ----------- Some more cleanup Modified Paths: -------------- dcplusplus/trunk/client/ShareManager.cpp dcplusplus/trunk/client/ShareManager.h dcplusplus/trunk/client/UploadManager.cpp Modified: dcplusplus/trunk/client/ShareManager.cpp =================================================================== --- dcplusplus/trunk/client/ShareManager.cpp 2006-10-07 15:02:06 UTC (rev 664) +++ dcplusplus/trunk/client/ShareManager.cpp 2006-10-07 21:51:27 UTC (rev 665) @@ -82,7 +82,7 @@ } } -string ShareManager::translateTTH(const TTHValue& tth) throw(ShareException) { +string ShareManager::toVirtual(const TTHValue& tth) throw(ShareException) { HashFileIter i = tthIndex.find(tth); if(i != tthIndex.end()) { return i->second->getADCPath(); @@ -91,7 +91,7 @@ } } -string ShareManager::translateFileName(const string& virtualFile) throw(ShareException) { +string ShareManager::toReal(const string& virtualFile) throw(ShareException) { if(virtualFile == "MyList.DcLst") { throw ShareException("NMDC-style lists no longer supported, please upgrade your client"); } else if(virtualFile == Transfer::USER_LIST_NAME_BZ || virtualFile == Transfer::USER_LIST_NAME) { @@ -109,23 +109,23 @@ } } -TTHValue ShareManager::getTTH(const string& virtualName) throw(ShareException) { +TTHValue ShareManager::getTTH(const string& virtualFile) throw(ShareException) { Lock l(cs); - string realName; + string realFile; Directory::File::Iter it; - if(!checkFile(virtualName, realName, it)) + if(!checkFile(virtualFile, realFile, it)) throw ShareException(); return it->getTTH(); } -MemoryInputStream* ShareManager::getTree(const string& aFile) { +MemoryInputStream* ShareManager::getTree(const string& virtualFile) { TigerTree tree; - if(aFile.compare(0, 4, "TTH/") == 0) { - if(!HashManager::getInstance()->getTree(TTHValue(aFile.substr(4)), tree)) + if(virtualFile.compare(0, 4, "TTH/") == 0) { + if(!HashManager::getInstance()->getTree(TTHValue(virtualFile.substr(4)), tree)) return 0; } else { try { - TTHValue tth = getTTH(aFile); + TTHValue tth = getTTH(virtualFile); HashManager::getInstance()->getTree(tth, tree); } catch(const Exception&) { return 0; @@ -191,7 +191,7 @@ bool ShareManager::checkFile(const string& virtualFile, string& realFile, Directory::File::Iter& it) { string file; if(virtualFile.compare(0, 4, "TTH/") == 0) { - file = translateTTH(TTHValue(virtualFile.substr(4))); + file = toVirtual(TTHValue(virtualFile.substr(4))); } else if(virtualFile.empty() || virtualFile[0] != '/') { return false; } else { Modified: dcplusplus/trunk/client/ShareManager.h =================================================================== --- dcplusplus/trunk/client/ShareManager.h 2006-10-07 15:02:06 UTC (rev 664) +++ dcplusplus/trunk/client/ShareManager.h 2006-10-07 21:51:27 UTC (rev 665) @@ -57,9 +57,9 @@ void addDirectory(const string& aDirectory, const string & aName) throw(ShareException); void removeDirectory(const string& aName, bool duringRefresh = false); void renameDirectory(const string& oName, const string& nName) throw(ShareException); - string translateTTH(const TTHValue& tth) throw(ShareException); - string translateFileName(const string& aFile) throw(ShareException); - TTHValue getTTH(const string& aFile) throw(ShareException); + string toVirtual(const TTHValue& tth) throw(ShareException); + string toReal(const string& virtualFile) throw(ShareException); + TTHValue getTTH(const string& virtualFile) throw(ShareException); void refresh(bool dirs = false, bool aUpdate = true, bool block = false) throw(ThreadException, ShareException); void setDirty() { xmlDirty = true; } @@ -70,7 +70,7 @@ StringPairList getDirectories() const { Lock l(cs); return virtualMap; } MemoryInputStream* generatePartialList(const string& dir, bool recurse); - MemoryInputStream* getTree(const string& aFile); + MemoryInputStream* getTree(const string& virtualFile); AdcCommand getFileInfo(const string& aFile) throw(ShareException); Modified: dcplusplus/trunk/client/UploadManager.cpp =================================================================== --- dcplusplus/trunk/client/UploadManager.cpp 2006-10-07 15:02:06 UTC (rev 664) +++ dcplusplus/trunk/client/UploadManager.cpp 2006-10-07 21:51:27 UTC (rev 665) @@ -88,7 +88,7 @@ string sourceFile; try { if(aType == Transfer::TYPE_FILE) { - sourceFile = ShareManager::getInstance()->translateFileName(aFile); + sourceFile = ShareManager::getInstance()->toReal(aFile); if(aFile == Transfer::USER_LIST_NAME) { // Unpack before sending... @@ -123,7 +123,7 @@ } } } else if(aType == Transfer::TYPE_TTHL) { - sourceFile = ShareManager::getInstance()->translateFileName(aFile); + sourceFile = ShareManager::getInstance()->toReal(aFile); MemoryInputStream* mis = ShareManager::getInstance()->getTree(aFile); if(!mis) { aSource.fileNotAvail(); @@ -183,7 +183,7 @@ // Check for tth root identifier string tFile = aFile; if (tFile.compare(0, 4, "TTH/") == 0) - tFile = ShareManager::getInstance()->translateTTH(TTHValue(aFile.substr(4))); + tFile = ShareManager::getInstance()->toVirtual(TTHValue(aFile.substr(4))); addFailedUpload(aSource, tFile + " (" + Util::toString((aStartPos*1000/(size+10))/10.0)+"% of " + Util::formatBytes(size) + " done)"); @@ -474,9 +474,9 @@ if(type == Transfer::TYPE_FILE) { try { - string realFile = ShareManager::getInstance()->translateFileName(ident); + string realFile = ShareManager::getInstance()->toReal(ident); TTHValue tth = ShareManager::getInstance()->getTTH(ident); - string virtualFile = ShareManager::getInstance()->translateTTH(tth); + string virtualFile = ShareManager::getInstance()->toVirtual(tth); int64_t size = File::getSize(realFile); SearchResult* sr = new SearchResult(SearchResult::TYPE_FILE, size, virtualFile, tth); aSource->send(sr->toRES(AdcCommand::TYPE_CLIENT)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |