2019-11-29 13:40:00 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file appimage.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 29 11, 2019
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentina project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2019 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2019-11-29 13:40:00 +01:00
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
#include "appimage.h"
|
|
|
|
|
2020-07-13 15:11:57 +02:00
|
|
|
#include <QCoreApplication>
|
2024-02-10 14:53:02 +01:00
|
|
|
#include <QString>
|
2020-07-13 15:11:57 +02:00
|
|
|
#include <QVector>
|
2024-02-10 14:53:02 +01:00
|
|
|
#include <unicode/putil.h>
|
2019-11-29 13:40:00 +01:00
|
|
|
|
2024-02-10 14:53:02 +01:00
|
|
|
#include "compatibility.h"
|
|
|
|
#include "def.h"
|
2019-11-29 13:40:00 +01:00
|
|
|
|
2024-02-10 14:53:02 +01:00
|
|
|
using namespace Qt::Literals::StringLiterals;
|
2020-07-13 15:11:57 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief AppImageRoot returns path to AppImage root folder. Because after mount path to /usr folder looks like
|
|
|
|
* /tmp/.mount_valentXwmbwE/usr, the root part must be extracted to fix all paths when application is in AppImage
|
|
|
|
* format.
|
|
|
|
*
|
|
|
|
* Function we return empty if expected path is not compatible with current application directory path.
|
|
|
|
* @return path to AppImage root folder
|
|
|
|
*/
|
|
|
|
QString AppImageRoot()
|
|
|
|
{
|
|
|
|
return AppImageRoot(QCoreApplication::applicationDirPath(), QString(BINDIR));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString AppImageRoot(const QString &applicationDir, const QString &defaultAppDir)
|
|
|
|
{
|
|
|
|
QStringList appSub = SplitFilePaths(applicationDir);
|
|
|
|
QStringList defaultSub = SplitFilePaths(defaultAppDir);
|
|
|
|
|
|
|
|
if (appSub.isEmpty() || defaultSub.isEmpty() || appSub.size() <= defaultSub.size())
|
|
|
|
{
|
2024-02-10 14:53:02 +01:00
|
|
|
return {};
|
2020-07-13 15:11:57 +02:00
|
|
|
}
|
|
|
|
|
2020-07-13 15:28:13 +02:00
|
|
|
appSub = Reverse(appSub);
|
|
|
|
defaultSub = Reverse(defaultSub);
|
2020-07-13 15:11:57 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < defaultSub.size(); ++i)
|
|
|
|
{
|
|
|
|
if (defaultSub.at(i) != appSub.at(i))
|
|
|
|
{
|
2024-02-10 14:53:02 +01:00
|
|
|
return {};
|
2020-07-13 15:11:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList rootSub = appSub.mid(defaultSub.size());
|
2020-07-13 15:28:13 +02:00
|
|
|
rootSub = Reverse(rootSub);
|
2020-07-13 15:11:57 +02:00
|
|
|
|
2024-02-10 14:53:02 +01:00
|
|
|
return '/'_L1 + rootSub.join('/');
|
2020-07-13 15:11:57 +02:00
|
|
|
}
|