Power System Platform  2026w11a-beta
Loading...
Searching...
No Matches
Path.cpp
1/*
2 * Copyright (C) 2026 Thales Lima Oliveira <thales@ufu.br>
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 2 of the License, or
7 * 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 <https://www.gnu.org/licenses/>.
16 */
17
18#include "Path.h"
19
20#include <wx/stdpaths.h>
21#include <wx/filename.h>
22#include <wx/dir.h>
23#include <wx/msgdlg.h>
24
25wxString Paths::GetExecutablePath()
26{
27 return wxStandardPaths::Get().GetExecutablePath();
28}
29
30wxString Paths::GetExecutableDir()
31{
32 wxFileName exe(wxStandardPaths::Get().GetExecutablePath());
33 return exe.GetPath();
34}
35
36wxString Paths::GetDataPath()
37{
38 wxFileName exe(wxStandardPaths::Get().GetExecutablePath());
39
40 // 1. Installed layout (bin/../share/psp-ufu/data)
41 wxString installData = exe.GetPath() + "/../share/psp-ufu/data";
42
43 wxFileName fnInstall(installData);
44 fnInstall.Normalize(wxPATH_NORM_DOTS);
45
46 if (wxDirExists(fnInstall.GetFullPath()))
47 return fnInstall.GetFullPath();
48
49 // 2. macOS / AppImage resources
50 wxString resources = wxStandardPaths::Get().GetResourcesDir() + "/data";
51
52 if (wxDirExists(resources))
53 return resources;
54
55 // 3. Standard Linux install (/usr/share/psp-ufu/data)
56 wxString dataDir = wxStandardPaths::Get().GetDataDir() + "/data";
57
58 if (wxDirExists(dataDir))
59 return dataDir;
60
61 // 4. Portable layout (Windows or development build)
62 wxString portable = exe.GetPath() + "/../data";
63
64 wxFileName fn(portable);
65 fn.Normalize(wxPATH_NORM_DOTS);
66
67 if (wxDirExists(fn.GetFullPath()))
68 return fn.GetFullPath();
69
70 wxMessageDialog msgDialog(nullptr,
71 _("Data directory not found."),
72 _("Error"),
73 wxOK | wxCENTRE | wxICON_ERROR);
74
75 msgDialog.ShowModal();
76
77 return "";
78}
79
80wxString Paths::GetDocumentsPath()
81{
82 return wxStandardPaths::Get().GetDocumentsDir();
83}