mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-09 07:39:26 +01:00
Merge pull request #10327 from AdmiralCurtiss/config-port-usb
Config: Port USBPassthrough setting to new config system.
This commit is contained in:
commit
df0870f79d
@ -3,10 +3,13 @@
|
||||
|
||||
#include "Core/Config/MainSettings.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "AudioCommon/AudioCommon.h"
|
||||
#include "Common/Config/Config.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Common/Version.h"
|
||||
#include "Core/Config/DefaultLocale.h"
|
||||
#include "Core/HW/EXI/EXI_Device.h"
|
||||
@ -307,4 +310,46 @@ const Info<int> MAIN_BLUETOOTH_PASSTHROUGH_PID{{System::Main, "BluetoothPassthro
|
||||
const Info<std::string> MAIN_BLUETOOTH_PASSTHROUGH_LINK_KEYS{
|
||||
{System::Main, "BluetoothPassthrough", "LinkKeys"}, ""};
|
||||
|
||||
// Main.USBPassthrough
|
||||
|
||||
const Info<std::string> MAIN_USB_PASSTHROUGH_DEVICES{{System::Main, "USBPassthrough", "Devices"},
|
||||
""};
|
||||
|
||||
static std::set<std::pair<u16, u16>> LoadUSBWhitelistFromString(const std::string& devices_string)
|
||||
{
|
||||
std::set<std::pair<u16, u16>> devices;
|
||||
for (const auto& pair : SplitString(devices_string, ','))
|
||||
{
|
||||
const auto index = pair.find(':');
|
||||
if (index == std::string::npos)
|
||||
continue;
|
||||
|
||||
const u16 vid = static_cast<u16>(strtol(pair.substr(0, index).c_str(), nullptr, 16));
|
||||
const u16 pid = static_cast<u16>(strtol(pair.substr(index + 1).c_str(), nullptr, 16));
|
||||
if (vid && pid)
|
||||
devices.emplace(vid, pid);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
static std::string SaveUSBWhitelistToString(const std::set<std::pair<u16, u16>>& devices)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
for (const auto& device : devices)
|
||||
oss << fmt::format("{:04x}:{:04x}", device.first, device.second) << ',';
|
||||
std::string devices_string = oss.str();
|
||||
if (!devices_string.empty())
|
||||
devices_string.pop_back();
|
||||
return devices_string;
|
||||
}
|
||||
|
||||
std::set<std::pair<u16, u16>> GetUSBDeviceWhitelist()
|
||||
{
|
||||
return LoadUSBWhitelistFromString(Config::Get(Config::MAIN_USB_PASSTHROUGH_DEVICES));
|
||||
}
|
||||
|
||||
void SetUSBDeviceWhitelist(const std::set<std::pair<u16, u16>>& devices)
|
||||
{
|
||||
Config::SetBase(Config::MAIN_USB_PASSTHROUGH_DEVICES, SaveUSBWhitelistToString(devices));
|
||||
}
|
||||
} // namespace Config
|
||||
|
@ -4,7 +4,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "Common/Common.h"
|
||||
#include "Common/Config/Config.h"
|
||||
@ -257,4 +259,10 @@ extern const Info<int> MAIN_BLUETOOTH_PASSTHROUGH_VID;
|
||||
extern const Info<int> MAIN_BLUETOOTH_PASSTHROUGH_PID;
|
||||
extern const Info<std::string> MAIN_BLUETOOTH_PASSTHROUGH_LINK_KEYS;
|
||||
|
||||
// Main.USBPassthrough
|
||||
|
||||
extern const Info<std::string> MAIN_USB_PASSTHROUGH_DEVICES;
|
||||
std::set<std::pair<u16, u16>> GetUSBDeviceWhitelist();
|
||||
void SetUSBDeviceWhitelist(const std::set<std::pair<u16, u16>>& devices);
|
||||
|
||||
} // namespace Config
|
||||
|
@ -28,7 +28,7 @@ bool IsSettingSaveable(const Config::Location& config_location)
|
||||
for (const std::string_view section :
|
||||
{"NetPlay", "General", "GBA", "Display", "Network", "Analytics", "AndroidOverlayButtons",
|
||||
"DSP", "GameList", "FifoPlayer", "AutoUpdate", "Movie", "Input", "Debug",
|
||||
"BluetoothPassthrough"})
|
||||
"BluetoothPassthrough", "USBPassthrough"})
|
||||
{
|
||||
if (config_location.section == section)
|
||||
return true;
|
||||
|
@ -91,7 +91,6 @@ void SConfig::SaveSettings()
|
||||
SaveGeneralSettings(ini);
|
||||
SaveInterfaceSettings(ini);
|
||||
SaveCoreSettings(ini);
|
||||
SaveUSBPassthroughSettings(ini);
|
||||
|
||||
ini.Save(File::GetUserPath(F_DOLPHINCONFIG_IDX));
|
||||
|
||||
@ -195,20 +194,6 @@ void SConfig::SaveCoreSettings(IniFile& ini)
|
||||
core->Set("CustomRTCValue", m_customRTCValue);
|
||||
}
|
||||
|
||||
void SConfig::SaveUSBPassthroughSettings(IniFile& ini)
|
||||
{
|
||||
IniFile::Section* section = ini.GetOrCreateSection("USBPassthrough");
|
||||
|
||||
std::ostringstream oss;
|
||||
for (const auto& device : m_usb_passthrough_devices)
|
||||
oss << fmt::format("{:04x}:{:04x}", device.first, device.second) << ',';
|
||||
std::string devices_string = oss.str();
|
||||
if (!devices_string.empty())
|
||||
devices_string.pop_back();
|
||||
|
||||
section->Set("Devices", devices_string);
|
||||
}
|
||||
|
||||
void SConfig::LoadSettings()
|
||||
{
|
||||
Config::Load();
|
||||
@ -220,7 +205,6 @@ void SConfig::LoadSettings()
|
||||
LoadGeneralSettings(ini);
|
||||
LoadInterfaceSettings(ini);
|
||||
LoadCoreSettings(ini);
|
||||
LoadUSBPassthroughSettings(ini);
|
||||
}
|
||||
|
||||
void SConfig::LoadGeneralSettings(IniFile& ini)
|
||||
@ -329,25 +313,6 @@ void SConfig::LoadCoreSettings(IniFile& ini)
|
||||
core->Get("CustomRTCValue", &m_customRTCValue, 946684800);
|
||||
}
|
||||
|
||||
void SConfig::LoadUSBPassthroughSettings(IniFile& ini)
|
||||
{
|
||||
IniFile::Section* section = ini.GetOrCreateSection("USBPassthrough");
|
||||
m_usb_passthrough_devices.clear();
|
||||
std::string devices_string;
|
||||
section->Get("Devices", &devices_string, "");
|
||||
for (const auto& pair : SplitString(devices_string, ','))
|
||||
{
|
||||
const auto index = pair.find(':');
|
||||
if (index == std::string::npos)
|
||||
continue;
|
||||
|
||||
const u16 vid = static_cast<u16>(strtol(pair.substr(0, index).c_str(), nullptr, 16));
|
||||
const u16 pid = static_cast<u16>(strtol(pair.substr(index + 1).c_str(), nullptr, 16));
|
||||
if (vid && pid)
|
||||
m_usb_passthrough_devices.emplace(vid, pid);
|
||||
}
|
||||
}
|
||||
|
||||
void SConfig::ResetRunningGameMetadata()
|
||||
{
|
||||
SetRunningGameMetadata("00000000", "", 0, 0, DiscIO::Region::Unknown);
|
||||
@ -490,11 +455,6 @@ void SConfig::LoadDefaults()
|
||||
ResetRunningGameMetadata();
|
||||
}
|
||||
|
||||
bool SConfig::IsUSBDeviceWhitelisted(const std::pair<u16, u16> vid_pid) const
|
||||
{
|
||||
return m_usb_passthrough_devices.find(vid_pid) != m_usb_passthrough_devices.end();
|
||||
}
|
||||
|
||||
// Static method to make a simple game ID for elf/dol files
|
||||
std::string SConfig::MakeGameID(std::string_view file_name)
|
||||
{
|
||||
|
@ -128,10 +128,6 @@ struct SConfig
|
||||
bool bLockCursor = false;
|
||||
std::string theme_name;
|
||||
|
||||
// USB passthrough settings
|
||||
std::set<std::pair<u16, u16>> m_usb_passthrough_devices;
|
||||
bool IsUSBDeviceWhitelisted(std::pair<u16, u16> vid_pid) const;
|
||||
|
||||
// Custom RTC
|
||||
bool bEnableCustomRTC;
|
||||
u32 m_customRTCValue;
|
||||
@ -237,12 +233,10 @@ private:
|
||||
void SaveGeneralSettings(IniFile& ini);
|
||||
void SaveInterfaceSettings(IniFile& ini);
|
||||
void SaveCoreSettings(IniFile& ini);
|
||||
void SaveUSBPassthroughSettings(IniFile& ini);
|
||||
|
||||
void LoadGeneralSettings(IniFile& ini);
|
||||
void LoadInterfaceSettings(IniFile& ini);
|
||||
void LoadCoreSettings(IniFile& ini);
|
||||
void LoadUSBPassthroughSettings(IniFile& ini);
|
||||
|
||||
void SetRunningGameMetadata(const std::string& game_id, const std::string& gametdb_id,
|
||||
u64 title_id, u16 revision, DiscIO::Region region);
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/Thread.h"
|
||||
#include "Core/ConfigManager.h"
|
||||
#include "Core/Config/MainSettings.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/IOS/USB/Common.h"
|
||||
#include "Core/IOS/USB/LibusbDevice.h"
|
||||
@ -115,7 +115,8 @@ bool USBHost::AddNewDevices(std::set<u64>& new_devices, DeviceChangeHooks& hooks
|
||||
const bool always_add_hooks)
|
||||
{
|
||||
#ifdef __LIBUSB__
|
||||
if (SConfig::GetInstance().m_usb_passthrough_devices.empty())
|
||||
auto whitelist = Config::GetUSBDeviceWhitelist();
|
||||
if (whitelist.empty())
|
||||
return true;
|
||||
|
||||
if (m_context.IsValid())
|
||||
@ -123,8 +124,7 @@ bool USBHost::AddNewDevices(std::set<u64>& new_devices, DeviceChangeHooks& hooks
|
||||
m_context.GetDeviceList([&](libusb_device* device) {
|
||||
libusb_device_descriptor descriptor;
|
||||
libusb_get_device_descriptor(device, &descriptor);
|
||||
const std::pair<u16, u16> vid_pid = {descriptor.idVendor, descriptor.idProduct};
|
||||
if (!SConfig::GetInstance().IsUSBDeviceWhitelisted(vid_pid))
|
||||
if (whitelist.count({descriptor.idVendor, descriptor.idProduct}) == 0)
|
||||
return true;
|
||||
|
||||
auto usb_device = std::make_unique<USB::LibusbDevice>(m_ios, device, descriptor);
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
#include "Core/Config/MainSettings.h"
|
||||
#include "Core/ConfigManager.h"
|
||||
|
||||
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
||||
@ -109,9 +110,10 @@ void USBDeviceAddToWhitelistDialog::RefreshDeviceList()
|
||||
return;
|
||||
const auto selection_string = usb_inserted_devices_list->currentItem();
|
||||
usb_inserted_devices_list->clear();
|
||||
auto whitelist = Config::GetUSBDeviceWhitelist();
|
||||
for (const auto& device : current_devices)
|
||||
{
|
||||
if (SConfig::GetInstance().IsUSBDeviceWhitelisted(device.first))
|
||||
if (whitelist.count({device.first.first, device.first.second}) != 0)
|
||||
continue;
|
||||
usb_inserted_devices_list->addItem(QString::fromStdString(device.second));
|
||||
}
|
||||
@ -141,14 +143,16 @@ void USBDeviceAddToWhitelistDialog::AddUSBDeviceToWhitelist()
|
||||
const u16 vid = static_cast<u16>(std::stoul(vid_string, nullptr, 16));
|
||||
const u16 pid = static_cast<u16>(std::stoul(pid_string, nullptr, 16));
|
||||
|
||||
if (SConfig::GetInstance().IsUSBDeviceWhitelisted({vid, pid}))
|
||||
auto whitelist = Config::GetUSBDeviceWhitelist();
|
||||
auto it = whitelist.emplace(vid, pid);
|
||||
if (!it.second)
|
||||
{
|
||||
ModalMessageBox::critical(this, tr("USB Whitelist Error"),
|
||||
tr("This USB device is already whitelisted."));
|
||||
return;
|
||||
}
|
||||
SConfig::GetInstance().m_usb_passthrough_devices.emplace(vid, pid);
|
||||
SConfig::GetInstance().SaveSettings();
|
||||
Config::SetUSBDeviceWhitelist(whitelist);
|
||||
Config::Save();
|
||||
accept();
|
||||
}
|
||||
|
||||
|
@ -283,14 +283,17 @@ void WiiPane::OnUSBWhitelistRemoveButton()
|
||||
QString pid = QString(split[1]);
|
||||
const u16 vid_u16 = static_cast<u16>(std::stoul(vid.toStdString(), nullptr, 16));
|
||||
const u16 pid_u16 = static_cast<u16>(std::stoul(pid.toStdString(), nullptr, 16));
|
||||
SConfig::GetInstance().m_usb_passthrough_devices.erase({vid_u16, pid_u16});
|
||||
auto whitelist = Config::GetUSBDeviceWhitelist();
|
||||
whitelist.erase({vid_u16, pid_u16});
|
||||
Config::SetUSBDeviceWhitelist(whitelist);
|
||||
PopulateUSBPassthroughListWidget();
|
||||
}
|
||||
|
||||
void WiiPane::PopulateUSBPassthroughListWidget()
|
||||
{
|
||||
m_whitelist_usb_list->clear();
|
||||
for (const auto& device : SConfig::GetInstance().m_usb_passthrough_devices)
|
||||
auto whitelist = Config::GetUSBDeviceWhitelist();
|
||||
for (const auto& device : whitelist)
|
||||
{
|
||||
QListWidgetItem* usb_lwi =
|
||||
new QListWidgetItem(QString::fromStdString(USBUtils::GetDeviceName(device)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user