HMG4 GetCurrentFolder()

Moderator: Rathinagiri

Post Reply
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

HMG4 GetCurrentFolder()

Post by l3whmg » Tue Mar 01, 2011 8:58 pm

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?
Luigi from Italy
www.L3W.it

User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Post by l3whmg » Tue Mar 01, 2011 10:30 pm

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
Luigi from Italy
www.L3W.it

User avatar
Rathinagiri
Posts: 5263
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 169 times
Been thanked: 172 times
Contact:

Post by Rathinagiri » Wed Mar 02, 2011 2:51 am

Thank you Luigi.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Post by l3whmg » Wed Mar 02, 2011 4:32 pm

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.
Luigi from Italy
www.L3W.it

User avatar
Rathinagiri
Posts: 5263
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 169 times
Been thanked: 172 times
Contact:

Post by Rathinagiri » Wed Mar 02, 2011 5:36 pm

Thanks a lot Luigi.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

Post Reply