/**
   * Method for making the directory for the imported file
   *
   * @param musicFile
   * @return path to the directory
   * @throws IOException
   */
  public static String makeFileDir(MusicFile musicFile) throws IOException {
    File level_1;
    File level_2;
    File level_3;

    String pathToMusicLibrary;

    pathToMusicLibrary = PropertiesUtils.getProperty(LibraryProperties.FILEPATH);
    OrderingProperty orderingMode = PropertiesUtils.getOrderingProperty();

    // Cleaning artist and album
    String artist = cleanString(musicFile.getTag().getArtist());
    String album = cleanString(musicFile.getTag().getAlbum());
    artist = clearForbiddenCharacters(artist);
    album = clearForbiddenCharacters(album);

    // Ordering: A - Artist - Album
    if (orderingMode == OrderingProperty.AAA) {
      if (NUMBERS.contains(artist.substring(0, 1))) {
        level_1 = new File(pathToMusicLibrary + "\\" + "123");
        level_2 = new File(pathToMusicLibrary + "\\" + "123" + "\\" + artist);
        level_3 = new File(pathToMusicLibrary + "\\" + "123" + "\\" + artist + "\\" + album);
      } else {
        level_1 = new File(pathToMusicLibrary + "\\" + artist.substring(0, 1).toUpperCase());
        level_2 =
            new File(
                pathToMusicLibrary
                    + "\\"
                    + artist.toUpperCase().substring(0, 1).toUpperCase()
                    + "\\"
                    + (artist.toUpperCase()).substring(0, 1).toUpperCase()
                    + artist.substring(1, artist.length()));
        level_3 =
            new File(
                pathToMusicLibrary
                    + "\\"
                    + artist.toUpperCase().substring(0, 1).toUpperCase()
                    + "\\"
                    + (artist.toUpperCase()).substring(0, 1).toUpperCase()
                    + artist.substring(1, artist.length())
                    + "\\"
                    + (album.toUpperCase()).substring(0, 1).toUpperCase()
                    + album.substring(1, album.length()));
      }

      if (level_1.exists() == false) {
        level_1.mkdir();
      }

      if (level_2.exists() == false) {
        level_2.mkdir();
      }

      if (level_3.exists() == false) {
        level_3.mkdir();
      }

      return level_3.getAbsolutePath();

      // Genre - Artist - Album
    } else if (orderingMode == OrderingProperty.GAA) {
      String genre = cleanString(musicFile.getTag().getGenre());
      genre = clearForbiddenCharacters(genre);

      level_1 =
          new File(
              pathToMusicLibrary
                  + "\\"
                  + genre.substring(0, 1).toUpperCase()
                  + genre.substring(1, genre.length()));
      level_2 =
          new File(
              pathToMusicLibrary
                  + "\\"
                  + genre.substring(0, 1).toUpperCase()
                  + genre.substring(1, genre.length())
                  + "\\"
                  + artist.substring(0, 1).toUpperCase()
                  + artist.substring(1, artist.length()));
      level_3 =
          new File(
              pathToMusicLibrary
                  + "\\"
                  + genre.substring(0, 1).toUpperCase()
                  + genre.substring(1, genre.length())
                  + "\\"
                  + artist.substring(0, 1).toUpperCase()
                  + artist.substring(1, artist.length())
                  + "\\"
                  + album.substring(0, 1).toUpperCase()
                  + album.substring(1, album.length()));

      if (level_1.exists() == false) {
        level_1.mkdir();
      }

      if (level_2.exists() == false) {
        level_2.mkdir();
      }

      if (level_3.exists() == false) {
        level_3.mkdir();
      }

      return level_3.getAbsolutePath();

      // Artist - Album
    } else if (orderingMode == OrderingProperty.AA) {
      level_1 =
          new File(
              pathToMusicLibrary
                  + "\\"
                  + artist.toUpperCase().charAt(0)
                  + artist.substring(1, artist.length()));
      level_2 =
          new File(
              pathToMusicLibrary
                  + "\\"
                  + artist.toUpperCase().charAt(0)
                  + artist.substring(1, artist.length())
                  + "\\"
                  + album.substring(0, 1).toUpperCase()
                  + album.substring(1, album.length()));

      if (level_1.exists() == false) {
        level_1.mkdir();
      }

      if (level_2.exists() == false) {
        level_2.mkdir();
      }

      return level_2.getAbsolutePath();
    }

    return "";
  }
  /** Constructs the profile grid pane */
  private ProfileSettings() {
    // Setting the style sheet
    this.getStylesheets()
        .add(this.getClass().getResource("css/profile_settings.css").toExternalForm());
    this.getStyleClass().add("grid");

    // Library Settings
    musicLibrarySettings_Label = new Label("Music Library");
    musicLibrarySettings_Label.setId("LabelBig");

    musicLibraryPath_Label = new Label("Path to Library:");
    musicLibraryPath_Label.setId("LabelSmall");
    orderingMode_Label = new Label("Ordering Mode:");
    musicLibraryPath = new TextField("");
    musicLibraryPath.setEditable(false);

    orderingMode_Label = new Label("Ordering Mode");
    orderingMode_Label.setId("LabelSmall");
    orderingMode = new ChoiceBox<String>();
    orderingMode.setItems(FXCollections.observableArrayList(AAA, AA, GAA));

    chooseDirToMusicLibrary = new Button();
    chooseDirToMusicLibrary.setId("OpenFolderButton");
    chooseDirToMusicLibrary.setGraphic(
        new ImageView(PropertiesUtils.getProperty(IconProperties.OPEN_FOLDER_IMPORT)));
    chooseDirToMusicLibrary.setOnAction(getButtonSetLibraryEventHandler());

    CenterGridPane.setConstraints(musicLibrarySettings_Label, 0, 0, 3, 1);
    CenterGridPane.setConstraints(musicLibraryPath_Label, 0, 1, 1, 1);
    CenterGridPane.setConstraints(musicLibraryPath, 1, 1, 1, 1);
    CenterGridPane.setConstraints(chooseDirToMusicLibrary, 2, 1, 1, 1);
    CenterGridPane.setConstraints(orderingMode_Label, 0, 2, 1, 1);
    CenterGridPane.setConstraints(orderingMode, 1, 2, 3, 1);

    // Import Settings
    importSettings_Label = new Label("Import Settings");
    importSettings_Label.setId("LabelBig");
    keepFiles_Label = new Label("Keep original files:");
    keepFiles_Label.setId("LabelSmall");
    keepFiles = new RadioButton();

    justTagFiles_Label = new Label("Just tag files:");
    justTagFiles_Label.setId("LabelSmall");
    justTagFiles = new RadioButton();

    CenterGridPane.setConstraints(importSettings_Label, 0, 4, 3, 1);
    CenterGridPane.setConstraints(keepFiles_Label, 0, 5, 1, 1);
    CenterGridPane.setConstraints(keepFiles, 1, 5, 1, 1);
    CenterGridPane.setConstraints(justTagFiles_Label, 0, 6, 1, 1);
    CenterGridPane.setConstraints(justTagFiles, 1, 6, 1, 1);

    // Playlist export settings
    playlistSettings_Label = new Label("Playlist Export Settings");
    playlistSettings_Label.setId("LabelBig");

    playListExport_Label = new Label("Playlist Export");
    playListExport_Label.setId("LabelSmall");
    playListExport = new RadioButton();

    playListName_Label = new Label("Playlist-Name:");
    playListName_Label.setId("LabelSmall");
    playListName = new TextField();

    playListExportPath_Label = new Label("Export Directory");
    playListExportPath_Label.setId("LabelSmall");
    playListExportPath = new TextField("");
    playListExportPath.setEditable(false);
    chooseDirToExportPlayList = new Button();
    chooseDirToExportPlayList.setId("OpenFolderButton");
    chooseDirToExportPlayList.setGraphic(
        new ImageView(PropertiesUtils.getProperty(IconProperties.OPEN_FOLDER_IMPORT)));
    chooseDirToExportPlayList.setOnAction(getButtonSetPlayListDirEventHandler());
    playListHeader = new Label("Playlist Header-Language");
    playListHeaderMode = new ChoiceBox<String>();
    playListHeaderMode.setItems(FXCollections.observableArrayList(germanHeader, englishHeader));

    CenterGridPane.setConstraints(playlistSettings_Label, 0, 8, 3, 1);
    CenterGridPane.setConstraints(playListExport_Label, 0, 9, 1, 1);
    CenterGridPane.setConstraints(playListExport, 1, 9, 1, 1);
    CenterGridPane.setConstraints(playListName_Label, 0, 10, 1, 1);
    CenterGridPane.setConstraints(playListName, 1, 10, 1, 1);
    CenterGridPane.setConstraints(playListExportPath_Label, 0, 11, 1, 1);
    CenterGridPane.setConstraints(playListExportPath, 1, 11, 1, 1);
    CenterGridPane.setConstraints(chooseDirToExportPlayList, 2, 11, 1, 1);
    CenterGridPane.setConstraints(playListHeader, 0, 12, 1, 1);
    CenterGridPane.setConstraints(playListHeaderMode, 1, 12, 1, 1);

    /** Restore and apply button */
    applyButton = new Button("Apply");
    applyButton.setOnAction(getButtonApplyEventHandler());

    restoreButton = new Button("Restore");
    restoreButton.setOnAction(getButtonRestoreEventHandler());

    CenterGridPane.setConstraints(restoreButton, 1, 13, 1, 1, HPos.RIGHT, VPos.CENTER);
    CenterGridPane.setConstraints(applyButton, 2, 13, 1, 1);

    this.getChildren()
        .addAll(
            musicLibrarySettings_Label,
            musicLibraryPath_Label,
            musicLibraryPath,
            chooseDirToMusicLibrary,
            orderingMode_Label,
            orderingMode,
            importSettings_Label,
            keepFiles_Label,
            keepFiles,
            justTagFiles_Label,
            justTagFiles,
            playlistSettings_Label,
            playListExport_Label,
            playListExport,
            playListName_Label,
            playListName,
            playListExportPath_Label,
            playListExportPath,
            chooseDirToExportPlayList,
            restoreButton,
            applyButton,
            playListHeader,
            playListHeaderMode);

    /** Reading the properties and adding them to the pane */
    readProperties();
  }
  /**
   * Checks for a certain file if there is already a music file in the library
   *
   * @param musicFile to be checked
   * @return boolean indicating whether there is a duplicate already
   */
  public static boolean checkForDuplicates(MusicFile musicFile)
      throws CannotReadException, IOException, TagException, ReadOnlyFileException,
          InvalidAudioFrameException {
    // The Directories
    File firstLevelDir;
    File secondLevelDir;
    File thridLevelDir;

    // The direcotryPaths
    String firstLevelDir_path;
    String secondLevelDir_path;
    String thridLevelDir_path;

    // Clearing the readFiles list
    readFiles.clear();

    // Reading the tag
    MusicTag tag = musicFile.getTag();
    boolean duplicate = false;

    // Reading the path to the music library and ordering Mode
    String pathToLibrary = PropertiesUtils.getProperty(LibraryProperties.FILEPATH);
    OrderingProperty orderingMode = PropertiesUtils.getOrderingProperty();

    // Cleaning the Strings
    String artist =
        MusicFileUtils.clearForbiddenCharacters(MusicFileUtils.cleanString(tag.getArtist()));
    String album =
        MusicFileUtils.clearForbiddenCharacters(MusicFileUtils.cleanString(tag.getAlbum()));
    String titlename =
        MusicFileUtils.clearForbiddenCharacters(MusicFileUtils.cleanString(tag.getTitlename()));
    String genre =
        MusicFileUtils.clearForbiddenCharacters(MusicFileUtils.cleanString(tag.getGenre()));

    if (orderingMode == OrderingProperty.AAA || orderingMode == OrderingProperty.GAA) {
      // Building the Directorystrings
      // Ordering: A - Artist - Album
      if (orderingMode == OrderingProperty.AAA) {
        firstLevelDir_path = pathToLibrary + "\\" + artist.substring(0, 1).toUpperCase();
        secondLevelDir_path =
            firstLevelDir_path
                + "\\"
                + artist.substring(0, 1).toUpperCase()
                + artist.substring(1, artist.length());
        thridLevelDir_path =
            secondLevelDir_path
                + "\\"
                + album.substring(0, 1).toUpperCase()
                + album.substring(1, album.length());
        // Genre - Artist - Album
      } else {
        firstLevelDir_path =
            pathToLibrary
                + "\\"
                + genre.substring(0, 1).toUpperCase()
                + genre.substring(1, genre.length()).toUpperCase();
        secondLevelDir_path =
            firstLevelDir_path
                + "\\"
                + artist.substring(0, 1).toUpperCase()
                + artist.substring(1, artist.length());
        thridLevelDir_path =
            secondLevelDir_path
                + "\\"
                + album.substring(0, 1).toUpperCase()
                + album.substring(1, album.length());
      }

      // First checking whether there is a Directory for the music file
      firstLevelDir = new File(firstLevelDir_path);
      secondLevelDir = new File(secondLevelDir_path);
      thridLevelDir = new File(thridLevelDir_path);

      // The artist subFolder exists
      if (firstLevelDir.exists()) {
        if (secondLevelDir.exists()) {
          if (thridLevelDir.exists()) {
            // Reading the files of the directory:
            addDirContent(thridLevelDir);

            // Checking for the similar file:
            for (File file : readFiles) {
              System.out.println(file.getAbsolutePath());
              if (compareAcousticIds(new MusicFile(file.getAbsolutePath(), true), musicFile)
                  >= 90.0) {
                musicFile.setPossibleDuplicate(true);
                duplicate = true;
                break;
              } else if (file.getAbsolutePath().contains(titlename)) {
                duplicate = true;
                break;
              }
            }
          } else {
            // Reading the files of the directory:
            addDirContent(secondLevelDir);

            // Checking for the similar file:
            for (File file : readFiles) {
              if (compareAcousticIds(new MusicFile(file.getAbsolutePath(), true), musicFile)
                  >= 90.0) {
                musicFile.setPossibleDuplicate(true);
                duplicate = true;
                break;
              } else if (file.getAbsolutePath().contains(titlename)) {
                duplicate = true;
                break;
              }
            }
          }
        } else {
          duplicate = false;
        }
      } else {
        duplicate = false;
      }

      // Artist - Album
    } else {
      firstLevelDir_path =
          pathToLibrary
              + "\\"
              + artist.substring(0, 1).toUpperCase()
              + artist.substring(1, artist.length());
      secondLevelDir_path =
          firstLevelDir_path
              + "\\"
              + album.substring(0, 1).toUpperCase()
              + album.substring(1, album.length());

      // First checking whether there is a Directory for the music file
      firstLevelDir = new File(firstLevelDir_path);
      secondLevelDir = new File(secondLevelDir_path);

      // The artist subFolder exists
      if (firstLevelDir.exists()) {
        if (secondLevelDir.exists()) {
          // Reading the files of the directory:
          addDirContent(secondLevelDir);

          // Checking for the similar file:
          for (File file : readFiles) {

            // Compare the AcoustID's
            if (compareAcousticIds(new MusicFile(file.getAbsolutePath()), musicFile) >= 90.0) {
              musicFile.setPossibleDuplicate(true);
              duplicate = true;
              break;
            } else if (file.getAbsolutePath().contains(titlename)) {
              duplicate = true;
              break;
            }
          }
        } else {

          // Reading the files of the directory:
          addDirContent(firstLevelDir);

          // Checking for the similar file:
          for (File file : readFiles) {
            if (compareAcousticIds(new MusicFile(file.getAbsolutePath(), true), musicFile)
                >= 90.0) {
              musicFile.setPossibleDuplicate(true);
              duplicate = true;
              break;
            } else if (file.getAbsolutePath().contains(titlename)) {
              duplicate = true;
              break;
            }
          }
        }
      } else {
        duplicate = false;
      }
    }

    return duplicate;
  }