More System-Paths

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

More System-Paths

Post by GPI »

At the moment only GetHomeDirectory() and GetTempDirectory() exist, but this isn't engouth.

Also GetHomeDirectory() points to "C:\Users\<accountname>\" (on Vista/Win7) which isn't a good path to store datas.

i miss:

GetAppDataDirectory() - "C:\Users\<accountname>\AppData\Roaming" (Enviroment-Variable %appdata%) - only for current user
GetAllAppDataDirecotry() - "C:\ProgramData" (Enviroment-Variable %ALLUSERSPROFILE%) - datas for all users of a pc.
GetOwnFileName() - Return the Name of the own exe-File Prg.s = Space(#MAX_PATH+1): GetModuleFileName_(GetModuleHandle_(0), @Prg, #MAX_PATH)


Also nice would be:
GetMyDocumentsDirectory()
GetMyMusicDirectory()
GetMyPictureDirectory()
GetMyVideoDirectory()
Important note - under Vista/Win7 it is possible to declare more than on MyDocuments-Folder...
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: More System-Paths

Post by gnozal »

GPI wrote:GetOwnFileName() - Return the Name of the own exe-File Prg.s = Space(#MAX_PATH+1): GetModuleFileName_(GetModuleHandle_(0), @Prg, #MAX_PATH)
ProgramFilename() ;-)
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: More System-Paths

Post by MachineCode »

As for the rest, I'm pretty sure I read that since they're not cross-platform, they're not being added.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: More System-Paths

Post by GPI »

I think, the "GetHomeDirectory"-Command give the wrong value back on a windows system.

it is correct, that, the "c:\user\<accountname>\" folder is the home directory under win7, BUT nobody should write in it directly! A good windows-Programm should use for example the %appdata%-folder.

Linux and MacOs doesn't have a MyDocuments-Folder? I can't believe it.

When the System not support the "MyVideo"-Directory, it should return the MyDocuments-Directory., same for music, picture and so on. I forgot one very intressting special folder: SaveGame

When a System doesn't have a "ALLUSERSPROFILE" it should return the same path as "GetHomeDirectory".
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: More System-Paths

Post by IdeasVacuum »

One of the experts (obviously not me) posted this for Windows:

Code: Select all

Procedure.s GetSpecialFolder(iVal.l)
;-------------------------------------
#CSIDL_DESKTOP = $0                 ;{desktop}
#CSIDL_INTERNET = $1                ;Internet Explorer (icon on desktop)
#CSIDL_PROGRAMS = $2                ;Start Menu\Programs
#CSIDL_CONTROLS = $3                ;My Computer\Control Panel
#CSIDL_PRINTERS = $4                ;My Computer\Printers
#CSIDL_PERSONAL = $5                ;My Documents
#CSIDL_FAVORITES = $6               ;{user}\Favourites
#CSIDL_STARTUP = $7                 ;Start Menu\Programs\Startup
#CSIDL_RECENT = $8                  ;{user}\Recent
#CSIDL_SENDTO = $9                  ;{user}\SendTo
#CSIDL_BITBUCKET = $A               ;{desktop}\Recycle Bin
#CSIDL_STARTMENU = $B               ;{user}\Start Menu
#CSIDL_DESKTOPDIRECTORY = $10       ;{user}\Desktop
#CSIDL_DRIVES = $11                 ;My Computer
#CSIDL_NETWORK = $12                ;Network Neighbourhood
#CSIDL_NETHOOD = $13                ;{user}\nethood
#CSIDL_FONTS = $14                  ;windows\fonts
#CSIDL_TEMPLATES = $15
#CSIDL_COMMON_STARTMENU = $16       ;All Users\Start Menu
#CSIDL_COMMON_PROGRAMS = $17        ;All Users\Programs
#CSIDL_COMMON_STARTUP = $18         ;All Users\Startup
#CSIDL_COMMON_DESKTOPDIRECTORY = $19;All Users\Desktop
#CSIDL_APPDATA = $1A                ;{user}\Application Data
#CSIDL_PRINTHOOD = $1B              ;{user}\PrintHood
#CSIDL_LOCAL_APPDATA = $1C          ;{user}\Local Settings\Application Data (non roaming)
#CSIDL_ALTSTARTUP = $1D             ;non localized startup
#CSIDL_COMMON_ALTSTARTUP = $1E      ;non localized common startup
#CSIDL_COMMON_FAVORITES = $1F
#CSIDL_INTERNET_CACHE = $20
#CSIDL_COOKIES = $21
#CSIDL_HISTORY = $22
#CSIDL_COMMON_APPDATA = $23          ;All Users\Application Data
#CSIDL_WINDOWS = $24                 ;GetWindowsDirectory()
#CSIDL_SYSTEM = $25                  ;GetSystemDirectory()
#CSIDL_PROGRAM_FILES = $26           ;C:\Program Files
#CSIDL_MYPICTURES = $27              ;C:\Program Files\My Pictures
#CSIDL_PROFILE = $28                 ;USERPROFILE
#CSIDL_SYSTEMX86 = $29               ;x86 system directory on RISC
#CSIDL_PROGRAM_FILESX86 = $2A        ;x86 C:\Program Files on RISC
#CSIDL_PROGRAM_FILES_COMMON = $2B    ;C:\Program Files\Common
#CSIDL_PROGRAM_FILES_COMMONX86 = $2C ;x86 Program Files\Common on RISC
#CSIDL_COMMON_TEMPLATES = $2D        ;All Users\Templates
#CSIDL_COMMON_DOCUMENTS = $2E        ;All Users\Documents
#CSIDL_COMMON_ADMINTOOLS = $2F       ;All Users\Start Menu\Programs\Administrative Tools
#CSIDL_ADMINTOOLS = $30              ;{user}\Start Menu\Programs\Administrative Tools
#CSIDL_FLAG_CREATE = $8000          ;combine with CSIDL_ value to force
                                                  ;create on SHGetSpecialFolderLocation()
#CSIDL_FLAG_DONT_VERIFY = $4000      ;combine with CSIDL_ value to force
                                                  ;create on SHGetSpecialFolderLocation()
#CSIDL_FLAG_MASK = $FF00             ;mask for all possible flag values
#SHGFP_TYPE_CURRENT = $0             ;current value for user, verify it exists
#SHGFP_TYPE_DEFAULT = $1


Protected Folder_ID, SpecialFolderLocation.s

  If SHGetSpecialFolderLocation_(0, iVal, @Folder_ID) = 0

          SpecialFolderLocation = Space(#MAX_PATH)
          SHGetPathFromIDList_(Folder_ID, @SpecialFolderLocation)
          
                  If SpecialFolderLocation
                  
                          If Right(SpecialFolderLocation, 1) <> "\"
                          
                                  SpecialFolderLocation + "\"
                          
                          EndIf
                  
                  EndIf
          
          CoTaskMemFree_(Folder_ID) 
  
EndIf

       ProcedureReturn SpecialFolderLocation

EndProcedure
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: More System-Paths

Post by GPI »

thanks, but what should i do, when i want to write a programm that should work on linux and windos. A nativ solution in PureBasic, which support all os would be better.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: More System-Paths

Post by MachineCode »

And just to be pedantic, on Win XP it's called "My Documents" but on Win 7 it's just "Documents". What is it called on Linux and Mac? And therefore, what would the team name the command? :)
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: More System-Paths

Post by GPI »

MachineCode wrote:And just to be pedantic, on Win XP it's called "My Documents" but on Win 7 it's just "Documents". What is it called on Linux and Mac? And therefore, what would the team name the command? :)
The name of the command shouldn't be a problem...

Why not simple "DocumentsDirectory()" - should fit for all systems.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: More System-Paths

Post by ts-soft »

most of this paths a windows only paths so there is no equivalent on linux. the best solution is to use CompilerDirectives


greetings
Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: More System-Paths

Post by GPI »

Where is the place, where a Linux-app should store a documents, appdata for all user and appdata for the current user? Doesn't this things exists?

My personal opinion is, that a good pure-basic programm should run without any compiler directives under Windows, Linux and MacOs. And for a windows-Program this paths are important.

my suggestion:

GetHomeDirectory([oldstyle]) should return C:\Users\<accountname>\AppData\Roaming and not C:\Users\<accountname>\ (windows 7) - when the optional parameter oldstyle is #True, it should return C:\Users\<accountname>\ - for backward compatiblity

GetAllUserHomeDirectory() should return C:\ProgramData (when a system doesn't have a special directory for this, it should return the path of the executable)

GetDocumentDirectory([dir]) location where documents should saved - (should return the GetHomeDirectory(), when no special path exist)
[dir] should be #pb_document (default), #pb_document_video, #pb_document_music, #pb_document_picture, #pb_document_savegame

When a system doesn't support #pb_document_video, it should do return the path of the default document-folder. (XP for example)

Or, add a optional Parameter for GetHomeDirectory()
#PB_Home (default), #pb_home_documents, #pb_home_music, #pb_home_video, #pb_home_picture, #pb_home_savegame, #pb_home_alluser

Many Commands in PureBasic are not avaible for all systems. Like MDIGadget(), or SpritePixelCollision() - only on directx it would check a pixel-collision, with linux, macos, opengl it make the same as SpriteCollision().
Post Reply