Page 1 of 1

referring to folder in standalone

Posted: Thu Oct 09, 2014 3:41 pm
by cwkalish
Hi.
I see that I can include a folder of files along with a standalone. How would I refer to that folder/files within the livecode stack? I have a bunch of images I want to use in my stack. Is it better to just create a library of those images rather than putting them in a folder? I can see with a standalone, this might amount to the same thing?

Thanks for any guidance.
-Chuck

Re: referring to folder in standalone

Posted: Thu Oct 09, 2014 4:06 pm
by FourthWorld
See the specialFolderPath function in the dictionary. Also, to help with setting up those paths differently between development and runtime, see the environment function.

Re: referring to folder in standalone

Posted: Thu Oct 09, 2014 5:22 pm
by jmburnod
Hi Chuck,

I use often specialFolderPath("documents") to store files used by stacks.
Sometimes I use path of the folder where the stack or standalone is.
This function return it for stack and standalone in OSX and windows

Code: Select all

function getPathFolder
   put the filename of this stack into P 
   set the itemdel to "/"
   if the environment = "development" then
      delete  item-1 of P
      put p
   else -- It's in a StandAlone mode. 
      if the platform = "MacOS" then 
         deleteĀ  item -4 to -1 of P 
      else 
         delete  item-1 of P 
      end if 
   end if	
      set the itemdel to ","
   return p
end getPathFolder
Best regards
Jean-Marc

Re: referring to folder in standalone

Posted: Thu Oct 09, 2014 6:38 pm
by cwkalish
Thanks very much for the code-- it was the different paths between Windows and Mac standalones that was troubling me.

Re: referring to folder in standalone

Posted: Thu Oct 09, 2014 6:55 pm
by Klaus
Hi Chuck,

if you are "only" using referenced images/media in your stack, simply use RELATIVE pathnames for the filenames of your images and video/audio in the IDE.

Do like this:
1. put the folder(s) with your images/media into the same folder as your stack, the one you make a standalone from.
2. enter something like this for the filenames of your images, I use a folder named "images" in my example:
images/name_of_image.jpg
Know what I mean?

Et voila, this will work on Mac and WIndows, as long as you add this/these folders via the "Copy files" tab in the standalone builder.
LC will put the folders into the right place so the filename(s) will always be correct, no disappeared images :D


Best

Klaus

Re: referring to folder in standalone

Posted: Thu Oct 16, 2014 2:43 pm
by cwkalish
Even better. Thanks.

Just to be clear, I don't need to set any specialfolder or default path?

Re: referring to folder in standalone

Posted: Sun Nov 09, 2014 6:21 pm
by xanant
Hi
about referring to folder in standalone Klaus says:
[indent]" ...Do like this:
1. put the folder(s) with your images/media into the same folder as your stack, the one you make a standalone from.
2. enter something like this for the filenames of your images, I use a folder named "images" in my example:
images/name_of_image.jpg
Know what I mean?

Et voila, this will work on Mac and WIndows, as long as you add this/these folders via the "Copy files" tab in the standalone builder.
LC will put the folders into the right place so the filename(s) will always be correct, no disappeared images :D"[/indent]

I use a folder named "Data" and a .txt file "fileBckpCorsi" so:
Data/fileBckpCorsi.txt
But creating the standalone via the "Copy Files" tab in the builder, suggested by Klaus, it does correctly work in "Windows XP", but NOT in "MacOS 10.6.8". In MacOS-standalone the file named "fileBckpCorsi.txt" in my folder "Data" is not loaded by "openStack" handler while correctly does in Windows. Yes, folder (with its .txt file) is put into the right place by LC (right-click in standalone bundle), but no trace of the text file.
Someone telling me what am I doing wrong?
thanks
xanant

Re: referring to folder in standalone

Posted: Sun Nov 09, 2014 7:25 pm
by Klaus
Hi xanant,

this is supposed to work with images, sound and video files, but obviously not for other files :D
Could you please show us your "openstack" script?


Best

Klaus

Re: referring to folder in standalone

Posted: Mon Nov 10, 2014 3:11 pm
by xanant
Hi Klaus
thanks for replay. This is my handler:
on openStack
-- carica i files registrati all'ultimo utilizzo (load files saved in last backUp)
put URL "file:Data/fileBckpNomeCorsi.txt" into fld "ElencoNomeCorsi" of stack Corsi
put URL "file:Data/fileBckpCorsi.txt" into fld "ElencoCorsi" of stack Corsi
put fld "ElencoNomeCorsi" of stack Corsi into btn "Scegli il Corso..."
end openStack

The idea is to keep data separated from the interface, using the fields only to work or to see the data. I don't want to use custom properties or array neither specialFolder or relative path, so a closeStack save data into the URL and, on next start, the openStack re-load data from the URL. I always use Copy Files tab on Standalone Application Settings. My trouble is that this works correctly in Windows but not in Mac. Folder "Data" with its "text files" is at right location, in bundle (right-click) on Mac and in folder Windows in Win (so also in Linux). I wonder why Mac doesn't see the folder Data and its contents while yes in Windows?
Best regards
xanant

Re: referring to folder in standalone

Posted: Mon Nov 10, 2014 4:44 pm
by Klaus
Hi xanant,

ah, I see!

Problems are:
1. relative filenames obviously only work with images, sound and audio files!
2. "the defaulfolder" is different on Mac and Windows, due to the special folder structure of APPs on Mac!
On WIndows "the defaultfolder" is the one where the EXE resides, on the Mac that is the folder
where the complete APP bundle resides.

Code: Select all

Windows:
Any folder
  Your.Exe
  folderwithmedia

Mac:
Any folder
  Your.app
    Contents
      MacOS
         YOUR (the actual binary app)
         folderwithmedia
On both platform the folder "Any folder" will be "the defaultfolder" when your app starts,
that's why this works on Windows only!

Do something like this, will also work crossplatform:

Code: Select all

on openstack
   put the effective filename of this stakc into tPath
   set itemdel to "/"
   ## Delete the EXE or filename of stack from the path
   delete last item of tPath

   put tPath & "/Data/fileBckpNomeCorsi.txt" tFile1
   put tPath & "/Data/fileBckpCorsi.txt"  into tFile2
  
   ## Now use these 2 pathnames:
   put URL ("file:" & tFile1) into fld "ElencoNomeCorsi" of stack "Corsi"
   etc...

 ## HINT: Unless CORSI is a VARIABLE, please ALWAYS use QUOTES around names/strings/code]
Best

Klaus

Re: referring to folder in standalone

Posted: Mon Nov 10, 2014 7:50 pm
by xanant
Hi Klaus
thank you so much... now it's going well on MacOs and Win!
The distinction is subtle and very useful, indeed crucial.
Thanks also for the Hint about quotes on stack names.. had missed.
Best regards
xanant