summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Borisov <b0ric.alex@gmail.com>2012-03-30 00:42:18 +0300
committerAlex Borisov <b0ric.alex@gmail.com>2012-03-30 00:42:18 +0300
commitfcc5a8982adc2e2b8cdd9491ac458986b94cac5a (patch)
tree824c9cc98af61c3aba073f93e6f5e8850aad0c42
parentec80c67bcfec64177910f39d31c4b20974629096 (diff)
FIX: proxy order, speed color, client update issue
-rw-r--r--client/Dialog.cpp2
-rw-r--r--client/DownloadClient.cpp45
-rw-r--r--client/DownloadClient.h17
-rw-r--r--client/Proxifier.cpp16
-rw-r--r--client/Proxifier.h4
-rw-r--r--client/main.cpp6
6 files changed, 63 insertions, 27 deletions
diff --git a/client/Dialog.cpp b/client/Dialog.cpp
index 3e96784..19e7ddc 100644
--- a/client/Dialog.cpp
+++ b/client/Dialog.cpp
@@ -246,7 +246,7 @@ void ProxyDialog::StaticProxyToggled(bool on)
proxifier->TurnProxyOff(active[i]);
}
}
- proxifier->TurnProxyOn(*proxy);
+ proxifier->TurnProxyOn(*proxy, true);
}
void ProxyDialog::CountryActivated(int index)
diff --git a/client/DownloadClient.cpp b/client/DownloadClient.cpp
index 110601a..0175df7 100644
--- a/client/DownloadClient.cpp
+++ b/client/DownloadClient.cpp
@@ -8,13 +8,14 @@ DownloadClient::DownloadClient(): isDownloading(false), current(NULL), currentId
{
}
-DownloadClient::DownloadClient(QString addr): SslClient(addr), isDownloading(false), current(NULL), currentId(-1)
+DownloadClient::DownloadClient(QString addr):
+ SslClient(addr), isDownloading(false), current(NULL), currentId(-1)
{
}
void DownloadClient::Download(const string &filename)
{
- pair<string, string> file(filename, 0);
+ pair<string, string> file(filename, "0");
vector<pair<string, string> > fileList;
fileList.push_back(file);
Download(fileList);
@@ -42,18 +43,31 @@ void DownloadClient::Download(const vector<pair<string, string> > &fileList)
connect(this, SIGNAL(ReplyRecieved(SslClient::RequestType&, QByteArray&)),
this, SLOT(FileDataRecieved(SslClient::RequestType&, QByteArray&)));
- isDownloading = true;
+
+ isDownloading = true;
files = fileList;
+ for(unsigned i = 0; i < files.size(); i++)
+ {
+ status[files[i].first] = 0;
+ }
DoDownload();
}
void DownloadClient::DoDownload()
{
currentId++;
-
+
if (currentId < (int)files.size())
{
- pair<string, string> file = files[currentId];
+ pair<string, string> file = files[currentId];
+ if (status[file.first] > MAX_DOWNLOAD_ATTEMPTS)
+ {
+ Logger::Warn("Maximum number of %d download retries exceeded. Skipping %s\n",
+ MAX_DOWNLOAD_ATTEMPTS, file.first.c_str());
+ DoDownload();
+ return;
+ }
+
QString filename = QString::fromLocal8Bit(file.first.c_str());
string md5 = file.second;
current = new QFile(filename);
@@ -61,14 +75,16 @@ void DownloadClient::DoDownload()
{
Logger::Info("Can't open file: path isn't available\n");
DoDownload();
+ return;
}
Logger::Info("Downloading file (%d of %u): %s\n", currentId + 1, files.size(), file.first.c_str());
- SendFileRequest(file.first);
+ status[file.first]++;
+ SendFileRequest(file.first);
}
else
{
- Logger::Info("All files have been downloaded.\n");
+ Logger::Info("All files have been downloaded.\n");
isDownloading = false;
emit downloadFinished();
}
@@ -103,15 +119,20 @@ void DownloadClient::FileDataRecieved(SslClient::RequestType &type, QByteArray &
QString md5string = QString::fromLocal8Bit(file.second.c_str());
QString filename = QString::fromLocal8Bit(file.first.c_str());
QByteArray md5 = md5_sum(filename);
- if (md5 == md5string)
- {
+ if (md5 == md5string)
+ {
Logger::Trace("File %s was downloaded correctly!\n", filename.toStdString().c_str());
+ if (QString::compare(filename, QString("client.bin.tmp")) == 0)
+ {
+ Logger::Trace("Copying client.bin.tmp => client.bin.latest\n");
+ current->copy(QString("client.bin.latest"));
+ }
}
else
{
- Logger::Error("File %s was downloaded incorrectly! Removing and trying again!\n", filename.toStdString().c_str());
- current->remove();
- currentId--;
+ Logger::Error("File %s was downloaded incorrectly! Removing and trying again!\n", filename.toStdString().c_str());
+ current->remove();
+ currentId--;
}
// free pointer to the current file
delete current;
diff --git a/client/DownloadClient.h b/client/DownloadClient.h
index 8af8131..3e03718 100644
--- a/client/DownloadClient.h
+++ b/client/DownloadClient.h
@@ -8,6 +8,7 @@
#include <QObject>
#include "SslClient.h"
+using std::map;
using std::pair;
using std::string;
using std::vector;
@@ -55,7 +56,15 @@ signals:
*/
void downloadFinished();
+private slots:
+ void FileDataRecieved(SslClient::RequestType &type, QByteArray &confdata);
+
private:
+ /**
+ * @brief maximum number of retries when downloading files
+ */
+ static const int MAX_DOWNLOAD_ATTEMPTS = 3;
+
/**
* @brief indicates that program is downloading file(s) right now
*/
@@ -71,6 +80,11 @@ private:
*/
int currentId;
+ /**
+ * @brief number of failed download attempt per single file
+ */
+ map<string, int> status;
+
/**
* @brief List of file to
*/
@@ -80,9 +94,6 @@ private:
* @brief start file-by-file downloading process
*/
void DoDownload();
-
-private slots:
- void FileDataRecieved(SslClient::RequestType &type, QByteArray &confdata);
};
#endif
diff --git a/client/Proxifier.cpp b/client/Proxifier.cpp
index c80657f..675e98b 100644
--- a/client/Proxifier.cpp
+++ b/client/Proxifier.cpp
@@ -252,7 +252,7 @@ vector<Proxy> Proxifier::GetActiveProxies()
return result;
}
-bool Proxifier::TurnProxyOn(Proxy& proxy)
+bool Proxifier::TurnProxyOn(Proxy& proxy, bool isStatic)
{
if (!valid)
{
@@ -302,15 +302,13 @@ bool Proxifier::TurnProxyOn(Proxy& proxy)
{
// proxy is not enabled - remove it and add again
RemoveProxyFromChain(proxyId, chainId);
- bool isHttp = (stricmp(proxy.type.c_str(), "http") == 0);
- AddProxyToChain(proxyId, chainId, isHttp);
+ AddProxyToChain(proxyId, chainId, isStatic);
}
}
else
{
// proxy not found in the target chain - add it
- bool isHttp = (stricmp(proxy.type.c_str(), "http") == 0);
- AddProxyToChain(proxyId, chainId, isHttp);
+ AddProxyToChain(proxyId, chainId, isStatic);
}
}
@@ -939,7 +937,7 @@ bool Proxifier::AddChain(string& name, int *id)
return true;
}
-bool Proxifier::AddProxyToChain(int proxyId, int chainId, bool isHttp)
+bool Proxifier::AddProxyToChain(int proxyId, int chainId, bool isStatic)
{
Logger::Trace("Adding proxy to chain in Proxifier config\n");
// read XML DOM structure
@@ -998,14 +996,14 @@ bool Proxifier::AddProxyToChain(int proxyId, int chainId, bool isHttp)
QDomText nameTxt = configDom.createTextNode(idTxt);
proxyElem.appendChild(nameTxt);
// append Http proxies to then end, but prepend other ones
- if (isHttp)
+ if (isStatic)
{
- chainElem.appendChild(proxyElem);
+ chainElem.insertAfter(proxyElem, chainElem.firstChildElement());
}
else
{
// first child is 'Name'
- chainElem.insertAfter(proxyElem, chainElem.firstChildElement());
+ chainElem.appendChild(proxyElem);
}
break;
}
diff --git a/client/Proxifier.h b/client/Proxifier.h
index 712e79c..9806c42 100644
--- a/client/Proxifier.h
+++ b/client/Proxifier.h
@@ -57,7 +57,7 @@ public:
* @note adds specified proxy to Proxifier's Proxy list and in "Client" chain<br/>
* Also adds "Client" chain to "Default" rule if its not there
*/
- bool TurnProxyOn(Proxy& proxy);
+ bool TurnProxyOn(Proxy& proxy, bool isStatic = false);
/**
* @brief turn proxy off
* @param proxy Proxy class that represents particular proxy
@@ -234,7 +234,7 @@ private:
* chainId chain ID to add proxy to
* @return true on success or false otherwise
*/
- bool AddProxyToChain(int proxyId, int chainId, bool isHttp = false);
+ bool AddProxyToChain(int proxyId, int chainId, bool isStatic = false);
/**
* @brief remove proxy from proxy chain
* @param proxyId proxy ID to remove to proxy chain
diff --git a/client/main.cpp b/client/main.cpp
index ce83fcb..b2477cf 100644
--- a/client/main.cpp
+++ b/client/main.cpp
@@ -59,6 +59,12 @@ int main(int argc, char *argv[])
Logger::Error("Can't launch updater to update client app\n");
}
}
+ else
+ {
+ QFile* newClientFile = new QFile(newClient.fileName());
+ newClientFile->remove();
+ delete newClientFile;
+ }
}
// check if initial config exists (config.cfg)
// without it application is useless