PonyPlayer
platform.hpp
浏览该文件的文档.
1//
2// Created by ColorsWind on 2022/5/22.
3//
4
5#pragma once
6
7#include <QtCore>
8#include <QCoreApplication>
9#include <QStandardPaths>
10#include <QDesktopServices>
11
12#ifdef __APPLE__
13#include <CoreFoundation/CFURL.h>
14#include <CoreFoundation/CFString.h>
15#include <CoreFoundation/CFBundle.h>
16#endif
17
18
19namespace PonyPlayer {
20 inline QString getAssetsDir() {
21#ifdef __APPLE__
22 CFURLRef resourcesDirUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
23 CFURLRef resourcesDirAbsoluteUrl = CFURLCopyAbsoluteURL(resourcesDirUrl);
24 CFStringRef macPath = CFURLCopyFileSystemPath(resourcesDirAbsoluteUrl, kCFURLPOSIXPathStyle);
25 QString path = QString::fromCFString(macPath);
26 CFRelease(resourcesDirUrl);
27 CFRelease(resourcesDirAbsoluteUrl);
28 CFRelease(macPath);
29 return path;
30#elif WIN32
31 return QCoreApplication::applicationDirPath().append(u"/assets"_qs);
32#elif defined(__linux__)
33 return QStandardPaths::locate(QStandardPaths::AppDataLocation, "assets", QStandardPaths::LocateDirectory);
34#endif
35 }
36
37 inline void showFileInExplorer(const QString& filePath) {
38#ifdef Q_OS_MAC
39 QStringList arguments;
40 arguments.append("-e");
41 arguments.append("tell application \"Finder\"");
42 arguments.append("-e");
43 arguments.append("activate");
44 arguments.append("select POSIX file \""+ filePath +"\"");
45 arguments.append("-e");
46 arguments.append("end tell");
47 QProcess::startDetached("osascript", arguments);
48#elif defined(Q_OS_WIN32)
49 QStringList arguments;
50 arguments.append("/select,");
51 arguments.append(QDir::toNativeSeparators(filePath));
52 QProcess::startDetached("explorer.exe", arguments);
53#elif defined(Q_OS_LINUX)
54 QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
55#endif
56 }
57}
Definition: audioformat.hpp:155
void showFileInExplorer(const QString &filePath)
Definition: platform.hpp:37
QString getAssetsDir()
Definition: platform.hpp:20