mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-24 14:49:53 -06:00
move emuDirectory to main.cpp, and make it a QString. remove more Platform shit.
This commit is contained in:
@ -31,14 +31,6 @@ class Firmware;
|
|||||||
namespace Platform
|
namespace Platform
|
||||||
{
|
{
|
||||||
|
|
||||||
void Init(int argc, char** argv);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Frees all resources that were allocated in \c Init
|
|
||||||
* or by any other \c Platform function.
|
|
||||||
*/
|
|
||||||
void DeInit();
|
|
||||||
|
|
||||||
enum StopReason {
|
enum StopReason {
|
||||||
/**
|
/**
|
||||||
* The emulator stopped for some unspecified reason.
|
* The emulator stopped for some unspecified reason.
|
||||||
|
@ -32,8 +32,6 @@
|
|||||||
using namespace melonDS;
|
using namespace melonDS;
|
||||||
AudioSettingsDialog* AudioSettingsDialog::currentDlg = nullptr;
|
AudioSettingsDialog* AudioSettingsDialog::currentDlg = nullptr;
|
||||||
|
|
||||||
extern std::string EmuDirectory;
|
|
||||||
|
|
||||||
|
|
||||||
AudioSettingsDialog::AudioSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::AudioSettingsDialog)
|
AudioSettingsDialog::AudioSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::AudioSettingsDialog)
|
||||||
{
|
{
|
||||||
@ -262,7 +260,7 @@ void AudioSettingsDialog::on_btnMicWavBrowse_clicked()
|
|||||||
{
|
{
|
||||||
QString file = QFileDialog::getOpenFileName(this,
|
QString file = QFileDialog::getOpenFileName(this,
|
||||||
"Select WAV file...",
|
"Select WAV file...",
|
||||||
QString::fromStdString(EmuDirectory),
|
emuDirectory,
|
||||||
"WAV files (*.wav);;Any file (*.*)");
|
"WAV files (*.wav);;Any file (*.*)");
|
||||||
|
|
||||||
if (file.isEmpty()) return;
|
if (file.isEmpty()) return;
|
||||||
|
@ -31,8 +31,6 @@ using namespace melonDS;
|
|||||||
|
|
||||||
CameraSettingsDialog* CameraSettingsDialog::currentDlg = nullptr;
|
CameraSettingsDialog* CameraSettingsDialog::currentDlg = nullptr;
|
||||||
|
|
||||||
extern std::string EmuDirectory;
|
|
||||||
|
|
||||||
extern CameraManager* camManager[2];
|
extern CameraManager* camManager[2];
|
||||||
|
|
||||||
|
|
||||||
@ -253,7 +251,7 @@ void CameraSettingsDialog::on_btnSrcImageBrowse_clicked()
|
|||||||
{
|
{
|
||||||
QString file = QFileDialog::getOpenFileName(this,
|
QString file = QFileDialog::getOpenFileName(this,
|
||||||
"Select image file...",
|
"Select image file...",
|
||||||
QString::fromStdString(EmuDirectory),
|
emuDirectory,
|
||||||
"Image files (*.png *.jpg *.jpeg *.bmp);;Any file (*.*)");
|
"Image files (*.png *.jpg *.jpeg *.bmp);;Any file (*.*)");
|
||||||
|
|
||||||
if (file.isEmpty()) return;
|
if (file.isEmpty()) return;
|
||||||
|
@ -35,8 +35,6 @@ using Platform::LogLevel;
|
|||||||
|
|
||||||
CheatsDialog* CheatsDialog::currentDlg = nullptr;
|
CheatsDialog* CheatsDialog::currentDlg = nullptr;
|
||||||
|
|
||||||
extern std::string EmuDirectory;
|
|
||||||
|
|
||||||
|
|
||||||
CheatsDialog::CheatsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::CheatsDialog)
|
CheatsDialog::CheatsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::CheatsDialog)
|
||||||
{
|
{
|
||||||
|
@ -34,7 +34,6 @@ namespace Platform = melonDS::Platform;
|
|||||||
|
|
||||||
PathSettingsDialog* PathSettingsDialog::currentDlg = nullptr;
|
PathSettingsDialog* PathSettingsDialog::currentDlg = nullptr;
|
||||||
|
|
||||||
extern std::string EmuDirectory;
|
|
||||||
extern bool RunningSomething;
|
extern bool RunningSomething;
|
||||||
|
|
||||||
bool PathSettingsDialog::needsReset = false;
|
bool PathSettingsDialog::needsReset = false;
|
||||||
@ -124,7 +123,7 @@ void PathSettingsDialog::on_btnSaveFileBrowse_clicked()
|
|||||||
{
|
{
|
||||||
QString dir = QFileDialog::getExistingDirectory(this,
|
QString dir = QFileDialog::getExistingDirectory(this,
|
||||||
"Select save files path...",
|
"Select save files path...",
|
||||||
QString::fromStdString(EmuDirectory));
|
emuDirectory);
|
||||||
|
|
||||||
if (dir.isEmpty()) return;
|
if (dir.isEmpty()) return;
|
||||||
|
|
||||||
@ -141,7 +140,7 @@ void PathSettingsDialog::on_btnSavestateBrowse_clicked()
|
|||||||
{
|
{
|
||||||
QString dir = QFileDialog::getExistingDirectory(this,
|
QString dir = QFileDialog::getExistingDirectory(this,
|
||||||
"Select savestates path...",
|
"Select savestates path...",
|
||||||
QString::fromStdString(EmuDirectory));
|
emuDirectory);
|
||||||
|
|
||||||
if (dir.isEmpty()) return;
|
if (dir.isEmpty()) return;
|
||||||
|
|
||||||
@ -158,7 +157,7 @@ void PathSettingsDialog::on_btnCheatFileBrowse_clicked()
|
|||||||
{
|
{
|
||||||
QString dir = QFileDialog::getExistingDirectory(this,
|
QString dir = QFileDialog::getExistingDirectory(this,
|
||||||
"Select cheat files path...",
|
"Select cheat files path...",
|
||||||
QString::fromStdString(EmuDirectory));
|
emuDirectory);
|
||||||
|
|
||||||
if (dir.isEmpty()) return;
|
if (dir.isEmpty()) return;
|
||||||
|
|
||||||
|
@ -48,8 +48,6 @@
|
|||||||
#define ftell _ftelli64
|
#define ftell _ftelli64
|
||||||
#endif // __WIN32__
|
#endif // __WIN32__
|
||||||
|
|
||||||
std::string EmuDirectory;
|
|
||||||
|
|
||||||
extern CameraManager* camManager[2];
|
extern CameraManager* camManager[2];
|
||||||
|
|
||||||
// REMOVE ME
|
// REMOVE ME
|
||||||
@ -65,124 +63,6 @@ void emuStop();
|
|||||||
namespace melonDS::Platform
|
namespace melonDS::Platform
|
||||||
{
|
{
|
||||||
|
|
||||||
void PathInit(int argc, char** argv)
|
|
||||||
{
|
|
||||||
// First, check for the portable directory next to the executable.
|
|
||||||
QString appdirpath = QCoreApplication::applicationDirPath();
|
|
||||||
QString portablepath = appdirpath + QDir::separator() + "portable";
|
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
// On Apple platforms we may need to navigate outside an app bundle.
|
|
||||||
// The executable directory would be "melonDS.app/Contents/MacOS", so we need to go a total of three steps up.
|
|
||||||
QDir bundledir(appdirpath);
|
|
||||||
if (bundledir.cd("..") && bundledir.cd("..") && bundledir.dirName().endsWith(".app") && bundledir.cd(".."))
|
|
||||||
{
|
|
||||||
portablepath = bundledir.absolutePath() + QDir::separator() + "portable";
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QDir portabledir(portablepath);
|
|
||||||
if (portabledir.exists())
|
|
||||||
{
|
|
||||||
EmuDirectory = portabledir.absolutePath().toStdString();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// If no overrides are specified, use the default path.
|
|
||||||
#if defined(__WIN32__) && defined(WIN32_PORTABLE)
|
|
||||||
EmuDirectory = appdirpath.toStdString();
|
|
||||||
#else
|
|
||||||
QString confdir;
|
|
||||||
QDir config(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
|
|
||||||
config.mkdir("melonDS");
|
|
||||||
confdir = config.absolutePath() + QDir::separator() + "melonDS";
|
|
||||||
EmuDirectory = confdir.toStdString();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QSharedMemory* IPCBuffer = nullptr;
|
|
||||||
int IPCInstanceID;
|
|
||||||
|
|
||||||
void IPCInit()
|
|
||||||
{
|
|
||||||
IPCInstanceID = 0;
|
|
||||||
|
|
||||||
IPCBuffer = new QSharedMemory("melonIPC");
|
|
||||||
|
|
||||||
#if !defined(Q_OS_WINDOWS)
|
|
||||||
// QSharedMemory instances can be left over from crashed processes on UNIX platforms.
|
|
||||||
// To prevent melonDS thinking there's another instance, we attach and then immediately detach from the
|
|
||||||
// shared memory. If no other process was actually using it, it'll be destroyed and we'll have a clean
|
|
||||||
// shared memory buffer after creating it again below.
|
|
||||||
if (IPCBuffer->attach())
|
|
||||||
{
|
|
||||||
IPCBuffer->detach();
|
|
||||||
delete IPCBuffer;
|
|
||||||
IPCBuffer = new QSharedMemory("melonIPC");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!IPCBuffer->attach())
|
|
||||||
{
|
|
||||||
Log(LogLevel::Info, "IPC sharedmem doesn't exist. creating\n");
|
|
||||||
if (!IPCBuffer->create(1024))
|
|
||||||
{
|
|
||||||
Log(LogLevel::Error, "IPC sharedmem create failed: %s\n", IPCBuffer->errorString().toStdString().c_str());
|
|
||||||
delete IPCBuffer;
|
|
||||||
IPCBuffer = nullptr;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
IPCBuffer->lock();
|
|
||||||
memset(IPCBuffer->data(), 0, IPCBuffer->size());
|
|
||||||
IPCBuffer->unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
IPCBuffer->lock();
|
|
||||||
u8* data = (u8*)IPCBuffer->data();
|
|
||||||
u16 mask = *(u16*)&data[0];
|
|
||||||
for (int i = 0; i < 16; i++)
|
|
||||||
{
|
|
||||||
if (!(mask & (1<<i)))
|
|
||||||
{
|
|
||||||
IPCInstanceID = i;
|
|
||||||
*(u16*)&data[0] |= (1<<i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IPCBuffer->unlock();
|
|
||||||
|
|
||||||
Log(LogLevel::Info, "IPC: instance ID %d\n", IPCInstanceID);
|
|
||||||
}
|
|
||||||
|
|
||||||
void IPCDeInit()
|
|
||||||
{
|
|
||||||
if (IPCBuffer)
|
|
||||||
{
|
|
||||||
IPCBuffer->lock();
|
|
||||||
u8* data = (u8*)IPCBuffer->data();
|
|
||||||
*(u16*)&data[0] &= ~(1<<IPCInstanceID);
|
|
||||||
IPCBuffer->unlock();
|
|
||||||
|
|
||||||
IPCBuffer->detach();
|
|
||||||
delete IPCBuffer;
|
|
||||||
}
|
|
||||||
IPCBuffer = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Init(int argc, char** argv)
|
|
||||||
{
|
|
||||||
PathInit(argc, argv);
|
|
||||||
IPCInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeInit()
|
|
||||||
{
|
|
||||||
IPCDeInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SignalStop(StopReason reason)
|
void SignalStop(StopReason reason)
|
||||||
{
|
{
|
||||||
emuStop();
|
emuStop();
|
||||||
@ -309,7 +189,7 @@ std::string GetLocalFilePath(const std::string& filename)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fullpath = QString::fromStdString(EmuDirectory) + QDir::separator() + qpath;
|
fullpath = emuDirectory + QDir::separator() + qpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fullpath.toStdString();
|
return fullpath.toStdString();
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "EmuInstance.h"
|
#include "main.h"
|
||||||
#include "DSi_NAND.h"
|
#include "DSi_NAND.h"
|
||||||
|
|
||||||
#include "TitleManagerDialog.h"
|
#include "TitleManagerDialog.h"
|
||||||
@ -36,8 +36,6 @@ using namespace melonDS::Platform;
|
|||||||
std::unique_ptr<DSi_NAND::NANDImage> TitleManagerDialog::nand = nullptr;
|
std::unique_ptr<DSi_NAND::NANDImage> TitleManagerDialog::nand = nullptr;
|
||||||
TitleManagerDialog* TitleManagerDialog::currentDlg = nullptr;
|
TitleManagerDialog* TitleManagerDialog::currentDlg = nullptr;
|
||||||
|
|
||||||
extern std::string EmuDirectory;
|
|
||||||
|
|
||||||
|
|
||||||
TitleManagerDialog::TitleManagerDialog(QWidget* parent, DSi_NAND::NANDImage& image) : QDialog(parent), ui(new Ui::TitleManagerDialog), nandmount(image)
|
TitleManagerDialog::TitleManagerDialog(QWidget* parent, DSi_NAND::NANDImage& image) : QDialog(parent), ui(new Ui::TitleManagerDialog), nandmount(image)
|
||||||
{
|
{
|
||||||
@ -300,7 +298,7 @@ void TitleManagerDialog::onImportTitleData()
|
|||||||
|
|
||||||
QString file = QFileDialog::getOpenFileName(this,
|
QString file = QFileDialog::getOpenFileName(this,
|
||||||
"Select file to import...",
|
"Select file to import...",
|
||||||
QString::fromStdString(EmuDirectory),
|
emuDirectory,
|
||||||
"Title data files (" + extensions + ");;Any file (*.*)");
|
"Title data files (" + extensions + ");;Any file (*.*)");
|
||||||
|
|
||||||
if (file.isEmpty()) return;
|
if (file.isEmpty()) return;
|
||||||
@ -374,7 +372,7 @@ void TitleManagerDialog::onExportTitleData()
|
|||||||
|
|
||||||
QString file = QFileDialog::getSaveFileName(this,
|
QString file = QFileDialog::getSaveFileName(this,
|
||||||
"Select path to export to...",
|
"Select path to export to...",
|
||||||
QString::fromStdString(EmuDirectory) + exportname,
|
emuDirectory + exportname,
|
||||||
"Title data files (" + extensions + ");;Any file (*.*)");
|
"Title data files (" + extensions + ");;Any file (*.*)");
|
||||||
|
|
||||||
if (file.isEmpty()) return;
|
if (file.isEmpty()) return;
|
||||||
@ -547,7 +545,7 @@ void TitleImportDialog::on_btnAppBrowse_clicked()
|
|||||||
{
|
{
|
||||||
QString file = QFileDialog::getOpenFileName(this,
|
QString file = QFileDialog::getOpenFileName(this,
|
||||||
"Select title executable...",
|
"Select title executable...",
|
||||||
QString::fromStdString(EmuDirectory),
|
emuDirectory,
|
||||||
"DSiWare executables (*.app *.nds *.dsi *.srl);;Any file (*.*)");
|
"DSiWare executables (*.app *.nds *.dsi *.srl);;Any file (*.*)");
|
||||||
|
|
||||||
if (file.isEmpty()) return;
|
if (file.isEmpty()) return;
|
||||||
@ -559,7 +557,7 @@ void TitleImportDialog::on_btnTmdBrowse_clicked()
|
|||||||
{
|
{
|
||||||
QString file = QFileDialog::getOpenFileName(this,
|
QString file = QFileDialog::getOpenFileName(this,
|
||||||
"Select title metadata...",
|
"Select title metadata...",
|
||||||
QString::fromStdString(EmuDirectory),
|
emuDirectory,
|
||||||
"DSiWare metadata (*.tmd);;Any file (*.*)");
|
"DSiWare metadata (*.tmd);;Any file (*.*)");
|
||||||
|
|
||||||
if (file.isEmpty()) return;
|
if (file.isEmpty()) return;
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
|
#include <QStandardPaths>
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QSocketNotifier>
|
#include <QSocketNotifier>
|
||||||
@ -128,6 +129,7 @@ QStringList ArchiveExtensions
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QString emuDirectory;
|
||||||
|
|
||||||
bool RunningSomething;
|
bool RunningSomething;
|
||||||
|
|
||||||
@ -215,6 +217,41 @@ static bool FileIsSupportedFiletype(const QString& filename, bool insideArchive
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void pathInit()
|
||||||
|
{
|
||||||
|
// First, check for the portable directory next to the executable.
|
||||||
|
QString appdirpath = QCoreApplication::applicationDirPath();
|
||||||
|
QString portablepath = appdirpath + QDir::separator() + "portable";
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
// On Apple platforms we may need to navigate outside an app bundle.
|
||||||
|
// The executable directory would be "melonDS.app/Contents/MacOS", so we need to go a total of three steps up.
|
||||||
|
QDir bundledir(appdirpath);
|
||||||
|
if (bundledir.cd("..") && bundledir.cd("..") && bundledir.dirName().endsWith(".app") && bundledir.cd(".."))
|
||||||
|
{
|
||||||
|
portablepath = bundledir.absolutePath() + QDir::separator() + "portable";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QDir portabledir(portablepath);
|
||||||
|
if (portabledir.exists())
|
||||||
|
{
|
||||||
|
emuDirectory = portabledir.absolutePath();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If no overrides are specified, use the default path.
|
||||||
|
#if defined(__WIN32__) && defined(WIN32_PORTABLE)
|
||||||
|
emuDirectory = appdirpath;
|
||||||
|
#else
|
||||||
|
QString confdir;
|
||||||
|
QDir config(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
|
||||||
|
config.mkdir("melonDS");
|
||||||
|
confdir = config.absolutePath() + QDir::separator() + "melonDS";
|
||||||
|
emuDirectory = confdir;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void emuStop()
|
void emuStop()
|
||||||
@ -269,8 +306,7 @@ int main(int argc, char** argv)
|
|||||||
printf("did you just call me a derp???\n");
|
printf("did you just call me a derp???\n");
|
||||||
|
|
||||||
MelonApplication melon(argc, argv);
|
MelonApplication melon(argc, argv);
|
||||||
|
pathInit();
|
||||||
Platform::Init(argc, argv);
|
|
||||||
|
|
||||||
CLI::CommandLineOptions* options = CLI::ManageArgs(melon);
|
CLI::CommandLineOptions* options = CLI::ManageArgs(melon);
|
||||||
|
|
||||||
@ -378,7 +414,6 @@ int main(int argc, char** argv)
|
|||||||
Config::Save();
|
Config::Save();
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
Platform::DeInit();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,5 +46,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern QString* systemThemeName;
|
extern QString* systemThemeName;
|
||||||
|
extern QString emuDirectory;
|
||||||
|
|
||||||
#endif // MAIN_H
|
#endif // MAIN_H
|
||||||
|
Reference in New Issue
Block a user