Merge pull request #546 from nadiaholmquist/feature/unix-xdg

Make melonDS properly installable systemwide on UNIX systems
This commit is contained in:
Arisotura
2020-01-28 21:37:36 +01:00
committed by GitHub
8 changed files with 140 additions and 33 deletions

View File

@ -21,6 +21,10 @@
#include <stdio.h>
#include <string.h>
#ifndef __WIN32__
#include <glib.h>
#endif
#include <SDL2/SDL.h>
#include "libui/ui.h"
@ -2681,6 +2685,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]);
@ -2707,6 +2712,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");
@ -2742,15 +2754,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();
@ -2796,7 +2816,18 @@ int main(int argc, char** argv)
}
}
{
FILE* f = Platform::OpenLocalFile("romlist.bin", "rb");
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)
{
u32 data;
@ -2805,18 +2836,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);
}
}