Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Exception thrown opening folder in "Playlist Directory" #76

Merged
merged 2 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,12 @@

import java.io.File;

/*
============================================================================
= Author: Jeremy Caron
= File: DirectoryThenFileThenAlphabeticalFileComparator.java
= Purpose: Sorts directories ahead of files, and then sorts files
= alphabetically (ignoring case).
============================================================================
*/

/**
*
* @author jcaron
* Sorts directories ahead of files, and then sorts files alphabetically (ignoring case).
*/
public class DirectoryThenFileThenAlphabeticalFileComparator implements java.util.Comparator<File>
{
/**
*
* @param a
* @param b
* @return
*/

@Override
public int compare(File a, File b)
{
Expand Down
44 changes: 7 additions & 37 deletions src/main/java/listfix/util/FileTypeSearch.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
/*
* listFix() - Fix Broken Playlists!
* Copyright (C) 2001-2014 Jeremy Caron
*
* This file is part of listFix().
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, please see http://www.gnu.org/licenses/
*/

package listfix.util;

import listfix.comparators.DirectoryThenFileThenAlphabeticalFileComparator;
Expand All @@ -29,14 +9,9 @@
import java.util.Collections;
import java.util.List;

/**
*
* @author jcaron
*/
public class FileTypeSearch
{
/**
*
* @param directoryToSearch
* @param filter
* @return
Expand All @@ -45,32 +20,27 @@ public List<File> findFiles(File directoryToSearch, FileFilter filter)
{
if (directoryToSearch.exists())
{
List<File> ol = new ArrayList<>();
File[] inodes = directoryToSearch.listFiles(filter);

if (inodes != null && inodes.length > 0)
{
ol.addAll(Arrays.asList(inodes));
Collections.sort(ol, new DirectoryThenFileThenAlphabeticalFileComparator());
File f;
List<File> ol = new ArrayList<>(Arrays.asList(inodes));
ol.sort(new DirectoryThenFileThenAlphabeticalFileComparator());
List<File> files = new ArrayList<>();
for (File ol1 : ol)
for (File file : ol)
{
f = ol1;
if (f.isDirectory())
if (file.isDirectory())
{
files.addAll(findFiles(f, filter));
files.addAll(findFiles(file, filter));
}
else
{
files.add(f);
files.add(file);
}
}

return files;
}
return null;
}
return null;
return Collections.emptyList();
}
}
2 changes: 1 addition & 1 deletion src/main/java/listfix/view/GUIScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ private void openIconButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-
private void openPlaylistFoldersFromPlaylistTree()
{
this.getSelectedFilesFromTreePlaylists().stream()
.map(File :: getParentFile)
.map(file -> file.isDirectory() ? file : file.getParentFile())
.filter(Objects :: nonNull)
.distinct()
.forEach(this :: openFolderInExplorerPerformed);
Expand Down