Mercurial > minori
annotate dep/animia/src/main.cpp @ 62:4c6dd5999b39
*: update
1. updated animia
2. use widestrings for filesystem on Windows
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 01 Oct 2023 06:16:06 -0400 |
parents | 6ff7aabeb9d7 |
children | 18979b066284 |
rev | line source |
---|---|
56
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
1 #include "bsd.h" |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
2 #include "linux.h" |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
3 #include "win32.h" |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
4 #include <string> |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
5 #include <unordered_map> |
62 | 6 #include <vector> |
56
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
7 #ifdef __linux__ |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
8 # define ON_LINUX |
62 | 9 #elif (defined(unix) || defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) |
56
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
10 # define ON_UNIX |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
11 #elif defined(_WIN32) |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
12 # define ON_WINDOWS |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
13 #endif |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
14 |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
15 namespace Animia { |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
16 |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
17 std::vector<int> get_all_pids() { |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
18 #ifdef ON_UNIX |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
19 return Unix::get_all_pids(); |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
20 #elif defined(ON_LINUX) |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
21 return Linux::get_all_pids(); |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
22 #elif defined(ON_WINDOWS) |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
23 return Windows::get_all_pids(); |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
24 #else |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
25 return {}; |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
26 #endif |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
27 } |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
28 |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
29 std::string get_process_name(int pid) { |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
30 #ifdef ON_UNIX |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
31 return Unix::get_process_name(pid); |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
32 #elif defined(ON_LINUX) |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
33 return Linux::get_process_name(pid); |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
34 #elif defined(ON_WINDOWS) |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
35 return Windows::get_process_name(pid); |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
36 #else |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
37 return ""; |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
38 #endif |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
39 } |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
40 |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
41 std::vector<std::string> get_open_files(int pid) { |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
42 #ifdef ON_UNIX |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
43 return Unix::get_open_files(pid); |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
44 #elif defined(ON_LINUX) |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
45 return Linux::get_open_files(pid); |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
46 #elif defined(ON_WINDOWS) |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
47 return Windows::get_open_files(pid); |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
48 #else |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
49 return {}; |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
50 #endif |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
51 } |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
52 |
62 | 53 std::vector<std::string> filter_system_files(const std::vector<std::string>& source) { |
54 #ifdef ON_WINDOWS | |
55 return Windows::filter_system_files(source); | |
56 #else | |
57 return source; | |
58 #endif | |
59 } | |
60 | |
56
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
61 std::unordered_map<int, std::vector<std::string>> get_all_open_files() { |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
62 #ifdef ON_UNIX |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
63 return Unix::get_all_open_files(); |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
64 #elif defined(ON_LINUX) |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
65 return Linux::get_all_open_files(); |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
66 #elif defined(ON_WINDOWS) |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
67 return Windows::get_all_open_files(); |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
68 #else |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
69 return {}; |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
70 #endif |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
71 } |
6ff7aabeb9d7
deps: add animia for open files detection
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
72 |
62 | 73 } // namespace Animia |