summaryrefslogtreecommitdiff
path: root/client/Config.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'client/Config.cpp')
-rw-r--r--client/Config.cpp52
1 files changed, 24 insertions, 28 deletions
diff --git a/client/Config.cpp b/client/Config.cpp
index e6174c1..6b1d4f9 100644
--- a/client/Config.cpp
+++ b/client/Config.cpp
@@ -21,15 +21,15 @@ Config::Config(): StaticProxySpeedLow(50)
return;
}
- string config = "";
- const int str_size = 512;
- char str[str_size] = {0};
- while (!configFile.eof())
- {
- configFile.read(str, str_size);
- config += str;
- }
- ParseConfig(str);
+ configFile.seekg (0, ios::end);
+ int length = configFile.tellg();
+ configFile.seekg (0, ios::beg);
+ char *buffer = new char [length];
+ configFile.read (buffer, length);
+ configFile.close();
+ string config = buffer;
+ ParseConfig(config);
+ delete[] buffer;
}
void Config::AcquireConfig()
@@ -274,24 +274,22 @@ void Config::ReadGenericProxy()
string filname = QCoreApplication::applicationDirPath().toStdString() +
"/config/proxy_list.cfg";
- ifstream proxyFile(filname.c_str(), std::ios::in);
+ ifstream proxyFile(filname.c_str(), std::ios::binary | std::ios::in);
if (! proxyFile)
{
Logger::Error("Can't open file %s\n", filname.c_str());
return;
}
- string proxies = "";
- const int str_size = 512;
- char str[str_size] = {0};
- while (!proxyFile.eof())
- {
- proxyFile.read(str, str_size);
- proxies += str;
- }
+ proxyFile.seekg (0, ios::end);
+ int length = proxyFile.tellg();
+ proxyFile.seekg (0, ios::beg);
+ char *buffer = new char [length];
+ proxyFile.read (buffer, length);
proxyFile.close();
-
+ string proxies = buffer;
ParseGenericProxies(proxies);
+ delete[] buffer;
}
/**
@@ -310,17 +308,15 @@ void Config::ReadStaticProxy()
return;
}
- string proxies = "";
- const int str_size = 512;
- char str[str_size] = {0};
- while (!proxyFile.eof())
- {
- proxyFile.read(str, str_size);
- proxies += str;
- }
+ proxyFile.seekg (0, ios::end);
+ int length = proxyFile.tellg();
+ proxyFile.seekg (0, ios::beg);
+ char *buffer = new char [length];
+ proxyFile.read (buffer, length);
proxyFile.close();
-
+ string proxies = buffer;
ParseStaticPorxies(proxies);
+ delete[] buffer;
}