diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-09-30 16:21:41 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-09-30 16:22:00 +0200 |
commit | ac4dc94acc5d1e1d8fd4867730b835e2aa1fcc89 (patch) | |
tree | 8ca3dc84958e572e3f890ac3f56dfda670c63f60 /opentrack-compat | |
parent | 03a164ed74d616e8d5203142ec7e9738c8aae547 (diff) | |
parent | eb7703b4ecea5540a4c4a65faa1ff4c53fe97631 (diff) |
Merge branch 'unstable' into trackhat-ui
Sponsored-by: TrackHat
* unstable: (112 commits)
Revert "accela: try more complex deadzone algorithm"
pt: add wiki link for calibration instructions
qfc: more gray colors when graph is disabled
qfc, mapping: disallow editing and change color when checkbox disabled
qfc: don't allow editing when disabled
plugin-support: workaround multiple copies of modules
accela: change translation gain
accela: change rotation gain
pt: change extraction code
freepie-udp: add license
freepie-udp: update
accela: try more complex deadzone algorithm
accela: add helpful comment
accela: revert to more quadratic spline at start
also save if save pending when start tracking
ui: force saving if saving timer is pending
accela: slightly more linear function
pose-widget: simplify
freepie-udp: nix harmless warning
pose-widget: add comment
simple-mat: add __restrict for GNU
ui: save settings on a timer
ui: show a warning if configuration directory can't be used
aruco: tune min/max marker size
win32-joystick: fix duplicate device name selection logic
ui: no need to reset settings on tracking start
ui: save profile when combobox text changes, not merely index
ui: save current tracker/filter/proto, not last
win32-joystick: fix COM failure path
win32-joystick: nix unused variable
win32-joystick: allow for unique selection of joysticks
qfc: also draw line from function start while moving
no need to save on tracking start anymore
save axis opts, not just spline control points
tracker: change centering order again
fix typo
cmake: don't say "opentrack" twice for osx build
ui: really don't switch profiles while refreshing combobox
pt: fix type mismatch
ui: save prior to switching configs
tracker_rs: adjusted tracker's name
ui: don't reload settings if config wasn't changed
ui: save everything before switching profiles
options: return .ini basename easier
tracker_rs: more readable icon
tracker_rs: prevent potential thread starvation
ui: switch to newly-created config
ui: decruft
ui: also bail on new config if its name is ".ini"
ui: auto-refresh config list
ui: display up to 20 profiles w/o scrolling
ui: create an empty config properly in another code branch
udp-tracker: silence harmless warning
plugin-support: fix typo
plugin-support: set more sane RTLD flags
plugin-support: free modules from address space when needed
ui: rename symbol to reflect current usage
ui: move some slots to private
ui, shortcuts: these are slots, actually
ui: no need to write anything to new empty config
ui: avoid potential memory leak
ft: new game support
game-data: chomp newlines in extractor
ui: append extension in the right place
simple-mat: fix arglist SFINAE
simple-mat: can use static_cast here
nix default empty config. it gets created on its own.
ui: these aren't qt slots
ui: nix wrong headers
ui: remove GNU GPL
ui: simplify condition
props changed only
main, ui: store config files in a predefined directory
pt: show extracted points' areas and success count
close dialogs on switch to new module
...
Diffstat (limited to 'opentrack-compat')
-rw-r--r-- | opentrack-compat/process-list.hpp | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/opentrack-compat/process-list.hpp b/opentrack-compat/process-list.hpp new file mode 100644 index 00000000..65735740 --- /dev/null +++ b/opentrack-compat/process-list.hpp @@ -0,0 +1,162 @@ +#pragma once + +#include <QDebug> +#include <QStringList> + +#if defined _WIN32 + +#include <windows.h> +#include <TlHelp32.h> + +template<typename = void> +static QStringList get_all_executable_names() +{ + QStringList ret; + HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (h == INVALID_HANDLE_VALUE) + return ret; + + PROCESSENTRY32 e; + e.dwSize = sizeof(e); + + if (Process32First(h, &e) != TRUE) + { + CloseHandle(h); + return ret; + } + + do { + ret.append(e.szExeFile); + } while (Process32Next(h, &e) == TRUE); + + CloseHandle(h); + + return ret; +} +#elif defined __APPLE__ +#include <libproc.h> +#include <sys/param.h> +#include <sys/types.h> +#include <sys/sysctl.h> +#include <cerrno> +#include <cstring> +#include <vector> + +template<typename = void> +static QStringList get_all_executable_names() +{ + QStringList ret; + std::vector<int> vec; + + while (true) + { + int numproc = proc_listpids(PROC_ALL_PIDS, 0, nullptr, 0); + if (numproc == -1) + { + qDebug() << "proc_listpids numproc failed" << errno; + return ret; + } + vec.resize(numproc); + int cnt = proc_listpids(PROC_ALL_PIDS, 0, &vec[0], sizeof(int) * numproc); + + if (cnt <= numproc) + { + std::vector<char> arglist; + int mib[2] { CTL_KERN, KERN_ARGMAX }; + size_t sz = sizeof(int); + int maxarg = 0; + if (sysctl(mib, 2, &maxarg, &sz, NULL, 0) == -1) + { + qDebug() << "sysctl KERN_ARGMAX" << errno; + return ret; + } + arglist.resize(maxarg); + for (int i = 0; i < numproc; i++) + { + size_t maxarg_ = (size_t)maxarg; + int mib[3] { CTL_KERN, KERN_PROCARGS2, vec[i] }; + if (sysctl(mib, 3, &arglist[0], &maxarg_, NULL, 0) == -1) + { + //qDebug() << "sysctl KERN_PROCARGS2" << vec[i] << errno; + continue; + } + QStringList cmdline; + for (unsigned j = sizeof(int) + strlen(&arglist[sizeof(int)]); j < maxarg_; j++) + { + QString arg(&arglist[j]); + if (arg.size() != 0) + { + cmdline << arg; + j += arg.size(); + } + } + if (cmdline.size() > 0) + { + int idx = cmdline[0].lastIndexOf('/'); + if (idx != -1) + { + QString tmp = cmdline[0].mid(idx+1); + if (cmdline.size() > 1 && (tmp == "wine.bin" || tmp == "wine")) + { + idx = cmdline[1].lastIndexOf('/'); + if (idx == -1) + idx = cmdline[1].lastIndexOf('\\'); + if (idx != -1) + { + ret.append(cmdline[1].mid(idx+1)); + } + else + ret.append(cmdline[1]); + } + else + { + ret.append(tmp); + } + } + else + ret.append(cmdline[0]); + } + } + return ret; + } + } +} + +#elif defined __linux + +#include <proc/readproc.h> +#include <cerrno> +template<typename = void> +static QStringList get_all_executable_names() +{ + QStringList ret; + proc_t** procs = readproctab(PROC_FILLCOM); + if (procs == nullptr) + { + qDebug() << "readproctab" << errno; + return ret; + } + for (int i = 0; procs[i]; i++) + { + // note, wine sets argv[0] so no parsing like in OSX case + auto proc = procs[i]; + if (proc->cmdline && proc->cmdline[0]) + { + QString tmp(proc->cmdline[0]); + const int idx = std::max(tmp.lastIndexOf('\\'), tmp.lastIndexOf('/')); + tmp = tmp.mid(idx == -1 ? 0 : idx+1); + ret.append(tmp); + } + freeproc(procs[i]); + } + free(procs); + return ret; +} + +#else +template<typename = void> +static QStringList get_all_executable_names() +{ + return QStringList(); +} +#endif |