PathUtils.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * MadHelix is a Java Swing-based GUI frontend for SoundHelix.
  3. * Copyright (C) 2018 UltrasonicMadness
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 3 only,
  7. * as published by the Free Software Foundation.
  8. *
  9. * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package org.ultrasonicmadness.madhelix.utils;
  18. import java.io.File;
  19. import java.util.ArrayList;
  20. public class PathUtils
  21. {
  22. // Get path to MadHelix.jar
  23. public static String getMainJarPath()
  24. {
  25. String mainJarPath = new File(System.getProperty("java.class.path"))
  26. .getAbsolutePath();
  27. return mainJarPath;
  28. }
  29. // Get path to directory containing MadHelix.jar
  30. public static String getParentDirPath()
  31. {
  32. String parentDirPath = new File(getMainJarPath()).getParent();
  33. return parentDirPath;
  34. }
  35. // Get path to directory containing SoundHelix xml files.
  36. public static String getStylesDirPath()
  37. {
  38. String stylesDirPath = getParentDirPath() + File.separator + "styles";
  39. return stylesDirPath;
  40. }
  41. // Get path to output directory for MIDI files.
  42. public static String getMidiDirPath()
  43. {
  44. String stylesDirPath = getParentDirPath() + File.separator + "midi";
  45. return stylesDirPath;
  46. }
  47. // Get list of available SoundHelix styles
  48. public static String[] getStyles()
  49. {
  50. ArrayList<String> styleList = new ArrayList<>();
  51. String[] fullFileList = new File(getStylesDirPath()).list();
  52. try
  53. {
  54. for (String fileName : fullFileList)
  55. {
  56. // Only return files ending with the extension XML
  57. if (fileName.substring(fileName.length() - 4).equals(".xml"))
  58. {
  59. // Remove .xml from the end of the style names
  60. styleList.add(fileName.substring(0, fileName.length() - 4));
  61. }
  62. }
  63. }
  64. catch (Exception e)
  65. {
  66. System.err.println("Error loading styles");
  67. }
  68. // Convert ArrayList to standard array.
  69. return styleList.toArray(new String[styleList.size()]);
  70. }
  71. }