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"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unicode/putil.h>
|
2020-07-13 15:11:57 +02:00
|
|
|
#include <QString>
|
|
|
|
#include <QCoreApplication>
|
2019-11-29 13:40:00 +01:00
|
|
|
#include <cstring>
|
2020-07-13 15:11:57 +02:00
|
|
|
#include <QVector>
|
2019-11-29 13:40:00 +01:00
|
|
|
extern "C" {
|
|
|
|
#include "binreloc.h"
|
|
|
|
}
|
2020-07-13 15:11:57 +02:00
|
|
|
#include "../vmisc/def.h"
|
|
|
|
#include "compatibility.h"
|
2019-11-29 13:40:00 +01:00
|
|
|
|
2020-07-13 15:11:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-11-29 13:40:00 +01:00
|
|
|
/* When deploying with AppImage based on OpenSuse, the ICU library has a hardcoded path to the icudt*.dat file.
|
|
|
|
* This prevents the library from using shared in memory data. There are few ways to resolve this issue. According
|
|
|
|
* to documentation we can either use ICU_DATA environment variable or the function u_setDataDirectory().
|
|
|
|
*/
|
|
|
|
char* IcuDataPath(const char* correction)
|
|
|
|
{
|
|
|
|
char * data_path = nullptr;
|
|
|
|
BrInitError error;
|
|
|
|
if (br_init (&error))
|
|
|
|
{
|
|
|
|
char *path = br_find_exe_dir(nullptr);
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
data_path = static_cast<char *> (malloc(strlen(path) + strlen(correction) + 1));
|
|
|
|
if(data_path)
|
|
|
|
{
|
|
|
|
strcpy(data_path, path);
|
|
|
|
strcat(data_path, correction);
|
|
|
|
u_setDataDirectory(data_path);
|
|
|
|
}
|
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data_path;
|
|
|
|
}
|
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())
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
return '/' + rootSub.join('/');
|
|
|
|
}
|