keep the ugliness confined in Platform.cpp

This commit is contained in:
Arisotura 2020-05-19 21:34:24 +02:00
parent 34506ff2bb
commit 9df8d91bdc
3 changed files with 53 additions and 46 deletions

View File

@ -24,6 +24,9 @@
namespace Platform
{
void Init(int argc, char** argv);
void DeInit();
void StopEmu();
// fopen() wrappers

View File

@ -53,7 +53,7 @@
#endif
extern char* EmuDirectory;
char* EmuDirectory;
void Stop(bool internal);
@ -84,6 +84,53 @@ u8 PacketBuffer[2048];
#define NIFI_VER 1
void Init(int argc, char** argv)
{
#if defined(__WIN32__) || defined(UNIX_PORTABLE)
if (argc > 0 && strlen(argv[0]) > 0)
{
int len = strlen(argv[0]);
while (len > 0)
{
if (argv[0][len] == '/') break;
if (argv[0][len] == '\\') break;
len--;
}
if (len > 0)
{
EmuDirectory = new char[len+1];
strncpy(EmuDirectory, argv[0], len);
EmuDirectory[len] = '\0';
}
else
{
EmuDirectory = new char[2];
strcpy(EmuDirectory, ".");
}
}
else
{
EmuDirectory = new char[2];
strcpy(EmuDirectory, ".");
}
#else
const char* confdir = g_get_user_config_dir();
const char* confname = "/melonDS";
int cdlen = strlen(confdir);
int cnlen = strlen(confname);
EmuDirectory = new char[cdlen + cnlen + 1];
strncpy(&EmuDirectory[0], confdir, cdlen);
strncpy(&EmuDirectory[cdlen], confname, cnlen);
EmuDirectory[cdlen+cnlen] = '\0';
#endif
}
void DeInit()
{
delete[] EmuDirectory;
}
void StopEmu()
{
//Stop(true);

View File

@ -54,8 +54,6 @@
// TODO: uniform variable spelling
char* EmuDirectory;
bool RunningSomething;
MainWindow* mainWindow;
@ -865,11 +863,6 @@ void MainWindow::onInputConfigFinished(int res)
}
// FIXME!!!!
#if (!defined(__WIN32__) && !defined(UNIX_PORTABLE))
#include <glib.h>
#endif
int main(int argc, char** argv)
{
srand(time(NULL));
@ -877,43 +870,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]);
while (len > 0)
{
if (argv[0][len] == '/') break;
if (argv[0][len] == '\\') break;
len--;
}
if (len > 0)
{
EmuDirectory = new char[len+1];
strncpy(EmuDirectory, argv[0], len);
EmuDirectory[len] = '\0';
}
else
{
EmuDirectory = new char[2];
strcpy(EmuDirectory, ".");
}
}
else
{
EmuDirectory = new char[2];
strcpy(EmuDirectory, ".");
}
#else
const char* confdir = g_get_user_config_dir();
const char* confname = "/melonDS";
int cdlen = strlen(confdir);
int cnlen = strlen(confname);
EmuDirectory = new char[cdlen + cnlen + 1];
strncpy(&EmuDirectory[0], confdir, cdlen);
strncpy(&EmuDirectory[cdlen], confname, cnlen);
EmuDirectory[cdlen+cnlen] = '\0';
#endif
Platform::Init(argc, argv);
QApplication melon(argc, argv);
@ -1060,7 +1017,7 @@ int main(int argc, char** argv)
Config::Save();
SDL_Quit();
delete[] EmuDirectory;
Platform::DeInit();
return ret;
}