Cross-platform Shortcut creation
| 923 | |
| 924 | // Cross-platform Shortcut creation |
| 925 | QString createShortcut(QString destination, QString target, QStringList args, QString name, QString icon) |
| 926 | { |
| 927 | if (destination.isEmpty()) { |
| 928 | destination = PathCombine(getDesktopDir(), RemoveInvalidFilenameChars(name)); |
| 929 | } |
| 930 | if (!ensureFilePathExists(destination)) { |
| 931 | qWarning() << "Destination path can't be created!"; |
| 932 | return QString(); |
| 933 | } |
| 934 | #if defined(Q_OS_MACOS) |
| 935 | QDir application = destination + ".app/"; |
| 936 | |
| 937 | if (application.exists()) { |
| 938 | qWarning() << "Application already exists!"; |
| 939 | return QString(); |
| 940 | } |
| 941 | |
| 942 | if (!application.mkpath(".")) { |
| 943 | qWarning() << "Couldn't create application"; |
| 944 | return QString(); |
| 945 | } |
| 946 | |
| 947 | QDir content = application.path() + "/Contents/"; |
| 948 | QDir resources = content.path() + "/Resources/"; |
| 949 | QDir binaryDir = content.path() + "/MacOS/"; |
| 950 | QFile info(content.path() + "/Info.plist"); |
| 951 | |
| 952 | if (!(content.mkpath(".") && resources.mkpath(".") && binaryDir.mkpath("."))) { |
| 953 | qWarning() << "Couldn't create directories within application"; |
| 954 | return QString(); |
| 955 | } |
| 956 | if (!info.open(QIODevice::WriteOnly | QIODevice::Text)) { |
| 957 | qWarning() << "Failed to open file" << info.fileName() << "for writing:" << info.errorString(); |
| 958 | return QString(); |
| 959 | } |
| 960 | |
| 961 | QFile(icon).rename(resources.path() + "/Icon.icns"); |
| 962 | |
| 963 | // Create the Command file |
| 964 | QString exec = binaryDir.path() + "/Run.command"; |
| 965 | |
| 966 | QFile f(exec); |
| 967 | if (!f.open(QIODevice::WriteOnly | QIODevice::Text)) { |
| 968 | qWarning() << "Failed to open file" << f.fileName() << "for writing:" << f.errorString(); |
| 969 | return QString(); |
| 970 | } |
| 971 | QTextStream stream(&f); |
| 972 | |
| 973 | auto argstring = quoteArgs(args, "\"", "\\\""); |
| 974 | |
| 975 | stream << "#!/bin/bash" << "\n"; |
| 976 | stream << "\"" << target << "\" " << argstring << "\n"; |
| 977 | |
| 978 | stream.flush(); |
| 979 | f.close(); |
| 980 | |
| 981 | f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup | QFileDevice::ExeOther); |
| 982 |
no test coverage detected