changeset 148:aa4df5a84338

dep/animia: use std::pair instead of std::tuple
author Paper <mrpapersonic@gmail.com>
date Tue, 14 Nov 2023 13:27:13 -0500
parents 6fdf0632c003
children e41505d24733
files dep/animia/include/animia/fd.h dep/animia/include/animia/fd/bsd.h dep/animia/include/animia/fd/linux.h dep/animia/include/animia/fd/win32.h dep/animia/src/animia.cc dep/animia/src/fd/bsd.cc dep/animia/src/fd/linux.cc dep/animia/src/fd/win32.cc dep/animia/src/strategist.cc
diffstat 9 files changed, 21 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/dep/animia/include/animia/fd.h	Tue Nov 14 13:19:40 2023 -0500
+++ b/dep/animia/include/animia/fd.h	Tue Nov 14 13:27:13 2023 -0500
@@ -3,7 +3,7 @@
 
 #include <set>
 #include <string>
-#include <tuple>
+#include <utility>
 #include <string>
 #include <vector>
 
@@ -15,7 +15,7 @@
 	public:
 		virtual bool GetAllPids(std::set<pid_t>& pids) { return false; }
 		virtual bool GetProcessName(pid_t pid, std::string& result) { return false; }
-		virtual bool EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::tuple<pid_t, std::string>>& files) { return false; }
+		virtual bool EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::pair<pid_t, std::string>>& files) { return false; }
 };
 
 extern BaseFdTools& fd; // defined in fd.cc
--- a/dep/animia/include/animia/fd/bsd.h	Tue Nov 14 13:19:40 2023 -0500
+++ b/dep/animia/include/animia/fd/bsd.h	Tue Nov 14 13:27:13 2023 -0500
@@ -2,7 +2,7 @@
 #define __animia__animia__fd__linux_h
 
 #include <vector>
-#include <tuple>
+#include <utility>
 #include <string>
 #include <set>
 
@@ -19,7 +19,7 @@
 	public:
 		bool GetAllPids(std::set<pid_t>& pids) override;
 		bool GetProcessName(pid_t pid, std::string& result) override;
-		bool EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::tuple<pid_t, std::string>>& files) override;
+		bool EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::pair<pid_t, std::string>>& files) override;
 };
 
 }
--- a/dep/animia/include/animia/fd/linux.h	Tue Nov 14 13:19:40 2023 -0500
+++ b/dep/animia/include/animia/fd/linux.h	Tue Nov 14 13:27:13 2023 -0500
@@ -2,7 +2,7 @@
 #define __animia__animia__fd__linux_h
 
 #include <vector>
-#include <tuple>
+#include <utility>
 #include <string>
 #include <set>
 
@@ -20,7 +20,7 @@
 	public:
 		bool GetAllPids(std::set<pid_t>& pids) override;
 		bool GetProcessName(pid_t pid, std::string& result) override;
-		bool EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::tuple<pid_t, std::string>>& files) override;
+		bool EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::pair<pid_t, std::string>>& files) override;
 };
 
 }
--- a/dep/animia/include/animia/fd/win32.h	Tue Nov 14 13:19:40 2023 -0500
+++ b/dep/animia/include/animia/fd/win32.h	Tue Nov 14 13:27:13 2023 -0500
@@ -2,7 +2,7 @@
 #define __animia__animia__fd__win32_h
 
 #include <vector>
-#include <tuple>
+#include <utility>
 #include <string>
 #include <set>
 #include <memory>
@@ -25,7 +25,7 @@
 	public:
 		bool GetAllPids(std::set<pid_t>& pids) override;
 		bool GetProcessName(pid_t pid, std::string& result) override;
-		bool EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::tuple<pid_t, std::string>>& files) override;
+		bool EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::pair<pid_t, std::string>>& files) override;
 };
 
 }
--- a/dep/animia/src/animia.cc	Tue Nov 14 13:19:40 2023 -0500
+++ b/dep/animia/src/animia.cc	Tue Nov 14 13:27:13 2023 -0500
@@ -9,10 +9,17 @@
 
 namespace animia {
 
-static bool ProcessInPlayers(const std::vector<Player>& players, const std::string& name, Player& player_) {
+static bool ProcessInPlayers(const std::vector<Player>& players, std::string name, Player& player_) {
 	for (const auto& player : players) {
 		for (const auto& exe : player.executables) {
-			if (exe == name.substr(0, name.rfind(".exe"))) {
+			/* this is only really relevant on Windows, and even then
+			   executables can end in any number of extensions, so we should
+			   really remove them all... */
+			auto pos = name.rfind(".exe");
+			if (pos != std::string::npos)
+				name = name.substr(0, pos);
+
+			if (exe == name) {
 				player_ = player;
 				return true;
 			}
--- a/dep/animia/src/fd/bsd.cc	Tue Nov 14 13:19:40 2023 -0500
+++ b/dep/animia/src/fd/bsd.cc	Tue Nov 14 13:27:13 2023 -0500
@@ -84,7 +84,7 @@
 }
 
 /* this only works on OS X :( */
-bool UnixFdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::tuple<pid_t, std::string>>& files) {
+bool UnixFdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::pair<pid_t, std::string>>& files) {
 	for (const auto& pid : pids) {
 		int bufsz = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, NULL, 0);
 		if (bufsz == -1)
--- a/dep/animia/src/fd/linux.cc	Tue Nov 14 13:19:40 2023 -0500
+++ b/dep/animia/src/fd/linux.cc	Tue Nov 14 13:27:13 2023 -0500
@@ -124,7 +124,7 @@
 	return true;
 }
 
-bool LinuxFdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::tuple<pid_t, std::string>>& files) {
+bool LinuxFdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::pair<pid_t, std::string>>& files) {
 	for (const auto& pid : pids) {
 		const std::string path = PROC_LOCATION "/" + std::to_string(pid) + "/fd";
 
--- a/dep/animia/src/fd/win32.cc	Tue Nov 14 13:19:40 2023 -0500
+++ b/dep/animia/src/fd/win32.cc	Tue Nov 14 13:27:13 2023 -0500
@@ -243,7 +243,7 @@
 }
 
 /* this could be changed to being a callback, but... I'm too lazy right now :) */
-bool Win32FdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::tuple<pid_t, std::string>>& files) {
+bool Win32FdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::pair<pid_t, std::string>>& files) {
 	std::unordered_map<pid_t, Handle> proc_handles;
 
 	for (const pid_t& pid : pids) {
--- a/dep/animia/src/strategist.cc	Tue Nov 14 13:19:40 2023 -0500
+++ b/dep/animia/src/strategist.cc	Tue Nov 14 13:27:13 2023 -0500
@@ -50,7 +50,7 @@
 	bool success = false;
 
 	const std::set<pid_t> pids{result_.process.pid};
-	std::vector<std::tuple<pid_t, std::string>> files;
+	std::vector<std::pair<pid_t, std::string>> files;
 
 	fd.EnumerateOpenFiles(pids, files);