Use Qt abstractions instead of glib's for paths on Linux
This commit is contained in:
parent
9432a9f382
commit
ffe20c1236
|
@ -35,27 +35,9 @@ if (UNIX)
|
||||||
add_definitions(-DUNIX_PORTABLE)
|
add_definitions(-DUNIX_PORTABLE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
|
||||||
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
|
|
||||||
|
|
||||||
target_include_directories(melonDS PRIVATE ${GTK3_INCLUDE_DIRS})
|
|
||||||
target_link_libraries(melonDS ${GTK3_LIBRARIES})
|
|
||||||
|
|
||||||
ADD_DEFINITIONS(${GTK3_CFLAGS_OTHER})
|
|
||||||
|
|
||||||
add_custom_command(OUTPUT melon_grc.c
|
|
||||||
COMMAND glib-compile-resources --sourcedir=${CMAKE_SOURCE_DIR}
|
|
||||||
--target=${CMAKE_CURRENT_BINARY_DIR}/melon_grc.c
|
|
||||||
--generate-source "${CMAKE_SOURCE_DIR}/melon_grc.xml"
|
|
||||||
COMMAND glib-compile-resources --sourcedir=${CMAKE_SOURCE_DIR}
|
|
||||||
--target=${CMAKE_CURRENT_BINARY_DIR}/melon_grc.h
|
|
||||||
--generate-header "${CMAKE_SOURCE_DIR}/melon_grc.xml")
|
|
||||||
|
|
||||||
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||||
target_link_libraries(melonDS dl Qt5::Core Qt5::Gui Qt5::Widgets)
|
target_link_libraries(melonDS dl Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
target_sources(melonDS PUBLIC melon_grc.c)
|
|
||||||
elseif (WIN32)
|
elseif (WIN32)
|
||||||
target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc")
|
target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc")
|
||||||
target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32 Qt5::Core Qt5::Gui Qt5::Widgets)
|
target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32 Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||||
|
|
|
@ -37,7 +37,8 @@
|
||||||
#define socket_t SOCKET
|
#define socket_t SOCKET
|
||||||
#define sockaddr_t SOCKADDR
|
#define sockaddr_t SOCKADDR
|
||||||
#else
|
#else
|
||||||
#include <glib.h>
|
#include <QStandardPaths>
|
||||||
|
#include <QDir>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
@ -139,6 +140,7 @@ FILE* OpenFile(const char* path, const char* mode, bool mustexist)
|
||||||
FILE* OpenLocalFile(const char* path, const char* mode)
|
FILE* OpenLocalFile(const char* path, const char* mode)
|
||||||
{
|
{
|
||||||
std::string fullpath;
|
std::string fullpath;
|
||||||
|
|
||||||
if (path[0] == '/')
|
if (path[0] == '/')
|
||||||
{
|
{
|
||||||
// If it's an absolute path, just open that.
|
// If it's an absolute path, just open that.
|
||||||
|
@ -147,9 +149,10 @@ FILE* OpenLocalFile(const char* path, const char* mode)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Check user configuration directory
|
// Check user configuration directory
|
||||||
std::string confpath = std::string(g_get_user_config_dir()) + "/melonDS/";
|
QString confpath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/melonDS/";
|
||||||
g_mkdir_with_parents(confpath.c_str(), 0755);
|
confpath.append(path);
|
||||||
fullpath = confpath + path;
|
|
||||||
|
fullpath = confpath.toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return OpenFile(fullpath.c_str(), mode, mode[0] != 'w');
|
return OpenFile(fullpath.c_str(), mode, mode[0] != 'w');
|
||||||
|
@ -157,37 +160,27 @@ FILE* OpenLocalFile(const char* path, const char* mode)
|
||||||
|
|
||||||
FILE* OpenDataFile(const char* path)
|
FILE* OpenDataFile(const char* path)
|
||||||
{
|
{
|
||||||
const char* melondir = "melonDS";
|
QString melondir = "melonDS";
|
||||||
const char* const* sys_dirs = g_get_system_data_dirs();
|
QStringList sys_dirs = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
|
||||||
const char* user_dir = g_get_user_data_dir();
|
QString sep = QDir::separator();
|
||||||
|
|
||||||
// First check the user's data directory
|
const char* found = NULL;
|
||||||
char* fullpath = g_build_path("/", user_dir, melondir, path, NULL);
|
|
||||||
if (access(fullpath, R_OK) == 0)
|
|
||||||
{
|
|
||||||
FILE* f = fopen(fullpath, "r");
|
|
||||||
g_free(fullpath);
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
free(fullpath);
|
|
||||||
|
|
||||||
// Then check the system data directories
|
for (int i = 0; i < sys_dirs.size(); i++) {
|
||||||
for (size_t i = 0; sys_dirs[i] != NULL; i++)
|
QString f = sys_dirs.at(i) + sep + melondir + sep + QString(path);
|
||||||
{
|
|
||||||
const char* dir = sys_dirs[i];
|
|
||||||
char* fullpath = g_build_path("/", dir, melondir, path, NULL);
|
|
||||||
|
|
||||||
if (access(fullpath, R_OK) == 0)
|
if (QFile::exists(f)) {
|
||||||
{
|
found = f.toStdString().c_str();
|
||||||
FILE* f = fopen(fullpath, "r");
|
break;
|
||||||
g_free(fullpath);
|
|
||||||
return f;
|
|
||||||
}
|
}
|
||||||
free(fullpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* f = fopen(path, "rb");
|
if (found == NULL)
|
||||||
if (f) return f;
|
return NULL;
|
||||||
|
|
||||||
|
FILE* f = fopen(found, "rb");
|
||||||
|
if (f)
|
||||||
|
return f;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -299,7 +292,7 @@ FILE* OpenLocalFile(const char* path, const char* mode)
|
||||||
{
|
{
|
||||||
// Now check XDG_CONFIG_HOME
|
// Now check XDG_CONFIG_HOME
|
||||||
// TODO: check for memory leak there
|
// TODO: check for memory leak there
|
||||||
std::string fullpath = std::string(g_get_user_config_dir()) + "/melonDS/" + path;
|
std::string fullpath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation).toStdString() + "/melonDS/" + path;
|
||||||
f = OpenFile(fullpath.c_str(), mode, true);
|
f = OpenFile(fullpath.c_str(), mode, true);
|
||||||
if (f) { delete[] emudirpath; return f; }
|
if (f) { delete[] emudirpath; return f; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
@ -824,11 +825,9 @@ int main(int argc, char** argv)
|
||||||
strcpy(EmuDirectory, ".");
|
strcpy(EmuDirectory, ".");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
const char* confdir = g_get_user_config_dir();
|
QString confdir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/melonDS";
|
||||||
const char* confname = "/melonDS";
|
EmuDirectory = new char[confdir.length() + 1];
|
||||||
EmuDirectory = new char[strlen(confdir) + strlen(confname) + 1];
|
strcat(EmuDirectory, confdir.toStdString().c_str());
|
||||||
strcat(EmuDirectory, confdir);
|
|
||||||
strcat(EmuDirectory, confname);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QApplication melon(argc, argv);
|
QApplication melon(argc, argv);
|
||||||
|
|
Loading…
Reference in New Issue