summaryrefslogtreecommitdiff
path: root/Library/SDK/Modules/Strawberry.SystemInfo.js
blob: b52b1c20d48f5054ce9fd674ccc5961c477d2780 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
const os = require('os');
const fs = require('fs');

module.exports = {
    GetHardwareMemory: () => {
        return {
            Total: os.totalmem(),
            Free: os.freemem(),
            Used: os.totalmem() - os.freemem(),
        }
    },

    GetProcessors: () => {
        let cpus = os.cpus();
        return {
            Count: cpus.length,
            Model: cpus.map((i) => {
                return i.model;
            })
        }
    },

    Version: () => {
        return fs.readFileSync(_STRAWBERRY_SYSTEM_ROOT + "/Version").toString().trim().split("\n")[1].trim();
    },

    Processes: () => {
        let list = [];

        let p = Object.keys(require.cache).map((i) => {
            let cid = -1;
            return { name: i, children: [
                ...(require.cache[i].children.map((j) => {
                    cid++;

                    if (require.cache[i].children[cid] === undefined) {
                        return { name: j.id, children: [] }
                    } else {
                        return { name: j.id, children: [
                                ...(require.cache[i].children[cid].children.map((k) => {
                                    return { name: k.id, children: null }
                                }))
                            ]
                        }
                    }
                }))
            ] }
        });

        list.push("0000: " + chalk.magenta("strawberry-boot") + (global._STRAWBERRY_EMULATED ? chalk.gray(" (emulated)") : ""));

        let index = 0;
        let pid = 1;
        for (let proc of p) {
            if (proc === undefined) continue;

            if (proc['name'].startsWith(global._STRAWBERRY_SYSTEM_ROOT)) {
                proc['name'] = "/System" + proc['name'].substring(global._STRAWBERRY_SYSTEM_ROOT.length);
            }
            if (proc['name'].startsWith("/Strawberry")) {
                proc['name'] = proc['name'].substring(11);
            }
            if (proc['name'].startsWith("/System/Library/SDK/")) {
                proc['name'] = chalk.yellow(proc['name']);
            }
            if (proc['name'].startsWith("/System/StrawKit/")) {
                proc['name'] = chalk.red(proc['name']);
            }
            if (proc['name'].startsWith("/System/Applications/")) {
                proc['name'] = chalk.green(proc['name']);
            }
            if (!proc['name'].startsWith("/System")) {
                proc['name'] = chalk.cyan(proc['name']);
            }

            let s = pid.toString();
            let k = s;

            if (s.length > 3) {
                k = s;
            } else if (s.length > 2) {
                k = "0" + s;
            } else if (s.length > 1) {
                k = "00" + s;
            } else {
                k = "000" + s;
            }

            let childPrefix = " ";
            if (index >= p.length - 1) {
                list.push("  ┗ " + k + ": " + proc['name']);
                childPrefix = " ";
            } else {
                list.push("  ┣ " + k + ": " + proc['name']);
                childPrefix = "┃";
            }

            if (proc['children'].length > 0) {
                let cIndex = 0;

                for (let child of proc['children']) {
                    if (child === undefined) continue;

                    if (child['name'].startsWith(global._STRAWBERRY_SYSTEM_ROOT)) {
                        child['name'] = "/System" + child['name'].substring(global._STRAWBERRY_SYSTEM_ROOT.length);
                    }
                    if (child['name'].startsWith("/Strawberry")) {
                        child['name'] = child['name'].substring(11);
                    }
                    if (child['name'].startsWith("/System/Library/SDK/")) {
                        child['name'] = chalk.yellow(child['name']);
                    }
                    if (!child['name'].startsWith("/System")) {
                        child['name'] = chalk.cyan(child['name']);
                    }
                    if (child['name'].startsWith("/System/StrawKit/")) {
                        child['name'] = chalk.red(child['name']);
                    }
                    if (child['name'].startsWith("/System/Applications/")) {
                        child['name'] = chalk.green(child['name']);
                    }

                    pid++;
                    let o = pid.toString();
                    let j = o;

                    if (o.length > 3) {
                        j = o;
                    } else if (o.length > 2) {
                        j = "0" + o;
                    } else if (o.length > 1) {
                        j = "00" + o;
                    } else {
                        j = "000" + o;
                    }

                    let childChildPrefix = " ";
                    if (cIndex >= proc['children'].length - 1) {
                        childChildPrefix = " ";
                        list.push("  " + childPrefix + "   ┗ " + j + ": " + child['name']);
                    } else {
                        childChildPrefix = "┃";
                        list.push("  " + childPrefix + "   ┣ " + j + ": " + child['name']);
                    }

                    cIndex++;

                    if (child['children'].length > 0) {
                        let cIndex = 0;

                        for (let child2 of child['children']) {
                            if (child2 === undefined) continue;

                            if (child2['name'].startsWith(global._STRAWBERRY_SYSTEM_ROOT)) {
                                child2['name'] = "/System" + child2['name'].substring(global._STRAWBERRY_SYSTEM_ROOT.length);
                            }
                            if (child2['name'].startsWith("/Strawberry")) {
                                child2['name'] = child2['name'].substring(11);
                            }
                            if (child2['name'].startsWith("/System/Library/SDK/")) {
                                child2['name'] = chalk.yellow(child2['name']);
                            }
                            if (!child2['name'].startsWith("/System")) {
                                child2['name'] = chalk.cyan(child2['name']);
                            }
                            if (child2['name'].startsWith("/System/StrawKit/")) {
                                child2['name'] = chalk.red(child2['name']);
                            }
                            if (child2['name'].startsWith("/System/Applications/")) {
                                child2['name'] = chalk.green(child2['name']);
                            }

                            pid++;
                            let o = pid.toString();
                            let j = o;

                            if (o.length > 3) {
                                j = o;
                            } else if (o.length > 2) {
                                j = "0" + o;
                            } else if (o.length > 1) {
                                j = "00" + o;
                            } else {
                                j = "000" + o;
                            }

                            if (cIndex >= child['children'].length - 1) {
                                list.push("  " + childPrefix + "   " + childChildPrefix + "   ┗ " + j + ": " + child2['name']);
                            } else {
                                list.push("  " + childPrefix + "   " + childChildPrefix + "   ┣ " + j + ": " + child2['name']);
                            }

                            cIndex++;
                        }
                    }
                }
            }

            pid++; index++;
        }

        return list;
    }
}