PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/org/madsonic/booter/util/OperatingSystem.java

https://gitlab.com/madsonic/madsonic-booter
Java | 105 lines | 72 code | 11 blank | 22 comment | 30 complexity | 97e7ea15d06070f6139a7f7fe9b975e0 MD5 | raw file
  1. /*
  2. * This file is part of Madsonic.
  3. *
  4. * Madsonic is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * Madsonic is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with Madsonic. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. * Based upon Madsonic, Copyright 2009-2022 (C) Martin Karel
  18. *
  19. */
  20. package org.madsonic.booter.util;
  21. import java.util.Properties;
  22. public enum OperatingSystem {
  23. WINDOWS,
  24. OSX,
  25. LINUX,
  26. UNKNOWN;
  27. private static OperatingSystem initOS() {
  28. String osName = System.getProperty("os.name");
  29. if(osName.equals("Mac OS X"))
  30. return OSX;
  31. if(osName.startsWith("Windows "))
  32. return WINDOWS;
  33. if(osName.startsWith("Linux"))
  34. return LINUX;
  35. return UNKNOWN;
  36. }
  37. public static final OperatingSystem userOS = initOS();
  38. /**
  39. * @return user-displayable operating system version
  40. */
  41. public static String osVersion() {
  42. Properties p = System.getProperties();
  43. String osName = p.getProperty("os.name");
  44. String osVersion = p.getProperty("os.version");
  45. if((osVersion != null) && (osVersion.length() != 0))
  46. osName += " " + osVersion;
  47. switch(userOS) {
  48. case OSX:
  49. if(osVersion.startsWith("10.2"))
  50. osName += " Jaguar";
  51. else if(osVersion.startsWith("10.3"))
  52. osName += " Panther";
  53. else if(osVersion.startsWith("10.4"))
  54. osName += " Tiger";
  55. else if(osVersion.startsWith("10.5"))
  56. osName += " Leopard";
  57. else if(osVersion.startsWith("10.6"))
  58. osName += " Snow Leopard";
  59. else if(osVersion.startsWith("10.7"))
  60. osName += " Lion";
  61. else if(osVersion.startsWith("10.8"))
  62. osName += " Mountain Lion";
  63. else if(osVersion.startsWith("10.9"))
  64. osName += " Mavericks";
  65. else if(osVersion.startsWith("10.10"))
  66. osName += " Yosemite";
  67. else if(osVersion.startsWith("10.11"))
  68. osName += " El Capitan";
  69. else if(osVersion.startsWith("10.12"))
  70. osName += " Sierra";
  71. break;
  72. case WINDOWS:
  73. osName += " " + p.getProperty("sun.os.patch.level");
  74. break;
  75. case LINUX:
  76. break;
  77. case UNKNOWN:
  78. break;
  79. default:
  80. break;
  81. }
  82. osName += " (" + p.getProperty("os.arch") + ")";
  83. return osName;
  84. }
  85. public static boolean isWindows() {
  86. if (userOS == WINDOWS) {
  87. return true;
  88. }
  89. return false;
  90. }
  91. public static String javaVersion() {
  92. return "Java " + System.getProperties().getProperty("java.version");
  93. }
  94. }