← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2791: Heuristics to send additional levels of info in partial file lists

 

------------------------------------------------------------
revno: 2791
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sat 2012-01-07 18:52:55 +0100
message:
  Heuristics to send additional levels of info in partial file lists
modified:
  changelog.txt
  dcpp/ShareManager.cpp
  dcpp/ShareManager.h
  win32/DirectoryListingFrame.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2012-01-07 16:20:01 +0000
+++ changelog.txt	2012-01-07 17:52:55 +0000
@@ -1,5 +1,6 @@
 * Save and restore partial file lists (poy)
 * Apply ADL searches in partial file lists (poy)
+* [ADC] Heuristics to send additional levels of info in partial file lists (poy)
 
 -- 0.790 2011-12-29 --
 * Fav users frame becomes users frame and shows all users

=== modified file 'dcpp/ShareManager.cpp'
--- dcpp/ShareManager.cpp	2012-01-06 23:14:39 +0000
+++ dcpp/ShareManager.cpp	2012-01-07 17:52:55 +0000
@@ -841,7 +841,7 @@
 				newXmlFile.write(SimpleXML::utf8Header);
 				newXmlFile.write("<FileListing Version=\"1\" CID=\"" + ClientManager::getInstance()->getMe()->getCID().toBase32() + "\" Base=\"/\" Generator=\"" APPNAME " " VERSIONSTRING "\">\r\n");
 				for(auto i = directories.begin(); i != directories.end(); ++i) {
-					(*i)->toXml(newXmlFile, indent, tmp2, true);
+					(*i)->toXml(newXmlFile, indent, tmp2, -1);
 				}
 				newXmlFile.write("</FileListing>");
 				newXmlFile.flush();
@@ -894,7 +894,7 @@
 	if(dir == "/") {
 		for(auto i = directories.begin(); i != directories.end(); ++i) {
 			tmp.clear();
-			(*i)->toXml(sos, indent, tmp, recurse);
+			(*i)->toXml(sos, indent, tmp, recurse ? -1 : 0);
 		}
 	} else {
 		string::size_type i = 1, j = 1;
@@ -930,7 +930,7 @@
 			return 0;
 
 		for(auto it2 = root->directories.begin(); it2 != root->directories.end(); ++it2) {
-			it2->second->toXml(sos, indent, tmp, recurse);
+			it2->second->toXml(sos, indent, tmp, recurse ? -1 : 0);
 		}
 		root->filesToXml(sos, indent, tmp);
 	}
@@ -939,25 +939,36 @@
 	return new MemoryInputStream(xml);
 }
 
+/* params for partial file lists - when any of these params is not satisfied, an incomplete dir is
+returned rather than a full dir list. */
+const int8_t maxLevel = 2;
+const size_t maxItemsPerLevel[maxLevel] = { 16, 4 };
+
 #define LITERAL(n) n, sizeof(n)-1
-void ShareManager::Directory::toXml(OutputStream& xmlFile, string& indent, string& tmp2, bool fullList) const {
+void ShareManager::Directory::toXml(OutputStream& xmlFile, string& indent, string& tmp2, int8_t level) const {
 	xmlFile.write(indent);
 	xmlFile.write(LITERAL("<Directory Name=\""));
 	xmlFile.write(SimpleXML::escape(name, tmp2, true));
 
-	if(fullList) {
+	if(level < 0 || (level < maxLevel && directories.size() + files.size() <= maxItemsPerLevel[level])) {
 		xmlFile.write(LITERAL("\">\r\n"));
 
 		indent += '\t';
+		if(level >= 0)
+			++level;
+
 		for(auto i = directories.begin(); i != directories.end(); ++i) {
-			i->second->toXml(xmlFile, indent, tmp2, fullList);
+			i->second->toXml(xmlFile, indent, tmp2, level);
 		}
-
 		filesToXml(xmlFile, indent, tmp2);
 
+		if(level >= 0)
+			--level;
 		indent.erase(indent.length()-1);
+
 		xmlFile.write(indent);
 		xmlFile.write(LITERAL("</Directory>\r\n"));
+
 	} else {
 		if(directories.empty() && files.empty()) {
 			xmlFile.write(LITERAL("\" />\r\n"));

=== modified file 'dcpp/ShareManager.h'
--- dcpp/ShareManager.h	2011-12-27 20:06:53 +0000
+++ dcpp/ShareManager.h	2012-01-07 17:52:55 +0000
@@ -185,7 +185,8 @@
 		void search(SearchResultList& aResults, StringSearch::List& aStrings, int aSearchType, int64_t aSize, int aFileType, Client* aClient, StringList::size_type maxResults) const noexcept;
 		void search(SearchResultList& aResults, AdcSearch& aStrings, StringList::size_type maxResults) const noexcept;
 
-		void toXml(OutputStream& xmlFile, string& indent, string& tmp2, bool fullList) const;
+		/// @param level -1 to include all levels, or the current level.
+		void toXml(OutputStream& xmlFile, string& indent, string& tmp2, int8_t level) const;
 		void filesToXml(OutputStream& xmlFile, string& indent, string& tmp2) const;
 
 		File::Set::const_iterator findFile(const string& aFile) const { return find_if(files.begin(), files.end(), Directory::File::StringComp(aFile)); }

=== modified file 'win32/DirectoryListingFrame.cpp'
--- win32/DirectoryListingFrame.cpp	2012-01-07 16:34:26 +0000
+++ win32/DirectoryListingFrame.cpp	2012-01-07 17:52:55 +0000
@@ -506,7 +506,6 @@
 		loaded = true;
 		addRecent();
 
-		refreshTree(Text::toT(Util::toNmdcFile(base)));
 		std::for_each(dl->getRoot()->directories.cbegin(), dl->getRoot()->directories.cend(),
 			[this](DirectoryListing::Directory* d)
 		{
@@ -514,6 +513,7 @@
 				addDir(d, treeRoot);
 			}
 		});
+		refreshTree(Text::toT(Util::toNmdcFile(base)));
 
 	} catch(const Exception& e) {
 		error = Text::toT(e.getError());