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 {
|
2018-11-04 17:47:43 -06:00
|
|
|
desktopfile::DesktopFile getMainDesktopFile(std::vector<std::string>& desktopFilePaths,
|
|
|
|
|
std::vector<desktopfile::DesktopFile>& deployedDesktopFiles);
|
|
|
|
|
|
2018-11-04 15:05:49 -06:00
|
|
|
int deployAppDirRootFiles(std::vector<std::string> desktopFilePaths,
|
|
|
|
|
std::string customAppRunPath, appdir::AppDir& appDir) {
|
2018-11-04 14:59:27 -06:00
|
|
|
// 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")) {
|
2018-11-04 15:05:49 -06:00
|
|
|
if (!customAppRunPath.empty())
|
2018-11-04 14:59:27 -06:00
|
|
|
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 17:47:43 -06:00
|
|
|
try {
|
|
|
|
|
desktopfile::DesktopFile desktopFile = getMainDesktopFile(desktopFilePaths, deployedDesktopFiles);
|
2018-11-04 14:59:27 -06:00
|
|
|
|
2018-11-04 17:47:43 -06:00
|
|
|
ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl;
|
2018-11-04 14:59:27 -06:00
|
|
|
|
2018-11-04 17:47:43 -06:00
|
|
|
bool rv;
|
2018-11-04 14:59:27 -06:00
|
|
|
|
2018-11-04 17:47:43 -06:00
|
|
|
if (!customAppRunPath.empty()) {
|
|
|
|
|
rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath);
|
2018-11-04 14:24:04 -06:00
|
|
|
} else {
|
2018-11-04 17:47:43 -06:00
|
|
|
rv = appDir.createLinksInAppDirRoot(desktopFile);
|
2018-11-04 14:59:27 -06:00
|
|
|
}
|
|
|
|
|
|
2018-11-04 17:47:43 -06:00
|
|
|
if (!rv) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
} catch (const std::runtime_error& er) {
|
|
|
|
|
return -1;
|
2018-11-04 14:24:04 -06:00
|
|
|
}
|
|
|
|
|
}
|
2018-11-04 14:59:27 -06:00
|
|
|
return true;
|
2018-11-04 14:24:04 -06:00
|
|
|
}
|
2018-11-04 17:47:43 -06:00
|
|
|
|
|
|
|
|
desktopfile::DesktopFile getMainDesktopFile(std::vector<std::string>& desktopFilePaths,
|
|
|
|
|
std::vector<desktopfile::DesktopFile>& deployedDesktopFiles) {
|
|
|
|
|
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.empty()) {
|
|
|
|
|
auto firstDeployedDesktopFileName = boost::filesystem::path(
|
|
|
|
|
desktopFilePaths.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;
|
|
|
|
|
throw std::runtime_error("Old desktop file is not reachable.");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
desktopFile = deployedDesktopFiles[0];
|
|
|
|
|
ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:"
|
|
|
|
|
<< desktopFile.path() << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return desktopFile;
|
|
|
|
|
}
|
2018-11-04 14:24:04 -06:00
|
|
|
}
|