diff dep/animone/src/fd/win32.cc @ 337:a7d4e5107531

dep/animone: REFACTOR ALL THE THINGS 1: animone now has its own syntax divergent from anisthesia, making different platforms actually have their own sections 2: process names in animone are now called `comm' (this will probably break things). this is what its called in bsd/linux so I'm just going to use it everywhere 3: the X11 code now checks for the existence of a UTF-8 window title and passes it if available 4: ANYTHING THATS NOT LINUX IS 100% UNTESTED AND CAN AND WILL BREAK! I still actually need to test the bsd code. to be honest I'm probably going to move all of the bsds into separate files because they're all essentially different operating systems at this point
author Paper <paper@paper.us.eu.org>
date Wed, 19 Jun 2024 12:51:15 -0400
parents a4257370de16
children 74e2365326c6
line wrap: on
line diff
--- a/dep/animone/src/fd/win32.cc	Wed Jun 19 06:32:25 2024 -0400
+++ b/dep/animone/src/fd/win32.cc	Wed Jun 19 12:51:15 2024 -0400
@@ -180,33 +180,36 @@
 }
 
 bool GetProcessName(pid_t pid, std::string& name) {
-	std::wstring wname = GetProcessPath(pid);
-	if (wname.empty())
+	std::string path = GetProcessPath(pid);
+	if (path.empty() || !VerifyProcessPath(path))
 		return false;
 
-	name = ToUtf8String(GetFileNameWithoutExtension(GetFileNameFromPath(wname)));
+	name = GetFileNameFromPath(path);
+	if (!VerifyProcessFileName(name))
+		return false;
+
 	return true;
 }
 
 bool EnumerateOpenProcesses(process_proc_t process_proc) {
-	HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
-	if (hProcessSnap == INVALID_HANDLE_VALUE)
+	Handle process_snap(::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0));
+	if (process_snap.get() == INVALID_HANDLE_VALUE)
 		return false;
 
 	PROCESSENTRY32 pe32;
 	pe32.dwSize = sizeof(PROCESSENTRY32);
 
-	if (!::Process32First(hProcessSnap, &pe32))
-		return false;
-
-	if (!process_proc({pe32.th32ProcessID, pe32.szExeFile}))
+	if (!::Process32First(process_snap.get(), &pe32))
 		return false;
 
-	while (::Process32Next(hProcessSnap, &pe32))
-		if (!process_proc({pe32.th32ProcessID, pe32.szExeFile}))
+	do {
+		std::string name;
+		if (!GetProcessName(pe32.th32ProcessID, name))
+			continue;
+
+		if (!process_proc({.platform = ExecutablePlatform::Win32, .pid = pe32.th32ProcessID, .comm = name}))
 			return false;
-
-	::CloseHandle(hProcessSnap);
+	} while (::Process32Next(process_snap.get(), &pe32));
 
 	return true;
 }