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.

246 lines
11KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE examples.
  4. Copyright (c) 2020 - 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, vs2019, 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 getAllSystemInfo()
  90. {
  91. String systemInfo;
  92. systemInfo
  93. << "Here are a few system statistics..." << newLine
  94. << newLine
  95. << "Time and date: " << Time::getCurrentTime().toString (true, true) << newLine
  96. << "System up-time: " << RelativeTime::milliseconds ((int64) Time::getMillisecondCounterHiRes()).getDescription() << newLine
  97. << "Compilation date: " << Time::getCompilationDate().toString (true, false) << newLine
  98. << newLine
  99. << "Operating system: " << SystemStats::getOperatingSystemName() << newLine
  100. << "Host name: " << SystemStats::getComputerName() << newLine
  101. << "Device type: " << SystemStats::getDeviceDescription() << newLine
  102. << "Manufacturer: " << SystemStats::getDeviceManufacturer() << newLine
  103. << "User logon name: " << SystemStats::getLogonName() << newLine
  104. << "Full user name: " << SystemStats::getFullUserName() << newLine
  105. << "User region: " << SystemStats::getUserRegion() << newLine
  106. << "User language: " << SystemStats::getUserLanguage() << newLine
  107. << "Display language: " << SystemStats::getDisplayLanguage() << newLine
  108. << newLine;
  109. systemInfo
  110. << "Number of logical CPUs: " << SystemStats::getNumCpus() << newLine
  111. << "Number of physical CPUs: " << SystemStats::getNumPhysicalCpus() << newLine
  112. << "Memory size: " << SystemStats::getMemorySizeInMegabytes() << " MB" << newLine
  113. << "CPU vendor: " << SystemStats::getCpuVendor() << newLine
  114. << "CPU model: " << SystemStats::getCpuModel() << newLine
  115. << "CPU speed: " << SystemStats::getCpuSpeedInMegahertz() << " MHz" << newLine
  116. << "CPU has MMX: " << (SystemStats::hasMMX() ? "yes" : "no") << newLine
  117. << "CPU has FMA3: " << (SystemStats::hasFMA3() ? "yes" : "no") << newLine
  118. << "CPU has FMA4: " << (SystemStats::hasFMA4() ? "yes" : "no") << newLine
  119. << "CPU has SSE: " << (SystemStats::hasSSE() ? "yes" : "no") << newLine
  120. << "CPU has SSE2: " << (SystemStats::hasSSE2() ? "yes" : "no") << newLine
  121. << "CPU has SSE3: " << (SystemStats::hasSSE3() ? "yes" : "no") << newLine
  122. << "CPU has SSSE3: " << (SystemStats::hasSSSE3() ? "yes" : "no") << newLine
  123. << "CPU has SSE4.1: " << (SystemStats::hasSSE41() ? "yes" : "no") << newLine
  124. << "CPU has SSE4.2: " << (SystemStats::hasSSE42() ? "yes" : "no") << newLine
  125. << "CPU has 3DNOW: " << (SystemStats::has3DNow() ? "yes" : "no") << newLine
  126. << "CPU has AVX: " << (SystemStats::hasAVX() ? "yes" : "no") << newLine
  127. << "CPU has AVX2: " << (SystemStats::hasAVX2() ? "yes" : "no") << newLine
  128. << "CPU has AVX512F: " << (SystemStats::hasAVX512F() ? "yes" : "no") << newLine
  129. << "CPU has AVX512BW: " << (SystemStats::hasAVX512BW() ? "yes" : "no") << newLine
  130. << "CPU has AVX512CD: " << (SystemStats::hasAVX512CD() ? "yes" : "no") << newLine
  131. << "CPU has AVX512DQ: " << (SystemStats::hasAVX512DQ() ? "yes" : "no") << newLine
  132. << "CPU has AVX512ER: " << (SystemStats::hasAVX512ER() ? "yes" : "no") << newLine
  133. << "CPU has AVX512IFMA: " << (SystemStats::hasAVX512IFMA() ? "yes" : "no") << newLine
  134. << "CPU has AVX512PF: " << (SystemStats::hasAVX512PF() ? "yes" : "no") << newLine
  135. << "CPU has AVX512VBMI: " << (SystemStats::hasAVX512VBMI() ? "yes" : "no") << newLine
  136. << "CPU has AVX512VL: " << (SystemStats::hasAVX512VL() ? "yes" : "no") << newLine
  137. << "CPU has AVX512VPOPCNTDQ: " << (SystemStats::hasAVX512VPOPCNTDQ() ? "yes" : "no") << newLine
  138. << "CPU has Neon: " << (SystemStats::hasNeon() ? "yes" : "no") << newLine
  139. << newLine;
  140. systemInfo
  141. << "Current working directory: " << File::getCurrentWorkingDirectory().getFullPathName() << newLine
  142. << "Current application file: " << File::getSpecialLocation (File::currentApplicationFile).getFullPathName() << newLine
  143. << "Current executable file: " << File::getSpecialLocation (File::currentExecutableFile) .getFullPathName() << newLine
  144. << "Invoked executable file: " << File::getSpecialLocation (File::invokedExecutableFile) .getFullPathName() << newLine
  145. << newLine;
  146. systemInfo
  147. << "User home folder: " << File::getSpecialLocation (File::userHomeDirectory) .getFullPathName() << newLine
  148. << "User desktop folder: " << File::getSpecialLocation (File::userDesktopDirectory) .getFullPathName() << newLine
  149. << "User documents folder: " << File::getSpecialLocation (File::userDocumentsDirectory) .getFullPathName() << newLine
  150. << "User application data folder: " << File::getSpecialLocation (File::userApplicationDataDirectory) .getFullPathName() << newLine
  151. << "User music folder: " << File::getSpecialLocation (File::userMusicDirectory) .getFullPathName() << newLine
  152. << "User movies folder: " << File::getSpecialLocation (File::userMoviesDirectory) .getFullPathName() << newLine
  153. << "User pictures folder: " << File::getSpecialLocation (File::userPicturesDirectory) .getFullPathName() << newLine
  154. << "Common application data folder: " << File::getSpecialLocation (File::commonApplicationDataDirectory).getFullPathName() << newLine
  155. << "Common documents folder: " << File::getSpecialLocation (File::commonDocumentsDirectory) .getFullPathName() << newLine
  156. << "Local temp folder: " << File::getSpecialLocation (File::tempDirectory) .getFullPathName() << newLine
  157. << newLine;
  158. systemInfo
  159. << "File System roots: " << getFileSystemRoots() << newLine
  160. << "Free space in home folder: " << File::descriptionOfSizeInBytes (File::getSpecialLocation (File::userHomeDirectory)
  161. .getBytesFreeOnVolume()) << newLine
  162. << newLine
  163. << getDisplayInfo() << newLine
  164. << "Network IP addresses: " << newLine << getIPAddressList() << newLine
  165. << "Network card MAC addresses: " << newLine << getMacAddressList() << newLine;
  166. DBG (systemInfo);
  167. return systemInfo;
  168. }
  169. class SystemInfoDemo : public Component
  170. {
  171. public:
  172. SystemInfoDemo()
  173. {
  174. addAndMakeVisible (resultsBox);
  175. resultsBox.setReadOnly (true);
  176. resultsBox.setMultiLine (true);
  177. resultsBox.setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  178. resultsBox.setFont ({ Font::getDefaultMonospacedFontName(), 12.0f, Font::plain });
  179. resultsBox.setText (getAllSystemInfo());
  180. setSize (500, 500);
  181. }
  182. void paint (Graphics& g) override
  183. {
  184. g.fillAll (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground,
  185. Colour::greyLevel (0.93f)));
  186. }
  187. void resized() override
  188. {
  189. resultsBox.setBounds (getLocalBounds().reduced (8));
  190. }
  191. private:
  192. TextEditor resultsBox;
  193. void lookAndFeelChanged() override
  194. {
  195. resultsBox.applyFontToAllText (resultsBox.getFont());
  196. }
  197. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SystemInfoDemo)
  198. };