package xyz.veronie.bgg.ui.helpers; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.LocalResourceManager; public enum Resources { INSTANCE; private Path prefixPath; private Path tmpDir; private LocalResourceManager resourceManager; private Resources() { try { if(prefixPath == null) { tmpDir = Paths.get(Constants.TMP_PREFIX); if(!Files.exists(tmpDir)) { Files.createDirectory(tmpDir); } } else { tmpDir = Paths.get(prefixPath + File.separator + Constants.TMP_PREFIX); if(!Files.exists(tmpDir)) { Files.createDirectory(tmpDir); } } Path thumbPath = getThumbsDir(); if(!Files.exists(thumbPath)) { Files.createDirectory(thumbPath); } System.out.println("tmp dir: " + tmpDir.toAbsolutePath()); } catch(IOException ex) { ex.printStackTrace(); } resourceManager = new LocalResourceManager(JFaceResources.getResources()); } public Path getThumbsDir() { return Paths.get(tmpDir + File.separator + Constants.THUMB_CACHE_DIR); } public Path getTmpDir() { return tmpDir; } public void dispose() { try { Files.delete(tmpDir); } catch (IOException e) { e.printStackTrace(); } getResourceManager().dispose(); } public LocalResourceManager getResourceManager() { return resourceManager; } }