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.

236 lines
10KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE examples.
  4. Copyright (c) 2017 - ROLI Ltd.
  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, vs2017, linux_make, androidstudio, xcode_iphone
  27. type: Component
  28. mainClass: SystemInfoDemo
  29. useLocalCopy: 1
  30. END_JUCE_PIP_METADATA
  31. *******************************************************************************/
  32. #pragma once
  33. #include "../Assets/DemoUtilities.h"
  34. //==============================================================================
  35. static String getMacAddressList()
  36. {
  37. Array<MACAddress> macAddresses;
  38. MACAddress::findAllAddresses (macAddresses);
  39. String addressList;
  40. for (auto& addr : macAddresses)
  41. addressList << addr.toString() << newLine;
  42. return addressList;
  43. }
  44. static String getFileSystemRoots()
  45. {
  46. Array<File> roots;
  47. File::findFileSystemRoots (roots);
  48. StringArray rootList;
  49. for (auto& r : roots)
  50. rootList.add (r.getFullPathName());
  51. return rootList.joinIntoString (", ");
  52. }
  53. static String getIPAddressList()
  54. {
  55. Array<IPAddress> addresses;
  56. IPAddress::findAllAddresses (addresses);
  57. String addressList;
  58. for (auto& addr : addresses)
  59. addressList << " " << addr.toString() << newLine;
  60. return addressList;
  61. }
  62. static const char* getDisplayOrientation()
  63. {
  64. switch (Desktop::getInstance().getCurrentOrientation())
  65. {
  66. case Desktop::upright: return "Upright";
  67. case Desktop::upsideDown: return "Upside-down";
  68. case Desktop::rotatedClockwise: return "Rotated Clockwise";
  69. case Desktop::rotatedAntiClockwise: return "Rotated Anti-clockwise";
  70. default: jassertfalse; break;
  71. }
  72. return nullptr;
  73. }
  74. static String getDisplayInfo()
  75. {
  76. auto& displays = Desktop::getInstance().getDisplays();
  77. String displayDesc;
  78. for (int i = 0; i < displays.displays.size(); ++i)
  79. {
  80. auto display = displays.displays.getReference (i);
  81. displayDesc << "Display " << (i + 1) << (display.isMain ? " (main)" : "") << ":" << newLine
  82. << " Total area: " << display.totalArea.toString() << newLine
  83. << " User area: " << display.userArea .toString() << newLine
  84. << " DPI: " << display.dpi << newLine
  85. << " Scale: " << display.scale << newLine
  86. << newLine;
  87. }
  88. displayDesc << "Orientation: " << getDisplayOrientation() << newLine;
  89. return displayDesc;
  90. }
  91. static String getAllSystemInfo()
  92. {
  93. String systemInfo;
  94. systemInfo
  95. << "Here are a few system statistics..." << newLine
  96. << newLine
  97. << "Time and date: " << Time::getCurrentTime().toString (true, true) << newLine
  98. << "System up-time: " << RelativeTime::milliseconds ((int64) Time::getMillisecondCounterHiRes()).getDescription() << newLine
  99. << "Compilation date: " << Time::getCompilationDate().toString (true, false) << newLine
  100. << newLine
  101. << "Operating system: " << SystemStats::getOperatingSystemName() << newLine
  102. << "Host name: " << SystemStats::getComputerName() << newLine
  103. << "Device type: " << SystemStats::getDeviceDescription() << newLine
  104. << "Manufacturer: " << SystemStats::getDeviceManufacturer() << newLine
  105. << "User logon name: " << SystemStats::getLogonName() << newLine
  106. << "Full user name: " << SystemStats::getFullUserName() << newLine
  107. << "User region: " << SystemStats::getUserRegion() << newLine
  108. << "User language: " << SystemStats::getUserLanguage() << newLine
  109. << "Display language: " << SystemStats::getDisplayLanguage() << newLine
  110. << newLine;
  111. systemInfo
  112. << "Number of logical CPUs: " << SystemStats::getNumCpus() << newLine
  113. << "Number of physical CPUs: " << SystemStats::getNumPhysicalCpus() << newLine
  114. << "Memory size: " << SystemStats::getMemorySizeInMegabytes() << " MB" << newLine
  115. << "CPU vendor: " << SystemStats::getCpuVendor() << newLine
  116. << "CPU model: " << SystemStats::getCpuModel() << newLine
  117. << "CPU speed: " << SystemStats::getCpuSpeedInMegaherz() << " MHz" << newLine
  118. << "CPU has MMX: " << (SystemStats::hasMMX() ? "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 Neon: " << (SystemStats::hasNeon() ? "yes" : "no") << newLine
  129. << newLine;
  130. systemInfo
  131. << "Current working directory: " << File::getCurrentWorkingDirectory().getFullPathName() << newLine
  132. << "Current application file: " << File::getSpecialLocation (File::currentApplicationFile).getFullPathName() << newLine
  133. << "Current executable file: " << File::getSpecialLocation (File::currentExecutableFile) .getFullPathName() << newLine
  134. << "Invoked executable file: " << File::getSpecialLocation (File::invokedExecutableFile) .getFullPathName() << newLine
  135. << newLine;
  136. systemInfo
  137. << "User home folder: " << File::getSpecialLocation (File::userHomeDirectory) .getFullPathName() << newLine
  138. << "User desktop folder: " << File::getSpecialLocation (File::userDesktopDirectory) .getFullPathName() << newLine
  139. << "User documents folder: " << File::getSpecialLocation (File::userDocumentsDirectory) .getFullPathName() << newLine
  140. << "User application data folder: " << File::getSpecialLocation (File::userApplicationDataDirectory) .getFullPathName() << newLine
  141. << "User music folder: " << File::getSpecialLocation (File::userMusicDirectory) .getFullPathName() << newLine
  142. << "User movies folder: " << File::getSpecialLocation (File::userMoviesDirectory) .getFullPathName() << newLine
  143. << "User pictures folder: " << File::getSpecialLocation (File::userPicturesDirectory) .getFullPathName() << newLine
  144. << "Common application data folder: " << File::getSpecialLocation (File::commonApplicationDataDirectory).getFullPathName() << newLine
  145. << "Common documents folder: " << File::getSpecialLocation (File::commonDocumentsDirectory) .getFullPathName() << newLine
  146. << "Local temp folder: " << File::getSpecialLocation (File::tempDirectory) .getFullPathName() << newLine
  147. << newLine;
  148. systemInfo
  149. << "File System roots: " << getFileSystemRoots() << newLine
  150. << "Free space in home folder: " << File::descriptionOfSizeInBytes (File::getSpecialLocation (File::userHomeDirectory)
  151. .getBytesFreeOnVolume()) << newLine
  152. << newLine
  153. << getDisplayInfo() << newLine
  154. << "Network IP addresses: " << newLine << getIPAddressList() << newLine
  155. << "Network card MAC addresses: " << newLine << getMacAddressList() << newLine;
  156. DBG (systemInfo);
  157. return systemInfo;
  158. }
  159. class SystemInfoDemo : public Component
  160. {
  161. public:
  162. SystemInfoDemo()
  163. {
  164. addAndMakeVisible (resultsBox);
  165. resultsBox.setReadOnly (true);
  166. resultsBox.setMultiLine (true);
  167. resultsBox.setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  168. resultsBox.setFont ({ Font::getDefaultMonospacedFontName(), 12.0f, Font::plain });
  169. resultsBox.setText (getAllSystemInfo());
  170. setSize (500, 500);
  171. }
  172. void paint (Graphics& g) override
  173. {
  174. g.fillAll (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground,
  175. Colour::greyLevel (0.93f)));
  176. }
  177. void resized() override
  178. {
  179. resultsBox.setBounds (getLocalBounds().reduced (8));
  180. }
  181. private:
  182. TextEditor resultsBox;
  183. void lookAndFeelChanged() override
  184. {
  185. resultsBox.applyFontToAllText (resultsBox.getFont());
  186. }
  187. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SystemInfoDemo)
  188. };