VPTissue Reference Manual
InstallDirs.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "InstallDirs.h"
21 
22 #include <string>
23 #include <sstream>
24 #include <QDir>
25 #include <QFileInfo>
26 #include <QString>
27 #include <QApplication>
28 
29 using namespace std;
30 
31 namespace SimShell {
32 
33 std::string InstallDirs::g_data_dir;
34 std::string InstallDirs::g_root_dir;
35 std::string InstallDirs::g_workspace_dir;
36 bool InstallDirs::g_initialized = false;
37 
38 
39 inline void InstallDirs::Check()
40 {
41  if (!g_initialized) {
42  Initialize();
43  }
44 }
45 
46 void InstallDirs::Initialize()
47 {
48  //------- Retrieving Install Root Path
49  {
50  QDir dir(QApplication::applicationDirPath());
51 
52  #if defined(__APPLE__)
53  if (dir.dirName() == "MacOS") {
54  // app
55  // -Contents <-Root Path
56  // -MacOS
57  // -binaries
58  dir.cdUp();
59  } else
60  #endif
61  if (dir.dirName().toLower() == "debug" || dir.dirName().toLower() == "release") {
62  //x/exec <-Root Path
63  // -bin
64  // -release/debug
65  // -binaries
66  dir.cdUp();
67  dir.cdUp();
68  } else
69  #if defined(__WIN32__)
70  if (dir.dirName() != "bin") {
71  // Do Nothing, binaries in root folder
72  } else
73  #endif
74  {
75  //x/exec <-Root Path
76  // -bin
77  // -binaries
78  dir.cdUp();
79  }
80 
81  const bool exists = dir.exists();
82  const string path = dir.absolutePath().toStdString();
83  g_root_dir = (exists) ? dir.absolutePath().toStdString() : "";
84  }
85  //------- Retrieving Data Dir
86  {
87  QDir dir(QString::fromStdString(g_root_dir));
88  const bool exists = dir.cd("data");
89  g_data_dir = (exists) ? dir.absolutePath().toStdString() : "";
90  }
91  //------- Retrieving Workspace
92  {
93  QDir dir(QString::fromStdString(g_data_dir));
94  const bool exists = dir.cd("simPT_Default_workspace");
95  const string path = dir.absolutePath().toStdString();
96  g_workspace_dir = (exists) ? dir.absolutePath().toStdString() : "";
97  }
98 
99  g_initialized = true;
100 }
101 
102 string InstallDirs::GetDataDir()
103 {
104  Check();
105  return g_data_dir;
106 }
107 
108 string InstallDirs::GetRootDir()
109 {
110  Check();
111  return g_root_dir;
112 }
113 
114 string InstallDirs::GetWorkspaceDir()
115 {
116  Check();
117  return g_workspace_dir;
118 }
119 
120 } // namespace
121 
122 
STL namespace.
Namespace for generic graphical shell for simulators.
Definition: SimSession.h:32
Interface for FileSys.