Bundle update with new Apple structure

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Bundle update with new Apple structure

Post by quailcreek » Thu Jul 30, 2015 8:41 pm

Hi,
I'm doing an update to an desktop app I created awhile ago. The user writes to a sub-folder in the app bundle into a folder called Scoring Data. After installing the update, with the new bundle structure, there are two Scoring Data folders. one in the MacOS folder and another in the Resources/_MacOS/Scoring Data. The files which the user has created and that have been saved to the MacOS/Scoring Data folder are still there. What I'm trying to do with the code below is move the existing stacks from MacOS/Scoring Data to Resources/_MacOS/Scoring Data. Things seem to work until I get to the repeat.

Any help is appreciated.

Code: Select all

on MouseUP 
if the platform = "MacOS" and the environment = "standalone application" then
      put the defaultfolder into tOldDir
      
      put StackPathMAC(the filename of this stack) & "MacOS/Scoring Data" into tFromPath
      
      answer "tFromPath =" && tFromPath
      
      put StackPath(the filename of this stack) into tToPath
      
      answer "tToPath =" && tToPath
      
      set the defaultfolder to tFromPath
      put the files into tFileList
     
      if tFileList is not empty then
          answer tFileList -- this gives the correct list of stacks

         repeat for each line nLine in tFileList
            put line nLine of tFileList into tFileName

            answer tFileName -- not getting to this

            put url ("binfile:" & tFromPath & "/" & tFileName) into url ("binfile:" & tToPath & tFileName)
         end repeat
                  
         set the defaultfolder to tOldDir
      end if
   end if

answer “Copy complete”
end MouseUP
--------------------------------
function StackPath pPath
   set the itemDelimiter to slash
   
   if the platform = "MacOS" and the environment = "standalone application" then
      
      get the effective filename of stack pPath
      put item 1 to -3 of it into pPath
      put "/Resources/_MacOS" after pPath
      return pPath & "/"
      
   else
      delete last item of pPath -- remove the last item to get the path to the containing folder
      return pPath & "/"
   end if
end StackPath
--------------------------------
function StackPathMAC pPathMAC -- only used for this situation
   set the itemDelimiter to slash
   
      get the effective filename of stack pPathMAC
      put item 1 to -3 of it into pPathMAC
      return pPathMAC & "/"
      
end StackPathMAC
Tom
MacBook Pro OS Mojave 10.14

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Bundle update with new Apple structure

Post by quailcreek » Fri Jul 31, 2015 2:59 am

I found my mistake.

repeat for each line nLine in tFileList
changed to
repeat with nLine = 1 to the number of lines of tFileList
Tom
MacBook Pro OS Mojave 10.14

Klaus
Posts: 11576
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Bundle update with new Apple structure

Post by Klaus » Fri Jul 31, 2015 11:21 am

Hi Tom,

please keep in mind that the "Application" folder is WRITE protected for the average user!
Means that may silently fail for some users, if the app is installed correctly in the App folder!


Best

Klaus

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Bundle update with new Apple structure

Post by quailcreek » Fri Jul 31, 2015 3:45 pm

Thanks, Klaus.

I have the bundle installed to the users home directory so read\write it's an issue.
Tom
MacBook Pro OS Mojave 10.14

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7427
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Bundle update with new Apple structure

Post by FourthWorld » Fri Jul 31, 2015 4:19 pm

quailcreek wrote:I have the bundle installed to the users home directory so read\write it's an issue.
...right now. Apple so strongly recommends against writing in the app bundle that I wouldn't be surprised to find some day they completely prohibit it at the OS level, and there are likely some Gatekeeper configurations available now which would prevent that.

Apple suggests using the Documents, Application Support, and Preferences folders for writable files. The paths to these can be found with LiveCode's specialFolderPath function. These folders are also where users expect to find application-specific files.

I would advise against spending time on any architecture dependent on Apple not enforcing their guidelines. Sooner or later, it will break as they continue to make OS X ever more secure.

After all, the app bundle is where the plist file resides, which determines many aspects of what an app can or can't do. If your app can write to its bundle so can others, and your plist could be replaced by malware. Don't bank on the bundle being writable forever.

As for the difference you found with reading files in the bundle, this was a change introduce fairly recently in LiveCode to comply with new sandboxing requirements, described on page 10 of the Release Notes for v6.7 where it first appeared, in the section titled "Relocation of resources for Mac standalone applications (6.7.5-rc-1)":
http://downloads.livecode.com/livecode/ ... 7_rc_1.pdf
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Bundle update with new Apple structure

Post by quailcreek » Fri Jul 31, 2015 7:21 pm

Great information, Richard.

I will stop writing to the bundle. This app was written over 8 years ago when things were different, including my coding abilities and knowledge. For the current update I am too far down the road but I will be changing my ways.

Thanks agin.
Tom
MacBook Pro OS Mojave 10.14

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7427
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Bundle update with new Apple structure

Post by FourthWorld » Fri Jul 31, 2015 7:34 pm

That's one of the great things about computing: it keeps us young because whatever we learned yesterday becomes obsolete by next week, so we never get complacent resting on our laurels. :)
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Post Reply

Return to “Mac OS”