From: <arn...@us...> - 2006-05-21 08:46:08
|
Revision: 605 Author: arnetheduck Date: 2006-05-21 01:45:42 -0700 (Sun, 21 May 2006) ViewCVS: http://svn.sourceforge.net/dcplusplus/?rev=605&view=rev Log Message: ----------- Bugfixes, removed nmdc file list support Modified Paths: -------------- dcplusplus/trunk/changelog.txt dcplusplus/trunk/client/CryptoManager.cpp dcplusplus/trunk/client/CryptoManager.h dcplusplus/trunk/client/QueueManager.cpp dcplusplus/trunk/client/ShareManager.cpp dcplusplus/trunk/client/ShareManager.h dcplusplus/trunk/client/UploadManager.cpp dcplusplus/trunk/client/UserConnection.h dcplusplus/trunk/windows/MainFrm.cpp dcplusplus/trunk/windows/MainFrm.h dcplusplus/trunk/windows/QueueFrame.cpp dcplusplus/trunk/windows/QueueFrame.h dcplusplus/trunk/windows/TransferView.cpp dcplusplus/trunk/windows/WinUtil.h dcplusplus/trunk/windows/main.cpp Modified: dcplusplus/trunk/changelog.txt =================================================================== --- dcplusplus/trunk/changelog.txt 2006-05-20 16:17:09 UTC (rev 604) +++ dcplusplus/trunk/changelog.txt 2006-05-21 08:45:42 UTC (rev 605) @@ -17,6 +17,11 @@ * [bug 464] Added option for masked password prompt (thanks ullner) * [bug 922] Updated help links (thanks xan) * Fixed op count +* [bug 230] Added settings to tray menu +* [bug 403] Unfinished file lists deleted since they're never resumed anyway +* [bug 639] Separated remove user from queue menu option +* [bug 766] Fixed broken app titlebar +* Removed support for generating NMDC-style file lists (old clients won't be able to download from you) -- 0.689 2006-04-01 -- * Fixed displaying of available bytes when user list is off Modified: dcplusplus/trunk/client/CryptoManager.cpp =================================================================== --- dcplusplus/trunk/client/CryptoManager.cpp 2006-05-20 16:17:09 UTC (rev 604) +++ dcplusplus/trunk/client/CryptoManager.cpp 2006-05-21 08:45:42 UTC (rev 605) @@ -229,168 +229,3 @@ delete[] leaves; delete root; } - -/** - * Counts the occurances of each characters, and adds the total number of - * different characters to the end of the array. - */ -int CryptoManager::countChars(const string& aString, int* c, u_int8_t& csum) { - int chars = 0; - const u_int8_t* a = (const u_int8_t*)aString.data(); - string::size_type len = aString.length(); - for(string::size_type i=0; i<len; i++) { - - if(c[a[i]] == 0) - chars++; - - c[a[i]]++; - csum^=a[i]; - } - return chars; -} - -void CryptoManager::walkTree(list<Node*>& aTree) { - while(aTree.size() > 1) { - // Merge the first two nodes - Node* node = new Node(aTree.front(), *(++aTree.begin())); - aTree.pop_front(); - aTree.pop_front(); - - bool done = false; - for(list<Node*>::iterator i=aTree.begin(); i != aTree.end(); ++i) { - if(*node <= *(*i)) { - aTree.insert(i, node); - done = true; - break; - } - } - - if(!done) - aTree.push_back(node); - - } -} - -void CryptoManager::recurseLookup(vector<u_int8_t>* table, Node* node, vector<u_int8_t>& u_int8_ts) { - if(node->chr != -1) { - table[node->chr] = u_int8_ts; - return; - } - - u_int8_ts.push_back(0); - recurseLookup(table, node->left, u_int8_ts); - u_int8_ts.pop_back(); - - u_int8_ts.push_back(1); - recurseLookup(table, node->right, u_int8_ts); - u_int8_ts.pop_back(); -} - -/** - * Builds a table over the characters available (for fast lookup). - * Stores each character as a set of u_int8_ts with values {0, 1}. - */ -void CryptoManager::buildLookup(vector<u_int8_t>* table, Node* aRoot) { - vector<u_int8_t> left; - vector<u_int8_t> right; - - left.push_back(0); - right.push_back(1); - - recurseLookup(table, aRoot->left, left); - recurseLookup(table, aRoot->right, right); -} - - -struct greaterNode { - bool operator() (const Node* a, const Node* b) const { - return *a < *b; - } -}; - -/** - * Encodes a set of data with DC's version of huffman encoding.. - * @todo Use real streams maybe? or something else than string (operator[] contains a compare, slow...) - */ -void CryptoManager::encodeHuffman(const string& is, string& os) { - - // We might as well expect this much data as huffman encoding doesn't go very far... - os.reserve(is.size()); - if(is.length() == 0) { - os.append("HE3\x0d"); - - // Nada... - os.append(7, '\0'); - return; - } - // First, we count all characters - u_int8_t csum = 0; - int count[256]; - memset(count, 0, sizeof(count)); - int chars = countChars(is, count, csum); - - // Next, we create a set of nodes and add it to a list, removing all characters that never occur. - - list<Node*> nodes; - - int i; - for(i=0; i<256; i++) { - if(count[i] > 0) { - nodes.push_back(new Node(i, count[i])); - } - } - - nodes.sort(greaterNode()); -#ifdef _DEBUG - for(list<Node*>::iterator it = nodes.begin(); it != nodes.end(); ++it) dcdebug("%.02x:%d, ", (*it)->chr, (*it)->weight); - dcdebug("\n"); -#endif - - walkTree(nodes); - dcassert(nodes.size() == 1); - - Node* root = nodes.front(); - vector<u_int8_t> lookup[256]; - - // Build a lookup table for fast character lookups - buildLookup(lookup, root); - delete root; - - // Reserve some memory to avoid all those copies when appending... - os.reserve(is.size() * 3 / 4); - - os.append("HE3\x0d"); - - // Checksum - os.append(1, csum); - string::size_type sz = is.size(); - os.append((char*)&sz, 4); - - // Character count - os.append((char*)&chars, 2); - - // The characters and their bitlengths - for(i=0; i<256; i++) { - if(count[i] > 0) { - os.append(1, (u_int8_t)i); - os.append(1, (u_int8_t)lookup[i].size()); - } - } - - BitOutputStream bos(os); - // The tree itself, ie the bits of each character - for(i=0; i<256; i++) { - if(count[i] > 0) { - bos.put(lookup[i]); - } - } - - dcdebug("u_int8_ts: %lu\n", os.size()); - bos.skipToByte(); - - for(string::size_type j=0; j<is.size(); j++) { - dcassert(lookup[(u_int8_t)is[j]].size() != 0); - bos.put(lookup[(u_int8_t)is[j]]); - } - bos.skipToByte(); -} Modified: dcplusplus/trunk/client/CryptoManager.h =================================================================== --- dcplusplus/trunk/client/CryptoManager.h 2006-05-20 16:17:09 UTC (rev 604) +++ dcplusplus/trunk/client/CryptoManager.h 2006-05-21 08:45:42 UTC (rev 605) @@ -78,7 +78,6 @@ bool isExtended(const string& aLock) { return strncmp(aLock.c_str(), "EXTENDEDPROTOCOL", 16) == 0; } void decodeHuffman(const u_int8_t* /*is*/, string& /*os*/, const size_t /*len*/) throw(CryptoException); - void encodeHuffman(const string& is, string& os); void decodeBZ2(const u_int8_t* is, size_t sz, string& os) throw(CryptoException); private: Modified: dcplusplus/trunk/client/QueueManager.cpp =================================================================== --- dcplusplus/trunk/client/QueueManager.cpp 2006-05-20 16:17:09 UTC (rev 604) +++ dcplusplus/trunk/client/QueueManager.cpp 2006-05-21 08:45:42 UTC (rev 605) @@ -53,7 +53,7 @@ #include <fnmatch.h> #endif -const string QueueManager::USER_LIST_NAME = "MyList.DcLst"; +const string QueueManager::USER_LIST_NAME = "files.xml"; namespace { const string TEMP_EXTENSION = ".dctmp"; @@ -899,7 +899,7 @@ } } } else if(!aDownload->isSet(Download::FLAG_TREE_DOWNLOAD)) { - if(!aDownload->getTempTarget().empty() && aDownload->getTempTarget() != aDownload->getTarget()) { + if(!aDownload->getTempTarget().empty() && (aDownload->isSet(Download::FLAG_USER_LIST) || aDownload->getTempTarget() != aDownload->getTarget())) { File::deleteFile(aDownload->getTempTarget() + Download::ANTI_FRAG_EXT); File::deleteFile(aDownload->getTempTarget()); } Modified: dcplusplus/trunk/client/ShareManager.cpp =================================================================== --- dcplusplus/trunk/client/ShareManager.cpp 2006-05-20 16:17:09 UTC (rev 604) +++ dcplusplus/trunk/client/ShareManager.cpp 2006-05-21 08:45:42 UTC (rev 605) @@ -44,8 +44,8 @@ #include <limits> ShareManager::ShareManager() : hits(0), listLen(0), bzXmlListLen(0), - xmlDirty(true), nmdcDirty(false), refreshDirs(false), update(false), initial(true), listN(0), refreshing(0), lFile(NULL), - xFile(NULL), lastXmlUpdate(0), lastNmdcUpdate(0), lastFullUpdate(GET_TICK()), bloom(1<<20) + xmlDirty(true), refreshDirs(false), update(false), initial(true), listN(0), refreshing(0), lFile(NULL), + xFile(NULL), lastXmlUpdate(0), lastFullUpdate(GET_TICK()), bloom(1<<20) { SettingsManager::getInstance()->addListener(this); TimerManager::getInstance()->addListener(this); @@ -80,21 +80,11 @@ FindClose(hFind); } - hFind = FindFirstFile(Text::toT(Util::getConfigPath() + "MyList*.DcLst").c_str(), &data); - if(hFind != INVALID_HANDLE_VALUE) { - do { - File::deleteFile(Util::getAppPath() + Text::fromT(data.cFileName)); - } while(FindNextFile(hFind, &data)); - - FindClose(hFind); - } - #else DIR* dir = opendir(Util::getAppName().c_str()); if (dir) { while (struct dirent* ent = readdir(dir)) { - if (fnmatch("files*.xml.bz2", ent->d_name, 0) == 0 || - fnmatch("MyList*.DcLst", ent->d_name, 0) == 0) { + if (fnmatch("files*.xml.bz2", ent->d_name, 0) == 0) { File::deleteFile(Util::getConfigPath() + ent->d_name); } } @@ -121,21 +111,20 @@ if(i != tthIndex.end()) { return i->second->getADCPath(); } else { - throw ShareException("File Not Available"); + throw ShareException(UserConnection::FILE_NOT_AVAILABLE); } } string ShareManager::translateFileName(const string& aFile) throw(ShareException) { RLock<> l(cs); if(aFile == "MyList.DcLst") { - generateNmdcList(); - return getListFile(); + throw ShareException("NMDC-style lists no longer supported, please upgrade your client"); } else if(aFile == "files.xml.bz2" || aFile == "files.xml") { generateXmlList(); return getBZXmlFile(); } else { if(aFile.length() < 3) - throw ShareException("File Not Available"); + throw ShareException(UserConnection::FILE_NOT_AVAILABLE); string file; @@ -143,25 +132,25 @@ if(aFile.compare(0, 4, "TTH/") == 0) { file = translateTTH(aFile.substr(4)); } else if(aFile[0] != '/') { - throw ShareException("File Not Available"); + throw ShareException(UserConnection::FILE_NOT_AVAILABLE); } else { file = aFile; } string::size_type i = file.find('/', 1); if(i == string::npos) - throw ShareException("File Not Available"); + throw ShareException(UserConnection::FILE_NOT_AVAILABLE); RLock<> l(cs); StringPairIter j = lookupVirtual(file.substr(1, i-1)); if(j == virtualMap.end()) { - throw ShareException("File Not Available"); + throw ShareException(UserConnection::FILE_NOT_AVAILABLE); } file = file.substr(i + 1); Directory::File::Iter it; if(!checkFile(j->second, file, it)) { - throw ShareException("File Not Available"); + throw ShareException(UserConnection::FILE_NOT_AVAILABLE); } #ifdef _WIN32 @@ -193,13 +182,13 @@ } if(aFile.compare(0, 4, "TTH/") != 0) - throw ShareException("File Not Available"); + throw ShareException(UserConnection::FILE_NOT_AVAILABLE); RLock<> l(cs); TTHValue val(aFile.substr(4)); HashFileIter i = tthIndex.find(&val); if(i == tthIndex.end()) { - throw ShareException("File Not Available"); + throw ShareException(UserConnection::FILE_NOT_AVAILABLE); } Directory::File::Iter f = i->second; @@ -888,47 +877,7 @@ lastXmlUpdate = GET_TICK(); } } -void ShareManager::generateNmdcList() { - Lock l(listGenLock); - if(nmdcDirty && (lastNmdcUpdate + 15 * 60 * 1000 < GET_TICK() || lastNmdcUpdate < lastFullUpdate)) { - listN++; - try { - string tmp; - string tmp2; - string indent; - - for(Directory::MapIter i = directories.begin(); i != directories.end(); ++i) { - i->second->toNmdc(tmp, indent, tmp2); - } - - string newName = Util::getConfigPath() + "MyList" + Util::toString(listN) + ".DcLst"; - tmp2.clear(); - CryptoManager::getInstance()->encodeHuffman(tmp, tmp2); - File(newName, File::WRITE, File::CREATE | File::TRUNCATE).write(tmp2); - - if(lFile != NULL) { - delete lFile; - lFile = NULL; - File::deleteFile(getListFile()); - } - try { - File::renameFile(newName, Util::getConfigPath() + "MyList.DcLst"); - newName = Util::getConfigPath() + "MyList.DcLst"; - } catch(const FileException&) { - } - lFile = new File(newName, File::READ, File::OPEN); - setListFile(newName); - listLen = File::getSize(newName); - } catch(const Exception&) { - // No new file lists... - } - - nmdcDirty = false; - lastNmdcUpdate = GET_TICK(); - } -} - MemoryInputStream* ShareManager::generatePartialList(const string& dir, bool recurse) { if(dir[0] != '/' || dir[dir.size()-1] != '/') return NULL; Modified: dcplusplus/trunk/client/ShareManager.h =================================================================== --- dcplusplus/trunk/client/ShareManager.h 2006-05-20 16:17:09 UTC (rev 604) +++ dcplusplus/trunk/client/ShareManager.h 2006-05-21 08:45:42 UTC (rev 605) @@ -61,7 +61,7 @@ string translateFileName(const string& aFile) throw(ShareException); bool getTTH(const string& aFile, TTHValue& tth) throw(); void refresh(bool dirs = false, bool aUpdate = true, bool block = false) throw(ThreadException, ShareException); - void setDirty() { xmlDirty = nmdcDirty = true; } + void setDirty() { xmlDirty = true; } void search(SearchResult::List& l, const string& aString, int aSearchType, int64_t aSize, int aFileType, Client* aClient, StringList::size_type maxResults); void search(SearchResult::List& l, const StringList& params, StringList::size_type maxResults); @@ -81,9 +81,6 @@ string getShareSizeString() { return Util::toString(getShareSize()); } string getShareSizeString(const string& aDir) { return Util::toString(getShareSize(aDir)); } - int64_t getListLen() { return generateNmdcList(), listLen; } - string getListLenString() { return Util::toString(getListLen()); } - SearchManager::TypeModes getType(const string& fileName); string validateVirtual(const string& /*aVirt*/); @@ -260,7 +257,6 @@ TTHValue xmlRoot; bool xmlDirty; - bool nmdcDirty; bool refreshDirs; bool update; bool initial; @@ -273,7 +269,6 @@ File* xFile; u_int32_t lastXmlUpdate; - u_int32_t lastNmdcUpdate; u_int32_t lastFullUpdate; mutable RWLock<> cs; @@ -297,7 +292,6 @@ Directory* buildTree(const string& aName, Directory* aParent); void addTree(Directory* aDirectory); void addFile(Directory* dir, Directory::File::Iter i); - void generateNmdcList(); void generateXmlList(); bool loadCache(); Modified: dcplusplus/trunk/client/UploadManager.cpp =================================================================== --- dcplusplus/trunk/client/UploadManager.cpp 2006-05-20 16:17:09 UTC (rev 604) +++ dcplusplus/trunk/client/UploadManager.cpp 2006-05-21 08:45:42 UTC (rev 605) @@ -138,8 +138,8 @@ aSource->fileNotAvail(); return false; } - } catch(const ShareException&) { - aSource->fileNotAvail(); + } catch(const ShareException& e) { + aSource->fileNotAvail(e.getError()); return false; } @@ -409,7 +409,7 @@ } void UploadManager::on(GetListLength, UserConnection* conn) throw() { - conn->listLen(ShareManager::getInstance()->getListLenString()); + conn->listLen("42"); } void UploadManager::on(AdcCommand::GET, UserConnection* aSource, const AdcCommand& c) throw() { Modified: dcplusplus/trunk/client/UserConnection.h =================================================================== --- dcplusplus/trunk/client/UserConnection.h 2006-05-20 16:17:09 UTC (rev 604) +++ dcplusplus/trunk/client/UserConnection.h 2006-05-21 08:45:42 UTC (rev 605) @@ -242,7 +242,7 @@ void error(const string& aError) { send("$Error " + aError + '|'); } void listLen(const string& aLength) { send("$ListLen " + aLength + '|'); } void maxedOut() { isSet(FLAG_NMDC) ? send("$MaxedOut|") : send(AdcCommand(AdcCommand::SEV_RECOVERABLE, AdcCommand::ERROR_SLOTS_FULL, "Slots full")); } - void fileNotAvail() { isSet(FLAG_NMDC) ? send("$Error " + FILE_NOT_AVAILABLE + "|") : send(AdcCommand(AdcCommand::SEV_RECOVERABLE, AdcCommand::ERROR_FILE_NOT_AVAILABLE, FILE_NOT_AVAILABLE)); } + void fileNotAvail(const std::string& msg = Util::emptyString) { isSet(FLAG_NMDC) ? send("$Error " + (msg.empty() ? FILE_NOT_AVAILABLE : msg) + "|") : send(AdcCommand(AdcCommand::SEV_RECOVERABLE, AdcCommand::ERROR_FILE_NOT_AVAILABLE, FILE_NOT_AVAILABLE)); } // ADC Stuff void sup(const StringList& features) { Modified: dcplusplus/trunk/windows/MainFrm.cpp =================================================================== --- dcplusplus/trunk/windows/MainFrm.cpp 2006-05-20 16:17:09 UTC (rev 604) +++ dcplusplus/trunk/windows/MainFrm.cpp 2006-05-21 08:45:42 UTC (rev 605) @@ -959,6 +959,7 @@ mnuTrayMenu.AppendMenu(MF_STRING, IDC_TRAY_SHOW, CTSTRING(MENU_SHOW)); mnuTrayMenu.AppendMenu(MF_STRING, IDC_TRAY_QUIT, CTSTRING(MENU_EXIT)); mnuTrayMenu.AppendMenu(MF_STRING, IDC_OPEN_DOWNLOADS, CTSTRING(MENU_OPEN_DOWNLOADS_DIR)); + mnuTrayMenu.AppendMenu(MF_STRING, ID_FILE_SETTINGS, CTSTRING(MENU_SETTINGS)); GetCursorPos(&pt); SetForegroundWindow(m_hWnd); mnuTrayMenu.TrackPopupMenu(TPM_BOTTOMALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON,pt.x,pt.y,m_hWnd); Modified: dcplusplus/trunk/windows/MainFrm.h =================================================================== --- dcplusplus/trunk/windows/MainFrm.h 2006-05-20 16:17:09 UTC (rev 604) +++ dcplusplus/trunk/windows/MainFrm.h 2006-05-21 08:45:42 UTC (rev 605) @@ -349,7 +349,6 @@ } links; HWND createToolbar(); - void buildMenu(); void updateTray(bool add = true); void autoConnect(const FavoriteHubEntry::List& fl); Modified: dcplusplus/trunk/windows/QueueFrame.cpp =================================================================== --- dcplusplus/trunk/windows/QueueFrame.cpp 2006-05-20 16:17:09 UTC (rev 604) +++ dcplusplus/trunk/windows/QueueFrame.cpp 2006-05-21 08:45:42 UTC (rev 605) @@ -1217,6 +1217,17 @@ return 0; } +void QueueFrame::onTab() { + if(showTree) { + HWND focus = ::GetFocus(); + if(focus == ctrlDirs.m_hWnd) { + ctrlQueue.SetFocus(); + } else if(focus == ctrlQueue.m_hWnd) { + ctrlDirs.SetFocus(); + } + } +} + void QueueFrame::updateQueue() { Lock l(cs); Modified: dcplusplus/trunk/windows/QueueFrame.h =================================================================== --- dcplusplus/trunk/windows/QueueFrame.h 2006-05-20 16:17:09 UTC (rev 604) +++ dcplusplus/trunk/windows/QueueFrame.h 2006-05-21 08:45:42 UTC (rev 605) @@ -133,16 +133,7 @@ return 0; } - void onTab() { - if(showTree) { - HWND focus = ::GetFocus(); - if(focus == ctrlDirs.m_hWnd) { - ctrlQueue.SetFocus(); - } else if(focus == ctrlQueue.m_hWnd) { - ctrlDirs.SetFocus(); - } - } - } + void onTab(); LRESULT onShowTree(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled) { bHandled = FALSE; Modified: dcplusplus/trunk/windows/TransferView.cpp =================================================================== --- dcplusplus/trunk/windows/TransferView.cpp 2006-05-20 16:17:09 UTC (rev 604) +++ dcplusplus/trunk/windows/TransferView.cpp 2006-05-21 08:45:42 UTC (rev 605) @@ -65,6 +65,7 @@ transferMenu.CreatePopupMenu(); appendUserItems(transferMenu); + transferMenu.AppendMenu(MF_SEPARATOR); transferMenu.AppendMenu(MF_STRING, IDC_FORCE, CTSTRING(FORCE_ATTEMPT)); transferMenu.AppendMenu(MF_STRING, IDC_COPY_NICK, CTSTRING(COPY_NICK)); transferMenu.AppendMenu(MF_SEPARATOR); Modified: dcplusplus/trunk/windows/WinUtil.h =================================================================== --- dcplusplus/trunk/windows/WinUtil.h 2006-05-20 16:17:09 UTC (rev 604) +++ dcplusplus/trunk/windows/WinUtil.h 2006-05-21 08:45:42 UTC (rev 605) @@ -124,8 +124,9 @@ menu.AppendMenu(MF_STRING, IDC_PRIVATEMESSAGE, CTSTRING(SEND_PRIVATE_MESSAGE)); menu.AppendMenu(MF_STRING, IDC_ADD_TO_FAVORITES, CTSTRING(ADD_TO_FAVORITES)); menu.AppendMenu(MF_STRING, IDC_GRANTSLOT, CTSTRING(GRANT_EXTRA_SLOT)); + menu.AppendMenu(MF_STRING, IDC_CONNECT, CTSTRING(CONNECT_FAVUSER_HUB)); + menu.AppendMenu(MF_SEPARATOR); menu.AppendMenu(MF_STRING, IDC_REMOVEALL, CTSTRING(REMOVE_FROM_ALL)); - menu.AppendMenu(MF_STRING, IDC_CONNECT, CTSTRING(CONNECT_FAVUSER_HUB)); } }; Modified: dcplusplus/trunk/windows/main.cpp =================================================================== --- dcplusplus/trunk/windows/main.cpp 2006-05-20 16:17:09 UTC (rev 604) +++ dcplusplus/trunk/windows/main.cpp 2006-05-21 08:45:42 UTC (rev 605) @@ -266,7 +266,8 @@ } } - if(wndMain.CreateEx(NULL, rc, 0, WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_WINDOWEDGE) == NULL) { + int rtl = ResourceManager::getInstance()->isRTL() ? WS_EX_RTLREADING : 0; + if(wndMain.CreateEx(NULL, rc, 0, rtl | WS_EX_APPWINDOW | WS_EX_WINDOWEDGE) == NULL) { ATLTRACE(_T("Main window creation failed!\n")); return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |