Added WebP thumbnail support
[meviz.git] / src / main / java / eu / svjatoslav / meviz / htmlindexer / indexer / FilesystemIndexRemover.java
1 package eu.svjatoslav.meviz.htmlindexer.indexer;
2
3 import eu.svjatoslav.commons.file.IOHelper;
4 import eu.svjatoslav.meviz.htmlindexer.CommandlineHandler;
5 import eu.svjatoslav.meviz.htmlindexer.layouts.Layout;
6 import eu.svjatoslav.meviz.htmlindexer.Utils;
7
8 import java.io.File;
9 import java.io.IOException;
10
11 public class FilesystemIndexRemover {
12
13     private final CommandlineHandler commandlineHandler;
14
15     public FilesystemIndexRemover(final CommandlineHandler commandlineHandler)
16             throws IOException {
17         this.commandlineHandler = commandlineHandler;
18
19         removeIndex(commandlineHandler.getWorkingDirectory());
20     }
21
22     private void removeIndex(final File workingDirectory) throws IOException {
23
24         // remove thumbnails directory from current directory
25         final File thumbnailsDirectory = Utils
26                 .getThumbnailsDirectory(workingDirectory);
27         if (thumbnailsDirectory.exists()) {
28             System.out.println("Deleting thumbnails directory: "
29                     + thumbnailsDirectory);
30             IOHelper.deleteRecursively(thumbnailsDirectory);
31         }
32
33         // recursively remove thumbnail directories from sub directories
34         File[] files = workingDirectory.listFiles();
35         if (files != null)
36             for (final File subFile : files)
37                 if (subFile.isDirectory())
38                     removeIndex(subFile);
39
40         for (final Layout layout : Utils.getLayouts()) {
41             final File indexFile = Utils.getLayoutIndexFile(layout,
42                     workingDirectory);
43
44             if (indexFile.exists())
45                 if (Utils.isMevizGeneratedIndexFile(indexFile)) {
46                     System.out.println("Deleting generated index file: "
47                             + indexFile);
48                     indexFile.delete();
49                 }
50         }
51
52     }
53
54 }