Skip to content

Commit

Permalink
find the actual AppImage path if launched from AppImageLauncher's fs
Browse files Browse the repository at this point in the history
  • Loading branch information
antony-jr committed May 27, 2020
1 parent c206956 commit f8eb89d
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/appimageupdateinformation_p.cc
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,45 @@ void AppImageUpdateInformationPrivate::getInfo(void) {

// Check if it's a AppImageLauncher's path, if so then use the map file to
// get the actual appimage path.
bool tryUsingProgramArguments = false;
QRegExp rx(QString::fromUtf8("/run/user/*/appimagelauncherfs/*.AppImage"));
rx.setPatternSyntax(QRegExp::Wildcard);

if(rx.exactMatch(s_AppImagePath)) {
QFileInfo pathInfo(s_AppImagePath);
QString mapPath = pathInfo.absolutePath();
mapPath += QString::fromUtf8("/map");

QString fileID = pathInfo.fileName();

QFile mapFile(mapPath);
if(mapFile.open(QIODevice::ReadOnly | QIODevice::Text)){
while (!mapFile.atEnd()) {
QByteArray line = mapFile.readLine();
QString str(line);
auto parts = str.split(QString::fromUtf8(" -> "));
QString partID = parts.at(0).left(fileID.size());
if(fileID == partID){
// Remove trailling new line
QString parsedPath = parts.at(1).left(parts.at(1).size() - 1);

bc.unlock();
setAppImage(parsedPath);
bc.lock();
break;
}
QCoreApplication::processEvents();
}
mapFile.close();
}else{
tryUsingProgramArguments = true; // Try to parse from QCoreApplication.
}

}

/*
* Lets try getting it from QCoreApplication arguments. */
if(s_AppImagePath.isEmpty() || rx.exactMatch(s_AppImagePath)) {
if(s_AppImagePath.isEmpty() || tryUsingProgramArguments) {
auto arguments = QCoreApplication::arguments();
if(!arguments.isEmpty()) {
bc.unlock();
Expand Down Expand Up @@ -595,8 +628,8 @@ void AppImageUpdateInformationPrivate::getInfo(void) {
auto magicBytes = read(p_AppImage, /*offset=*/8,/*maxchars=*/ 3);
if (magicBytes[0] != 'A' || magicBytes[1] != 'I') {
/*
* If its not an AppImage then lets check if its a linux desktop file , If so then parse the 'Exec'
* to find the actual AppImage.
* If its not an AppImage then lets check if its a linux desktop file,
* If so then parse the 'Exec' to find the actual AppImage.
*/
magicBytes = read(p_AppImage, 0, 15);
if(magicBytes == "[Desktop Entry]") {
Expand Down

0 comments on commit f8eb89d

Please sign in to comment.