PageRenderTime 23ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

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

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