forked from StarOpenSource/Engine
Add more default directories
This commit is contained in:
parent
ed1c1d3b1a
commit
8d5cb0ce23
1 changed files with 76 additions and 8 deletions
|
@ -62,18 +62,78 @@ public final class FileAccess {
|
|||
|
||||
/**
|
||||
* Contains a {@link FileAccess} instance to
|
||||
* a cache directory provided by the engine.
|
||||
* a temporary cache directory provided by the engine.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns a {@link FileAccess} instance to
|
||||
* a cache directory provided by the engine.
|
||||
* a temporary cache directory provided by the engine.
|
||||
*
|
||||
* @return cache directory
|
||||
* @since v1-alpha8
|
||||
* @return temporary cache directory
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@Getter
|
||||
private static FileAccess cacheDirectory;
|
||||
private static FileAccess temporaryCacheDirectory;
|
||||
|
||||
/**
|
||||
* Contains a {@link FileAccess} instance to
|
||||
* the persistent cache directory of the system.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns a {@link FileAccess} instance to
|
||||
* the persistent cache directory of the system.
|
||||
*
|
||||
* @return persistent cache directory
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@Getter
|
||||
private static FileAccess persistentCacheDirectory;
|
||||
|
||||
/**
|
||||
* Contains a {@link FileAccess} instance
|
||||
* to the user's home directory.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns a {@link FileAccess} instance
|
||||
* to the user's home directory.
|
||||
*
|
||||
* @return home directory
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@Getter
|
||||
private static FileAccess homeDirectory;
|
||||
|
||||
/**
|
||||
* Contains a {@link FileAccess} instance
|
||||
* to the user's configuration directory.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns a {@link FileAccess} instance
|
||||
* to the user's configuration directory.
|
||||
*
|
||||
* @return configuration directory
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@Getter
|
||||
private static FileAccess configDirectory;
|
||||
|
||||
/**
|
||||
* Contains a {@link FileAccess} instance
|
||||
* to the user's data directory.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns a {@link FileAccess} instance
|
||||
* to the user's data directory.
|
||||
*
|
||||
* @return data directory
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@Getter
|
||||
private static FileAccess dataDirectory;
|
||||
|
||||
// -----> Instance variables
|
||||
/**
|
||||
|
@ -167,8 +227,15 @@ public final class FileAccess {
|
|||
* @since v1-alpha8
|
||||
*/
|
||||
public static void initializeInstances() throws IOException {
|
||||
if (Engine.getInstance().getState() == EngineState.EARLY_STARTUP)
|
||||
cacheDirectory = new FileAccess(System.getProperties().getProperty("java.io.tmpdir").replace("\\", "/") + "/sosengine-cache-" + ProcessHandle.current().pid()).createDirectory().deleteOnShutdown();
|
||||
// TODO add support for non-default and/or non-unix directories here
|
||||
|
||||
if (Engine.getInstance().getState() == EngineState.EARLY_STARTUP) {
|
||||
temporaryCacheDirectory = new FileAccess(System.getProperties().getProperty("java.io.tmpdir") + "/sosengine-cache-" + ProcessHandle.current().pid()).createDirectory().deleteOnShutdown();
|
||||
homeDirectory = new FileAccess(System.getProperties().getProperty("user.home")).createDirectory();
|
||||
persistentCacheDirectory = homeDirectory.traverse( ".cache").createDirectory();
|
||||
configDirectory = homeDirectory.traverse(".config").createDirectory();
|
||||
dataDirectory = homeDirectory.traverse(".local/share").createDirectory();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Deletes all files scheduled for deletion.
|
||||
|
@ -207,6 +274,7 @@ public final class FileAccess {
|
|||
public static @NotNull Path formatPath(@NotNull String path) {
|
||||
return Path.of(
|
||||
path
|
||||
.replace("\\", "/")
|
||||
.replace("/./", "/")
|
||||
.replace("/", File.separator)
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue