Page 1 of 1

HMG4 GetCurrentFolder()

Posted: Tue Mar 01, 2011 8:58 pm
by l3whmg
Hi guys,
I'm sorry if I'm jumping from a problem to another, but to check HMG4 I'm porting my projects and test.

Anyway, at the beginning of my program I read a configuration file and set up directory with Harbour/XBase commands:

Code: Select all

SET( _SET_PATH,.... )
and

Code: Select all

SET( _SET_DEFAULT,.....)

I've used GetCurrentFolder() function (dialogs.prg), but the result is not quite correct when used in a MsWin. I see "/" instead of "\".
This function use returned value of QDir():currentPath(). Yes, I know, many HARBOUR functions are able to use this value... I believe that many developers could have written its own functions based on the Microsoft operating system.

I've read QT documentation here(http://doc.qt.nokia.com/latest/qdir.htm ... Separators) and this could be the solution:

Code: Select all

FUNCTION GetCurrentFolder()
   RETURN QDir():toNativeSeparators( QDir():currentPath() )
From QT documentation about ":toNativeSeparators":
<<Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system.
On Windows, toNativeSeparators("c:/winnt/system32") returns "c:\winnt\system32".
The returned string may be the same as the argument on some operating systems, for example on Unix.
This function was introduced in Qt 4.2
.>>
This is the opposite function: cQtStyledPath := QDir():fromNativeSeparators( PathName )

Today, the Harbour compiler provides some additional function (Attention: don't use "CurDir()". My opinion is that the value returned is not usable).
I would be the idea to use this UDF rather than those made available to QT, and so we give an example

Code: Select all

 FUNCTION GetCurrentFolder()
   LOCAL cPath, cFile, cExt, cDrive
   HB_FNAMESPLIT( HB_PROGNAME(), @cPath, @cFile, NIL, NIL )
   RETURN cPath
With this function I get the pathname (eg. local "D:\PathName\" remote "\\RemotePc\Path\").

This is the same as QDir():toNativeSeparators( QDir():currentPath() ) but with Harbour compiler functions.

What do you think?

Re: HMG4 GetCurrentFolder()

Posted: Tue Mar 01, 2011 10:30 pm
by l3whmg
Hi to everyone, I'm :oops:

This UDF can't be the solution.

Code: Select all

FUNCTION GetCurrentFolder()
   LOCAL cPath, cFile, cExt, cDrive
   HB_FNAMESPLIT( HB_PROGNAME(), @cPath, @cFile, NIL, NIL )
   RETURN cPath
I assume that everyone uses the installation directory of the program as well that has not changed the directory.

This one is better

Code: Select all

FUNCTION GetCurrentFolder()
   RETURN QDir():toNativeSeparators( QDir():currentPath() )
Someone can test on *nix system?

Cheers

Re: HMG4 GetCurrentFolder()

Posted: Wed Mar 02, 2011 2:51 am
by Rathinagiri
Thank you Luigi.

Re: HMG4 GetCurrentFolder()

Posted: Wed Mar 02, 2011 4:32 pm
by l3whmg
Hi friends,
I've commit this
2011-03-02 15:15 UTC+0100 Luigi Ferraris (<luigi at l3w.it>)
* source/misc.prg
+ Added GetUserHomeFolder(): Returns the user's home directory
+ Added GetRootPath(): Returns the absolute path of the root directory
* GetDesktopFolder(): introduced QDir():toNativeSeparators to normalize retturned value
* GetMyDocumentsFolder(): introduced QDir():toNativeSeparators to normalize retturned value
* GetProgramFilesFolder(): introduced QDir():toNativeSeparators to normalize retturned value
* GetTempFolder(): introduced QDir():toNativeSeparators to normalize retturned value
* source/dialogs.prg
* GetCurrentFolder(): introduced QDir():toNativeSeparators to normalize retturned value
About GetUserHomeFolder() it's not the same of GetMyDocumentsFolder()!
Returned value on MsWin systems:
GetUserHomeFolder() => C:\Documents and Settings\UserName
GetMyDocumentsFolder() => C:\Documents and Settings\UserName\Documents

IMHO, GetUserHomeFolder() function should be more reliable that GetMyDocumentsFolder() also in *nix systems. Or is more likely that there is a home directory rather than the directory "documents.".

Best regards.

Re: HMG4 GetCurrentFolder()

Posted: Wed Mar 02, 2011 5:36 pm
by Rathinagiri
Thanks a lot Luigi.