Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VFS; try to fix some segfaults (+ add libusb log callback) #15095

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Utilities/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ bool fs::create_path(const std::string& path)

#ifdef _WIN32
// Workaround: don't call is_dir with naked drive letter
if (parent.size() < path.size() && parent.back() != ':' && !is_dir(parent) && !create_path(parent))
if (parent.size() < path.size() && (parent.empty() || (parent.back() != ':' && !is_dir(parent) && !create_path(parent))))
#else
if (parent.size() < path.size() && !is_dir(parent) && !create_path(parent))
#endif
Expand Down
24 changes: 24 additions & 0 deletions rpcs3/Emu/Cell/lv2/sys_usbd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,30 @@ usb_handler_thread::usb_handler_thread()
return;
}

// Set LIBUSB_DEBUG env variable to receive log messages
libusb_set_log_cb(ctx, [](libusb_context* ctx, libusb_log_level level, const char* str)
{
if (!str) return;

const std::string msg = fmt::trim(str, " \t\n");

switch (level)
{
case LIBUSB_LOG_LEVEL_ERROR:
sys_usbd.error("libusb log: %s", msg);
break;
case LIBUSB_LOG_LEVEL_WARNING:
sys_usbd.warning("libusb log: %s", msg);
break;
case LIBUSB_LOG_LEVEL_INFO:
sys_usbd.notice("libusb log: %s", msg);
break;
case LIBUSB_LOG_LEVEL_DEBUG:
sys_usbd.trace("libusb log: %s", msg);
break;
}
}, LIBUSB_LOG_CB_CONTEXT);

for (u32 index = 0; index < MAX_SYS_USBD_TRANSFERS; index++)
{
transfers[index].transfer = libusb_alloc_transfer(8);
Expand Down
31 changes: 23 additions & 8 deletions rpcs3/Emu/vfs_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ std::string cfg_vfs::get(const cfg::string& _cfg, std::string_view emu_dir) cons

std::string cfg_vfs::get(const std::string& _cfg, const std::string& def, std::string_view emu_dir) const
{
std::string path = _cfg;

// Fallback
if (path.empty())
{
if (def.empty())
{
vfs_log.notice("VFS config called with empty path and empty default");
return {};
}

path = def;
}

std::string _emu_dir; // Storage only

if (emu_dir.empty())
Expand All @@ -34,18 +48,14 @@ std::string cfg_vfs::get(const std::string& _cfg, const std::string& def, std::s
emu_dir = _emu_dir;
}

std::string path = _cfg;
path = fmt::replace_all(path, "$(EmulatorDir)", emu_dir);

// Check if path does not end with a delimiter
if (path.empty())
{
// Fallback
path = def;
vfs_log.error("VFS config path empty (_cfg='%s', def='%s', emu_dir='%s')", _cfg, def, emu_dir);
}

path = fmt::replace_all(path, "$(EmulatorDir)", emu_dir);

// Check if path does not end with a delimiter
if (path.back() != fs::delim[0] && path.back() != fs::delim[1])
else if (path.back() != fs::delim[0] && path.back() != fs::delim[1])
{
path += '/';
}
Expand Down Expand Up @@ -74,6 +84,11 @@ cfg::device_info cfg_vfs::get_device_info(const cfg::device_entry& _cfg, std::st
def_path = def_it->second.path;
}

if (info.path.empty() && def_path.empty())
{
return info;
}

info.path = get(info.path, def_path, emu_dir);
return info;
}
Expand Down
1 change: 1 addition & 0 deletions rpcs3/rpcs3qt/vfs_dialog_usb_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ vfs_dialog_usb_input::vfs_dialog_usb_input(const QString& name, const cfg::devic
: QDialog(parent), m_gui_settings(std::move(_gui_settings)), m_gui_save(gui::fs_dev_usb_list)
{
ensure(!!info);
ensure(!name.isEmpty());
ensure(name.back() >= '0' && name.back() <= '7');

setWindowTitle(tr("Edit %0").arg(name));
Expand Down