It is currently Thu Nov 14, 2019 8:07 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: PB IDE Tool MyAppData
PostPosted: Tue Feb 10, 2015 9:41 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2025
Location: Germany
Hello

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 <...>"

Code:
;-TOP
; Tool    : MyAppData
; Author  : mk-soft
; Version : 1.2.0.2
; Create  : 10.02.2015
; Update  : 30.12.2018
;
; Comment:  Copied the folder MyAppData in the APP folder \Contents
;
; 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 © 2018 mk-soft. All rights reserved.</string>
;
; ***************************************************************************************
; Configure Tool 1
;
; Commandline:
;   /.../.../MyAppData.app/Contents/MacOS/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.app/Contents/MacOS/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
  ; 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
Procedure ReadPListFile()
  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 ReadPListInfo()
  Protected 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
          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
EndProcedure

;- Write new info.plist
Procedure WritePListFile()
  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
  Else
    MessageRequester("MyAppData", "Error write info.plist", #PB_MessageRequester_Error)
  EndIf
EndProcedure

; ---------------------------------------------------------------------------------------

;-Main
If InitParameters()
  CopyAppData()
  ReadPListFile()
  ReadPListInfo()
  WritePListFile()
EndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Last edited by mk-soft on Sun Dec 30, 2018 5:14 pm, edited 4 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: PB IDE Tool MyAppData
PostPosted: Sun Apr 22, 2018 4:27 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2025
Location: Germany
Update v1.2.0.2
- Added: Replace and insert keys and values into 'info.plist'

Example
Code:
;-TOP

; PLIST <key>CFBundleInfoDictionaryVersion</key>
; PLIST <string>6.0</string>
; PLIST <key>CFBundlePackageType</key>
; PLIST <string>APPL</string>
; PLIST <key>CFBundleVersion</key>
; PLIST <string>0.1</string>
; PLIST <key>CFBundleSignature</key>
; PLIST <string>PBAPP</string>
; PLIST <key>CFBundleShortVersionString</key>
; PLIST <string>1.0.2</string>
; PLIST <key>NSHumanReadableCopyright</key>
; PLIST <string>Copyright © 2018 mk-soft. All rights reserved.</string>

MessageRequester("Info", "Hello World!", #PB_MessageRequester_Info)

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Last edited by mk-soft on Sun Dec 30, 2018 3:07 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: PB IDE Tool MyAppData
PostPosted: Tue May 01, 2018 1:42 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2025
Location: Germany
Update v1.2.0.1
- Code cleanup

:wink:

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: PB IDE Tool MyAppData
PostPosted: Sun Dec 30, 2018 3:24 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2025
Location: Germany
Update v1.2.02
- Change syntax ";PLIST <...>" to ";[Space]PLIST <...>"

Some help functions...
Code:
; ---------------------------------------------------------------------------------------

Procedure.s GetAppPath()
  Protected bundlePathPtr = CocoaMessage(0,CocoaMessage(0,CocoaMessage(0,0,"NSBundle mainBundle"),"bundlePath"),"UTF8String")
  If bundlePathPtr
    Protected bundlePath.s = PeekS(bundlePathPtr,-1,#PB_UTF8) + "/"
  EndIf
  ProcedureReturn bundlePath
EndProcedure

; ---------------------------------------------------------------------------------------

Procedure.s GetContentsPath()
  Protected bundlePathPtr = CocoaMessage(0,CocoaMessage(0,CocoaMessage(0,0,"NSBundle mainBundle"),"bundlePath"),"UTF8String")
  If bundlePathPtr
    Protected bundlePath.s = PeekS(bundlePathPtr,-1,#PB_UTF8) + "/Contents/"
  EndIf
  ProcedureReturn bundlePath
EndProcedure

; ---------------------------------------------------------------------------------------

Procedure.s GetResourcePath()
  Protected bundlePathPtr = CocoaMessage(0,CocoaMessage(0,CocoaMessage(0,0,"NSBundle mainBundle"),"resourcePath"),"UTF8String")
  If bundlePathPtr
    Protected bundlePath.s = PeekS(bundlePathPtr,-1,#PB_UTF8) + "/"
  EndIf
  ProcedureReturn bundlePath
EndProcedure

; ---------------------------------------------------------------------------------------

Procedure.s GetResourceFile(Filename.s)
  Protected NSBundle, *NSPathString
  Protected file.s, ext.s, result.s
  NSBundle = CocoaMessage(0,0,"NSBundle mainBundle", 0)
  If NSBundle
    file = GetFilePart(Filename, #PB_FileSystem_NoExtension)
    ext = GetExtensionPart(Filename)
    *NSPathString = CocoaMessage(0, NSBundle, "pathForResource:$", @file, "ofType:$", @ext)
    If *NSPathString
      result = PeekS(CocoaMessage(0, *NSPathString, "UTF8String"), -1, #PB_UTF8)
    EndIf
  EndIf
  ProcedureReturn result
EndProcedure

; ---------------------------------------------------------------------------------------

EnableExplicit

Define r1.s

r1 = "AppPath: " + GetAppPath() + #LF$
r1 + "ContentsPath: " + GetContentsPath() + #LF$
r1 + "ResourcePath: " + GetResourcePath() + #LF$
r1 + "ResourceFile: " + GetResourceFile("Copy.png")

MessageRequester("Path", r1)

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 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