Mercurial > minori
diff dep/animone/src/util/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/util/win32.cc Wed Jun 19 06:32:25 2024 -0400 +++ b/dep/animone/src/util/win32.cc Wed Jun 19 12:51:15 2024 -0400 @@ -47,7 +47,7 @@ return ret; } -std::wstring GetProcessPath(DWORD process_id) { +std::string GetProcessPath(DWORD process_id) { // If we try to open a SYSTEM process, this function fails and the last error // code is ERROR_ACCESS_DENIED. // @@ -68,22 +68,17 @@ return std::wstring(); buffer.resize(buf_size); - return buffer; + return ToUtf8String(buffer); } -std::wstring GetFileNameFromPath(const std::wstring& path) { +std::string GetFileNameFromPath(const std::string& path) { const auto pos = path.find_last_of(L"/\\"); return pos != std::wstring::npos ? path.substr(pos + 1) : path; } -std::wstring GetFileNameWithoutExtension(const std::wstring& filename) { - const auto pos = filename.find_last_of(L"."); - return pos != std::wstring::npos ? filename.substr(0, pos) : filename; -} - static std::wstring GetSystemDirectory() { PWSTR path_wch; - SHGetKnownFolderPath(FOLDERID_Windows, 0, NULL, &path_wch); + SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, SHGFP_TYPE_CURRENT, &path_wch); std::wstring path_wstr(path_wch); CoTaskMemFree(path_wch); return path_wstr; @@ -99,7 +94,33 @@ std::wstring windir = GetSystemDirectory(); ::CharUpperBuffW(&windir.front(), windir.length()); + // XXX wtf is 4? return path.find(windir) == 4; } +bool VerifyProcessPath(const std::string& path) { + return !path.empty() && !IsSystemDirectory(path); +} + +bool VerifyProcessFileName(const std::string& name) { + static const std::set<std::string> invalid_names = { + // System files + "explorer.exe", // Windows Explorer + "taskeng.exe", // Task Scheduler Engine + "taskhost.exe", // Host Process for Windows Tasks + "taskhostex.exe", // Host Process for Windows Tasks + "taskmgr.exe", // Task Manager + "services.exe", // Service Control Manager + }; + + if (name.empty()) + return false; + + for (const auto& invalid_name : invalid_names) + if (util::EqualStrings(name, invalid_name)) + return false; + + return true; +} + } // namespace animone::internal::win32