Line 1... |
Line 1... |
1 |
/*
|
1 |
/*
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
3 |
*
|
3 |
*
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
5 |
*
|
5 |
*
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
9 |
* language governing permissions and limitations under the License.
|
9 |
* language governing permissions and limitations under the License.
|
Line 33... |
Line 33... |
33 |
static public final class XDG extends BaseDirs {
|
33 |
static public final class XDG extends BaseDirs {
|
34 |
protected XDG(final ProductInfo info, final String subdir) {
|
34 |
protected XDG(final ProductInfo info, final String subdir) {
|
35 |
super(info, subdir);
|
35 |
super(info, subdir);
|
36 |
}
|
36 |
}
|
37 |
|
37 |
|
- |
|
38 |
private String getHomePath() {
|
- |
|
39 |
// ATTN on FreeBSD man 8 service : "service command sets HOME to /" thus one should
|
- |
|
40 |
// probably not use this class (perhaps Portable).
|
- |
|
41 |
return StringUtils.coalesce(System.getenv("HOME"), System.getProperty("user.home"));
|
- |
|
42 |
}
|
- |
|
43 |
|
- |
|
44 |
private String getInHomePath(final String subPath) {
|
- |
|
45 |
final String homePath = getHomePath();
|
- |
|
46 |
// If no home, use current working directory
|
- |
|
47 |
return homePath == null ? subPath : homePath + '/' + subPath;
|
- |
|
48 |
}
|
- |
|
49 |
|
38 |
@Override
|
50 |
@Override
|
39 |
protected File _getAppDataFolder() {
|
51 |
protected File _getAppDataFolder() {
|
40 |
/*
|
52 |
/*
|
41 |
* $XDG_DATA_HOME defines the base directory relative to which user specific data files
|
53 |
* $XDG_DATA_HOME defines the base directory relative to which user specific data files
|
42 |
* should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to
|
54 |
* should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to
|
43 |
* $HOME/.local/share should be used.
|
55 |
* $HOME/.local/share should be used.
|
44 |
*/
|
56 |
*/
|
45 |
return new File(StringUtils.coalesce(System.getenv("XDG_DATA_HOME"), System.getenv("HOME") + "/.local/share"), this.getAppID());
|
57 |
return new File(StringUtils.coalesce(System.getenv("XDG_DATA_HOME"), getInHomePath(".local/share")), this.getAppID());
|
46 |
}
|
58 |
}
|
47 |
|
59 |
|
48 |
@Override
|
60 |
@Override
|
49 |
protected File _getPreferencesFolder() {
|
61 |
protected File _getPreferencesFolder() {
|
50 |
/*
|
62 |
/*
|
51 |
* $XDG_CONFIG_HOME defines the base directory relative to which user specific
|
63 |
* $XDG_CONFIG_HOME defines the base directory relative to which user specific
|
52 |
* configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty,
|
64 |
* configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty,
|
53 |
* a default equal to $HOME/.config should be used.
|
65 |
* a default equal to $HOME/.config should be used.
|
54 |
*/
|
66 |
*/
|
55 |
return new File(StringUtils.coalesce(System.getenv("XDG_CONFIG_HOME"), System.getenv("HOME") + "/.config"), this.getAppID());
|
67 |
return new File(StringUtils.coalesce(System.getenv("XDG_CONFIG_HOME"), getInHomePath(".config")), this.getAppID());
|
56 |
}
|
68 |
}
|
57 |
|
69 |
|
58 |
@Override
|
70 |
@Override
|
59 |
protected File _getCacheFolder() {
|
71 |
protected File _getCacheFolder() {
|
60 |
/*
|
72 |
/*
|
61 |
* $XDG_CACHE_HOME defines the base directory relative to which user specific
|
73 |
* $XDG_CACHE_HOME defines the base directory relative to which user specific
|
62 |
* non-essential data files should be stored. If $XDG_CACHE_HOME is either not set or
|
74 |
* non-essential data files should be stored. If $XDG_CACHE_HOME is either not set or
|
63 |
* empty, a default equal to $HOME/.cache should be used.
|
75 |
* empty, a default equal to $HOME/.cache should be used.
|
64 |
*/
|
76 |
*/
|
65 |
return new File(StringUtils.coalesce(System.getenv("XDG_CACHE_HOME"), System.getenv("HOME") + "/.cache"), this.getAppID());
|
77 |
return new File(StringUtils.coalesce(System.getenv("XDG_CACHE_HOME"), getInHomePath(".cache")), this.getAppID());
|
66 |
}
|
78 |
}
|
67 |
}
|
79 |
}
|
68 |
|
80 |
|
69 |
static public final class Unknown extends BaseDirs {
|
81 |
static public final class Unknown extends BaseDirs {
|
70 |
|
82 |
|
Line 209... |
Line 221... |
209 |
protected final String getAppFullID() {
|
221 |
protected final String getAppFullID() {
|
210 |
final String res = this.getInfo().getFullID();
|
222 |
final String res = this.getInfo().getFullID();
|
211 |
return res != null ? res : this.getAppID();
|
223 |
return res != null ? res : this.getAppID();
|
212 |
}
|
224 |
}
|
213 |
|
225 |
|
214 |
protected File getFolderToWrite(final File dir) throws IOException {
|
226 |
static public final File getFolderToWrite(final File dir) throws IOException {
|
- |
|
227 |
// MAYBE test for symlink
|
215 |
if (dir.isDirectory() && dir.canWrite())
|
228 |
if (dir.isDirectory() && dir.canWrite())
|
216 |
return dir;
|
229 |
return dir;
|
217 |
if (dir.exists())
|
230 |
if (dir.exists())
|
218 |
throw new IOException((dir.isDirectory() ? "Not writable: " : "Not a directory: ") + dir);
|
231 |
throw new IOException((dir.isDirectory() ? "Not writable: " : "Not a directory: ") + dir);
|
219 |
// create with 0700 mode (from § Referencing this specification)
|
232 |
// create with 0700 mode (from § Referencing this specification)
|
Line 244... |
Line 257... |
244 |
public final File getAppDataFolderToWrite() throws IOException {
|
257 |
public final File getAppDataFolderToWrite() throws IOException {
|
245 |
return getFolderToWrite(this.getAppDataFolder());
|
258 |
return getFolderToWrite(this.getAppDataFolder());
|
246 |
}
|
259 |
}
|
247 |
|
260 |
|
248 |
protected File _getPreferencesFolder() {
|
261 |
protected File _getPreferencesFolder() {
|
249 |
return this.getAppDataFolder();
|
262 |
return this._getAppDataFolder();
|
250 |
}
|
263 |
}
|
251 |
|
264 |
|
252 |
// where to write configuration
|
265 |
// where to write configuration
|
253 |
public final File getPreferencesFolder() {
|
266 |
public final File getPreferencesFolder() {
|
254 |
return getSubDir(_getPreferencesFolder());
|
267 |
return getSubDir(_getPreferencesFolder());
|
Line 269... |
Line 282... |
269 |
|
282 |
|
270 |
public final File getCacheFolderToWrite() throws IOException {
|
283 |
public final File getCacheFolderToWrite() throws IOException {
|
271 |
return getFolderToWrite(this.getCacheFolder());
|
284 |
return getFolderToWrite(this.getCacheFolder());
|
272 |
}
|
285 |
}
|
273 |
|
286 |
|
- |
|
287 |
protected File _getStateFolder() {
|
- |
|
288 |
return this._getCacheFolder();
|
- |
|
289 |
}
|
- |
|
290 |
|
- |
|
291 |
// where to write data that is non-essential but cannot be recreated
|
- |
|
292 |
// - logfiles
|
- |
|
293 |
// - state of application windows on exit
|
- |
|
294 |
// - recently opened files
|
- |
|
295 |
// See STATE directory in https://wiki.debian.org/XDGBaseDirectorySpecification
|
- |
|
296 |
public final File getStateFolder() {
|
- |
|
297 |
return getSubDir(_getStateFolder());
|
- |
|
298 |
}
|
- |
|
299 |
|
- |
|
300 |
public final File getStateFolderToWrite() throws IOException {
|
- |
|
301 |
return getFolderToWrite(this.getStateFolder());
|
- |
|
302 |
}
|
- |
|
303 |
|
274 |
@Override
|
304 |
@Override
|
275 |
public String toString() {
|
305 |
public String toString() {
|
276 |
return BaseDirs.class.getSimpleName() + " " + this.getClass().getSimpleName();
|
306 |
return BaseDirs.class.getSimpleName() + " " + this.getClass().getSimpleName();
|
277 |
}
|
307 |
}
|
278 |
|
308 |
|