From 7af658f0897c6d6ad1f67b9d7a9bc60955c029a0 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 4 Dec 2019 22:46:33 +0100 Subject: Add a UNIX_PORTABLE build option, turning it off makes a build of melonDS suitable for systemwide installation. --- src/NDSCart.cpp | 2 +- src/Platform.h | 8 +++++- src/libui_sdl/CMakeLists.txt | 8 ++++++ src/libui_sdl/Platform.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++ src/libui_sdl/main.cpp | 32 +++++++++++++++++----- 5 files changed, 106 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index 0ecd304..5654a7d 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -815,7 +815,7 @@ bool ReadROMParams(u32 gamecode, u32* params) // [gamecode] [ROM size] [save type] [reserved] // list must be sorted by gamecode - FILE* f = Platform::OpenLocalFile("romlist.bin", "rb"); + FILE* f = Platform::OpenDataFile("romlist.bin"); if (!f) return false; fseek(f, 0, SEEK_END); diff --git a/src/Platform.h b/src/Platform.h index ca6971e..dfe83d0 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -32,15 +32,21 @@ void StopEmu(); // can be optionally restricted to only opening a file that already exists. // * OpenLocalFile(): // opens files local to the emulator (melonDS.ini, BIOS, firmware, ...) -// checks, by order of priority: +// For Windows builds, or portable UNIX builds it checks, by order of priority: // * current working directory // * emulator directory (essentially where the melonDS executable is) if supported // * any platform-specific application data directories // in create mode, if the file doesn't exist, it will be created in the emulator // directory if supported, or in the current directory otherwise +// For regular UNIX builds, the user's configuration directory is always used. +// * OpenDataFile(): +// Opens a file that was installed alongside melonDS on UNIX systems in /usr/share, etc. +// Looks in the user's data directory first, then the system's. +// If on Windows or a portable UNIX build, this simply calls OpenLocalFile(). FILE* OpenFile(const char* path, const char* mode, bool mustexist=false); FILE* OpenLocalFile(const char* path, const char* mode); +FILE* OpenDataFile(const char* path); inline bool FileExists(const char* name) { diff --git a/src/libui_sdl/CMakeLists.txt b/src/libui_sdl/CMakeLists.txt index 64206bf..afd38e4 100644 --- a/src/libui_sdl/CMakeLists.txt +++ b/src/libui_sdl/CMakeLists.txt @@ -31,6 +31,11 @@ target_link_libraries(melonDS core ${SDL2_LIBRARIES} libui) if (UNIX) + option(UNIX_PORTABLE "Make a portable build that looks for its configuration in the current directory" ON) + if (UNIX_PORTABLE) + add_definitions(-DUNIX_PORTABLE) + endif() + find_package(PkgConfig REQUIRED) pkg_check_modules(GTK3 REQUIRED gtk+-3.0) pkg_check_modules(SDL2 REQUIRED sdl2) @@ -61,4 +66,7 @@ elseif (WIN32) target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi) endif () +install(FILES ../../melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) +install(FILES ../../icon/melon_256x256.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps) +install(FILES ../../romlist.bin DESTINATION ${CMAKE_INSTALL_PREFIX}/share/melonds) install(TARGETS melonDS RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp index 94b3791..5cbf344 100644 --- a/src/libui_sdl/Platform.cpp +++ b/src/libui_sdl/Platform.cpp @@ -135,6 +135,63 @@ FILE* OpenFile(const char* path, const char* mode, bool mustexist) return ret; } +#if !defined(UNIX_PORTABLE) && !defined(__WIN32__) + +FILE* OpenLocalFile(const char* path, const char* mode) +{ + std::string fullpath; + if (path[0] == '/') + { + // If it's an absolute path, just open that. + fullpath = std::string(path); + } + else + { + // Check user configuration directory + std::string confpath = std::string(g_get_user_config_dir()) + "/melonds/"; + g_mkdir_with_parents(confpath.c_str(), 0755); + fullpath = confpath + path; + } + + return OpenFile(fullpath.c_str(), mode, mode[0] != 'w'); +} + +FILE* OpenDataFile(const char* path) +{ + const char* melondir = "melonds"; + const char* const* sys_dirs = g_get_system_data_dirs(); + const char* user_dir = g_get_user_data_dir(); + + // First check the user's data directory + 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 (size_t i = 0; sys_dirs[i] != NULL; i++) + { + const char* dir = sys_dirs[i]; + char* fullpath = g_build_path("/", dir, melondir, path, NULL); + + if (access(fullpath, R_OK) == 0) + { + FILE* f = fopen(fullpath, "r"); + g_free(fullpath); + return f; + } + free(fullpath); + } + + return NULL; +} + +#else + FILE* OpenLocalFile(const char* path, const char* mode) { bool relpath = false; @@ -257,6 +314,13 @@ FILE* OpenLocalFile(const char* path, const char* mode) return NULL; } +FILE* OpenDataFile(const char* path) +{ + return OpenLocalFile(path, "r"); +} + +#endif + void* Thread_Create(void (*func)()) { diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index d6aa460..40b7079 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -21,6 +21,10 @@ #include #include +#ifndef __WIN32__ +#include +#endif + #include #include "libui/ui.h" @@ -2589,6 +2593,7 @@ int main(int argc, char** argv) printf("melonDS " MELONDS_VERSION "\n"); printf(MELONDS_URL "\n"); +#if defined(__WIN32__) || defined(UNIX_PORTABLE) if (argc > 0 && strlen(argv[0]) > 0) { int len = strlen(argv[0]); @@ -2615,6 +2620,13 @@ int main(int argc, char** argv) EmuDirectory = new char[2]; strcpy(EmuDirectory, "."); } +#else + const char* confdir = g_get_user_config_dir(); + const char* confname = "/melonds"; + EmuDirectory = new char[strlen(confdir) + strlen(confname) + 1]; + strcat(EmuDirectory, confdir); + strcat(EmuDirectory, confname); +#endif // http://stackoverflow.com/questions/14543333/joystick-wont-work-using-sdl SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); @@ -2650,15 +2662,23 @@ int main(int argc, char** argv) !Platform::LocalFileExists("bios9.bin") || !Platform::LocalFileExists("firmware.bin")) { - uiMsgBoxError( - NULL, - "BIOS/Firmware not found", +#if defined(__WIN32__) || defined(UNIX_PORTABLE) + const char* locationName = "the directory you run melonDS from"; +#else + char* locationName = EmuDirectory; +#endif + char msgboxtext[512]; + sprintf(msgboxtext, "One or more of the following required files don't exist or couldn't be accessed:\n\n" "bios7.bin -- ARM7 BIOS\n" "bios9.bin -- ARM9 BIOS\n" "firmware.bin -- firmware image\n\n" - "Dump the files from your DS and place them in the directory you run melonDS from.\n" - "Make sure that the files can be accessed."); + "Dump the files from your DS and place them in %s.\n" + "Make sure that the files can be accessed.", + locationName + ); + + uiMsgBoxError(NULL, "BIOS/Firmware not found", msgboxtext); uiUninit(); SDL_Quit(); @@ -2704,7 +2724,7 @@ int main(int argc, char** argv) } } { - FILE* f = Platform::OpenLocalFile("romlist.bin", "rb"); + FILE* f = Platform::OpenDataFile("romlist.bin"); if (f) { u32 data; -- cgit v1.2.3 From 959c37ead74968ef3bf8b66f852307f6e9fb10e3 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 4 Dec 2019 22:54:30 +0100 Subject: Open with rb instead of r in OpenDataFile to avoid potential problems with Windows. --- src/libui_sdl/Platform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp index 5cbf344..8942927 100644 --- a/src/libui_sdl/Platform.cpp +++ b/src/libui_sdl/Platform.cpp @@ -316,7 +316,7 @@ FILE* OpenLocalFile(const char* path, const char* mode) FILE* OpenDataFile(const char* path) { - return OpenLocalFile(path, "r"); + return OpenLocalFile(path, "rb"); } #endif -- cgit v1.2.3 From 4f87707cda26f9c6a7a70ad46232eefebc5a4d82 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Thu, 5 Dec 2019 00:11:52 +0100 Subject: If all else fails, look for data files (romlist.bin) in the current working direcoty. --- src/libui_sdl/Platform.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp index 8942927..8b83a01 100644 --- a/src/libui_sdl/Platform.cpp +++ b/src/libui_sdl/Platform.cpp @@ -186,6 +186,9 @@ FILE* OpenDataFile(const char* path) } free(fullpath); } + + FILE* f = fopen(path, "rb"); + if (f) return f; return NULL; } -- cgit v1.2.3 From 03f33fa5c3a47f17c3783ce045fc2f761ed11290 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Thu, 5 Dec 2019 00:12:40 +0100 Subject: Make UNIX builds non-portable by default. --- src/libui_sdl/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/libui_sdl/CMakeLists.txt b/src/libui_sdl/CMakeLists.txt index afd38e4..ae270e4 100644 --- a/src/libui_sdl/CMakeLists.txt +++ b/src/libui_sdl/CMakeLists.txt @@ -31,7 +31,7 @@ target_link_libraries(melonDS core ${SDL2_LIBRARIES} libui) if (UNIX) - option(UNIX_PORTABLE "Make a portable build that looks for its configuration in the current directory" ON) + option(UNIX_PORTABLE "Make a portable build that looks for its configuration in the current directory" OFF) if (UNIX_PORTABLE) add_definitions(-DUNIX_PORTABLE) endif() -- cgit v1.2.3 From 23bca8c17a3a630721e61079daf729ee1e5ed65f Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Thu, 5 Dec 2019 00:40:59 +0100 Subject: Tell the user where to place romlist.bin if it can't be found for UNIX non-portable builds. --- src/libui_sdl/main.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 40b7079..c7a4401 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -2724,6 +2724,17 @@ int main(int argc, char** argv) } } { + const char* romlist_missing = "Save memory type detection will not work correctly.\n\n" + "You should use the latest version of romlist.bin (provided in melonDS release packages)."; +#if !defined(UNIX_PORTABLE) && !defined(__WIN32__) + std::string missingstr = std::string(romlist_missing) + + "\n\nThe ROM list should be placed in " + g_get_user_data_dir() + "/melonds/, otherwise " + "melonDS will search for it in the current working directory."; + const char* romlist_missing_text = missingstr.c_str(); +#else + const char* romlist_missing_text = romlist_missing; +#endif + FILE* f = Platform::OpenDataFile("romlist.bin"); if (f) { @@ -2733,18 +2744,12 @@ int main(int argc, char** argv) if ((data >> 24) == 0) // old CRC-based list { - uiMsgBoxError(NULL, - "Your version of romlist.bin is outdated.", - "Save memory type detection will not work correctly.\n\n" - "You should use the latest version of romlist.bin (provided in melonDS release packages)."); + uiMsgBoxError(NULL, "Your version of romlist.bin is outdated.", romlist_missing_text); } } else { - uiMsgBoxError(NULL, - "romlist.bin not found.", - "Save memory type detection will not work correctly.\n\n" - "You should use the latest version of romlist.bin (provided in melonDS release packages)."); + uiMsgBoxError(NULL, "romlist.bin not found.", romlist_missing_text); } } -- cgit v1.2.3 From 43535c873ac1b4ce80212b052b0455a1eaaa0208 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Thu, 19 Dec 2019 02:48:11 +0100 Subject: Remove redundant desktop file and change desktop/icon file name to net.kuribo64.melonDS, also change melonds to melonDS. --- flatpak/net.kuribo64.melonDS.yml | 29 +++++++++++++++++++++++++++++ flatpak/net.kuribo64.melonds.desktop | 8 -------- flatpak/net.kuribo64.melonds.yml | 31 ------------------------------- melonDS.desktop | 11 ----------- net.kuribo64.melonDS.desktop | 11 +++++++++++ src/libui_sdl/CMakeLists.txt | 4 ++-- 6 files changed, 42 insertions(+), 52 deletions(-) create mode 100644 flatpak/net.kuribo64.melonDS.yml delete mode 100644 flatpak/net.kuribo64.melonds.desktop delete mode 100644 flatpak/net.kuribo64.melonds.yml delete mode 100644 melonDS.desktop create mode 100644 net.kuribo64.melonDS.desktop (limited to 'src') diff --git a/flatpak/net.kuribo64.melonDS.yml b/flatpak/net.kuribo64.melonDS.yml new file mode 100644 index 0000000..e336990 --- /dev/null +++ b/flatpak/net.kuribo64.melonDS.yml @@ -0,0 +1,29 @@ +--- +app-id: net.kuribo64.melonDS +runtime: org.freedesktop.Platform +runtime-version: '18.08' +sdk: org.freedesktop.Sdk +command: melonDS +finish-args: + - "--share=ipc" + - "--socket=x11" + - "--socket=pulseaudio" + - "--share=network" + - "--device=all" + - "--filesystem=home" +modules: + - name: libpcap + sources: + - type: archive + url: http://www.tcpdump.org/release/libpcap-1.9.0.tar.gz + sha256: 2edb88808e5913fdaa8e9c1fcaf272e19b2485338742b5074b9fe44d68f37019 + + - name: melonds + buildsystem: cmake-ninja + sources: + - type: git + url: https://github.com/Arisotura/melonDS.git + branch: master + post-install: + - "desktop-file-install --dir=/app/share/applications net.kuribo64.melonDS.desktop" + - "install -D icon/melon_256x256.png /app/share/icons/hicolor/256x256/apps/net.kuribo64.melonDS.png" diff --git a/flatpak/net.kuribo64.melonds.desktop b/flatpak/net.kuribo64.melonds.desktop deleted file mode 100644 index e91f10d..0000000 --- a/flatpak/net.kuribo64.melonds.desktop +++ /dev/null @@ -1,8 +0,0 @@ -[Desktop Entry] -Name=melonDS -Comment=Nintendo DS emulator -Exec=melonDS -Type=Application -Categories=Game; -Terminal=false -Icon=net.kuribo64.melonds diff --git a/flatpak/net.kuribo64.melonds.yml b/flatpak/net.kuribo64.melonds.yml deleted file mode 100644 index dcc97b5..0000000 --- a/flatpak/net.kuribo64.melonds.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- -app-id: net.kuribo64.melonds -runtime: org.freedesktop.Platform -runtime-version: '18.08' -sdk: org.freedesktop.Sdk -command: melonDS -finish-args: - - "--share=ipc" - - "--socket=x11" - - "--socket=pulseaudio" - - "--share=network" - - "--device=all" - - "--filesystem=home" -modules: - - name: libpcap - sources: - - type: archive - url: http://www.tcpdump.org/release/libpcap-1.9.0.tar.gz - sha256: 2edb88808e5913fdaa8e9c1fcaf272e19b2485338742b5074b9fe44d68f37019 - - - name: melonds - buildsystem: cmake-ninja - sources: - - type: git - url: https://github.com/StapleButter/melonDS.git - commit: d4d4965b2fffc69958685a25a9d9fc0c78b54567 - - type: file - path: net.kuribo64.melonds.desktop - post-install: - - "desktop-file-install --dir=/app/share/applications net.kuribo64.melonds.desktop" - - "install -D icon/melon_256x256.png /app/share/icons/hicolor/256x256/apps/net.kuribo64.melonds.png" diff --git a/melonDS.desktop b/melonDS.desktop deleted file mode 100644 index 3dd921c..0000000 --- a/melonDS.desktop +++ /dev/null @@ -1,11 +0,0 @@ -[Desktop Entry] -Name=melonDS -GenericName=Nintendo DS Emulator -Comment=A fast and accurate Nintendo DS emulator. -Exec=melonDS -Type=Application -Categories=Game;Emulator; -Terminal=false -Icon=melon_256x256 -MimeType=application/x-nintendo-ds-rom; -Keywords=emulator;Nintendo;DS;NDS;Nintendo DS; diff --git a/net.kuribo64.melonDS.desktop b/net.kuribo64.melonDS.desktop new file mode 100644 index 0000000..c0dafe2 --- /dev/null +++ b/net.kuribo64.melonDS.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Name=melonDS +GenericName=Nintendo DS Emulator +Comment=A fast and accurate Nintendo DS emulator. +Exec=melonDS +Type=Application +Categories=Game;Emulator; +Terminal=false +Icon=net.kuribo64.melonDS +MimeType=application/x-nintendo-ds-rom; +Keywords=emulator;Nintendo;DS;NDS;Nintendo DS; diff --git a/src/libui_sdl/CMakeLists.txt b/src/libui_sdl/CMakeLists.txt index ae270e4..8c3d042 100644 --- a/src/libui_sdl/CMakeLists.txt +++ b/src/libui_sdl/CMakeLists.txt @@ -66,7 +66,7 @@ elseif (WIN32) target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi) endif () -install(FILES ../../melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) -install(FILES ../../icon/melon_256x256.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps) +install(FILES ../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) +install(FILES ../../icon/melon_256x256.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps RENAME net.kuribo64.melonDS.png) install(FILES ../../romlist.bin DESTINATION ${CMAKE_INSTALL_PREFIX}/share/melonds) install(TARGETS melonDS RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) -- cgit v1.2.3 From c5623c4dcd122278e45a363b655be67d845ecf63 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Thu, 19 Dec 2019 02:52:34 +0100 Subject: Change the config/data dirs from "melonds" to "melonDS" for consistency. --- src/libui_sdl/CMakeLists.txt | 2 +- src/libui_sdl/Platform.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/libui_sdl/CMakeLists.txt b/src/libui_sdl/CMakeLists.txt index 8c3d042..2d384e4 100644 --- a/src/libui_sdl/CMakeLists.txt +++ b/src/libui_sdl/CMakeLists.txt @@ -68,5 +68,5 @@ endif () install(FILES ../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) install(FILES ../../icon/melon_256x256.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps RENAME net.kuribo64.melonDS.png) -install(FILES ../../romlist.bin DESTINATION ${CMAKE_INSTALL_PREFIX}/share/melonds) +install(FILES ../../romlist.bin DESTINATION ${CMAKE_INSTALL_PREFIX}/share/melonDS) install(TARGETS melonDS RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp index 8b83a01..cc1b734 100644 --- a/src/libui_sdl/Platform.cpp +++ b/src/libui_sdl/Platform.cpp @@ -148,7 +148,7 @@ FILE* OpenLocalFile(const char* path, const char* mode) else { // Check user configuration directory - std::string confpath = std::string(g_get_user_config_dir()) + "/melonds/"; + std::string confpath = std::string(g_get_user_config_dir()) + "/melonDS/"; g_mkdir_with_parents(confpath.c_str(), 0755); fullpath = confpath + path; } @@ -158,7 +158,7 @@ FILE* OpenLocalFile(const char* path, const char* mode) FILE* OpenDataFile(const char* path) { - const char* melondir = "melonds"; + const char* melondir = "melonDS"; const char* const* sys_dirs = g_get_system_data_dirs(); const char* user_dir = g_get_user_data_dir(); @@ -238,7 +238,7 @@ FILE* OpenLocalFile(const char* path, const char* mode) emudirpath[pathlen] = '\0'; } - // Locations are application directory, and AppData/melonDS on Windows or XDG_CONFIG_HOME/melonds on Linux + // Locations are application directory, and AppData/melonDS on Windows or XDG_CONFIG_HOME/melonDS on Linux FILE* f; @@ -300,7 +300,7 @@ FILE* OpenLocalFile(const char* path, const char* mode) { // Now check XDG_CONFIG_HOME // TODO: check for memory leak there - std::string fullpath = std::string(g_get_user_config_dir()) + "/melonds/" + path; + std::string fullpath = std::string(g_get_user_config_dir()) + "/melonDS/" + path; f = OpenFile(fullpath.c_str(), mode, true); if (f) { delete[] emudirpath; return f; } } -- cgit v1.2.3