dmolony-DiskBrowser/src/com/bytezone/diskbrowser/duplicates/DuplicateSwingWorker.java

93 lines
2.8 KiB
Java
Raw Normal View History

2016-12-07 10:42:01 +00:00
package com.bytezone.diskbrowser.duplicates;
import java.io.File;
import java.util.List;
2016-12-07 10:42:01 +00:00
import javax.swing.SwingWorker;
2016-12-07 10:42:01 +00:00
import com.bytezone.diskbrowser.utilities.Utility;
2020-02-08 09:54:50 +00:00
// -----------------------------------------------------------------------------------//
class DuplicateSwingWorker extends SwingWorker<Void, RootFolderData>
// -----------------------------------------------------------------------------------//
2016-12-07 10:42:01 +00:00
{
2016-12-12 08:31:58 +00:00
private final RootFolderData rootFolderData;
2016-12-07 10:42:01 +00:00
2020-02-08 09:54:50 +00:00
// ---------------------------------------------------------------------------------//
DuplicateSwingWorker (RootFolderData rootFolderData)
// ---------------------------------------------------------------------------------//
2016-12-07 10:42:01 +00:00
{
2016-12-12 23:46:09 +00:00
this.rootFolderData = rootFolderData;
2016-12-09 11:31:03 +00:00
}
2020-02-08 09:54:50 +00:00
// ---------------------------------------------------------------------------------//
2016-12-13 22:26:47 +00:00
@Override
protected Void doInBackground () throws Exception
2020-02-08 09:54:50 +00:00
// ---------------------------------------------------------------------------------//
2016-12-07 10:42:01 +00:00
{
2016-12-13 22:26:47 +00:00
traverse (rootFolderData.getRootFolder ());
return null;
2016-12-07 10:42:01 +00:00
}
2020-02-08 09:54:50 +00:00
// ---------------------------------------------------------------------------------//
@Override
protected void done ()
2020-02-08 09:54:50 +00:00
// ---------------------------------------------------------------------------------//
2016-12-07 10:42:01 +00:00
{
2016-12-15 00:01:42 +00:00
rootFolderData.done ();
2016-12-07 10:42:01 +00:00
}
2020-02-08 09:54:50 +00:00
// ---------------------------------------------------------------------------------//
@Override
2016-12-13 22:26:47 +00:00
protected void process (List<RootFolderData> chunks)
2020-02-08 09:54:50 +00:00
// ---------------------------------------------------------------------------------//
{
2016-12-13 22:26:47 +00:00
rootFolderData.progressPanel.repaint ();
}
2020-02-08 09:54:50 +00:00
// ---------------------------------------------------------------------------------//
2016-12-13 22:26:47 +00:00
private void traverse (File directory)
2020-02-08 09:54:50 +00:00
// ---------------------------------------------------------------------------------//
{
2016-12-15 00:01:42 +00:00
if (rootFolderData.progressPanel.cancelled)
return;
2016-12-13 22:26:47 +00:00
File[] files = directory.listFiles ();
if (files == null || files.length == 0)
{
2018-06-09 03:05:34 +00:00
// System.out.println ("Empty folder : " + directory.getAbsolutePath ());
2016-12-13 22:26:47 +00:00
return;
}
for (File file : files)
{
2016-12-15 00:01:42 +00:00
if (rootFolderData.progressPanel.cancelled)
return;
2018-07-25 05:48:14 +00:00
if (file.isHidden ())
continue;
2016-12-13 22:26:47 +00:00
if (file.isDirectory ())
{
2018-06-09 03:05:34 +00:00
if (file.getName ().equalsIgnoreCase ("emulators"))
System.out.println ("ignoring: " + file.getAbsolutePath ());
else
{
rootFolderData.incrementFolders ();
traverse (file);
}
2016-12-13 22:26:47 +00:00
}
else
{
String fileName = file.getName ().toLowerCase ();
if (Utility.validFileType (fileName) && file.length () > 0)
{
rootFolderData.incrementType (file, fileName);
2016-12-15 00:01:42 +00:00
if ((rootFolderData.totalDisks % 250) == 0)
2016-12-13 22:26:47 +00:00
publish (rootFolderData);
}
}
}
}
2016-12-07 10:42:01 +00:00
}