mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-26 23:55:40 +00:00
Qt: Source input profiles from program and user directory
This way Linux users as well as Windows users who use the Documents user directory can use the shipped input profiles.
This commit is contained in:
parent
814edecd05
commit
8d2c7db224
|
@ -335,7 +335,7 @@ void ControllerSettingsWidget::onSaveProfileClicked()
|
|||
return;
|
||||
}
|
||||
|
||||
m_host_interface->saveInputProfile(m_host_interface->getPathForInputProfile(name));
|
||||
m_host_interface->saveInputProfile(m_host_interface->getSavePathForInputProfile(name));
|
||||
});
|
||||
|
||||
QAction* browse = menu.addAction(tr("Browse..."));
|
||||
|
|
|
@ -73,14 +73,11 @@ public:
|
|||
/// Fills menu with save state info and handlers.
|
||||
void populateGameListContextMenu(const char* game_code, QWidget* parent_window, QMenu* menu);
|
||||
|
||||
ALWAYS_INLINE QString getPathForInputProfile(const QString& name) const
|
||||
ALWAYS_INLINE QString getSavePathForInputProfile(const QString& name) const
|
||||
{
|
||||
return QString::fromStdString(GetPathForInputProfile(name.toUtf8().constData()));
|
||||
}
|
||||
ALWAYS_INLINE std::vector<std::pair<std::string, std::string>> getInputProfileList() const
|
||||
{
|
||||
return GetInputProfileList();
|
||||
return QString::fromStdString(GetSavePathForInputProfile(name.toUtf8().constData()));
|
||||
}
|
||||
ALWAYS_INLINE InputProfileList getInputProfileList() const { return GetInputProfileList(); }
|
||||
void saveInputProfile(const QString& profile_path);
|
||||
|
||||
/// Returns a path relative to the user directory.
|
||||
|
|
|
@ -1358,30 +1358,49 @@ void CommonHostInterface::RegisterAudioHotkeys()
|
|||
});
|
||||
}
|
||||
|
||||
std::string CommonHostInterface::GetPathForInputProfile(const char* name) const
|
||||
std::string CommonHostInterface::GetSavePathForInputProfile(const char* name) const
|
||||
{
|
||||
return GetUserDirectoryRelativePath("inputprofiles/%s.ini", name);
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> CommonHostInterface::GetInputProfileList() const
|
||||
CommonHostInterface::InputProfileList CommonHostInterface::GetInputProfileList() const
|
||||
{
|
||||
InputProfileList profiles;
|
||||
|
||||
const std::string user_dir(GetUserDirectoryRelativePath("inputprofiles"));
|
||||
const std::string program_dir(GetProgramDirectoryRelativePath("inputprofiles"));
|
||||
|
||||
FindInputProfiles(user_dir, &profiles);
|
||||
if (user_dir != program_dir)
|
||||
FindInputProfiles(program_dir, &profiles);
|
||||
|
||||
return profiles;
|
||||
}
|
||||
|
||||
void CommonHostInterface::FindInputProfiles(const std::string& base_path, InputProfileList* out_list) const
|
||||
{
|
||||
FileSystem::FindResultsArray results;
|
||||
FileSystem::FindFiles(GetUserDirectoryRelativePath("inputprofiles").c_str(), "*.ini",
|
||||
FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_RELATIVE_PATHS, &results);
|
||||
FileSystem::FindFiles(base_path.c_str(), "*.ini", FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_RELATIVE_PATHS, &results);
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> profile_names;
|
||||
profile_names.reserve(results.size());
|
||||
out_list->reserve(out_list->size() + results.size());
|
||||
for (auto& it : results)
|
||||
{
|
||||
if (it.FileName.size() < 4)
|
||||
continue;
|
||||
|
||||
std::string profile_name = it.FileName.substr(0, it.FileName.length() - 4);
|
||||
std::string full_filename = GetUserDirectoryRelativePath("inputprofiles/%s", it.FileName.c_str());
|
||||
profile_names.emplace_back(std::move(profile_name), std::move(full_filename));
|
||||
}
|
||||
std::string name(it.FileName.substr(0, it.FileName.length() - 4));
|
||||
|
||||
return profile_names;
|
||||
// skip duplicates, we prefer the user directory
|
||||
if (std::any_of(out_list->begin(), out_list->end(),
|
||||
[&name](const InputProfileEntry& e) { return (e.name == name); }))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string filename(
|
||||
StringUtil::StdStringFromFormat("%s%c%s", base_path.c_str(), FS_OSPATH_SEPERATOR_CHARACTER, it.FileName.c_str()));
|
||||
out_list->push_back(InputProfileEntry{std::move(name), std::move(filename)});
|
||||
}
|
||||
}
|
||||
|
||||
void CommonHostInterface::ClearAllControllerBindings(SettingsInterface& si)
|
||||
|
|
|
@ -162,6 +162,13 @@ protected:
|
|||
float duration;
|
||||
};
|
||||
|
||||
struct InputProfileEntry
|
||||
{
|
||||
std::string name;
|
||||
std::string path;
|
||||
};
|
||||
using InputProfileList = std::vector<InputProfileEntry>;
|
||||
|
||||
CommonHostInterface();
|
||||
~CommonHostInterface();
|
||||
|
||||
|
@ -195,10 +202,10 @@ protected:
|
|||
virtual void UpdateInputMap() = 0;
|
||||
|
||||
/// Returns a path where an input profile with the specified name would be saved.
|
||||
std::string GetPathForInputProfile(const char* name) const;
|
||||
std::string GetSavePathForInputProfile(const char* name) const;
|
||||
|
||||
/// Returns a list of all input profiles. first - name, second - path
|
||||
std::vector<std::pair<std::string, std::string>> GetInputProfileList() const;
|
||||
InputProfileList GetInputProfileList() const;
|
||||
|
||||
/// Applies the specified input profile.
|
||||
void ApplyInputProfile(const char* profile_path, SettingsInterface& si);
|
||||
|
@ -283,6 +290,7 @@ private:
|
|||
void RegisterGraphicsHotkeys();
|
||||
void RegisterSaveStateHotkeys();
|
||||
void RegisterAudioHotkeys();
|
||||
void FindInputProfiles(const std::string& base_path, InputProfileList* out_list) const;
|
||||
void UpdateControllerInputMap(SettingsInterface& si);
|
||||
void UpdateHotkeyInputMap(SettingsInterface& si);
|
||||
void ClearAllControllerBindings(SettingsInterface& si);
|
||||
|
|
Loading…
Reference in a new issue