|
From: <arn...@us...> - 2006-12-13 20:57:21
|
Revision: 689
http://svn.sourceforge.net/dcplusplus/?rev=689&view=rev
Author: arnetheduck
Date: 2006-12-13 12:57:11 -0800 (Wed, 13 Dec 2006)
Log Message:
-----------
patches, reorder hublists to put the working ones first
Modified Paths:
--------------
dcplusplus/trunk/Example.xml
dcplusplus/trunk/changelog.txt
dcplusplus/trunk/client/FavoriteManager.cpp
dcplusplus/trunk/client/FavoriteManager.h
dcplusplus/trunk/client/SettingsManager.cpp
dcplusplus/trunk/client/StringDefs.cpp
dcplusplus/trunk/client/StringDefs.h
dcplusplus/trunk/client/Util.h
dcplusplus/trunk/windows/AboutDlg.h
dcplusplus/trunk/windows/PublicHubsFrm.cpp
dcplusplus/trunk/windows/PublicHubsFrm.h
Modified: dcplusplus/trunk/Example.xml
===================================================================
--- dcplusplus/trunk/Example.xml 2006-12-13 20:39:44 UTC (rev 688)
+++ dcplusplus/trunk/Example.xml 2006-12-13 20:57:11 UTC (rev 689)
@@ -178,6 +178,7 @@
<String Name="HubAddress">Address</String>
<String Name="HubListDownloaded">Hub list downloaded...</String>
<String Name="HubListEdit">Edit the hublist</String>
+ <String Name="HubListLoadedFromCache">Hub list loaded from cache...</String>
<String Name="HubName">Name</String>
<String Name="HubList">Hublist</String>
<String Name="HubPassword">Hub password</String>
Modified: dcplusplus/trunk/changelog.txt
===================================================================
--- dcplusplus/trunk/changelog.txt 2006-12-13 20:39:44 UTC (rev 688)
+++ dcplusplus/trunk/changelog.txt 2006-12-13 20:57:11 UTC (rev 689)
@@ -22,6 +22,8 @@
* [bug 1112] Port sign cleanup (thanks steven sheehy)
* [ADC] Fixed client-to-client connection sequence
* [bug 1064] Updated to YaSSL 1.5.0, should fix crash
+* [bug 446] Public hub lists are cached and downloaded only when user requests it (thanks poy)
+* [bug 1117] Fixed subfolders being created on filelist downloads (thanks mikael eman)
-- 0.698 2006-10-10 --
* [bug 1065] Code cleanup (thanks steven sheehy)
Modified: dcplusplus/trunk/client/FavoriteManager.cpp
===================================================================
--- dcplusplus/trunk/client/FavoriteManager.cpp 2006-12-13 20:39:44 UTC (rev 688)
+++ dcplusplus/trunk/client/FavoriteManager.cpp 2006-12-13 20:57:11 UTC (rev 689)
@@ -30,6 +30,25 @@
#include "SimpleXML.h"
#include "UserCommand.h"
+FavoriteManager::FavoriteManager() : lastId(0), useHttp(false), running(false), c(NULL), lastServer(0), listType(TYPE_NORMAL), dontSave(false) {
+ SettingsManager::getInstance()->addListener(this);
+ ClientManager::getInstance()->addListener(this);
+
+ File::ensureDirectory(Util::getHubListsPath());
+}
+
+FavoriteManager::~FavoriteManager() throw() {
+ ClientManager::getInstance()->removeListener(this);
+ SettingsManager::getInstance()->removeListener(this);
+ if(c) {
+ c->removeListener(this);
+ delete c;
+ c = NULL;
+ }
+
+ for_each(favoriteHubs.begin(), favoriteHubs.end(), DeleteFunction());
+}
+
UserCommand FavoriteManager::addUserCommand(int type, int ctx, int flags, const string& name, const string& command, const string& hub) {
// No dupes, add it...
Lock l(cs);
@@ -230,12 +249,12 @@
return false;
}
-void FavoriteManager::onHttpFinished() throw() {
+void FavoriteManager::onHttpFinished(bool fromHttp) throw() {
string::size_type i, j;
string* x;
string bzlist;
- if(listType == TYPE_BZIP2) {
+ if((listType == TYPE_BZIP2) && (!downloadBuf.empty())) {
try {
CryptoManager::getInstance()->decodeBZ2((uint8_t*)downloadBuf.data(), downloadBuf.size(), bzlist);
} catch(const CryptoException&) {
@@ -272,6 +291,15 @@
}
}
}
+
+ if(fromHttp) {
+ try {
+ File f(Util::getHubListsPath() + Util::validateFileName(publicListServer), File::WRITE, File::CREATE | File::TRUNCATE);
+ f.write(downloadBuf);
+ f.close();
+ } catch(const FileException&) { }
+ }
+
downloadBuf = Util::emptyString;
}
@@ -555,17 +583,12 @@
return lists.getTokens();
}
-bool FavoriteManager::setHubList(int aHubList) {
- if(!running) {
- lastServer = aHubList;
- StringList sl = getHubLists();
- publicListServer = sl[(lastServer) % sl.size()];
- return true;
- }
- return false;
+void FavoriteManager::setHubList(int aHubList) {
+ lastServer = aHubList;
+ refresh();
}
-void FavoriteManager::refresh() {
+void FavoriteManager::refresh(bool forceDownload /* = false */) {
StringList sl = getHubLists();
if(sl.empty())
return;
@@ -575,14 +598,37 @@
return;
}
- fire(FavoriteManagerListener::DownloadStarting(), publicListServer);
+ if(!forceDownload) {
+ string path = Util::getHubListsPath() + Util::validateFileName(publicListServer);
+ if(File::getSize(path) > 0) {
+ useHttp = false;
+ {
+ Lock l(cs);
+ publicListMatrix[publicListServer].clear();
+ }
+ listType = (Util::stricmp(path.substr(path.size() - 4), ".bz2") == 0) ? TYPE_BZIP2 : TYPE_NORMAL;
+ try {
+ downloadBuf = File(path, File::READ, File::OPEN).read();
+ } catch(const FileException&) {
+ downloadBuf = Util::emptyString;
+ }
+ if(!downloadBuf.empty()) {
+ onHttpFinished(false);
+ fire(FavoriteManagerListener::LoadedFromCache(), publicListServer);
+ return;
+ }
+ }
+ }
+
if(!running) {
- if(!c)
- c = new HttpConnection();
+ useHttp = true;
{
Lock l(cs);
publicListMatrix[publicListServer].clear();
}
+ fire(FavoriteManagerListener::DownloadStarting(), publicListServer);
+ if(c == NULL)
+ c = new HttpConnection();
c->addListener(this);
c->downloadFile(publicListServer);
running = true;
@@ -634,29 +680,36 @@
// HttpConnectionListener
void FavoriteManager::on(Data, HttpConnection*, const uint8_t* buf, size_t len) throw() {
- downloadBuf.append((const char*)buf, len);
+ if(useHttp)
+ downloadBuf.append((const char*)buf, len);
}
void FavoriteManager::on(Failed, HttpConnection*, const string& aLine) throw() {
c->removeListener(this);
lastServer++;
running = false;
- fire(FavoriteManagerListener::DownloadFailed(), aLine);
+ if(useHttp)
+ fire(FavoriteManagerListener::DownloadFailed(), aLine);
}
void FavoriteManager::on(Complete, HttpConnection*, const string& aLine) throw() {
c->removeListener(this);
- onHttpFinished();
+ if(useHttp)
+ onHttpFinished(true);
running = false;
- fire(FavoriteManagerListener::DownloadFinished(), aLine);
+ if(useHttp)
+ fire(FavoriteManagerListener::DownloadFinished(), aLine);
}
void FavoriteManager::on(Redirected, HttpConnection*, const string& aLine) throw() {
- fire(FavoriteManagerListener::DownloadStarting(), aLine);
+ if(useHttp)
+ fire(FavoriteManagerListener::DownloadStarting(), aLine);
}
void FavoriteManager::on(TypeNormal, HttpConnection*) throw() {
- listType = TYPE_NORMAL;
+ if(useHttp)
+ listType = TYPE_NORMAL;
}
void FavoriteManager::on(TypeBZ2, HttpConnection*) throw() {
- listType = TYPE_BZIP2;
+ if(useHttp)
+ listType = TYPE_BZIP2;
}
void FavoriteManager::on(UserUpdated, const OnlineUser& user) throw() {
Modified: dcplusplus/trunk/client/FavoriteManager.h
===================================================================
--- dcplusplus/trunk/client/FavoriteManager.h 2006-12-13 20:39:44 UTC (rev 688)
+++ dcplusplus/trunk/client/FavoriteManager.h 2006-12-13 20:57:11 UTC (rev 689)
@@ -121,6 +121,7 @@
typedef X<5> UserAdded;
typedef X<6> UserRemoved;
typedef X<7> StatusChanged;
+ typedef X<8> LoadedFromCache;
virtual void on(DownloadStarting, const string&) throw() { }
virtual void on(DownloadFailed, const string&) throw() { }
@@ -130,6 +131,7 @@
virtual void on(UserAdded, const FavoriteUser&) throw() { }
virtual void on(UserRemoved, const FavoriteUser&) throw() { }
virtual void on(StatusChanged, const User::Ptr&) throw() { }
+ virtual void on(LoadedFromCache, const string&) throw() { }
};
class SimpleXML;
@@ -147,15 +149,15 @@
TYPE_BZIP2
};
StringList getHubLists();
- bool setHubList(int /*aHubList*/);
+ void setHubList(int aHubList);
int getSelectedHubList() { return lastServer; }
- void refresh();
+ void refresh(bool forceDownload = false);
HubTypes getHubListType() { return listType; }
HubEntry::List getPublicHubs() {
Lock l(cs);
return publicListMatrix[publicListServer];
}
- bool isDownloading() { return running; }
+ bool isDownloading() { return (useHttp && running); }
// Favorite Users
typedef HASH_MAP_X(CID, FavoriteUser, CID::Hash, equal_to<CID>, less<CID>) FavoriteMap;
@@ -214,7 +216,7 @@
typedef map<string, HubEntry::List> PubListMap;
PubListMap publicListMatrix;
string publicListServer;
- bool running;
+ bool useHttp, running;
HttpConnection* c;
int lastServer;
HubTypes listType;
@@ -225,23 +227,9 @@
friend class Singleton<FavoriteManager>;
- FavoriteManager() : lastId(0), running(false), c(NULL), lastServer(0), listType(TYPE_NORMAL), dontSave(false) {
- SettingsManager::getInstance()->addListener(this);
- ClientManager::getInstance()->addListener(this);
- }
+ FavoriteManager();
+ virtual ~FavoriteManager() throw();
- virtual ~FavoriteManager() throw() {
- ClientManager::getInstance()->removeListener(this);
- SettingsManager::getInstance()->removeListener(this);
- if(c) {
- c->removeListener(this);
- delete c;
- c = NULL;
- }
-
- for_each(favoriteHubs.begin(), favoriteHubs.end(), DeleteFunction());
- }
-
FavoriteHubEntry::Iter getFavoriteHub(const string& aServer) {
for(FavoriteHubEntry::Iter i = favoriteHubs.begin(); i != favoriteHubs.end(); ++i) {
if(Util::stricmp((*i)->getServer(), aServer) == 0) {
@@ -266,7 +254,7 @@
virtual void on(TypeNormal, HttpConnection*) throw();
virtual void on(TypeBZ2, HttpConnection*) throw();
- void onHttpFinished() throw();
+ void onHttpFinished(bool fromHttp) throw();
// SettingsManagerListener
virtual void on(SettingsManagerListener::Load, SimpleXML& xml) throw() {
Modified: dcplusplus/trunk/client/SettingsManager.cpp
===================================================================
--- dcplusplus/trunk/client/SettingsManager.cpp 2006-12-13 20:39:44 UTC (rev 688)
+++ dcplusplus/trunk/client/SettingsManager.cpp 2006-12-13 20:57:11 UTC (rev 689)
@@ -135,7 +135,7 @@
setDefault(IGNORE_BOT_PMS, false);
setDefault(LIST_DUPES, true);
setDefault(BUFFER_SIZE, 64);
- setDefault(HUBLIST_SERVERS, "http://home.bandicoot.nl/adchublist.xml.bz2;http://adchublist.com/hublist.xml.bz2;http://www.hublist.org/PublicHubList.xml.bz2;http://dchublist.com/hublist.xml.bz2");
+ setDefault(HUBLIST_SERVERS, "http://dchublist.com/hublist.xml.bz2;http://adchublist.com/hublist.xml.bz2;http://home.bandicoot.nl/adchublist.xml.bz2;http://www.hublist.org/PublicHubList.xml.bz2");
setDefault(DOWNLOAD_SLOTS, 3);
setDefault(MAX_DOWNLOAD_SPEED, 0);
setDefault(LOG_DIRECTORY, Util::getConfigPath() + "Logs" PATH_SEPARATOR_STR);
Modified: dcplusplus/trunk/client/StringDefs.cpp
===================================================================
--- dcplusplus/trunk/client/StringDefs.cpp 2006-12-13 20:39:44 UTC (rev 688)
+++ dcplusplus/trunk/client/StringDefs.cpp 2006-12-13 20:57:11 UTC (rev 689)
@@ -179,6 +179,7 @@
"Address",
"Hub list downloaded...",
"Edit the hublist",
+"Hub list loaded from cache...",
"Name",
"Hublist",
"Hub password",
@@ -811,6 +812,7 @@
"HubAddress",
"HubListDownloaded",
"HubListEdit",
+"HubListLoadedFromCache",
"HubName",
"HubList",
"HubPassword",
Modified: dcplusplus/trunk/client/StringDefs.h
===================================================================
--- dcplusplus/trunk/client/StringDefs.h 2006-12-13 20:39:44 UTC (rev 688)
+++ dcplusplus/trunk/client/StringDefs.h 2006-12-13 20:57:11 UTC (rev 689)
@@ -182,6 +182,7 @@
HUB_ADDRESS, // "Address"
HUB_LIST_DOWNLOADED, // "Hub list downloaded..."
HUB_LIST_EDIT, // "Edit the hublist"
+ HUB_LIST_LOADED_FROM_CACHE, // "Hub list loaded from cache..."
HUB_NAME, // "Name"
HUB_LIST, // "Hublist"
HUB_PASSWORD, // "Hub password"
Modified: dcplusplus/trunk/client/Util.h
===================================================================
--- dcplusplus/trunk/client/Util.h 2006-12-13 20:39:44 UTC (rev 688)
+++ dcplusplus/trunk/client/Util.h 2006-12-13 20:57:11 UTC (rev 689)
@@ -162,6 +162,8 @@
/** Path of file lists */
static string getListPath() { return getConfigPath() + "FileLists" PATH_SEPARATOR_STR; }
+ /** Path of hub lists */
+ static string getHubListsPath() { return getConfigPath() + "HubLists" PATH_SEPARATOR_STR; }
/** Notepad filename */
static string getNotepadFile() { return getConfigPath() + "Notepad.txt"; }
Modified: dcplusplus/trunk/windows/AboutDlg.h
===================================================================
--- dcplusplus/trunk/windows/AboutDlg.h 2006-12-13 20:39:44 UTC (rev 688)
+++ dcplusplus/trunk/windows/AboutDlg.h 2006-12-13 20:57:11 UTC (rev 689)
@@ -27,9 +27,9 @@
#include "../client/SimpleXML.h"
static const TCHAR thanks[] = _T("Big thanks to all donators and people who have contributed with ideas ")
-_T("and code! Thanks go out to sourceforge for hosting the project. This application uses libzip2, ")
-_T("thanks to Julian R Steward and team for providing it. This application uses STLPort ")
-_T("(www.stlport.org), a most excellent STL package. zlib is also used in this application. ")
+_T("and code! Thanks go out to sourceforge for hosting the project. This application uses bzip2 (www.bzip.org), ")
+_T("thanks to Julian Seward and team for providing it. Thiz application uses zlib (www.zlib.net), ")
+_T("thanks to Jean-loup Gailly and Mark Adler for providing it. ")
_T("This product includes GeoIP data created by MaxMind, available from http://maxmind.com/. ")
_T("This product uses yassl from www.yassl.com, thanks to Todd Ouska and Larry Stefonic.")
_T("The following people have contributed code to ")
@@ -42,7 +42,7 @@
_T("defr, ullner, fleetcommand, liny, xan, olle svensson, mark gillespie, jeremy huddleston, ")
_T("bsod, sulan, jonathan stone, tim burton, izzzo, guitarm, paka, nils maier, jens oknelid, yoji, ")
_T("krzysztof tyszecki, poison, pothead, pur, bigmuscle, martin, jove, bart vullings, ")
-_T("steven sheehy, tobias nygren, poy, dorian, stephan hohe, mafa_45. ")
+_T("steven sheehy, tobias nygren, poy, dorian, stephan hohe, mafa_45, mikael eman. ")
_T("Keep it coming!");
class AboutDlg : public CDialogImpl<AboutDlg>, private HttpConnectionListener
Modified: dcplusplus/trunk/windows/PublicHubsFrm.cpp
===================================================================
--- dcplusplus/trunk/windows/PublicHubsFrm.cpp 2006-12-13 20:39:44 UTC (rev 688)
+++ dcplusplus/trunk/windows/PublicHubsFrm.cpp 2006-12-13 20:57:11 UTC (rev 689)
@@ -139,10 +139,8 @@
hubs = FavoriteManager::getInstance()->getPublicHubs();
if(FavoriteManager::getInstance()->isDownloading())
ctrlStatus.SetText(0, CTSTRING(DOWNLOADING_HUB_LIST));
- else {
- if(hubs.empty())
- FavoriteManager::getInstance()->refresh();
- }
+ else if(hubs.empty())
+ FavoriteManager::getInstance()->refresh();
updateList();
@@ -210,12 +208,9 @@
}
LRESULT PublicHubsFrame::onClickedRefresh(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
- ctrlHubs.DeleteAllItems();
- users = 0;
- visibleHubs = 0;
ctrlStatus.SetText(0, CTSTRING(DOWNLOADING_HUB_LIST));
- FavoriteManager::getInstance()->refresh();
-
+ FavoriteManager::getInstance()->refresh(true);
+ updateDropDown();
return 0;
}
@@ -424,11 +419,11 @@
}
LRESULT PublicHubsFrame::onSpeaker(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) {
- if(wParam == FINISHED) {
+ if((wParam == FINISHED) || (wParam == LOADED_FROM_CACHE)) {
hubs = FavoriteManager::getInstance()->getPublicHubs();
updateList();
tstring* x = (tstring*)lParam;
- ctrlStatus.SetText(0, (TSTRING(HUB_LIST_DOWNLOADED) + _T(" (") + (*x) + _T(")")).c_str());
+ ctrlStatus.SetText(0, (((wParam == LOADED_FROM_CACHE) ? TSTRING(HUB_LIST_LOADED_FROM_CACHE) : TSTRING(HUB_LIST_DOWNLOADED)) + _T(" (") + (*x) + _T(")")).c_str());
delete x;
} else if(wParam == STARTING) {
tstring* x = (tstring*)lParam;
Modified: dcplusplus/trunk/windows/PublicHubsFrm.h
===================================================================
--- dcplusplus/trunk/windows/PublicHubsFrm.h 2006-12-13 20:39:44 UTC (rev 688)
+++ dcplusplus/trunk/windows/PublicHubsFrm.h 2006-12-13 20:57:11 UTC (rev 689)
@@ -124,6 +124,7 @@
enum {
FINISHED,
+ LOADED_FROM_CACHE,
STARTING,
FAILED
};
@@ -164,6 +165,7 @@
virtual void on(DownloadStarting, const string& l) throw() { speak(STARTING, l); }
virtual void on(DownloadFailed, const string& l) throw() { speak(FAILED, l); }
virtual void on(DownloadFinished, const string& l) throw() { speak(FINISHED, l); }
+ virtual void on(LoadedFromCache, const string& l) throw() { speak(LOADED_FROM_CACHE, l); }
void speak(int x, const string& l) {
PostMessage(WM_SPEAKER, x, (LPARAM)new tstring(Text::toT(l)));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|