Hi,

some time ago support for using xdg-folders was added to trunk.
As i wouldn't mind reducing the number of .folders in my home (and being more standards compliant) , i welcome that change.

Freecol however doesn't recognise my system as xdg-compliant, so i looked into the code.

In src/net/sf/freecol/common/io/FreeColDirectories.java i found this :

        File home = getUserDefaultDirectory();

        if (home == null) return -1; // Fail badly

        String[][] xdg = { { XDG_CONFIG_HOME_ENV, XDG_CONFIG_HOME_DEFAULT },

                           { XDG_DATA_HOME_ENV,   XDG_DATA_HOME_DEFAULT },

                           { XDG_CACHE_HOME_ENV,  XDG_CACHE_HOME_DEFAULT } };

        File[] todo = new File[xdg.length];

        for (int i = 0; i < xdg.length; i++) {

            String env = System.getenv(xdg[i][0]);

            File d = (env != null) ? new File(home, env)

                : new File(home, xdg[i][1]);

            if (d.exists()) {

                if (!d.isDirectory() || !d.canWrite()) {

                    return -1; // Fail hard if something is broken

                }

                ret = Math.max(ret, 0);

                File f = new File(d, FREECOL_DIRECTORY);

                if (f.exists()) {

                    if (!f.isDirectory() || !f.canWrite()) {

                        return -1; // Again, fail hard

                    }

                    dirs[i] = f;

                    todo[i] = null;

                    ret++;

                } else {

                    dirs[i] = d;

                    todo[i] = f;

                }

            } else {

                dirs[i] = null;

                todo[i] = d;

            }

        }


on my archlinux system none of those environment vars are present :
$ set |grep XDG
XDG_CONFIG_HOME=/home/panoramix/.config
XDG_CURRENT_DESKTOP=LXDE
XDG_MENU_PREFIX=lxde-
$

I looked at the http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html , and they don't mention any of the env vars that code checks for.

The basedir-spec mentions 4 basic vars : XDG_DATA_HOME, XDG_CONFIG_HOME, XDG_CACHE_HOME and XDG_RUNDIR_DIR .
Freecol uses the first 3.

from the basedir-spec :
If |$XDG_DATA_HOME| is either not set or empty, a default equal to |$HOME|/.local/share should be used.

If |$XDG_CONFIG_HOME| is either not set or empty, a default equal to |$HOME|/.config should be used.

If |$XDG_CACHE_HOME| is either not set or empty, a default equal to |$HOME|/.cache should be used.

applying that to the code would lead to something like this :

        File home = getUserDefaultDirectory();
        if (home == null) return -1; // Fail badly

        String[][] xdg = { { XDG_CONFIG_HOME_ENV, ".local/share" },
                           { XDG_DATA_HOME_ENV,   ".config" },
                           { XDG_CACHE_HOME_ENV,  ".cache" } };

        File[] todo = new File[xdg.length];
        for (int i = 0; i < xdg.length; i++) {
            String env = System.getenv(xdg[i] [0]);
            File d = (env != null) ? new File(home, env)
                : new File(home, xdg[i][1]);
# not sure if File (a, b) can handle a relative path as 2nd parameter, if not 
it needs adjusting
             if (d.exists()) {
                if (!d.isDirectory() || !d.canWrite()) {
                    return -1; // Fail hard if something is broken
                }
                ret = Math.max(ret, 0);
                File f = new File(d, FREECOL_DIRECTORY);
                if (f.exists()) {
                    if (!f.isDirectory() || !f.canWrite()) {
                        return -1; // Again, fail hard
                    }
                    dirs[i] = f;
                    todo[i] = null;
                    ret++;
                } else {
                    dirs[i] = d;
                    todo[i] = f;
                }
            } else {
                dirs[i] = null;
                todo[i] = d;
            }
        }


LoneVVolf

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers

Reply via email to