diff options
author | Alex Borisov <borisov.alexandr@rambler.ru> | 2011-12-03 16:25:42 +0200 |
---|---|---|
committer | Alex Borisov <borisov.alexandr@rambler.ru> | 2011-12-03 16:25:42 +0200 |
commit | 5d0b189266cd645dbe79a4ec3c216f07ea768cb1 (patch) | |
tree | 6c5a09ffc4b75e2e9ea3379c818178766dbefec8 /client | |
parent | 0995dea3bba87cdd181fafb70feb2c46b7c17864 (diff) |
FIX app not terminated when config.cfg do not exist
Diffstat (limited to 'client')
-rw-r--r-- | client/ProxyClientApp.cpp | 12 | ||||
-rw-r--r-- | client/main.cpp | 31 |
2 files changed, 30 insertions, 13 deletions
diff --git a/client/ProxyClientApp.cpp b/client/ProxyClientApp.cpp index 4bc5648..f9cbf78 100644 --- a/client/ProxyClientApp.cpp +++ b/client/ProxyClientApp.cpp @@ -11,17 +11,7 @@ using namespace std; ProxyClientApp::ProxyClientApp(int &argc, char *argv[]): QApplication(argc, argv) -{ - // check if initial config exists (config.cfg) - QString configPath = this_app->applicationDirPath()+ "/config.cfg"; - QFileInfo configInfo(configPath); - if (! configInfo.exists()) - { - Logger::Fatal("Initial configuration file (config.cfg) do not exist!\n"); - Logger::Fatal("Terminating!\n"); - return ; - } - +{ /* initiates UpdatedConfig singleton that start sending configuration requests */ UpdatedConfig *cfg = UpdatedConfig::CurrentConfig(); connect(cfg, SIGNAL(updated()), diff --git a/client/main.cpp b/client/main.cpp index 9e85eb4..9fd9c58 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -1,13 +1,40 @@ +#include <stdio.h> /* defines FILENAME_MAX */ +#ifdef WINDOWS + #include <direct.h> + #define GetCurrentDir _getcwd +#else + #include <unistd.h> + #define GetCurrentDir getcwd +#endif +#include <errno.h> + +#include <QString> +#include <QFileInfo> #include "ProxyClientApp.h" #include "client.h" -#include "Dialog.h" ProxyClientApp *this_app; int main(int argc, char *argv[]) { Logger::Info("Starting client application\n"); - this_app = new ProxyClientApp(argc, argv); + char currentPath[FILENAME_MAX]; + if (! GetCurrentDir(currentPath, sizeof(currentPath))) + { + return errno; + } + // check if initial config exists (config.cfg) + // without it application is useless + QString configPath = QString::fromLocal8Bit(currentPath) + "/config.cfg"; + QFileInfo configInfo(configPath); + if (! configInfo.exists()) + { + Logger::Fatal("Initial configuration file (config.cfg) do not exist!\n"); + Logger::Fatal("Terminating!\n"); + return -1; + } + + this_app = new ProxyClientApp(argc, argv); return this_app->exec(); } |