------------------------------------------------------------ revno: 3260 committer: poy <p...@123gen.com> branch nick: trunk timestamp: Mon 2013-04-15 19:29:39 +0200 message: download GeoIP updates directly to files modified: win32/MainWindow.cpp win32/MainWindow.h
-- 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 'win32/MainWindow.cpp' --- win32/MainWindow.cpp 2013-04-14 22:01:23 +0000 +++ win32/MainWindow.cpp 2013-04-15 17:29:39 +0000 @@ -1490,20 +1490,25 @@ if(conn) return; + auto& file = v6 ? geo6File : geo4File; + try { + file.reset(new File(GeoManager::getDbPath(v6) + ".gz", File::WRITE, File::CREATE | File::TRUNCATE)); + } catch(const FileException&) { + LogManager::getInstance()->message(str(F_("The %1% GeoIP database could not be updated") % (v6 ? "IPv6" : "IPv4"))); + return; + } + LogManager::getInstance()->message(str(F_("Updating the %1% GeoIP database...") % (v6 ? "IPv6" : "IPv4"))); - conn = HttpManager::getInstance()->download(Text::fromT(v6 ? links.geoip6 : links.geoip4)); + conn = HttpManager::getInstance()->download(Text::fromT(v6 ? links.geoip6 : links.geoip4), file.get()); } -void MainWindow::completeGeoUpdate(bool v6, bool success, const string& result) { - if(success && !result.empty()) { - try { - File(GeoManager::getDbPath(v6) + ".gz", File::WRITE, File::CREATE | File::TRUNCATE).write(result); - GeoManager::getInstance()->update(v6); - LogManager::getInstance()->message(str(F_("The %1% GeoIP database has been successfully updated") % (v6 ? "IPv6" : "IPv4"))); - return; - } catch(const FileException&) { } +void MainWindow::completeGeoUpdate(bool v6, bool success) { + if(success) { + GeoManager::getInstance()->update(v6); + LogManager::getInstance()->message(str(F_("The %1% GeoIP database has been successfully updated") % (v6 ? "IPv6" : "IPv4"))); + } else { + LogManager::getInstance()->message(str(F_("The %1% GeoIP database could not be updated") % (v6 ? "IPv6" : "IPv4"))); } - LogManager::getInstance()->message(str(F_("The %1% GeoIP database could not be updated") % (v6 ? "IPv6" : "IPv4"))); } void MainWindow::parseCommandLine(const tstring& cmdLine) @@ -1741,15 +1746,20 @@ void MainWindow::on(HttpManagerListener::Failed, HttpConnection* c, const string&) noexcept { if(c == conns[CONN_VERSION]) { conns[CONN_VERSION] = nullptr; + callAsync([this] { completeVersionUpdate(false, Util::emptyString); }); } else if(c == conns[CONN_GEO_V6]) { conns[CONN_GEO_V6] = nullptr; - callAsync([this] { completeGeoUpdate(true, false, Util::emptyString); }); + geo6File.reset(); + + callAsync([this] { completeGeoUpdate(true, false); }); } else if(c == conns[CONN_GEO_V4]) { conns[CONN_GEO_V4] = nullptr; - callAsync([this] { completeGeoUpdate(false, false, Util::emptyString); }); + geo4File.reset(); + + callAsync([this] { completeGeoUpdate(false, false); }); } } @@ -1762,15 +1772,26 @@ } else if(c == conns[CONN_GEO_V6]) { conns[CONN_GEO_V6] = nullptr; + geo6File.reset(); - auto str = static_cast<StringOutputStream*>(stream)->getString(); - callAsync([str, this] { completeGeoUpdate(true, true, str); }); + callAsync([this] { completeGeoUpdate(true, true); }); } else if(c == conns[CONN_GEO_V4]) { conns[CONN_GEO_V4] = nullptr; - - auto str = static_cast<StringOutputStream*>(stream)->getString(); - callAsync([str, this] { completeGeoUpdate(false, true, str); }); + geo4File.reset(); + + callAsync([this] { completeGeoUpdate(false, true); }); + } +} + +void MainWindow::on(HttpManagerListener::ResetStream, HttpConnection* c) noexcept { + if(c == conns[CONN_GEO_V6]) { + geo6File->setPos(0); + geo6File->setEOF(); + + } else if(c == conns[CONN_GEO_V4]) { + geo4File->setPos(0); + geo4File->setEOF(); } } === modified file 'win32/MainWindow.h' --- win32/MainWindow.h 2013-04-13 15:08:45 +0000 +++ win32/MainWindow.h 2013-04-15 17:29:39 +0000 @@ -140,6 +140,7 @@ static map<tstring, function<void ()>, noCaseStringLess> pluginCommands; HttpConnection* conns[CONN_LAST]; + unique_ptr<File> geo6File, geo4File; HANDLE stopperThread; @@ -222,7 +223,7 @@ void checkGeoUpdate(bool v6); void updateGeo(); void updateGeo(bool v6); - void completeGeoUpdate(bool v6, bool success, const string& result); + void completeGeoUpdate(bool v6, bool success); bool filter(MSG& msg); @@ -234,6 +235,7 @@ // HttpManagerListener void on(HttpManagerListener::Failed, HttpConnection*, const string&) noexcept; void on(HttpManagerListener::Complete, HttpConnection*, OutputStream*) noexcept; + void on(HttpManagerListener::ResetStream, HttpConnection*) noexcept; // LogManagerListener void on(LogManagerListener::Message, time_t t, const string& m) noexcept;
_______________________________________________ Mailing list: https://launchpad.net/~linuxdcpp-team Post to : linuxdcpp-team@lists.launchpad.net Unsubscribe : https://launchpad.net/~linuxdcpp-team More help : https://help.launchpad.net/ListHelp