MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / createShortcut

Function createShortcut

launcher/FileSystem.cpp:919–1144  ·  view source on GitHub ↗

Cross-platform Shortcut creation

Source from the content-addressed store, hash-verified

917
918// Cross-platform Shortcut creation
919bool createShortcut(QString destination, QString target, QStringList args, QString name, QString icon)
920{
921 if (destination.isEmpty()) {
922 destination = PathCombine(getDesktopDir(), RemoveInvalidFilenameChars(name));
923 }
924 if (!ensureFilePathExists(destination)) {
925 qWarning() << "Destination path can't be created!";
926 return false;
927 }
928#if defined(Q_OS_MACOS)
929 // Create the Application
930 QDir applicationDirectory =
931 QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/" + BuildConfig.LAUNCHER_NAME + " Instances/";
932
933 if (!applicationDirectory.mkpath(".")) {
934 qWarning() << "Couldn't create application directory";
935 return false;
936 }
937
938 QDir application = applicationDirectory.path() + "/" + name + ".app/";
939
940 if (application.exists()) {
941 qWarning() << "Application already exists!";
942 return false;
943 }
944
945 if (!application.mkpath(".")) {
946 qWarning() << "Couldn't create application";
947 return false;
948 }
949
950 QDir content = application.path() + "/Contents/";
951 QDir resources = content.path() + "/Resources/";
952 QDir binaryDir = content.path() + "/MacOS/";
953 QFile info = content.path() + "/Info.plist";
954
955 if (!(content.mkpath(".") && resources.mkpath(".") && binaryDir.mkpath("."))) {
956 qWarning() << "Couldn't create directories within application";
957 return false;
958 }
959 info.open(QIODevice::WriteOnly | QIODevice::Text);
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 f.open(QIODevice::WriteOnly | QIODevice::Text);
968 QTextStream stream(&f);
969
970 QString argstring;
971 if (!args.empty())
972 argstring = " \"" + args.join("\" \"") + "\"";
973
974 stream << "#!/bin/bash" << "\n";
975 stream << "\"" << target << "\" " << argstring << "\n";
976

Calls 15

PathCombineFunction · 0.85
getDesktopDirFunction · 0.85
ensureFilePathExistsFunction · 0.85
QFileClass · 0.85
existsMethod · 0.80
openMethod · 0.80
closeMethod · 0.80
appendMethod · 0.80
isEmptyMethod · 0.45
pathMethod · 0.45
renameMethod · 0.45

Tested by

no test coverage detected