The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

258 lines
12KB

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