It is currently Wed Aug 05, 2020 11:38 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: #Slash-DefaultPath-BinPath-DataPath.pbi
PostPosted: Thu Sep 28, 2017 11:51 am 
Offline
User
User
User avatar

Joined: Wed Mar 15, 2006 9:40 am
Posts: 98
Location: Germany
Code:
; #Slash-DefaultPath-BinPath-DataPath.pbi
;
; based on this code: http://www.purebasic.fr/german/viewtopic.php?f=8&t=27741
;
; perceives SystemDefaultProgramDataDirectory but also can handle portable binary or binary from IDE (use the SourcePath)
; so it is universal useable - "Use your path here" is not necessary anymore
; perceives "\bin" and use if applicable "..\data" if SystemDefaultProgramDataDirectory is not available
;
; erkennt SystemDefaultProgramDataDirectory; kann aber auch mit portablen Programmen oder Programmen aus der IDE umgehen (nutzt den SourcePath)
; dadurch ist es universell nutzbar- "Use your path here" ist nicht mehr notwendig
; erkennt "\bin" und nutzt gegebenenfalls "..\data" wenn SystemDefaultProgramDataDirectory nicht verfügbar ist
;
EnableExplicit

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Windows
    #Slash = "\"
  CompilerDefault
    #Slash = "/"
CompilerEndSelect

Procedure.s GetDefaultDataDirectory()
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      ProcedureReturn GetEnvironmentVariable("APPDATA") + #Slash
    CompilerCase #PB_OS_MacOS
      ProcedureReturn GetHomeDirectory() + "Library/Application Support/"
    CompilerCase #PB_OS_Linux
      ProcedureReturn GetHomeDirectory() +"."
  CompilerEndSelect
EndProcedure

Define.s DataPath, DefaultPath=GetDefaultDataDirectory()
Define.s BinPath = DefaultPath+GetFilePart(ProgramFilename(),#PB_FileSystem_NoExtension)
;Define.s BinPath = DefaultPath+"MyDifferentDirectoryName" ; fix, from Preference, ProgramParameter() or whatever

If Bool(Left(GetFilePart(ProgramFilename()), 9) = "PureBasic")
  BinPath = GetPathPart(ProgramFilename())
Else
  If FileSize(BinPath)=-1
    BinPath = GetPathPart(ProgramFilename())
  EndIf
EndIf

If Right(BinPath,4)="bin"+#Slash
  DataPath = Left(BinPath, Len(BinPath)-4)+"data"+#Slash
  CreateDirectory(DataPath)
Else
  DataPath = BinPath
EndIf
Code:
; for testing
;
EnableExplicit

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Windows
    #Slash = "\"
  CompilerDefault
    #Slash = "/"
CompilerEndSelect

Procedure.s GetDefaultDataDirectory()
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      ProcedureReturn GetEnvironmentVariable("APPDATA") + #Slash
    CompilerCase #PB_OS_MacOS
      ProcedureReturn GetHomeDirectory() + "Library/Application Support/"
    CompilerCase #PB_OS_Linux
      ProcedureReturn GetHomeDirectory() +"."
  CompilerEndSelect
EndProcedure

Define.s DataPath, DefaultPath=GetDefaultDataDirectory(), Title
Define.s BinPath = DefaultPath+GetFilePart(ProgramFilename(),#PB_FileSystem_NoExtension)
;Define.s BinPath = DefaultPath+"MyDifferentDirectoryName" ; fix, from Preference, ProgramParameter() or whatever

If Bool(Left(GetFilePart(ProgramFilename()), 9) = "PureBasic")
  Title= "from IDE" ; DataPath and BinPath = SourcePath
  BinPath = GetPathPart(ProgramFilename())
Else
  If FileSize(BinPath)=-1
    Title= "portable"
    BinPath = GetPathPart(ProgramFilename())
  Else
    Title="DefaultProgramDataDirectory"
  EndIf
EndIf

If Right(BinPath,4)="bin"+#Slash
  DataPath = Left(BinPath, Len(BinPath)-4)+"data"+#Slash
  CreateDirectory(DataPath)
Else
  DataPath = BinPath
EndIf

MessageRequester(Title, "BinPath :   "+BinPath+Chr(10)+"DataPath : "+DataPath, #PB_MessageRequester_Ok)

_________________
Please pardon my English, my native tongue is German.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 26 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye