| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "ipidsolver.h" |
| 7 | #include <filesystem> |
| 8 | #include <set> |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
| 12 | class ProcPIDSolver final : public IPIDSolver |
| 13 | { |
| 14 | public: |
| 15 | std::string app(int PID) override; |
| 16 | |
| 17 | private: |
| 18 | /// Gets the canonical path of the file procPIDPath/exe |
| 19 | /// @param procPIDPath the process /proc/PID path |
| 20 | /// @return canonical path of the file or empty string if procPIDPath/exe |
| 21 | /// is not a valid path |
| 22 | std::string procExeFileName(std::filesystem::path const &procPIDPath) const; |
| 23 | |
| 24 | /// Returns the last component of a windows or unix path |
| 25 | std::string lastComponent(std::string const &path) const; |
| 26 | |
| 27 | /// Gets the executable name (.exe) from a wine launch command line |
| 28 | /// @param cmdline /proc/PID/cmline file entries |
| 29 | /// @return executable name or empty string when the command line is not a valid wine |
| 30 | /// executable launch command line |
| 31 | std::string wineAppName(std::vector<std::string> const &cmdline) const; |
| 32 | |
| 33 | std::filesystem::path const procPath_{"/proc"}; |
| 34 | std::set<std::string> const wineExecutables_{ |
| 35 | "wine-preloader", "wine64-preloader", "wine", |
| 36 | "wine64", "wineloader", "wineloader64"}; |
| 37 | }; |