# HG changeset patch # User Paper # Date 1699997253 18000 # Node ID ffa535b6d630e6efa360ea466b6e9a2622bd2a92 # Parent e41505d24733f8dac9bd2fbea1b933a8998a00e3 *: avoid usage of std::[pair,tuple] https://arne-mertz.de/2017/03/smelly-pair-tuple/ it's better to use real structures and such where variables are easily known... also apparently using [] on structs is actually valid? I had no idea. diff -r e41505d24733 -r ffa535b6d630 dep/animia/include/animia/fd.h --- a/dep/animia/include/animia/fd.h Tue Nov 14 13:40:11 2023 -0500 +++ b/dep/animia/include/animia/fd.h Tue Nov 14 16:27:33 2023 -0500 @@ -11,11 +11,16 @@ namespace animia::internal { +struct OpenFile { + pid_t pid = 0; + std::string path; +}; + class BaseFdTools { public: virtual bool GetAllPids(std::set& pids) { return false; } virtual bool GetProcessName(pid_t pid, std::string& result) { return false; } - virtual bool EnumerateOpenFiles(const std::set& pids, std::vector>& files) { return false; } + virtual bool EnumerateOpenFiles(const std::set& pids, std::vector& files) { return false; } }; extern BaseFdTools& fd; // defined in fd.cc diff -r e41505d24733 -r ffa535b6d630 dep/animia/include/animia/fd/bsd.h --- a/dep/animia/include/animia/fd/bsd.h Tue Nov 14 13:40:11 2023 -0500 +++ b/dep/animia/include/animia/fd/bsd.h Tue Nov 14 16:27:33 2023 -0500 @@ -19,7 +19,7 @@ public: bool GetAllPids(std::set& pids) override; bool GetProcessName(pid_t pid, std::string& result) override; - bool EnumerateOpenFiles(const std::set& pids, std::vector>& files) override; + bool EnumerateOpenFiles(const std::set& pids, std::vector& files) override; }; } diff -r e41505d24733 -r ffa535b6d630 dep/animia/include/animia/fd/linux.h --- a/dep/animia/include/animia/fd/linux.h Tue Nov 14 13:40:11 2023 -0500 +++ b/dep/animia/include/animia/fd/linux.h Tue Nov 14 16:27:33 2023 -0500 @@ -20,7 +20,7 @@ public: bool GetAllPids(std::set& pids) override; bool GetProcessName(pid_t pid, std::string& result) override; - bool EnumerateOpenFiles(const std::set& pids, std::vector>& files) override; + bool EnumerateOpenFiles(const std::set& pids, std::vector& files) override; }; } diff -r e41505d24733 -r ffa535b6d630 dep/animia/include/animia/fd/win32.h --- a/dep/animia/include/animia/fd/win32.h Tue Nov 14 13:40:11 2023 -0500 +++ b/dep/animia/include/animia/fd/win32.h Tue Nov 14 16:27:33 2023 -0500 @@ -25,7 +25,7 @@ public: bool GetAllPids(std::set& pids) override; bool GetProcessName(pid_t pid, std::string& result) override; - bool EnumerateOpenFiles(const std::set& pids, std::vector>& files) override; + bool EnumerateOpenFiles(const std::set& pids, std::vector& files) override; }; } diff -r e41505d24733 -r ffa535b6d630 dep/animia/src/fd.cc --- a/dep/animia/src/fd.cc Tue Nov 14 13:40:11 2023 -0500 +++ b/dep/animia/src/fd.cc Tue Nov 14 16:27:33 2023 -0500 @@ -1,3 +1,4 @@ +#include "animia/os.h" #include "animia/fd.h" #ifdef ANIMIA_ON_WIN32 diff -r e41505d24733 -r ffa535b6d630 dep/animia/src/fd/bsd.cc --- a/dep/animia/src/fd/bsd.cc Tue Nov 14 13:40:11 2023 -0500 +++ b/dep/animia/src/fd/bsd.cc Tue Nov 14 16:27:33 2023 -0500 @@ -109,7 +109,11 @@ continue; */ - files.push_back({pid, vnodeInfo.pvip.vip_path}); + OpenFile file; + file.pid = pid; + file.path = vnodeInfo.pvip.vip_path; + + files.push_back(file); } } } diff -r e41505d24733 -r ffa535b6d630 dep/animia/src/fd/linux.cc --- a/dep/animia/src/fd/linux.cc Tue Nov 14 13:40:11 2023 -0500 +++ b/dep/animia/src/fd/linux.cc Tue Nov 14 16:27:33 2023 -0500 @@ -124,7 +124,7 @@ return true; } -bool LinuxFdTools::EnumerateOpenFiles(const std::set& pids, std::vector>& files) { +bool LinuxFdTools::EnumerateOpenFiles(const std::set& pids, std::vector& files) { for (const auto& pid : pids) { const std::string path = PROC_LOCATION "/" + std::to_string(pid) + "/fd"; @@ -137,7 +137,11 @@ if (!IsRegularFile(name)) continue; - files.push_back({pid, name}); + OpenFile file; + file.pid = pid; + file.path = name; + + files.push_back(file); } } return true; diff -r e41505d24733 -r ffa535b6d630 dep/animia/src/fd/win32.cc --- a/dep/animia/src/fd/win32.cc Tue Nov 14 13:40:11 2023 -0500 +++ b/dep/animia/src/fd/win32.cc Tue Nov 14 16:27:33 2023 -0500 @@ -224,7 +224,7 @@ bool Win32FdTools::GetProcessName(pid_t pid, std::string& result) { unsigned long ret_size = 0; // size given by GetModuleBaseNameW Handle handle(::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid)); - if (!handle.get()) + if (handle.get() == INVALID_HANDLE_VALUE) return false; /* agh... */ @@ -243,12 +243,12 @@ } /* this could be changed to being a callback, but... I'm too lazy right now :) */ -bool Win32FdTools::EnumerateOpenFiles(const std::set& pids, std::vector>& files) { +bool Win32FdTools::EnumerateOpenFiles(const std::set& pids, std::vector& files) { std::unordered_map proc_handles; for (const pid_t& pid : pids) { const HANDLE handle = ::OpenProcess(PROCESS_DUP_HANDLE, false, pid); - if (handle) + if (handle != INVALID_HANDLE_VALUE) proc_handles[pid] = Handle(handle); } @@ -269,7 +269,7 @@ continue; Handle handle(DuplicateHandle(proc_handles[pid].get(), h.HandleValue)); - if (!handle.get()) + if (handle.get() == INVALID_HANDLE_VALUE) continue; if (GetFileType(handle.get()) != FILE_TYPE_DISK) @@ -279,8 +279,11 @@ if (!IsFilePathOk(path)) continue; - /* create an empty vector if it doesn't exist, probably unnecessary */ - files.push_back({pid, path}); + OpenFile file; + file.pid = pid; + file.path = path; + + files.push_back(file); } return true; diff -r e41505d24733 -r ffa535b6d630 dep/animia/src/strategist.cc --- a/dep/animia/src/strategist.cc Tue Nov 14 13:40:11 2023 -0500 +++ b/dep/animia/src/strategist.cc Tue Nov 14 16:27:33 2023 -0500 @@ -50,12 +50,12 @@ bool success = false; const std::set pids{result_.process.pid}; - std::vector> files; + std::vector files; fd.EnumerateOpenFiles(pids, files); - for (const auto& [pid, file] : files) { - success |= AddMedia({MediaInfoType::File, file}); + for (const auto& file : files) { + success |= AddMedia({MediaInfoType::File, file.path}); } return success; diff -r e41505d24733 -r ffa535b6d630 include/core/config.h --- a/include/core/config.h Tue Nov 14 13:40:11 2023 -0500 +++ b/include/core/config.h Tue Nov 14 16:27:33 2023 -0500 @@ -11,6 +11,11 @@ #include #include +struct MediaPlayer { + bool enabled = true; + animia::Player player; +}; + class Config { public: int Load(); @@ -44,9 +49,7 @@ struct { public: bool detect_media_players; - /* preferably web browsers would be in a separate vector, - but whatever :/ */ - std::vector> players; + std::vector players; } recognition; struct { diff -r e41505d24733 -r ffa535b6d630 src/core/config.cc --- a/src/core/config.cc Tue Nov 14 13:40:11 2023 -0500 +++ b/src/core/config.cc Tue Nov 14 16:27:33 2023 -0500 @@ -64,8 +64,14 @@ return false; recognition.players.reserve(players.size()); - for (const auto& player : players) - recognition.players.push_back({true, player}); + for (const auto& player : players) { + MediaPlayer mediaplayer; + + mediaplayer.enabled = true; + mediaplayer.player = player; + + recognition.players.push_back(mediaplayer); + } } for (auto& [enabled, player] : recognition.players) { diff -r e41505d24733 -r ffa535b6d630 src/gui/dialog/settings/recognition.cc --- a/src/gui/dialog/settings/recognition.cc Tue Nov 14 13:40:11 2023 -0500 +++ b/src/gui/dialog/settings/recognition.cc Tue Nov 14 16:27:33 2023 -0500 @@ -49,7 +49,7 @@ if (!item) return; size_t i = item->data(Qt::UserRole).toUInt(); - players[i].first = item->checkState(); + players[i].enabled = item->checkState(); }); /* this is down here because the listwidget state depends on it */ connect(checkbox, &QCheckBox::stateChanged, this, [this, listwidget](int state) {