Add XDG_DATA_HOME as default storage location#353
Conversation
* XDG_DATA_HOME/xlcore will be used if it exists * ~/.xlcore will be the fallback if the above is not found and ~/.xlcore is found * XDG_DATA_HOME/xlcore will be created and used if neither of the above are true
|
i dont know if there was already an issue associated with this, but linking related issue which this appears to address: #177 really glad to see someone updating this project to use the xdg basedir spec! a few thoughts on the current implementation follow. i am not a reviewer/codeowner for this project, so be advised my thoughts here are not review blockers in any way. with that in mind:
a purpose of the xdg basedir specification is to enable relocating these by providing
a suggestion to consider for the subdirectory name: instead of using the appname,
|
|
I have no great opinion one way or the other about using dev.goats.xivlauncher as the folder name; I was simply following the naming scheme currently in use. However, I do see a potential benefit to using dev.goats.xivlauncher: nobody is likely to have created this folder before. I have added this patch to my xivlauncher-rb fork, and for several people, the launcher has ended up using XDG_DATA_HOME/xlcore when they already had a ~/.xlcore and (supposedly) did not have XDG_DATA_HOME/xlcore. I suspect that these users had at one point created the XDG_DATA_HOME/xlcore folder with XL_PATH/XL_USERDIR and forgot about it. As for the use of XL_USERDIR, its purpose is both for backwards compatibility for people currently using it, and also for dual-boxing. You need separate prefixes and ffxivConfig folders to launch two copies of the game with xivlauncher. So you could have your main config at XDG_DATA_HOME/dev.goats.xivlauncher, and your second config in the XDG_DATA_HOME/dev.goats.xivlauncher.2 folder, for example. |
| storage = new Storage(APP_NAME); | ||
| // XDG will handle the storage path for Linux and Mac. It will fall back to the old ~/.xlcore path on Linux and Mac if it exists and the XDG path does not. | ||
| var userDir = XDG.GetStoragePath(APP_NAME, CoreEnvironmentSettings.UserDir); | ||
| storage = new Storage(APP_NAME, userDir); |
There was a problem hiding this comment.
Why are we not packing all that logic into the Storage class, where it makes sense to be?
There was a problem hiding this comment.
Here's a PR for that: goatcorp/FFXIVQuickLauncher#1867
In the mean time, I'd still like to get this added, since it can take a very long time to get anything linux-related merged into XL.
|
|
||
| static XDG() | ||
| { | ||
| if (Environment.OSVersion.Platform == PlatformID.Win32NT) |
There was a problem hiding this comment.
XDG as a concept mostly makes sense on Linux...
| } | ||
| else if (platform == Platform.Linux || platform == Platform.Mac) | ||
| { | ||
| if (Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), appName))) |
There was a problem hiding this comment.
On macOS Environment.SpecialFolder doesn't give you XDG paths, but rather system native locations, such as $HOME/Library/Application Support etc.
There was a problem hiding this comment.
According to the documentation I was reading, $HOME/Library/Application Support/{appName} (or just $HOME/Library/{appname})is the closest there is to XDG_DATA_HOME, and this at least doesn't pollute the ~/Library folder directly. I could switch to using environment variables directly, and that would create ~/.local/share/dev.goats.xlcore for Mac users. Not sure if xlcore even compiles for macos, though.
Also move ~/.xlcore to XDG_DATA_HOME/dev.goats.xlcore if possible If not, fall back to using ~/.xlcore
| } | ||
| else if (platform == Platform.Linux || platform == Platform.Mac) | ||
| { | ||
| var xdgStoragePath = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), $"dev.goats.{appName}")); |
There was a problem hiding this comment.
the application id used for the flatpak is dev.goats.xivlauncher, not dev.goats.xlcore
* Rename XDG to StorageHelper * Set appname to dev.goats.xivlauncher instead of xlcore
|
Switched to using goatcorp/FFXIVQuickLauncher#1867 for the submodule, and renamed a few things. If ~/.xlcore is found and is on the same volume, it will be moved to ~/.local/share/dev.goats.xivlauncher. If it is on a different volume, the move is considered to be too slow, and it will be used in place. |
Because DirectoryInfo.MoveTo() throws an error if the locations are not on the same volume. No need to check drives and paths and all that
|
I think this is ready to go, as soon as PR 1867 is merged into XL.Common. However, the flatpak release will need |
|
After a bit more poking around and testing, flatpak just seems to be a problem in general. The It's probably better to not use the filesystem option. |
After moving ~/.xlcore to XDG_DATA_HOME/d.g.x, make a symlink back at ~/.xlcore pointing to the new location. Disable with XL_MAKE_SYMLINK=0. In the future, we can change this to off by default, so symlinks will only be created on demand. For now, having ~/.xlcore is probably best for steamdeck users.
string.IsNullOrEmpty
|
This patch now does the following:
|
it was accidentally re-using GamePath
This patch adds $XDG_DATA_HOME (default: ~/.local/share) as the default location for the xlcore folder. This (better) obeys the XDG desktop specification. Ideally, the ini files would go in $XDG_CONFIG_HOME/xlcore (default: ~/.config), but that would require extensive reworking of the storage system, and isn't really worth it. I'm using $XDG_DATA_HOME because $XDG_CONFIG_HOME really shouldn't be used to store large amounts of data. It's not uncommon for people to back up ~/.config to a git repo, for example.
Edit to add:
In the interest of full disclosure, I think VSCode has enabled AI generation by default, because it kept finishing my code blocks and comments for me. I did not ask it to do anything, or prompt it, it just kept completing my code blocks, and occasionally adding extra parenthesis and semicolons in the wrong spot. I tried turning it off, but it kept "fixing" my code. So a bit of this is technically AI generated, though it is what I intended to do.
It is very annoying, and I think I'm going to ditch VSCode now, because sometimes I hit tab to indent, and it decides to generate a new function that doesn't work or even do anything useful.