comparison 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
comparison
equal deleted inserted replaced
336:d260549151d6 337:a7d4e5107531
178 178
179 return true; 179 return true;
180 } 180 }
181 181
182 bool GetProcessName(pid_t pid, std::string& name) { 182 bool GetProcessName(pid_t pid, std::string& name) {
183 std::wstring wname = GetProcessPath(pid); 183 std::string path = GetProcessPath(pid);
184 if (wname.empty()) 184 if (path.empty() || !VerifyProcessPath(path))
185 return false; 185 return false;
186 186
187 name = ToUtf8String(GetFileNameWithoutExtension(GetFileNameFromPath(wname))); 187 name = GetFileNameFromPath(path);
188 if (!VerifyProcessFileName(name))
189 return false;
190
188 return true; 191 return true;
189 } 192 }
190 193
191 bool EnumerateOpenProcesses(process_proc_t process_proc) { 194 bool EnumerateOpenProcesses(process_proc_t process_proc) {
192 HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 195 Handle process_snap(::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0));
193 if (hProcessSnap == INVALID_HANDLE_VALUE) 196 if (process_snap.get() == INVALID_HANDLE_VALUE)
194 return false; 197 return false;
195 198
196 PROCESSENTRY32 pe32; 199 PROCESSENTRY32 pe32;
197 pe32.dwSize = sizeof(PROCESSENTRY32); 200 pe32.dwSize = sizeof(PROCESSENTRY32);
198 201
199 if (!::Process32First(hProcessSnap, &pe32)) 202 if (!::Process32First(process_snap.get(), &pe32))
200 return false; 203 return false;
201 204
202 if (!process_proc({pe32.th32ProcessID, pe32.szExeFile})) 205 do {
203 return false; 206 std::string name;
204 207 if (!GetProcessName(pe32.th32ProcessID, name))
205 while (::Process32Next(hProcessSnap, &pe32)) 208 continue;
206 if (!process_proc({pe32.th32ProcessID, pe32.szExeFile})) 209
210 if (!process_proc({.platform = ExecutablePlatform::Win32, .pid = pe32.th32ProcessID, .comm = name}))
207 return false; 211 return false;
208 212 } while (::Process32Next(process_snap.get(), &pe32));
209 ::CloseHandle(hProcessSnap);
210 213
211 return true; 214 return true;
212 } 215 }
213 216
214 /* this could be changed to being a callback, but... I'm too lazy right now :) */ 217 /* this could be changed to being a callback, but... I'm too lazy right now :) */