here is a very small code to copy folders and files on-fly into own app
Folder structure:
../[Project-Path]/MyAppData/
Folders inside MyAppData:
./Resources
./Library <- if needed
Update v1.2
- Added: Replace and insert keys and values into 'info.plist'
Update v1.2.01
- Code cleanup
Update v1.2.02
- Change syntax ";PLIST <...>" to ";[Space]PLIST <...>"
Update v1.03.1
- Build with compilermode console
Update v1.04.0
- Added check is Application
Code: Select all
;-TOP
; Tool : MyAppData - Copied the folder MyAppData in the APP folder \Contents
; Author : mk-soft
; Version : 1.04.0
; Create : 10.02.2015
; Update : 16.01.2022
;
; Commpilermode : Console
;
; Info.plist
;
; PLIST <key>CFBundleSignature</key>
; PLIST <string>PB-TOOL</string>
; PLIST <key>CFBundleShortVersionString</key>
; PLIST <string>1.2.0.2</string>
; PLIST <key>CFBundleName</key>
; PLIST <string>PB-Tool MyAppData</string>
; PLIST <key>NSHumanReadableCopyright</key>
; PLIST <string>Copyright © 2022 mk-soft. All rights reserved.</string>
;
; ***************************************************************************************
; Configure Tool 1
;
; Commandline:
; MyAppData
;
; Arguments:
; "%FILE"
;
; Working Directorory
; Nothing
;
; Name:
; MyAppData Run
;
; Event to trigger the tool:
; After Compile/Run
;
; Option:
; Wait until tools quits
;
; ---------------------------------------------------------------------------------------
;
; Configure Tool 2
;
; Commandline:
; MyAppData
;
; Arguments:
; "%FILE"
;
; Working Directorory
; Nothing
;
; Name:
; MyAppData Executable
;
; Event to trigger the tool:
; After Create Executable
;
; Option:
; Nothing
;
; ---------------------------------------------------------------------------------------
;
; Format for new info.plist
;
; Begin without space '; PLIST {keys and values}
;
; Example
; ; PLIST <key>CFBundleSignature</key>
; ; PLIST <string>PBAPP</string>
; ; PLIST <key>CFBundleShortVersionString</key>
; ; PLIST <string>1.0.1.0</string>
; ; PLIST <key>NSHumanReadableCopyright</key>
; ; PLIST <string>Copyright © 2018 mk-soft. All rights reserved.</string>
; **********************************************
EnableExplicit
Structure udtDict
key.s
List value.s()
EndStructure
Global NewList plist.s()
Global NewList dict.udtDict()
Global file_code.s
Global file_app.s
Global path_contents.s
; ---------------------------------------------------------------------------------------
Procedure InitParameters()
; Parameter source file
file_code = ProgramParameter()
If file_code = ""
ProcedureReturn 0
EndIf
; Parameter execute file
file_app = GetEnvironmentVariable("PB_TOOL_Executable")
If file_app = ""
ProcedureReturn 0
EndIf
If GetExtensionPart(file_app) <> "app"
ProcedureReturn 0
EndIf
; Set path to contents
path_contents = file_app + "/Contents/"
ProcedureReturn 1
EndProcedure
; ---------------------------------------------------------------------------------------
;- Copy folder MyAppData to Contents
Procedure CopyAppData()
Protected path_data.s
path_data = GetPathPart(file_code) + "MyAppData"
If FileSize(path_data) <> -2
ProcedureReturn 0
EndIf
If CopyDirectory(path_data, path_contents, "*", #PB_FileSystem_Recursive) = 0
MessageRequester("MyAppData", "Error copy data" + #CR$ + path_data + " to " + path_contents)
ProcedureReturn 0
EndIf
ProcedureReturn 1
EndProcedure
; ---------------------------------------------------------------------------------------
;- Read info.plist from Application
Procedure ReadPList()
Protected file_plist.s, text.s, dict.i, key.s, value.s, newkey.i, pos
file_plist.s = path_contents + "info.plist"
If ReadFile(0, file_plist)
While Not Eof(0)
text.s = ReadString(0, #PB_UTF8)
If Bool(text)
If FindString(text, "<dict>")
AddElement(plist())
plist() = text
dict = #True
ElseIf FindString(text, "</dict>")
AddElement(plist())
plist() = text
dict = #False
ElseIf Not dict
AddElement(plist())
plist() = text
EndIf
If dict
pos = FindString(text, "<key>")
If pos >= 1 And pos <= 3
AddElement(dict())
dict()\key = Trim(text)
newkey = #True
ElseIf newkey
AddElement(dict()\value())
dict()\value() = Trim(text)
EndIf
EndIf
EndIf
Wend
CloseFile(0)
EndIf
EndProcedure
;- Read new info.plist from source
Procedure ReadInfo()
Protected r1, text.s, key.s, lkey.s, value.s, newkey, addkey
If ReadFile(0, file_code)
While Not Eof(0)
text.s = ReadString(0, #PB_UTF8)
If Bool(text)
If FindString(text, "; PLIST ", 1, #PB_String_NoCase) = 1
r1 = #True
text = RTrim(Mid(text, 9))
If FindString(text, "<key>") = 1 ; New key only with first place
key = Trim(text)
lkey = LCase(key)
newkey = #True
addkey = #True
ForEach dict()
If LCase(dict()\key) = lkey
ClearList(dict()\value())
addkey = #False
Break
EndIf
Next
If addkey
ResetList(dict())
AddElement(dict())
dict()\key = key
EndIf
ElseIf newkey
AddElement(dict()\value())
dict()\value() = text
EndIf
EndIf
EndIf
Wend
CloseFile(0)
EndIf
ProcedureReturn r1
EndProcedure
;- Write new info.plist
Procedure WritePList()
Protected file_plist.s
file_plist.s = path_contents + "info.plist"
If CreateFile(0, file_plist)
ForEach plist()
WriteStringN(0, plist(), #PB_UTF8)
If FindString(plist(), "<dict>") = 1
ForEach dict()
WriteStringN(0, #TAB$ + dict()\key, #PB_UTF8)
ForEach dict()\value()
WriteStringN(0, #TAB$ + dict()\value(), #PB_UTF8)
Next
Next
EndIf
Next
EndIf
EndProcedure
; ---------------------------------------------------------------------------------------
;-Main
If InitParameters()
CopyAppData()
ReadPList()
If ReadInfo()
WritePList()
EndIf
EndIf