2018-11-04 14:24:04 -06:00
|
|
|
#include <iostream>
|
|
|
|
|
#include <boost/filesystem/path.hpp>
|
|
|
|
|
|
|
|
|
|
#include <linuxdeploy/core/appdir.h>
|
|
|
|
|
#include <linuxdeploy/core/log.h>
|
|
|
|
|
#include <linuxdeploy/util/util.h>
|
|
|
|
|
|
|
|
|
|
#include "linuxdeploy.h"
|
|
|
|
|
|
|
|
|
|
using namespace linuxdeploy::core;
|
|
|
|
|
|
|
|
|
|
using namespace linuxdeploy::core::log;
|
|
|
|
|
using namespace linuxdeploy::util;
|
|
|
|
|
namespace bf = boost::filesystem;
|
|
|
|
|
|
2018-11-04 14:59:27 -06:00
|
|
|
namespace linuxdeploy {
|
|
|
|
|
int deployAppDirRootFiles(args::ValueFlagList<std::string>& desktopFilePaths,
|
|
|
|
|
args::ValueFlag<std::string>& customAppRunPath, appdir::AppDir& appDir) {
|
|
|
|
|
// search for desktop file and deploy it to AppDir root
|
|
|
|
|
ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl;
|
2018-11-04 14:24:04 -06:00
|
|
|
|
2018-11-04 14:59:27 -06:00
|
|
|
if (is_regular_file(appDir.path() / "AppRun")) {
|
|
|
|
|
if (customAppRunPath)
|
|
|
|
|
ldLog() << LD_WARNING << "AppRun exists but custom AppRun specified, overwriting existing AppRun"
|
|
|
|
|
<< std::endl;
|
|
|
|
|
else
|
|
|
|
|
ldLog() << LD_WARNING << "AppRun exists, skipping deployment" << std::endl;
|
2018-11-04 14:24:04 -06:00
|
|
|
} else {
|
2018-11-04 14:59:27 -06:00
|
|
|
auto deployedDesktopFiles = appDir.deployedDesktopFiles();
|
2018-11-04 14:24:04 -06:00
|
|
|
|
2018-11-04 14:59:27 -06:00
|
|
|
desktopfile::DesktopFile desktopFile;
|
|
|
|
|
|
|
|
|
|
if (deployedDesktopFiles.empty()) {
|
|
|
|
|
ldLog() << LD_WARNING
|
|
|
|
|
<< "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root"
|
|
|
|
|
<< std::endl;
|
|
|
|
|
} else {
|
|
|
|
|
if (!desktopFilePaths.Get().empty()) {
|
|
|
|
|
auto firstDeployedDesktopFileName = boost::filesystem::path(
|
|
|
|
|
desktopFilePaths.Get().front()).filename().string();
|
|
|
|
|
|
|
|
|
|
auto desktopFileMatchingName = find_if(
|
|
|
|
|
deployedDesktopFiles.begin(),
|
|
|
|
|
deployedDesktopFiles.end(),
|
|
|
|
|
[&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) {
|
|
|
|
|
auto fileName = desktopFile.path().filename().string();
|
|
|
|
|
return fileName == firstDeployedDesktopFileName;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (desktopFileMatchingName != deployedDesktopFiles.end()) {
|
|
|
|
|
desktopFile = *desktopFileMatchingName;
|
|
|
|
|
} else {
|
|
|
|
|
ldLog() << LD_ERROR << "Could not find desktop file deployed earlier any more:"
|
|
|
|
|
<< firstDeployedDesktopFileName << std::endl;
|
|
|
|
|
return 1;
|
2018-11-04 14:24:04 -06:00
|
|
|
}
|
|
|
|
|
} else {
|
2018-11-04 14:59:27 -06:00
|
|
|
desktopFile = deployedDesktopFiles[0];
|
|
|
|
|
ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:"
|
|
|
|
|
<< desktopFile.path() << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl;
|
|
|
|
|
|
|
|
|
|
bool rv;
|
|
|
|
|
|
|
|
|
|
if (customAppRunPath) {
|
|
|
|
|
rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath.Get());
|
|
|
|
|
} else {
|
|
|
|
|
rv = appDir.createLinksInAppDirRoot(desktopFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!rv) {
|
2018-11-04 14:24:04 -06:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-04 14:59:27 -06:00
|
|
|
return true;
|
2018-11-04 14:24:04 -06:00
|
|
|
}
|
|
|
|
|
}
|