One Use Only Files

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am
Location: Australia

Re: One Use Only Files

Post by bidgeeman » Sun Aug 20, 2017 1:20 am

Hi again.[SOLVED] Reinstalled LC 9 and it works fine.
Just trying to implement the "set script" code and LC is being extremely laggy? Has anyone else experienced this?
It takes about 10 seconds to do anything then notifies that the script has to be reloaded but it seems to completely
slow everything down?
Bidge

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2029
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: One Use Only Files

Post by [-hh] » Sun Aug 20, 2017 10:22 pm

You could try:

Code: Select all

lock screen; lock messages
And begore that try to comment out the set-script-lines. I can't really believe this should be the culprit.
shiftLock happens

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am
Location: Australia

Re: One Use Only Files

Post by bidgeeman » Mon Aug 21, 2017 12:26 am

Hi [-hh]
Thanks again for the help :) Just about to start into it for the day.

Bidge

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am
Location: Australia

Re: One Use Only Files

Post by bidgeeman » Mon Aug 21, 2017 7:42 am

I am having problems browsing a file folder of images I have set up on the internet.
Just getting a bunch of html gobbledygook and the .png files at the botton withing the
html container. I've not had any experience with opening files from the internet with LC
so I am probably doing something wrong as this is working perfectly from the computer.

"put tFolder" is where i get the html

Code: Select all

on mouseUp
   lock screen	
   global gFileList  
   local tFolder
   put "" into gFileList
   put url "http://www.bidgeposter.com/ThumbTest/" into tFolder
   put tFolder
   put the files into tFileList
   repeat for each item i in ".png,.jpg"
      put tFileList into temp
      filter temp with ("*"&i)
      repeat for each line l in temp
         put tFolder & slash & l & cr after gFileList -- add to global	
      end repeat
   end repeat
   if gFileList = "" then -- no images
      answer "No images found in this folder."
   end if


  put empty into field "Field"
   set the text of field "Field" to gFileList
   put the number of lines in field "Field" into tImages
   if there is a group "CCTVObject" then delete group "CCTVObject"
   create group "CCTVObject"
   put empty into group "CCTVObject"
   set the opaque of group "CCTVObject" to true
   set the showBorder of group "CCTVObject" to true
   repeat with x=1 to tImages
      copy image "back" to group "CCTVObject" 
      set the name of the last image to ("back" & x)
      add 60 to y 
      set the location of image ("back" & x) to 122,y        
   end repeat
   set the borderWidth of group "CCTVObject" to 3
   set the vScrollbar of group "CCTVObject" to true
   set the threeD of group "CCTVObject" to true
   set the scrollbarWidth of group "CCTVObject" to 12
   set the backgroundColor of group "CCTVObject" to black
   set the loc of group "CCTVObject" to 369, 352
   set the height of group "CCTVObject" to 446
   set the width of group "CCTVObject" to 90
   unlock screen

end mouseUp
Even if I try to browse the folder with a button I get this:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Index of /ThumbTest</title>
 </head>
 <body>
<h1>Index of /ThumbTest</h1>
<ul><li><a href="/"> Parent Directory</a></li>
<li><a href="Image1.png"> Image1.png</a></li>
<li><a href="Image2.png"> Image2.png</a></li>
<li><a href="Image3.png"> Image3.png</a></li>
<li><a href="Image4.png"> Image4.png</a></li>
<li><a href="Image5.png"> Image5.png</a></li>
</ul>
</body></html>
EDIT: Oh...and yes klaus...I even tried binfile :)
Thanks again
Bidge

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

Re: One Use Only Files

Post by Klaus » Mon Aug 21, 2017 11:10 am

Hi David,

a couple of things...

1. the correct syntax for getting all files in a folder is:
...
set the directory to "path/to/folder"
put the files into tFiles
...
## Or in newer versions of LC:
put files("path/to/folder") into tFiles
...

2. That does not work over the internet with folders on a server!

3. This:
...
put url "http://www.bidgeposter.com/ThumbTest/" into tFolder
...
will return:
a. the content of the file "index.htm" or "index.lc" or whatever should be the start page for that internet address, if any.
Just as if you had entered this into your browsers address field!
b. If there is no INDEX in that folder, then, depending on the settings of the server, you will get a HTML formatted list of files in that folder, as you have experienced.
c. Or nothing, if the server is not set set this way.

You will need a PHP or LC script which will return a list of files in a folder, like this one.
Put it into any folder on the server and it will return all files in that folder:

Code: Select all

<?php
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>
Name it "filelisting.php" and then you can:
...
put url "http://www.bidgeposter.com/ThumbTest/filelisting.php" into tFilesOnServer
...


Best

Klaus

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am
Location: Australia

Re: One Use Only Files

Post by bidgeeman » Mon Aug 21, 2017 11:24 am

Klaus.
Thank you so much. I was in the process of writing html filtering scripts
and it has been giving me a headache. Your help is very much appreciated.
I had no idea it could be that complicated. It worked perfectly except it also
returned the "tFilesOnServer.php" file that was in the directory :)
(I can filter that one out with script;)
Again, thank you so much Klaus.
Bidge

bogs
Posts: 3467
Joined: Sat Feb 25, 2017 10:45 pm

Re: One Use Only Files

Post by bogs » Mon Aug 21, 2017 2:01 pm

You may also want to watch out for things like this in your coding adventures, unlike the line in your repeat structure further down, what is tFolder being "put" into?
bidgeeman wrote: ...
put url "http://www.bidgeposter.com/ThumbTest/" into tFolder
put tFolder
With no container statement, it probably only introduces ambiguity. It could also end the world in 5, 3, 8..., well, we don't know! Computers iz stoopid like you wouldn't believe, instructions need to be given to them as if they were given to a young child with no experiences in life yet, specify everything.

Something else you want to pay attention to is naming controls. You never ever not EVAH want to use the default names given, as is the case later in your code:

Code: Select all

put empty into field "Field"
Name things so that they have meaning if at all possible for the use they are being put to, for example

Code: Select all

field "fileList"
if you are using the field to list files. You will find this far more meaningful and useful later when you are staring at a list of fields or buttons or whatnot named "object 1, object 2, object 3..." etc. and have to click on each one to find out what you thought it should be doing when you placed or created it.

Don't sweat the small mistakes, someone once told me, but do try to not repeat them over and over :lol:
{btw, happens to me all the time :roll: }
Image

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am
Location: Australia

Re: One Use Only Files

Post by bidgeeman » Mon Aug 21, 2017 2:25 pm

Thank you so much guys.
bogs:
My naming skills leave a lot to be desired and I really appreciate the pointers.
I think I used "put tFolder" to see what was being written to that file.
(Arrrrg!!!...my end of the world variable has been discovered)
field "Field" is just being used for my experimentation. Probably not a good idea
to post such bad code here in case someone like me are looking for samples and
answers :(
I'll be more careful next time.

Bidge

bogs
Posts: 3467
Joined: Sat Feb 25, 2017 10:45 pm

Re: One Use Only Files

Post by bogs » Mon Aug 21, 2017 2:49 pm

bogs wrote:...etc. and have to click on each one to find out what you thought it should be doing when you placed or created it.
bidgeeman wrote:I think I used "put tFolder" to see what was being written to that file.
OH NOES, it started already :D :D :D
bidgeeman wrote:My naming skills leave a lot to be desired...
If your the only maintainer, naming skill only has to be good enough for you to remember. Just wait till you start reviewing someone else's code < shuddering...>
bidgeeman wrote:(Arrrrg!!!...my end of the world variable has been discovered)
Interestingly enough, "put x" *does* serve a great purpose in the messagebox, for instance "put the colorNames" works quite nicely in there, where you are only dealing with a few lines of code. Learn to use and love the messagebox, it would be the ideal place to put your end of the world variables :D

It is in the editor where just sticking it in randomly can cause you problems down the road when you think your program is finished, people start using it, you forgot it was in there, and get flooded with "WHY THE #@%$ IS THIS %$#@ BOX POPPING UP!!!!!!!!" :evil: emails :P

As for the field "Field", everyone throws together demos for something that are quick and dirty, just beware of falling into the habit of letting it slide into your work. As someone starting out, you just want to make sure it doesn't become a habit that is terrible hard to break later on.
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5024
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: One Use Only Files

Post by jacque » Mon Aug 21, 2017 5:05 pm

bidgeeman wrote:Klaus.
Thank you so much. I was in the process of writing html filtering scripts
and it has been giving me a headache.
Just for future reference, here's a quick way to strip html tags from text:

Code: Select all

set the htmltext of the templateField to tRawData 
put the text of the templateField into tText
It works most of the time.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

MaxV
Posts: 1574
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: One Use Only Files

Post by MaxV » Mon Aug 21, 2017 5:14 pm

bidgeeman wrote:Hi Klaus. Edit[SOLVED]
I'm tossing around multiple ideas for protecting my images. I have a poster designer and have a library of backgrounds that can be used to assemble a simple poster design with a bit of text and an imported photo. I have had already an experience of being pirated from a small shop where I sell a few bits and pieces of artwork. That system allows anyone to buy the actual design and download it. I'm sure you can imagine how it might feel to suddenly find someone is selling your work. (being a muso ;)

I would like to try and protect my images this time around but at the same time allow people to print out their customized versions of the poster. I've seen server hosted images that only allow images to stream but that means I would have to build an entire browser in my app so people can see what images are there. I'm not sure how to go about this but it seems like it could be a good solution. Also not sure what problems this might present, ie, people being offline, the amount of time it takes to download images to a gallery etc. Just after some advice from the experts on the forum like yourself.

Hope that helps explain.
Bidge
A very common solution used for printing picture softwares is to store image in a database. Only who has the database credentials can load images in your livecode software, no way to download in any way.
The (livecode) software load the image at low resolutions (adding your logo, etc.), user can modify it. Then he pays you, and you give the ok to print at full resolution, without logo, etc.
No browser, just livecode image control(s) and database connection.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5024
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: One Use Only Files

Post by jacque » Mon Aug 21, 2017 5:18 pm

Interestingly enough, "put x" *does* serve a great purpose in the messagebox
Using "put" without a destination is supported syntax. In the IDE, the content goes to the message box. On mobile it goes to stdout where it can be picked up by a terminal for debugging. In LC server scripts, content goes to the browser window, or is returned to the caller if it's a response to a POST or GET request.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 3467
Joined: Sat Feb 25, 2017 10:45 pm

Re: One Use Only Files

Post by bogs » Mon Aug 21, 2017 8:40 pm

jacque wrote:Using "put" without a destination is supported syntax. In the IDE, the content goes to the message box. On mobile it goes to stdout where it can be picked up by a terminal for debugging. In LC server scripts, content goes to the browser window, or is returned to the caller if it's a response to a POST or GET request.
Oh that is just awesome to know, I was under the impression the only place to use it without a container was in the message box.

See Bidge? If you can somehow write the program that taps this lass's brain, you'll be in clover :)

I still somehow feel that if your end user see's popups where one isn't expected, though, your going to get mail, so strip em out when done (unless they are part of the plan as Jacque outlined) :D
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5024
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: One Use Only Files

Post by jacque » Mon Aug 21, 2017 10:37 pm

bogs wrote:I still somehow feel that if your end user see's popups where one isn't expected, though, your going to get mail, so strip em out when done (unless they are part of the plan as Jacque outlined) :D
That's certainly true if users are running your stack in the IDE. Someone wrote a script once to search for all empty "puts" so you could find and remove them as needed. That was a long time ago though and I don't have a reference.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am
Location: Australia

Re: One Use Only Files

Post by bidgeeman » Tue Aug 22, 2017 12:13 am

MaxV wrote:
The (livecode) software load the image at low resolutions (adding your logo, etc.), user can modify it. Then he pays you, and you give the ok to print at full resolution, without logo, etc.
I*s there a way to control the resolution of an image or are you referring to loading a low res/snapshot copy of an image?
Not come across resolution controls in LC yet but it sounds very interesting. I have noticed that when you resize and image then export a snapshot, the image maintains the resolution of the resized version. Maybe that's what you were referring to? Resize then export snapshot? Aside from that,
dealing with a database is a bit out of my league at the moment unfortunately :(

Regards
Bidge

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”