-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use dev.dirs to calculate terasology directories #5284
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,8 +4,7 @@ | |||||
package org.terasology.engine.core; | ||||||
|
||||||
import com.google.common.collect.ImmutableList; | ||||||
import com.sun.jna.platform.win32.KnownFolders; | ||||||
import com.sun.jna.platform.win32.Shell32Util; | ||||||
import dev.dirs.ProjectDirectories; | ||||||
import org.slf4j.Logger; | ||||||
import org.slf4j.LoggerFactory; | ||||||
import org.terasology.engine.context.Context; | ||||||
|
@@ -33,15 +32,14 @@ | |||||
*/ | ||||||
public final class PathManager { | ||||||
private static final Logger LOGGER = LoggerFactory.getLogger(PathManager.class); | ||||||
private static final String TERASOLOGY_FOLDER_NAME = "Terasology"; | ||||||
private static final Path LINUX_HOME_SUBPATH = Paths.get(".local", "share", "terasology"); | ||||||
|
||||||
private static final ProjectDirectories PROJECT_DIRS = ProjectDirectories.from("org", "terasology", "terasology"); | ||||||
private static final Path PROJECT_PATH = Paths.get(PROJECT_DIRS.dataDir); | ||||||
private static final String SAVED_GAMES_DIR = "saves"; | ||||||
private static final String RECORDINGS_LIBRARY_DIR = "recordings"; | ||||||
private static final String LOG_DIR = "logs"; | ||||||
private static final String SHADER_LOG_DIR = "shaders"; | ||||||
private static final String LOG_DIR = PROJECT_DIRS.dataLocalDir + "/logs"; | ||||||
private static final String SHADER_LOG_DIR = PROJECT_DIRS.dataLocalDir + "/shaders"; | ||||||
private static final String MODULE_DIR = "modules"; | ||||||
private static final String MODULE_CACHE_DIR = "cachedModules"; | ||||||
private static final String MODULE_CACHE_DIR = PROJECT_DIRS.cacheDir + "/cachedModules"; | ||||||
private static final String SCREENSHOT_DIR = "screenshots"; | ||||||
private static final String NATIVES_DIR = "natives"; | ||||||
private static final String CONFIGS_DIR = "configs"; | ||||||
|
@@ -67,7 +65,7 @@ public final class PathManager { | |||||
|
||||||
private PathManager() { | ||||||
installPath = findInstallPath(); | ||||||
homePath = installPath; | ||||||
homePath = PROJECT_PATH; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. returning projectpath in a function called findinstallpath i thought is too much :) but let me digest your suggestion ... |
||||||
} | ||||||
|
||||||
private static Path findInstallPath() { | ||||||
|
@@ -159,7 +157,11 @@ static PathManager setInstance(PathManager pathManager) { | |||||
} | ||||||
|
||||||
/** | ||||||
* Uses the given path as the home instead of the default home path. | ||||||
* Uses the given path as the home instead of the default home path. Especially interesting for unit tests, as java>17 does not | ||||||
* make it easy to set environment variables. see: https://www.baeldung.com/java-unit-testing-environment-variables . | ||||||
* | ||||||
* Currently LOG_DIR and LOG_SHADER_DIR are not affected here, as not based on homePath. | ||||||
* | ||||||
* @param rootPath Path to use as the home path. | ||||||
* @throws IOException Thrown when required directories cannot be accessed. | ||||||
*/ | ||||||
|
@@ -173,33 +175,8 @@ public void useOverrideHomePath(Path rootPath) throws IOException { | |||||
* @throws IOException Thrown when required directories cannot be accessed. | ||||||
*/ | ||||||
public void useDefaultHomePath() throws IOException { | ||||||
switch (OS.get()) { | ||||||
case LINUX: | ||||||
homePath = Paths.get(System.getProperty("user.home")).resolve(LINUX_HOME_SUBPATH); | ||||||
break; | ||||||
case MACOSX: | ||||||
homePath = Paths.get(System.getProperty("user.home"), "Library", "Application Support", TERASOLOGY_FOLDER_NAME); | ||||||
break; | ||||||
case WINDOWS: | ||||||
String savedGamesPath = Shell32Util | ||||||
.getKnownFolderPath(KnownFolders.FOLDERID_SavedGames); | ||||||
if (savedGamesPath == null) { | ||||||
savedGamesPath = Shell32Util | ||||||
.getKnownFolderPath(KnownFolders.FOLDERID_Documents); | ||||||
} | ||||||
Path rawPath; | ||||||
if (savedGamesPath != null) { | ||||||
rawPath = Paths.get(savedGamesPath); | ||||||
} else { | ||||||
rawPath = new JFileChooser().getFileSystemView().getDefaultDirectory() | ||||||
.toPath(); | ||||||
} | ||||||
homePath = rawPath.resolve(TERASOLOGY_FOLDER_NAME); | ||||||
break; | ||||||
default: | ||||||
homePath = Paths.get(System.getProperty("user.home")).resolve(LINUX_HOME_SUBPATH); | ||||||
break; | ||||||
} | ||||||
// use datadir, .local/share for linux e.g. | ||||||
homePath = PROJECT_PATH; | ||||||
updateDirs(); | ||||||
} | ||||||
|
||||||
|
@@ -316,8 +293,8 @@ public Path getSandboxPath() { | |||||
private void updateDirs() throws IOException { | ||||||
savesPath = homePath.resolve(SAVED_GAMES_DIR); | ||||||
recordingsPath = homePath.resolve(RECORDINGS_LIBRARY_DIR); | ||||||
logPath = homePath.resolve(LOG_DIR); | ||||||
shaderLogPath = logPath.resolve(SHADER_LOG_DIR); | ||||||
logPath = Paths.get(LOG_DIR); | ||||||
shaderLogPath = Paths.get(SHADER_LOG_DIR); | ||||||
Comment on lines
-319
to
+297
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
the reason why i like the new appdir / xdg / macos directory structure so much is that one can properly separate stuff which should be in a backup and what not. config i want to backup. shared data as well. local data not, but depends on the use case. cache and logs i never want a backup. coming back to your question: i did not see any harm at the moment to leave e.g. config in homedirectory, even it is not xdg compliant. |
||||||
screenshotPath = homePath.resolve(SCREENSHOT_DIR); | ||||||
nativesPath = installPath.resolve(NATIVES_DIR); | ||||||
configsPath = homePath.resolve(CONFIGS_DIR); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,14 +274,7 @@ private void handleLaunchArguments() throws IOException { | |
setMemoryLimit(maxDataSize); | ||
} | ||
|
||
if (homeDir != null) { | ||
logger.info("homeDir is {}", homeDir); | ||
PathManager.getInstance().useOverrideHomePath(homeDir); | ||
// TODO: what is this? | ||
// PathManager.getInstance().chooseHomePathManually(); | ||
} else { | ||
PathManager.getInstance().useDefaultHomePath(); | ||
} | ||
PathManager.getInstance().useDefaultHomePath(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not have been removed. Having the ability to override the game's home directory is important for testing with multiple clients. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is this test done, or in other words, why setting XDG environment variables is not good enough? |
||
|
||
if (isHeadless) { | ||
crashReportEnabled = false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.