Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ TheIDE and Library: Releases and ChangeLogs » GetHomeDirectory, GetHomeDirFile in Win32
GetHomeDirectory, GetHomeDirFile in Win32 [message #10395] Thu, 05 July 2007 20:37 Go to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Now working in Win32 too, thanks to Benoit.
Re: GetHomeDirectory, GetHomeDirFile in Win32 [message #10493 is a reply to message #10395] Thu, 12 July 2007 11:02 Go to previous messageGo to next message
benoitc is currently offline  benoitc
Messages: 17
Registered: July 2007
Location: Nice (France)
Promising Member
Thanks.

BTW, it might be good to update ConfigFile() as well for Windows to be more compliant with Windows path used for application.

Instead of using the EXE directory.
return GetExeDirFile(file);

We can store config file in the "Application Data" Windows directory that belong to the user.
String p = GetHomeDirFile("Application Data\\" + GetExeTitle());
static bool b;
if(!b) {
	RealizeDirectory(p);
	b = true;
}
return AppendFileName(p, file);


Regards,
Benoit
Re: GetHomeDirectory, GetHomeDirFile in Win32 [message #10499 is a reply to message #10493] Thu, 12 July 2007 21:49 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
benoitc wrote on Thu, 12 July 2007 05:02

Thanks.

BTW, it might be good to update ConfigFile() as well for Windows to be more compliant with Windows path used for application.

Instead of using the EXE directory.
return GetExeDirFile(file);

We can store config file in the "Application Data" Windows directory that belong to the user.
String p = GetHomeDirFile("Application Data\\" + GetExeTitle());
static bool b;
if(!b) {
	RealizeDirectory(p);
	b = true;
}
return AppendFileName(p, file);


Regards,
Benoit


Sure, I was thinking about it too, however, I feel like for most applications in win32 (at least for those I sell to my customers), keeping .cfg in exedir leads to much simpler maintenance (uninstall? delete the folder. broken .cfg? you know where to find it). But perhaps it could be some flag switching the behaviour, with exedir as default?

Mirek
Re: GetHomeDirectory, GetHomeDirFile in Win32 [message #10511 is a reply to message #10499] Fri, 13 July 2007 10:31 Go to previous messageGo to next message
benoitc is currently offline  benoitc
Messages: 17
Registered: July 2007
Location: Nice (France)
Promising Member
I think it depends of the application type, but today most win32 applications allow a per user config, so in that case you cannot really put that in the exe directory.
Regarding the installation point, if you use a installer (Nullsoft Scriptable Install System), it can take care of the copy to user directory.

As you said, the best is to propose both approaches, and keep the exe dir as default for compatibility reason.

Regards,
Benoit
Re: GetHomeDirectory, GetHomeDirFile in Win32 [message #10512 is a reply to message #10511] Fri, 13 July 2007 13:35 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK:

void UseHomeDirectoryConfig(bool b = true);
Re: GetHomeDirectory, GetHomeDirFile in Win32 [message #10728 is a reply to message #10512] Wed, 25 July 2007 18:36 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
It might be a better idea to use getenv("APPDATA") for application config (equivalent to HOMEDRIVE\HOMEPATH\Application Data) rather than the users root profile directory.

On a slight tangent, I'm going modify FileSel to include links to My Documents(Win32)/Home(Linux) and Desktop as their absence has been annoying me for ages. The safest way I've found to get these paths one windows is (for My Docs):
	TCHAR path[MAX_PATH];
	HRESULT hr = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, path);

MDSN page here. Does anyone know of a better way? Has this been done already?

[Updated on: Wed, 25 July 2007 18:37]

Report message to a moderator

Re: GetHomeDirectory, GetHomeDirFile in Win32 [message #10729 is a reply to message #10728] Wed, 25 July 2007 19:22 Go to previous messageGo to next message
Zardos is currently offline  Zardos
Messages: 62
Registered: April 2007
Member
mrjt wrote on Wed, 25 July 2007 18:36

It might be a Does anyone know of a better way? Has this been done already?


For my personal requirements I have already written some functions to get the default pathes on windows (including vista) what I have found is to use the values from the registry:

HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVers ion\\Explorer\\User Shell Folders

You are probably interested in the Keys:
"Personal"
"Desktop"

...Of course I would share the code, but all this is just an ugly hack with some very specific funtions.

Basically I have the following funtions for storing configurations:
String GetConfigPath(const char*name, const char *subpath);
inline String UserConfigPath(const char *subpath = NULL) { return GetConfigPath("AppData", AppendFileName(GetExeTitle(), subpath)); }
inline String AllUserConfigPath(const char *subpath = NULL) { return GetConfigPath("Common AppData", AppendFileName(GetExeTitle(), subpath)); }
inline String AppConfigPath(const char *subpath = NULL) { return GetConfigPath("ExeConfigFilePath", subpath); }
inline String UserLocalPath(const char *subpath = NULL) { return GetConfigPath("Local AppData", AppendFileName(GetExeTitle(), subpath)); }

String UserConfigFile(const char *file = NULL, const char* subpath = NULL);
String AllUserConfigFile(const char *file = NULL, const char* subpath = NULL);
String AppConfigFile(const char *file = NULL, const char* subpath = NULL);
String UserLocalFile(const char *file = NULL, const char* subpath = NULL);


... well, probably not useful for you.

Edit: The link you mention is declared: Deprecated... I guess its better to use the registry values, and probably the usual way.

[Updated on: Wed, 25 July 2007 19:25]

Report message to a moderator

Re: GetHomeDirectory, GetHomeDirFile in Win32 [message #10737 is a reply to message #10729] Thu, 26 July 2007 10:38 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
Zardos wrote


Edit: The link you mention is declared: Deprecated... I guess its better to use the registry values, and probably the usual way.

I noticed that too, although it's only depreciated because MS introduced a new non-backwards compatible function in Vista (under Vista the above code is a wrapper for this new method).

Thanks for the tip on registry entries, I suspect that all SHGetFolderPath is doing is reading from these, so I may as well cut out the middle-man Smile.

Cheers,
James

[Updated on: Thu, 26 July 2007 10:40]

Report message to a moderator

Re: GetHomeDirectory, GetHomeDirFile in Win32 [message #10738 is a reply to message #10737] Thu, 26 July 2007 11:55 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
String  ConfigFile(const char *file) {
#if defined(PLATFORM_WIN32)
	return GetExeDirFile(file);
#elif defined(PLATFORM_POSIX)
	String p = GetHomeDirFile(".config/upp-aris/" + GetExeTitle());  //aris002
	...

this what I'm using on my ArchLinux (I stopped using M$ so I didn't change that part) to avoid all the Ultimate++ home dirs config mess.
AFAIK, if you want to comply to freedesktop recommendations, configs must go under ==> /home/username/.config/appname or /home/username/.config/appgroup/appname.
Re: GetHomeDirectory, GetHomeDirFile in Win32 [message #10746 is a reply to message #10738] Fri, 27 July 2007 12:41 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Hm, is there any summary about what changes I should do to U++? Smile

Mirek
Re: GetHomeDirectory, GetHomeDirFile in Win32 [message #10751 is a reply to message #10746] Fri, 27 July 2007 14:42 Go to previous message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
luzr wrote on Fri, 27 July 2007 11:41

Hm, is there any summary about what changes I should do to U++? Smile

Mirek


Let's create Smile :
http://www.ultimatepp.org/forum/index.php?t=msg&th=2580& amp;start=0&
Previous Topic: DropList::NotNull implemented, fixed refreshing right button after closing popuped list
Next Topic: New simple static widget DisplayCtrl...
Goto Forum:
  


Current Time: Fri Mar 29 11:33:55 CET 2024

Total time taken to generate the page: 0.01939 seconds