mirror of https://github.com/PCSX2/pcsx2.git
cdvdgigaherz: Switch to using the new settings system
Also refactor the default drive selection and GUI code so optical drive detection is shared. Note: This breaks the current config, but there's only one setting anyway.
This commit is contained in:
parent
dce3c57e6a
commit
59247c7838
|
@ -17,6 +17,9 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include "svnrev.h"
|
#include "svnrev.h"
|
||||||
|
|
||||||
|
Settings g_settings;
|
||||||
|
static std::string s_config_file{"inis/cdvdGigaherz.ini"};
|
||||||
|
|
||||||
void (*newDiscCB)();
|
void (*newDiscCB)();
|
||||||
|
|
||||||
HANDLE hThread_keepAlive = nullptr;
|
HANDLE hThread_keepAlive = nullptr;
|
||||||
|
@ -113,12 +116,20 @@ void __inline lba_to_msf(s32 lba, u8 *m, u8 *s, u8 *f)
|
||||||
*f = (u8)(lba % 75);
|
*f = (u8)(lba % 75);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReadSettings()
|
||||||
|
{
|
||||||
|
g_settings.Load(s_config_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteSettings()
|
||||||
|
{
|
||||||
|
g_settings.Save(s_config_file);
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// CDVD processing functions //
|
// CDVD processing functions //
|
||||||
|
|
||||||
char csrc[20];
|
|
||||||
|
|
||||||
bool cdvd_is_open = false;
|
bool cdvd_is_open = false;
|
||||||
bool cdvdKeepAlive_is_open = false;
|
bool cdvdKeepAlive_is_open = false;
|
||||||
bool disc_has_changed = false;
|
bool disc_has_changed = false;
|
||||||
|
@ -192,7 +203,7 @@ void StopKeepAliveThread()
|
||||||
|
|
||||||
void CALLBACK CDVDsetSettingsDir(const char *dir)
|
void CALLBACK CDVDsetSettingsDir(const char *dir)
|
||||||
{
|
{
|
||||||
CfgSetSettingsDir(dir);
|
s_config_file = std::string(dir ? dir : "inis") + "/cdvdGigaherz.ini";
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 CALLBACK CDVDinit()
|
s32 CALLBACK CDVDinit()
|
||||||
|
@ -204,29 +215,13 @@ s32 CALLBACK CDVDopen(const char *pTitleFilename)
|
||||||
{
|
{
|
||||||
ReadSettings();
|
ReadSettings();
|
||||||
|
|
||||||
if (source_drive == '-') {
|
auto drive = GetValidDrive();
|
||||||
// MSDN : Trailing backslash is required to ensure consistent behavior across
|
if (drive.empty())
|
||||||
// various versions of Windows and storage types.
|
|
||||||
char temp[] = "A:\\";
|
|
||||||
|
|
||||||
for (char d = 'A'; d <= 'Z'; d++) {
|
|
||||||
temp[0] = d;
|
|
||||||
if (GetDriveType(temp) == DRIVE_CDROM) {
|
|
||||||
source_drive = d;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (source_drive == '-')
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(csrc, "\\\\.\\%c:", source_drive);
|
|
||||||
|
|
||||||
printf(" * CDVD: Opening drive '%s'...\n", csrc);
|
|
||||||
|
|
||||||
// open device file
|
// open device file
|
||||||
try {
|
try {
|
||||||
src = new IOCtlSrc(csrc);
|
src = new IOCtlSrc(drive);
|
||||||
} catch (std::runtime_error &ex) {
|
} catch (std::runtime_error &ex) {
|
||||||
fputs(ex.what(), stdout);
|
fputs(ex.what(), stdout);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#define CDVDdefs
|
#define CDVDdefs
|
||||||
#include <PS2Edefs.h>
|
#include <PS2Edefs.h>
|
||||||
|
#include "Settings.h"
|
||||||
|
|
||||||
struct track
|
struct track
|
||||||
{
|
{
|
||||||
|
@ -69,7 +70,7 @@ class IOCtlSrc
|
||||||
bool Reopen();
|
bool Reopen();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IOCtlSrc(const char *filename);
|
IOCtlSrc(decltype(m_filename) filename);
|
||||||
~IOCtlSrc();
|
~IOCtlSrc();
|
||||||
|
|
||||||
u32 GetSectorCount() const;
|
u32 GetSectorCount() const;
|
||||||
|
@ -86,13 +87,13 @@ extern IOCtlSrc *src;
|
||||||
|
|
||||||
void configure();
|
void configure();
|
||||||
|
|
||||||
extern char source_drive;
|
|
||||||
|
|
||||||
extern HINSTANCE hinst;
|
extern HINSTANCE hinst;
|
||||||
|
|
||||||
void ReadSettings();
|
void ReadSettings();
|
||||||
void WriteSettings();
|
void WriteSettings();
|
||||||
void CfgSetSettingsDir(const char *dir);
|
std::string GetValidDrive();
|
||||||
|
|
||||||
|
extern Settings g_settings;
|
||||||
|
|
||||||
extern bool cdvd_is_open;
|
extern bool cdvd_is_open;
|
||||||
extern bool cdvdKeepAlive_is_open;
|
extern bool cdvdKeepAlive_is_open;
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
IOCtlSrc::IOCtlSrc(const char *filename)
|
IOCtlSrc::IOCtlSrc(decltype(m_filename) filename)
|
||||||
: m_filename(filename)
|
: m_filename(filename)
|
||||||
{
|
{
|
||||||
if (!Reopen())
|
if (!Reopen())
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//GiGaHeRz SPU2 Driver
|
//Copyright (C) 2016 PCSX2 Dev Team
|
||||||
//Copyright (c) David Quintana <DavidQuintana@canal21.com>
|
//Copyright (c) David Quintana <DavidQuintana@canal21.com>
|
||||||
//
|
//
|
||||||
//This library is free software; you can redistribute it and/or
|
//This library is free software; you can redistribute it and/or
|
||||||
|
@ -21,23 +21,8 @@
|
||||||
#include <commctrl.h>
|
#include <commctrl.h>
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
// Config Vars
|
|
||||||
|
|
||||||
// DEBUG
|
|
||||||
|
|
||||||
char source_drive;
|
|
||||||
|
|
||||||
char CfgFile[MAX_PATH + 10] = "inis/cdvdGigaherz.ini";
|
char CfgFile[MAX_PATH + 10] = "inis/cdvdGigaherz.ini";
|
||||||
|
|
||||||
void CfgSetSettingsDir(const char *dir)
|
|
||||||
{
|
|
||||||
// a better std::string version, but it's inconvenient for other reasons.
|
|
||||||
//CfgFile = std::string(( dir == NULL ) ? "inis/" : dir) + "cdvdGigaherz.ini";
|
|
||||||
|
|
||||||
strcpy_s(CfgFile, (dir == NULL) ? "inis" : dir);
|
|
||||||
strcat_s(CfgFile, "/cdvdGigaherz.ini");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*| Config File Format: |¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯*\
|
/*| Config File Format: |¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯*\
|
||||||
+--+---------------------+------------------------+
|
+--+---------------------+------------------------+
|
||||||
|
@ -127,72 +112,39 @@ void CfgReadStr(char *Section, char *Name, char *Data, int DataSize, char *Defau
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
void ReadSettings()
|
|
||||||
{
|
|
||||||
char temp[512];
|
|
||||||
|
|
||||||
CfgReadStr("Config", "Source", temp, 511, "-");
|
|
||||||
source_drive = temp[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void WriteSettings()
|
|
||||||
{
|
|
||||||
char temp[2];
|
|
||||||
|
|
||||||
temp[0] = source_drive;
|
|
||||||
temp[1] = 0;
|
|
||||||
|
|
||||||
CfgWriteStr("Config", "Source", temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *path[] = {
|
|
||||||
"A:", "B:", "C:", "D:", "E:", "F:", "G:", "H:", "I:", "J:", "K:", "L:", "M:",
|
|
||||||
"N:", "O:", "P:", "Q:", "R:", "S:", "T:", "U:", "V:", "W:", "X:", "Y:", "Z:",
|
|
||||||
};
|
|
||||||
|
|
||||||
static INT_PTR CALLBACK ConfigProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
static INT_PTR CALLBACK ConfigProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
int wmId, wmEvent;
|
|
||||||
char temp[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
switch (uMsg) {
|
switch (uMsg) {
|
||||||
case WM_INITDIALOG: {
|
case WM_INITDIALOG: {
|
||||||
int n = -1;
|
std::vector<std::string> &drives =
|
||||||
int s = 0;
|
*reinterpret_cast<std::vector<std::string> *>(lParam);
|
||||||
|
HWND combobox = GetDlgItem(hWnd, IDC_DRIVE);
|
||||||
SendMessage(GetDlgItem(hWnd, IDC_DRIVE), CB_RESETCONTENT, 0, 0);
|
std::string drive;
|
||||||
for (char d = 'A'; d <= 'Z'; d++) {
|
g_settings.Get("drive", drive);
|
||||||
if (GetDriveType(path[d - 'A']) == DRIVE_CDROM) {
|
for (size_t n = 0; n < drives.size(); ++n) {
|
||||||
n++;
|
SendMessage(combobox, CB_ADDSTRING, 0,
|
||||||
|
reinterpret_cast<LPARAM>(drives[n].c_str()));
|
||||||
SendMessage(GetDlgItem(hWnd, IDC_DRIVE), CB_ADDSTRING, 0, (LPARAM)path[d - 'A']);
|
if (drive == drives[n])
|
||||||
|
SendMessage(combobox, CB_SETCURSEL, n, 0);
|
||||||
if (source_drive == d) {
|
|
||||||
s = n;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n != -1)
|
|
||||||
SendMessage(GetDlgItem(hWnd, IDC_DRIVE), CB_SETCURSEL, s, 0);
|
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
wmId = LOWORD(wParam);
|
|
||||||
wmEvent = HIWORD(wParam);
|
|
||||||
// Parse the menu selections:
|
// Parse the menu selections:
|
||||||
switch (wmId) {
|
switch (LOWORD(wParam)) {
|
||||||
case IDOK:
|
case IDOK: {
|
||||||
if (SendMessage(GetDlgItem(hWnd, IDC_DRIVE), CB_GETCOUNT, 0, 0) > 0) {
|
HWND combobox = GetDlgItem(hWnd, IDC_DRIVE);
|
||||||
GetDlgItemText(hWnd, IDC_DRIVE, temp, 20);
|
LRESULT index = SendMessage(combobox, CB_GETCURSEL, 0, 0);
|
||||||
temp[19] = 0;
|
if (index != CB_ERR) {
|
||||||
source_drive = temp[0];
|
LRESULT length = SendMessage(combobox, CB_GETLBTEXTLEN,
|
||||||
|
index, 0);
|
||||||
|
std::vector<char> drive(length + 1);
|
||||||
|
SendMessage(combobox, CB_GETLBTEXT, index,
|
||||||
|
reinterpret_cast<LPARAM>(drive.data()));
|
||||||
|
g_settings.Set("drive", std::string(drive.data()));
|
||||||
WriteSettings();
|
WriteSettings();
|
||||||
}
|
}
|
||||||
EndDialog(hWnd, 0);
|
EndDialog(hWnd, 0);
|
||||||
break;
|
} break;
|
||||||
case IDCANCEL:
|
case IDCANCEL:
|
||||||
EndDialog(hWnd, 0);
|
EndDialog(hWnd, 0);
|
||||||
break;
|
break;
|
||||||
|
@ -207,13 +159,47 @@ static INT_PTR CALLBACK ConfigProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::vector<std::string> GetOpticalDriveList()
|
||||||
|
{
|
||||||
|
DWORD size = GetLogicalDriveStrings(0, nullptr);
|
||||||
|
std::vector<char> drive_strings(size);
|
||||||
|
if (GetLogicalDriveStrings(size, drive_strings.data()) != size - 1)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
std::vector<std::string> drives;
|
||||||
|
for (auto p = drive_strings.data(); *p; ++p) {
|
||||||
|
if (GetDriveType(p) == DRIVE_CDROM)
|
||||||
|
drives.push_back(p);
|
||||||
|
while (*p)
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
return drives;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetValidDrive()
|
||||||
|
{
|
||||||
|
std::string drive;
|
||||||
|
g_settings.Get("drive", drive);
|
||||||
|
if (drive.empty() || GetDriveType(drive.c_str()) != DRIVE_CDROM) {
|
||||||
|
auto drives = GetOpticalDriveList();
|
||||||
|
if (drives.empty())
|
||||||
|
return {};
|
||||||
|
drive = drives.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(" * CDVD: Opening drive '%s'...\n", drive.c_str());
|
||||||
|
|
||||||
|
// The drive string has the form "X:\", but to open the drive, the string
|
||||||
|
// has to be in the form "\\.\X:"
|
||||||
|
drive.pop_back();
|
||||||
|
drive.insert(0, "\\\\.\\");
|
||||||
|
return drive;
|
||||||
|
}
|
||||||
|
|
||||||
void configure()
|
void configure()
|
||||||
{
|
{
|
||||||
ReadSettings();
|
ReadSettings();
|
||||||
INT_PTR ret = DialogBoxParam(hinst, MAKEINTRESOURCE(IDD_CONFIG), GetActiveWindow(), ConfigProc, 1);
|
auto drives = GetOpticalDriveList();
|
||||||
if (ret == -1) {
|
DialogBoxParam(hinst, MAKEINTRESOURCE(IDD_CONFIG), GetActiveWindow(),
|
||||||
MessageBoxEx(GetActiveWindow(), "Error Opening the config dialog.", "OMG ERROR!", MB_OK, 0);
|
ConfigProc, reinterpret_cast<LPARAM>(&drives));
|
||||||
return;
|
|
||||||
}
|
|
||||||
ReadSettings();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue