| 1 | /**************************************************************************** |
| 2 | ** SASM - simple IDE for assembler development |
| 3 | ** Copyright (C) 2013 Dmitriy Manushin |
| 4 | ** Contact: site: http://dman95.github.io/SASM/ |
| 5 | ** e-mail: [email protected] |
| 6 | ** |
| 7 | ** This file is part of SASM. |
| 8 | ** |
| 9 | ** SASM is free software: you can redistribute it and/or modify |
| 10 | ** it under the terms of the GNU General Public License as published by |
| 11 | ** the Free Software Foundation, either version 3 of the License, or |
| 12 | ** (at your option) any later version. |
| 13 | ** |
| 14 | ** SASM is distributed in the hope that it will be useful, |
| 15 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | ** GNU General Public License for more details. |
| 18 | ** |
| 19 | ** You should have received a copy of the GNU General Public License |
| 20 | ** along with SASM. If not, see <http://www.gnu.org/licenses/>. |
| 21 | ** |
| 22 | ** Этот файл — часть SASM. |
| 23 | ** |
| 24 | ** SASM - свободная программа: вы можете перераспространять ее и/или |
| 25 | ** изменять ее на условиях Стандартной общественной лицензии GNU в том виде, |
| 26 | ** в каком она была опубликована Фондом свободного программного обеспечения; |
| 27 | ** либо версии 3 лицензии, либо (по вашему выбору) любой более поздней |
| 28 | ** версии. |
| 29 | ** |
| 30 | ** SASM распространяется в надежде, что она будет полезной, |
| 31 | ** но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА |
| 32 | ** или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Стандартной |
| 33 | ** общественной лицензии GNU. |
| 34 | ** |
| 35 | ** Вы должны были получить копию Стандартной общественной лицензии GNU |
| 36 | ** вместе с этой программой. Если это не так, см. |
| 37 | ** <http://www.gnu.org/licenses/>.) |
| 38 | ** |
| 39 | ****************************************************************************/ |
| 40 | |
| 41 | #include "common.h" |
| 42 | |
| 43 | /** |
| 44 | * @file common.cpp |
| 45 | * Contains common functions. |
| 46 | */ |
| 47 | |
| 48 | QString Common::applicationDataPath() |
| 49 | { |
| 50 | #ifdef Q_OS_WIN32 |
| 51 | QString appDir = QCoreApplication::applicationDirPath(); |
| 52 | if (! QFile::exists(appDir + "/NASM")) { |
| 53 | appDir = QCoreApplication::applicationDirPath() + "/Windows"; |
| 54 | } |
| 55 | if (! QFile::exists(appDir + "/NASM")) { |
| 56 | appDir = QCoreApplication::applicationDirPath(); |
| 57 | } |
| 58 | return appDir; |
| 59 | #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined( __NetBSD__) || defined(__DragonFly__) |
| 60 | QString path = QCoreApplication::applicationDirPath(); |
| 61 | QString appDir = path.left(path.length() - 4) + QString("/share/sasm"); //replace /bin with /share/sasm |
| 62 | if (! QFile::exists(appDir)) { |
| 63 | appDir = QCoreApplication::applicationDirPath() + "/share/sasm"; |
| 64 | } |
| 65 | if (! QFile::exists(appDir)) { |
| 66 | appDir = QCoreApplication::applicationDirPath() + "/BSD/share/sasm"; |
| 67 | } |
| 68 | return appDir; |
| 69 | #else |
| 70 | QString path = QCoreApplication::applicationDirPath(); |
| 71 | QString appDir = path.left(path.length() - 4) + QString("/share/sasm"); //replace /bin with /share/sasm |
| 72 | if (! QFile::exists(appDir)) { |
| 73 | appDir = QCoreApplication::applicationDirPath() + "/share/sasm"; |
| 74 | } |
| 75 | if (! QFile::exists(appDir)) { |
| 76 | appDir = QCoreApplication::applicationDirPath() + "/Linux/share/sasm"; |
| 77 | } |
| 78 | return appDir; |
| 79 | #endif |
| 80 | } |
| 81 | |
| 82 | QString Common::pathInTemp(QString path) |
| 83 | { |
| 84 | #ifdef Q_OS_WIN32 |
| 85 | QString temp = qgetenv("PROGRAMDATA"); |
| 86 | #else |
| 87 | QString temp = QDir::tempPath(); |
| 88 | #endif |
| 89 | QChar lastSymbol = temp[temp.length() - 1]; |
| 90 | if (lastSymbol == QChar('/') || lastSymbol == QChar('\\')) { |
| 91 | temp.chop(1); |
| 92 | } |
| 93 | if (! QFile::exists(temp + "/SASM")) { |
| 94 | QDir().mkpath(temp + "/SASM"); |
| 95 | } |
| 96 | QString tempPath = temp + "/SASM"; |
| 97 | if (!path.isEmpty()) { |
| 98 | tempPath += "/" + path; |
| 99 | } |
| 100 | tempPath = QDir::toNativeSeparators(tempPath); |
| 101 | return tempPath; |
| 102 | } |