1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-14 21:35:03 -05:00
filebot/source/net/filebot/ApplicationFolder.java

55 lines
1.3 KiB
Java
Raw Normal View History

2016-08-04 03:05:54 -04:00
package net.filebot;
import static net.filebot.Logging.*;
2016-08-04 03:05:54 -04:00
import static net.filebot.Settings.*;
import java.io.File;
import java.io.IOException;
2018-04-15 12:00:19 -04:00
import java.nio.file.Files;
import java.nio.file.LinkOption;
2018-04-15 12:00:19 -04:00
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.logging.Level;
2016-08-04 03:05:54 -04:00
public enum ApplicationFolder {
// real user home (the user.home will point to the application-specific container in sandbox environments)
UserHome(System.getProperty(isMacSandbox() ? "UserHome" : "user.home")),
2016-08-04 03:05:54 -04:00
2016-11-25 10:59:26 -05:00
AppData(System.getProperty("application.dir", UserHome.resolve(".filebot").getPath())),
2016-08-04 03:05:54 -04:00
2016-11-25 12:19:17 -05:00
TemporaryFiles(System.getProperty("java.io.tmpdir")),
2016-08-04 03:05:54 -04:00
2016-11-25 10:59:26 -05:00
Cache(System.getProperty("application.cache", AppData.resolve("cache").getPath()));
2016-08-04 03:05:54 -04:00
private File path;
2016-08-04 03:05:54 -04:00
ApplicationFolder(String path) {
try {
// use canonical file path
2018-04-15 12:00:19 -04:00
Path f = Paths.get(path);
// create folders if necessary
if (!Files.exists(f, LinkOption.NOFOLLOW_LINKS)) {
Files.createDirectories(f);
}
this.path = f.toRealPath(LinkOption.NOFOLLOW_LINKS).toFile();
} catch (IOException e) {
debug.log(Level.WARNING, e, e::toString);
// default to file path as is
this.path = new File(path).getAbsoluteFile();
}
2016-08-04 03:05:54 -04:00
}
2016-11-25 12:37:09 -05:00
public File get() {
2016-08-04 03:05:54 -04:00
return path;
}
public File resolve(String name) {
2016-11-25 10:59:26 -05:00
return new File(path, name);
2016-08-04 03:05:54 -04:00
}
}