MCPcopy Create free account
hub / github.com/TheAssassin/AppImageLauncher / integrateAppImage

Function integrateAppImage

src/shared/shared.cpp:880–946  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

878}
879
880IntegrationState integrateAppImage(const QString& pathToAppImage, const QString& pathToIntegratedAppImage) {
881 // need std::strings to get working pointers with .c_str()
882 const auto oldPath = pathToAppImage.toStdString();
883 const auto newPath = pathToIntegratedAppImage.toStdString();
884
885 // create target directory
886 QDir().mkdir(QFileInfo(QFile(pathToIntegratedAppImage)).dir().absolutePath());
887
888 // check whether AppImage is in integration directory already
889 if (QFileInfo(pathToAppImage).absoluteFilePath() != QFileInfo(pathToIntegratedAppImage).absoluteFilePath()) {
890 // need to check whether file exists
891 // if it does, the existing AppImage needs to be removed before rename can be called
892 if (QFile(pathToIntegratedAppImage).exists()) {
893 std::ostringstream message;
894 message << QObject::tr("AppImage with same filename has already been integrated.").toStdString() << std::endl
895 << std::endl
896 << QObject::tr("Do you wish to overwrite the existing AppImage?").toStdString() << std::endl
897 << QObject::tr("Choosing No will run the AppImage once, and leave the system in its current state.").toStdString();
898
899 auto* messageBox = new QMessageBox(
900 QMessageBox::Warning,
901 QObject::tr("Warning"),
902 QString::fromStdString(message.str()),
903 QMessageBox::Yes | QMessageBox::No
904 );
905
906 messageBox->setDefaultButton(QMessageBox::No);
907 messageBox->show();
908
909 QApplication::exec();
910
911 if (messageBox->clickedButton() == messageBox->button(QMessageBox::No)) {
912 return INTEGRATION_ABORTED;
913 }
914
915 QFile(pathToIntegratedAppImage).remove();
916 }
917
918 if (!QFile(pathToAppImage).rename(pathToIntegratedAppImage)) {
919 auto* messageBox = new QMessageBox(
920 QMessageBox::Critical,
921 QObject::tr("Error"),
922 QObject::tr("Failed to move AppImage to target location.\n"
923 "Try to copy AppImage instead?"),
924 QMessageBox::Ok | QMessageBox::Cancel
925 );
926
927 messageBox->setDefaultButton(QMessageBox::Ok);
928 messageBox->show();
929
930 QApplication::exec();
931
932 if (messageBox->clickedButton() == messageBox->button(QMessageBox::Cancel))
933 return INTEGRATION_FAILED;
934
935 if (!QFile(pathToAppImage).copy(pathToIntegratedAppImage)) {
936 displayError("Failed to copy AppImage to target location");
937 return INTEGRATION_FAILED;

Callers 1

mainFunction · 0.85

Calls 2

displayErrorFunction · 0.85

Tested by

no test coverage detected