After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 503722 - Do not store data in Vista's HOME folder, use AppData instead
Do not store data in Vista's HOME folder, use AppData instead
Status: RESOLVED FIXED
Product: GnuCash
Classification: Other
Component: Windows
2.4.x
Other Windows
: Normal normal
: ---
Assigned To: Geert Janssens
Christian Stimming
: 568175 Stju (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2007-12-15 09:07 UTC by Andy
Modified: 2018-06-29 21:56 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Andy 2007-12-15 09:07:39 UTC
Vista's %HOME% folder, e.g. c:\users\andy only contains special folders or shortcuts to them, it does not contain application data. It would be a lot more compliant to Vista's guidelines if GnuCash used its own subfolder in (Local)AppData. 

Or in other words, Visata %HOME% <> GnuCash %HOME% but rather something like GnuCash %HOME% = Vista %LOCALAPPDATA%\GnuCash

Vista's %HOME% folder contains e.g. the special Music, Pictures, Documents folders as well as a few 'OS' folders like AppData. I have configured Vista to show all files (including hidden ones) and when I go from my Documents to my Pictures, I have to browse through all the GnuCash private application data files to find my Pictures.

For now I have made a workaround in gnucash.bat by adding
set HOME=%LOCALAPPDATA%\GnuCash
mkdir %HOME%

This workaround still has some open issues:
1) should this be %APPDATA% to allow for roaming users?
2) it probably needs some migration code as well to preserve preferences
Comment 1 Phil Longstaff 2009-04-28 12:25:35 UTC
Does your workaround also work for XP?  Windows 7?
Comment 2 Andy 2009-09-20 14:47:28 UTC
No idea; I only have vista installed at home. 
Maybe somebody else can test/comment?
Comment 3 Phil Longstaff 2009-11-07 22:11:41 UTC
Sounds like this should be done in the gnucash.cmd file.  Is there an easy way to determine what version the OS is so that HOME can be set properly?
Comment 4 graham lane 2010-02-09 22:31:31 UTC
I am using 2.2.9 and Windows 7. Same issue, lots of Gnucash files in my user folder.
Comment 5 Sam Morris 2010-06-30 23:06:26 UTC
It would be better to use the proper Windows API function to determine where user data should be stored.

SHGetFolderPath <http://msdn.microsoft.com/en-us/library/bb762181(v=VS.85).aspx>, which works on Windows 2000 and later, should be called with nFolder set to CSIDL_APPDATA.

Glib has a g_get_user_config_dir function which appears to call this underneath. Don't be tempted to use g_get_user_data_dir: it returns the path to the user's My Documents directory (doh!)
Comment 6 Jonathan Van Dusen 2010-10-15 15:25:47 UTC
Just wanted to verify that Andy's workaround works perfectly on Windows 7 x64. Thanks!
Comment 7 Geert Janssens 2011-01-14 19:29:20 UTC
I have been looking into this.

LOCALAPPDATA is a new environment variable in Windows, starting from Windows Vista. So it can't be used on Windows XP. Additionally, as of GnuCash 2.4 there is no longer a 'gnucash.bat' so that way of setting environment variables won't work anymore.

But there should be other ways to do something similar now.
* locate the file C:\Program Files\GnuCash\etc\gnucash\environment (you may have to adjust the path if you didn't install GnuCash in its default location)
* inside this file, add a line:
GNC_DOT_DIR=$LOCALAPPDATA/GnuCash
* if you wish to keep the info that was stored in .gnucash for your future GnuCash runs, move the directory <your home dir>\.gnucash to <your local app data dir> and rename it to GnuCash

Unfortunatly I don't have Vista or Windows 7 so I can't verify these steps. Can you please test this with GnuCash 2.4 and see if that works ? Be sure you have removed the old .gnucash (after taking a backup if you care for its contents) before running the test.

If that works, I will try to get that worked out in code.
Comment 8 Geert Janssens 2011-01-15 10:48:53 UTC
Small correction to the above workaround:
You should add the line
GNC_DOT_DIR={LOCALAPPDATA}/GnuCash
The one with the $ sign mentioned in comment 7 won't work.

And by the way, Windows XP users can use APPDATA instead, like this:
GNC_DOT_DIR={APPDATA}/GnuCash

I verified the XP case and that works. Can someone with a Vista or Windows 7 system run the following commands in a console windows and post the output in a comment here, please ?
echo %APPDATA%
echo %LOCALAPPDATA%

Thanks
Comment 9 Geert Janssens 2011-01-15 11:02:10 UTC
To be complete, I should add that the trick above only solves part of the problem: it will get rid of the .gnucash directory. GnuCash on Windows comes bundled with a lot of gnome libraries which also create directories in the wrong place. On my system I currently have:
- .banking
- .gconf
- .gconfd
- .gnome2
- .gnome2_private
- .gnucash

All of these are generated by GnuCash or one of the bundled libraries. The .gnucash one can relatively easily be eliminated. I will have to search for the others.
Comment 10 Sam Morris 2011-01-15 11:52:16 UTC
I don't think that the local application data directory is the correct place to store the user's data. For a computer not part of a domain, it doesn't make any difference; but when the computer is on a domain, the user's appdata folder is replicated to other computers in the domain, and so follows them around the network as they log into different computers; the local appdata is not.

MS' guidelines say that only user settings applicable to a single computer (e.g., selected screen resolution in a game) should be stored in the corresponding local directory.
Comment 11 Geert Janssens 2011-01-15 13:41:01 UTC
Quick update, .gconfd is hardcoded in the source code of GConf (one of the
gnome libraries used by GnuCash). Changing it would require us to patch GConf
we ship with GnuCash. A one-line patch would suffice:

--- gconf-internals.c-org       2011-01-15 14:36:34.000000000 +0100
+++ gconf-internals.c   2011-01-15 14:36:56.000000000 +0100
@@ -700,7 +700,7 @@
   if (quark != 0)
     return g_quark_to_string (quark);

-  home_copy = g_strdup (g_get_home_dir ());
+  home_copy = g_strdup (g_get_user_config_dir ());

   /* Replace backslashes with forward slashes */
   for (p = home_copy; *p; p++)

.gconf can be overridden via a configuration file that ships with it. This
config file doesn't seem to cope well with the APPDATA environment variable on
XP, so likely it won't work with Vista or W7's LOCALAPPDATA either. However,
the above patch would automatically fix the default location for .gconf as
well.

Also like Sam already suggests, I think we can safely
use APPDATA which would make GnuCash roaming friendly. Roaming is used to
provide a user an environment that is independent of the PC he's sitting in
front of. So in a roaming environment, it makes sense a user's GnuCash
preferences travel with him. If roaming is not used, it makes no difference if
we use APPDATA or LOCALAPPDATA, so we could just as well settle for APPDATA.

I haven't looked at the .gnome2* or .banking directories yet.
Comment 12 Andy 2011-01-15 15:52:18 UTC
As predicted: modifying the environment file solves the .gnucash folder but not the others.

For now I've created a gnucash.cmd file next to the gnucash.exe and modified the start menu to call the .cmd instead of the .exe
Content-wise it's just
set HOME=%APPDATA%\GnuCash
mkdir %HOME%
call gnucash.exe

I've tested this on Vista.
Comment 13 Geert Janssens 2011-01-15 16:06:01 UTC
Just out of curiosity, why didn't you alter the environment file as I outlined ?

There's no need for a wrapper script like you have created, at least not on Windows XP.
Comment 14 Andy 2011-01-16 12:55:06 UTC
> As predicted: modifying the environment file solves 
> the .gnucash folder but not the others.

I did modify it; but I only saw an effect on the one gnucash folder; not on the others.  With the etc/environment file modified, I still have .gconf & .gconfd & .gnome2 & .gnome2_private.

My testing on Vista & Win7 (with the released 2.4 version; not a nightly build) fully confirmed the behavior discussed in previous comments. 

PS. I mentioned my gnucash.cmd workaround in case other users were upgrading and wanted a tested scenario to follow. It's just a workaround as on Vista the cmd file results in an extra window.

Conclusion: you are on the right track but additionally a solution is needed for the bundled libraries.
Comment 15 Geert Janssens 2011-01-16 14:53:09 UTC
Ok, I understand your comment 12 now. Thanks.
Comment 16 Geert Janssens 2011-01-25 10:07:58 UTC
*** Bug 580166 has been marked as a duplicate of this bug. ***
Comment 17 Geert Janssens 2011-01-25 10:19:21 UTC
A clever user reported on the mailing list to have changed the HOME environment variable via the environment file and reported that all directories now got properly relocated.

So instead of 
GNC_DOT_DIR={APPDATA}/GnuCash
add the line
HOME={APPDATA}/GnuCash

in the environment file, and all the dot-directories mentioned in comment 9 should now be generated under %APPDATA%\GnuCash.

If you wish to keep your preferences, copy the old directories in there first before restarting GnuCash.
Comment 18 Geert Janssens 2011-01-25 11:51:47 UTC
*** Bug 568175 has been marked as a duplicate of this bug. ***
Comment 19 Christian Stimming 2011-02-21 08:05:17 UTC
*** Bug 642739 has been marked as a duplicate of this bug. ***
Comment 20 Geert Janssens 2011-02-22 12:54:47 UTC
Just for clarity, I'll add here that bug 642739 is not a duplicate and has been restored in its independent state.
Comment 21 Randy Orrison 2011-03-16 15:09:08 UTC
> A clever user reported on the mailing list to have changed the HOME environment
> variable via the environment file and reported that all directories now got
> properly relocated.
> 
> So instead of 
> GNC_DOT_DIR={APPDATA}/GnuCash
> add the line
> HOME={APPDATA}/GnuCash

I can confirm that this works fine in Windows 7 and XP.  I make the change manually every time I install or update GnuCash.
Comment 22 Paulo Martin 2011-11-04 23:32:01 UTC
(In reply to comment #17)
> A clever user reported on the mailing list to have changed the HOME environment
> variable via the environment file and reported that all directories now got
> properly relocated.
> 
> So instead of 
> GNC_DOT_DIR={APPDATA}/GnuCash
> add the line
> HOME={APPDATA}/GnuCash
> 
> in the environment file, and all the dot-directories mentioned in comment 9
> should now be generated under %APPDATA%\GnuCash.
> 
> If you wish to keep your preferences, copy the old directories in there first
> before restarting GnuCash.

Guys, I have little knowledge on programing, and I'm trying to solve this problem, but I'm not succeeding.
I successfully found, opened and edited the environment file, but after writing the line "HOME={APPDATA}/GnuCash" nothing happened. How exactly should I write the line "HOME={APPDATA}/GnuCash"? In the end of the environment file? The beginning? What is the exact syntax? Should I use " or ', or any other sign?
Comment 23 Geert Janssens 2012-03-06 11:43:17 UTC
Sorry for the slow reply.

The line should be added at the end of the environment file, without any quotes. So you should add this:
HOME={APPDATA}/GnuCash
Comment 24 Randy Orrison 2012-03-06 13:39:02 UTC
Is there a chance that this can get fixed in some release of GnuCash?  I'd think it's a pretty straightforward change to the distributed environment file.
Comment 25 Paulo Martin 2012-03-06 16:34:13 UTC
(In reply to comment #23)
> Sorry for the slow reply.
> 
> The line should be added at the end of the environment file, without any
> quotes. So you should add this:
> HOME={APPDATA}/GnuCash

Geert,

I successfully changed the environment file, and it worked perfectly.

Thanks for the answer.
Comment 26 Randy Orrison 2012-03-08 20:28:00 UTC
From a recent gnucash-user conversation, it appears that the {APPDATA}/GnuCash directory needs to be created before GnuCash runs for the first time.  When the bug is fixed, that will need to be done at setup time.

Here's the start of the thread: http://lists.gnucash.org/pipermail/gnucash-user/2011-February/038525.html the conclusion isn't in the archives yet.
Comment 27 Mutts 2012-06-06 07:39:34 UTC
Aloha. New user to GnuCash but this fix does not seem to work for my installation on Vista.  I needed to change the file permissions to save the environment file with the HOME={APPDATA}/GnuCash line but each time I start the Program the same directories are created in the Home folder.
Comment 28 Jonathan Van Dusen 2012-06-09 16:25:59 UTC
(In reply to comment #27)
> Aloha. New user to GnuCash but this fix does not seem to work for my
> installation on Vista.  I needed to change the file permissions to save the
> environment file with the HOME={APPDATA}/GnuCash line but each time I start the
> Program the same directories are created in the Home folder.

@Mutts: Changing permissions makes sense, so that's likely not the problem -- did you add the line to the environment file before you ran GnuCash for the first time? (See Randy's comment above.)
Comment 29 Mutts 2012-06-09 17:11:47 UTC
Unfortunately I did not add the file before the first run (at the time I wasn't aware of the issue).  Can this be remedied with a complete uninstall at this point?  If not, would there be any problem with setting the relevant folders/files as hidden?
Comment 30 Jonathan Van Dusen 2012-06-09 18:03:48 UTC
(In reply to comment #29)
> Unfortunately I did not add the file before the first run (at the time I wasn't
> aware of the issue).  Can this be remedied with a complete uninstall at this
> point?  If not, would there be any problem with setting the relevant
> folders/files as hidden?

A complete uninstall would probably be the best plan. If there's data you want to keep, you could back up your existing GnuCash folders first and then move them to the AppData folder when you edit the new environment file.

I think I once tried marking the folders as hidden, but found that GnuCash wouldn't remember my window size/location settings.
Comment 31 Paulo Martin 2012-06-23 13:00:58 UTC
(In reply to comment #30)
> (In reply to comment #29)
> > Unfortunately I did not add the file before the first run (at the time I wasn't
> > aware of the issue).  Can this be remedied with a complete uninstall at this
> > point?  If not, would there be any problem with setting the relevant
> > folders/files as hidden?
> 
> A complete uninstall would probably be the best plan. If there's data you want
> to keep, you could back up your existing GnuCash folders first and then move
> them to the AppData folder when you edit the new environment file.
> 
> I think I once tried marking the folders as hidden, but found that GnuCash
> wouldn't remember my window size/location settings.

Hello Guys. Just to give feedback:

I have just formatted my notebook and re-installed GnuCash 2.4.4. Again, this "folder" problem occurred. I changed the environment file before the first run, but it didn't work. What I did after that was to create a "GnuCash" folder directly under APPDATA\Roaming, and moved the created folders into it. The next time I opened GnuCash, no more folders appeared. So, there was no need to reinstall GnuCash. By the way, I use Windows 7.
Comment 32 Mutts 2012-06-24 19:21:05 UTC
(In reply to comment #31)
> (In reply to comment #30)
> > (In reply to comment #29)
> > > Unfortunately I did not add the file before the first run (at the time I wasn't
> > > aware of the issue).  Can this be remedied with a complete uninstall at this
> > > point?  If not, would there be any problem with setting the relevant
> > > folders/files as hidden?
> > 
> > A complete uninstall would probably be the best plan. If there's data you want
> > to keep, you could back up your existing GnuCash folders first and then move
> > them to the AppData folder when you edit the new environment file.
> > 
> > I think I once tried marking the folders as hidden, but found that GnuCash
> > wouldn't remember my window size/location settings.
> 
> Hello Guys. Just to give feedback:
> 
> I have just formatted my notebook and re-installed GnuCash 2.4.4. Again, this
> "folder" problem occurred. I changed the environment file before the first run,
> but it didn't work. What I did after that was to create a "GnuCash" folder
> directly under APPDATA\Roaming, and moved the created folders into it. The next
> time I opened GnuCash, no more folders appeared. So, there was no need to
> reinstall GnuCash. By the way, I use Windows 7.

Thanks Paulo, that did the trick on my Vista system :).
Comment 33 Geert Janssens 2017-08-26 20:30:54 UTC
A very old bug that will get fixed for gnucash 2.8.

After installing that version gnucash will use AppData(Roaming)\GnuCash by default instead of %HOME%\.gnucash. If there is still a %HOME%\.gnucash its contents will be migrated to AppData(Roaming)\GnuCash.

I'm afraid those that had added HOME={APPDATA}/GnuCash to their environment file will need to manually do this migration. That means you'll need to copy the contents of APPDATA\Roaming\Gnucash\.gnucash to APPDATA\Roaming\Gnucash (so one level higher).

Note also that from 2.8 onwards you should no longer modify environment directly. Instead create a second file called environment.local next to it and make your changes in there. That file should have the same layout:
[Variables]
var1=value1
....

The advantage is you'll no longer have to do this after each installation/update. This local file will never be overwritten.

Gnucash 2.8 is planned for the end of this year but we'll start the beta program soon and you may want to test the 2.7 intermediary releases when they come out and file bugs so 2.8 can be the best gnucash ever :)
Comment 34 John Ralls 2018-06-29 21:56:29 UTC
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=503722. Please update any external references or bookmarks.