1 /**********************************************************************************************
2    Copyright (C) 2015 Ivo Kronenberg <>
3 
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 
17 **********************************************************************************************/
18 
19 #include "config.h"
20 #include "CAppSetupWin.h"
21 #include "version.h"
22 
23 
initQMapShack()24 void CAppSetupWin::initQMapShack()
25 {
26     // setup environment variables for GDAL/Proj4
27     QString apppath = QCoreApplication::applicationDirPath();
28     apppath = apppath.replace("/", "\\");
29     QString gdalDir = QString("%1\\data").arg(apppath);
30     QString projDir = QString("%1\\share\\proj").arg(apppath);
31 
32     qunsetenv("GDAL_DRIVER_PATH");
33     IAppSetup::prepareGdal(gdalDir, projDir);
34 
35     QString appResourceDir = QString("%1\\translations").arg(apppath).toUtf8();
36     prepareTranslator(appResourceDir, "qtbase_");
37     prepareTranslator(appResourceDir, "qmapshack_");
38 
39     // limit PATH to application directory in order to avoid that wrong .dll's are loaded
40     path = apppath.toUtf8();
41     qputenv("PATH", path);
42 
43     // create directories
44     IAppSetup::path(defaultCachePath(), 0, true, "CACHE");
45     IAppSetup::path(userDataPath("WaypointIcons"), 0, true, "USER DATA");
46     IAppSetup::path(logDir(), 0, true, "LOG");
47 }
48 
49 
routinoPath(QString xmlFile)50 QString CAppSetupWin::routinoPath(QString xmlFile)
51 {
52     QString apppath = QCoreApplication::applicationDirPath();
53     apppath = apppath.replace("/", "\\");
54     QDir dirXml(QString("%1\\routino-xml").arg(apppath).toUtf8());
55     return IAppSetup::path(dirXml.absolutePath(), xmlFile, false, "ROUTINO");
56 }
57 
58 
defaultCachePath()59 QString CAppSetupWin::defaultCachePath()
60 {
61     return IAppSetup::path(QDir::home().absolutePath(), ".QMapShack/", false, 0);
62 }
63 
64 
userDataPath(QString subdir)65 QString CAppSetupWin::userDataPath(QString subdir)
66 {
67     QString path = QDir::home().absoluteFilePath(CONFIGDIR);
68     return IAppSetup::path(path, subdir, false, 0);
69 }
70 
71 
logDir()72 QString CAppSetupWin::logDir()
73 {
74     return QDir::temp().absolutePath();
75 }
76 
findExecutable(const QString & name)77 QString CAppSetupWin::findExecutable(const QString& name)
78 {
79     return QStandardPaths::findExecutable(name);
80 }
81 
helpFile()82 QString CAppSetupWin::helpFile()
83 {
84     QDir dirApp(QCoreApplication::applicationDirPath());
85     QDir dirHelp(dirApp.absoluteFilePath(_MKSTR(HELPPATH)));
86     return dirHelp.absoluteFilePath("QMSHelp.qhc");
87 }
88 
89