1 /*
2 ==============================================================================
3
4 This file is part of the JUCE examples.
5 Copyright (c) 2020 - Raw Material Software Limited
6
7 The code included in this file is provided under the terms of the ISC license
8 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
9 To use, copy, modify, and/or distribute this software for any purpose with or
10 without fee is hereby granted provided that the above copyright notice and
11 this permission notice appear in all copies.
12
13 THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
14 WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
15 PURPOSE, ARE DISCLAIMED.
16
17 ==============================================================================
18 */
19
20 /*******************************************************************************
21 The block below describes the properties of this PIP. A PIP is a short snippet
22 of code that can be read by the Projucer and used to generate a JUCE project.
23
24 BEGIN_JUCE_PIP_METADATA
25
26 name: SystemInfoDemo
27 version: 1.0.0
28 vendor: JUCE
29 website: http://juce.com
30 description: Displays system information.
31
32 dependencies: juce_core, juce_data_structures, juce_events, juce_graphics,
33 juce_gui_basics
34 exporters: xcode_mac, vs2019, linux_make, androidstudio, xcode_iphone
35
36 moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
37
38 type: Component
39 mainClass: SystemInfoDemo
40
41 useLocalCopy: 1
42
43 END_JUCE_PIP_METADATA
44
45 *******************************************************************************/
46
47 #pragma once
48
49 #include "../Assets/DemoUtilities.h"
50
51 //==============================================================================
getMacAddressList()52 static String getMacAddressList()
53 {
54 String addressList;
55
56 for (auto& addr : MACAddress::getAllAddresses())
57 addressList << addr.toString() << newLine;
58
59 return addressList;
60 }
61
getFileSystemRoots()62 static String getFileSystemRoots()
63 {
64 Array<File> roots;
65 File::findFileSystemRoots (roots);
66
67 StringArray rootList;
68 for (auto& r : roots)
69 rootList.add (r.getFullPathName());
70
71 return rootList.joinIntoString (", ");
72 }
73
getIPAddressList()74 static String getIPAddressList()
75 {
76 String addressList;
77
78 for (auto& addr : IPAddress::getAllAddresses())
79 addressList << " " << addr.toString() << newLine;
80
81 return addressList;
82 }
83
getDisplayOrientation()84 static const char* getDisplayOrientation()
85 {
86 switch (Desktop::getInstance().getCurrentOrientation())
87 {
88 case Desktop::upright: return "Upright";
89 case Desktop::upsideDown: return "Upside-down";
90 case Desktop::rotatedClockwise: return "Rotated Clockwise";
91 case Desktop::rotatedAntiClockwise: return "Rotated Anti-clockwise";
92 case Desktop::allOrientations: return "All";
93 default: jassertfalse; break;
94 }
95
96 return nullptr;
97 }
98
getDisplayInfo()99 static String getDisplayInfo()
100 {
101 auto& displays = Desktop::getInstance().getDisplays();
102
103 String displayDesc;
104
105 for (int i = 0; i < displays.displays.size(); ++i)
106 {
107 auto display = displays.displays.getReference (i);
108
109 displayDesc << "Display " << (i + 1) << (display.isMain ? " (main)" : "") << ":" << newLine
110 << " Total area: " << display.totalArea.toString() << newLine
111 << " User area: " << display.userArea .toString() << newLine
112 << " DPI: " << display.dpi << newLine
113 << " Scale: " << display.scale << newLine
114 << newLine;
115 }
116
117
118 displayDesc << "Orientation: " << getDisplayOrientation() << newLine;
119
120 return displayDesc;
121 }
122
getAllSystemInfo()123 static String getAllSystemInfo()
124 {
125 String systemInfo;
126
127 systemInfo
128 << "Here are a few system statistics..." << newLine
129 << newLine
130 << "Time and date: " << Time::getCurrentTime().toString (true, true) << newLine
131 << "System up-time: " << RelativeTime::milliseconds ((int64) Time::getMillisecondCounterHiRes()).getDescription() << newLine
132 << "Compilation date: " << Time::getCompilationDate().toString (true, false) << newLine
133 << newLine
134 << "Operating system: " << SystemStats::getOperatingSystemName() << newLine
135 << "Host name: " << SystemStats::getComputerName() << newLine
136 << "Device type: " << SystemStats::getDeviceDescription() << newLine
137 << "Manufacturer: " << SystemStats::getDeviceManufacturer() << newLine
138 << "User logon name: " << SystemStats::getLogonName() << newLine
139 << "Full user name: " << SystemStats::getFullUserName() << newLine
140 << "User region: " << SystemStats::getUserRegion() << newLine
141 << "User language: " << SystemStats::getUserLanguage() << newLine
142 << "Display language: " << SystemStats::getDisplayLanguage() << newLine
143 << newLine;
144
145 systemInfo
146 << "Number of logical CPUs: " << SystemStats::getNumCpus() << newLine
147 << "Number of physical CPUs: " << SystemStats::getNumPhysicalCpus() << newLine
148 << "Memory size: " << SystemStats::getMemorySizeInMegabytes() << " MB" << newLine
149 << "CPU vendor: " << SystemStats::getCpuVendor() << newLine
150 << "CPU model: " << SystemStats::getCpuModel() << newLine
151 << "CPU speed: " << SystemStats::getCpuSpeedInMegahertz() << " MHz" << newLine
152 << "CPU has MMX: " << (SystemStats::hasMMX() ? "yes" : "no") << newLine
153 << "CPU has FMA3: " << (SystemStats::hasFMA3() ? "yes" : "no") << newLine
154 << "CPU has FMA4: " << (SystemStats::hasFMA4() ? "yes" : "no") << newLine
155 << "CPU has SSE: " << (SystemStats::hasSSE() ? "yes" : "no") << newLine
156 << "CPU has SSE2: " << (SystemStats::hasSSE2() ? "yes" : "no") << newLine
157 << "CPU has SSE3: " << (SystemStats::hasSSE3() ? "yes" : "no") << newLine
158 << "CPU has SSSE3: " << (SystemStats::hasSSSE3() ? "yes" : "no") << newLine
159 << "CPU has SSE4.1: " << (SystemStats::hasSSE41() ? "yes" : "no") << newLine
160 << "CPU has SSE4.2: " << (SystemStats::hasSSE42() ? "yes" : "no") << newLine
161 << "CPU has 3DNOW: " << (SystemStats::has3DNow() ? "yes" : "no") << newLine
162 << "CPU has AVX: " << (SystemStats::hasAVX() ? "yes" : "no") << newLine
163 << "CPU has AVX2: " << (SystemStats::hasAVX2() ? "yes" : "no") << newLine
164 << "CPU has AVX512F: " << (SystemStats::hasAVX512F() ? "yes" : "no") << newLine
165 << "CPU has AVX512BW: " << (SystemStats::hasAVX512BW() ? "yes" : "no") << newLine
166 << "CPU has AVX512CD: " << (SystemStats::hasAVX512CD() ? "yes" : "no") << newLine
167 << "CPU has AVX512DQ: " << (SystemStats::hasAVX512DQ() ? "yes" : "no") << newLine
168 << "CPU has AVX512ER: " << (SystemStats::hasAVX512ER() ? "yes" : "no") << newLine
169 << "CPU has AVX512IFMA: " << (SystemStats::hasAVX512IFMA() ? "yes" : "no") << newLine
170 << "CPU has AVX512PF: " << (SystemStats::hasAVX512PF() ? "yes" : "no") << newLine
171 << "CPU has AVX512VBMI: " << (SystemStats::hasAVX512VBMI() ? "yes" : "no") << newLine
172 << "CPU has AVX512VL: " << (SystemStats::hasAVX512VL() ? "yes" : "no") << newLine
173 << "CPU has AVX512VPOPCNTDQ: " << (SystemStats::hasAVX512VPOPCNTDQ() ? "yes" : "no") << newLine
174 << "CPU has Neon: " << (SystemStats::hasNeon() ? "yes" : "no") << newLine
175 << newLine;
176
177 systemInfo
178 << "Current working directory: " << File::getCurrentWorkingDirectory().getFullPathName() << newLine
179 << "Current application file: " << File::getSpecialLocation (File::currentApplicationFile).getFullPathName() << newLine
180 << "Current executable file: " << File::getSpecialLocation (File::currentExecutableFile) .getFullPathName() << newLine
181 << "Invoked executable file: " << File::getSpecialLocation (File::invokedExecutableFile) .getFullPathName() << newLine
182 << newLine;
183
184 systemInfo
185 << "User home folder: " << File::getSpecialLocation (File::userHomeDirectory) .getFullPathName() << newLine
186 << "User desktop folder: " << File::getSpecialLocation (File::userDesktopDirectory) .getFullPathName() << newLine
187 << "User documents folder: " << File::getSpecialLocation (File::userDocumentsDirectory) .getFullPathName() << newLine
188 << "User application data folder: " << File::getSpecialLocation (File::userApplicationDataDirectory) .getFullPathName() << newLine
189 << "User music folder: " << File::getSpecialLocation (File::userMusicDirectory) .getFullPathName() << newLine
190 << "User movies folder: " << File::getSpecialLocation (File::userMoviesDirectory) .getFullPathName() << newLine
191 << "User pictures folder: " << File::getSpecialLocation (File::userPicturesDirectory) .getFullPathName() << newLine
192 << "Common application data folder: " << File::getSpecialLocation (File::commonApplicationDataDirectory).getFullPathName() << newLine
193 << "Common documents folder: " << File::getSpecialLocation (File::commonDocumentsDirectory) .getFullPathName() << newLine
194 << "Local temp folder: " << File::getSpecialLocation (File::tempDirectory) .getFullPathName() << newLine
195 << newLine;
196
197 systemInfo
198 << "File System roots: " << getFileSystemRoots() << newLine
199 << "Free space in home folder: " << File::descriptionOfSizeInBytes (File::getSpecialLocation (File::userHomeDirectory)
200 .getBytesFreeOnVolume()) << newLine
201 << newLine
202 << getDisplayInfo() << newLine
203 << "Network IP addresses: " << newLine << getIPAddressList() << newLine
204 << "Network card MAC addresses: " << newLine << getMacAddressList() << newLine;
205
206 DBG (systemInfo);
207 return systemInfo;
208 }
209
210 class SystemInfoDemo : public Component
211 {
212 public:
SystemInfoDemo()213 SystemInfoDemo()
214 {
215 addAndMakeVisible (resultsBox);
216 resultsBox.setReadOnly (true);
217 resultsBox.setMultiLine (true);
218 resultsBox.setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
219 resultsBox.setFont ({ Font::getDefaultMonospacedFontName(), 12.0f, Font::plain });
220 resultsBox.setText (getAllSystemInfo());
221
222 setSize (500, 500);
223 }
224
paint(Graphics & g)225 void paint (Graphics& g) override
226 {
227 g.fillAll (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground,
228 Colour::greyLevel (0.93f)));
229 }
230
resized()231 void resized() override
232 {
233 resultsBox.setBounds (getLocalBounds().reduced (8));
234 }
235
236 private:
237 TextEditor resultsBox;
238
lookAndFeelChanged()239 void lookAndFeelChanged() override
240 {
241 resultsBox.applyFontToAllText (resultsBox.getFont());
242 }
243
244 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SystemInfoDemo)
245 };
246