Posted: Mon Aug 06, 2007 11:34 pm
You might find these pretty useful.
GetProgramFilesDir() ;For example C:\Program Files\
Typically the default install location for programs.
Make sure to use \Company\Appname\ as a common courtesy.
GetApplicationDataDirectory() ;For example C:\Documents and Settings\username\Application Data\
The advised place to put program settings and such files.
Make sure to do the nice \Company\Appname\ thing here too
GetMyDocumentsDirectory() ;For example C:\Documents and Settings\username\My Documents\
The advised place to put documents, game save files, etc.
Make sure to do the nice \Company\Appname\ thing here too
GetTempDirectory() ;For example C:\Documents and Settings\username\Local Settings\Temp\
The advised place to put temporary files.
Make sure the filename is pretty unique or you make a folder that you put the temp files in, and always cleanup after yourself so you don't bloat the temp folder.
Code: Select all
Procedure.s GetKeyValue(topKey.l,sKey$,sValue$)
Protected lType.l,lpcbData.l,hKey.l,lpData$,path$
lpData$=Space(2048+1)
lpcbData=Len(lpData$)-1
If RegOpenKeyEx_(topKey,sKey$,#Null,#KEY_READ,@hKey)=#ERROR_SUCCESS
RegQueryValueEx_(hKey,sValue$,#Null,@lType,@lpData$,@lpcbData)
RegCloseKey_(hKey)
EndIf
ProcedureReturn Trim(lpData$)
EndProcedure
Procedure.s SpecialFolderLocation(csidl.l)
Protected location$,pidl.l
If SHGetSpecialFolderLocation_(#Null,csidl,@pidl)=#ERROR_SUCCESS
location$=Space(#MAX_PATH)
If SHGetPathFromIDList_(pidl,@location$)
If Right(location$,1)<>"\"
location$+"\"
EndIf
EndIf
If pidl
CoTaskMemFree_(pidl) ;Instead of messing with com imalloc free and whatnot.
EndIf
EndIf
ProcedureReturn Trim(location$)
EndProcedure
Procedure.s GetProgramFilesDir()
Protected os.l,value$,path$
os=OSVersion()
If os>#PB_OS_Windows_ME
path$=SpecialFolderLocation(#CSIDL_PROGRAM_FILES)
Else
value$=GetKeyValue(#HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\Currentversion","ProgramFilesDir")
If value$<>""
path$=value$
If Right(value$,1)<>"\"
path$+"\"
EndIf
EndIf
EndIf
If FileSize(path$)<>-2
If CreateDirectory(path$)=#False
path$=""
EndIf
EndIf
ProcedureReturn path$
EndProcedure
Procedure.s GetApplicationDataDirectory()
Protected path$
path$=SpecialFolderLocation(#CSIDL_APPDATA)
If path$="" ;Needed since Windows 95 do not support CSIDL_APPDATA "out of the box".
path$=GetProgramFilesDir()+"Application Data\"
EndIf
If FileSize(path$)<>-2
If CreateDirectory(path$)=#False
path$=""
EndIf
EndIf
ProcedureReturn path$
EndProcedure
Procedure.s GetMyDocumentsDirectory()
Protected path$
path$=SpecialFolderLocation(#CSIDL_PERSONAL) ;My Documents\ folder, use this rather than the other CSIDL
If FileSize(path$)<>-2
If CreateDirectory(path$)=#False
path$=""
EndIf
EndIf
ProcedureReturn path$
EndProcedure
Procedure.s GetTempDirectory()
Protected path$,pathlen.l,result.l
path$=Space(2048+1)
result=GetTempPath_(Len(path$)-1,@path$)
If (result=0) Or (result>Len(path$))
path$=""
Else
If Right(path$,1)<>"\"
path$+"\"
EndIf
If FileSize(path$)<>-2
If CreateDirectory(path$)=#False
path$=""
EndIf
EndIf
EndIf
ProcedureReturn path$
EndProcedure
Typically the default install location for programs.
Make sure to use \Company\Appname\ as a common courtesy.
GetApplicationDataDirectory() ;For example C:\Documents and Settings\username\Application Data\
The advised place to put program settings and such files.
Make sure to do the nice \Company\Appname\ thing here too
GetMyDocumentsDirectory() ;For example C:\Documents and Settings\username\My Documents\
The advised place to put documents, game save files, etc.
Make sure to do the nice \Company\Appname\ thing here too
GetTempDirectory() ;For example C:\Documents and Settings\username\Local Settings\Temp\
The advised place to put temporary files.
Make sure the filename is pretty unique or you make a folder that you put the temp files in, and always cleanup after yourself so you don't bloat the temp folder.