Problem with updating HTML files in LiveCode

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

TKYTKY
Posts: 46
Joined: Thu Jul 11, 2013 9:25 am

Problem with updating HTML files in LiveCode

Post by TKYTKY » Thu Nov 21, 2013 4:52 am

Hi,

I have been having problems for the past month with my update button of a certain browser. I have successfully been able to view my browser which is a html file, but when I tried to update within the app, it doesn't do anything with it. I am not sure if my coding has any problems but to no avail, I have not been able to make the update work. This is my coding.

Code: Select all

on touchEnd pId
   mobGUIUntouch the long id of me
   
   # LC5 : new visual effect syntax
   #lock screen for visual effect
   #go card "yourCard"
   #go prev card
   #go next card
   #wait for 0 millisecs with messages
   #unlock screen with visual effect "push left very fast"
end touchEnd


on touchRelease pId
   mobGUIUntouch the long id of me
end touchRelease


on touchStart pId
   mobGUITouch the long id of me
end touchStart


on mouseUp
   
   if the environment = "development" then touchEnd 1
   local tURL, tFile
   
   get url "http://intimes.eu.pn/docupdate.php" 
   put it into field"fieldA"
   replace"[" with "" in field "fieldA"
   replace "]" with "" in field"fieldA"
   
   set itemdelimiter to ","
   put item 1 of field "fieldA" into Pvalue
   put item 2 of field"fieldA" into Cvalue
   get char 2 of Pvalue
   put it into U1
   get char 3 of Cvalue
   put it into U2
   
   put "intimes.eu.pn/doc.php?p=", U2 into updateURL
   replace "," with "" updateURL

   put "Starting.." into field "fldUpdate"
     put "p", U2, ".html" into tFile
     replace "," with "" tFile
     put updateURL into tURL
     put "Updating.." into field "fldUpdate"
     libURLDownloadToFile tURL , ("Content/" & tFile), "Done"
     answer tfile
     wait 3 seconds
     answer tURL
     
     put "Done!" into field "fldUpdate"
     
     answer "Update Complete!"
end mouseUp


on mouseRelease
   if the environment = "development" then touchRelease 1
end mouseRelease


on mouseDown
   if the environment = "development" then touchStart 1
end mouseDown
This is my final year project and it's going to be due soon. Please help me! Thanks!

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Problem with updating HTML files in LiveCode

Post by Jellicle » Thu Nov 21, 2013 6:19 am

Your code confused me and is somewhat inefficient e.g. what is U1 for? Why are you putting text into fields and not variables?

I've re-written it the way I would do it (but I've left in the things that confuse me :). This works in the IDE - not tried it on mobile.

Not sure why you were downloading the file - it's text so why not just grab it and write it to a new file in your target directory on the device? BTW you must create your directories in the Documents folder - you'll see I've set the correct path for that in the writehtmlfile handler.

Hope this helps.

Code: Select all

on writehtmlfile fileTowrite,dataTowrite
   set the defaultFolder to (specialFolderPath("Documents") &"/Content")
   put dataTowrite into URL (("file:"&fileTowrite&".html"))
end writehtmlfile

on mouseUp
     local tURL, tFile
     get url "http://intimes.eu.pn/docupdate.php" 
     put it into field 1
     replace"[" with "" in field 1
     replace "]" with "" in field 1
     set itemdelimiter to ","
     put item 1 of field 1 into Pvalue
     put item 2 of field 1 into Cvalue
     get char 2 of Pvalue
     put it into U1
     get char 3 of Cvalue
     put it into U2
  put "p" & U2  into tFile
   replace "," with "" in tFile
  put "http://intimes.eu.pn/doc.php?p=" & U2 into updateURL
  put url updateURL into theHtml
  writehtmlfile tFile,theHtml
end mouseUp

Good luck!


Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

TKYTKY
Posts: 46
Joined: Thu Jul 11, 2013 9:25 am

Re: Problem with updating HTML files in LiveCode

Post by TKYTKY » Fri Nov 22, 2013 2:42 am

I changed the codes and it still doesn't update the html file. Also, it changes the label of my navigation bar to the url of "http://intimes.eu.pn/docupdate.php".
Attachments
Screen Shot 2013-11-22 at 9.53.34 AM.png
Interface of the browser.

TKYTKY
Posts: 46
Joined: Thu Jul 11, 2013 9:25 am

Re: Problem with updating HTML files in LiveCode

Post by TKYTKY » Fri Nov 22, 2013 2:58 am

My fieldA is invisible in the same card to read the data and get the numbers.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Problem with updating HTML files in LiveCode

Post by Jellicle » Fri Nov 22, 2013 4:52 am

I can't help you with MobGUI problems, sorry. I only looked at getting the html. I've attached the stack I made. I've tested it in the iOS simulator.

Gerry
Attachments
Untitled 1.livecode.zip
(1.84 KiB) Downloaded 291 times
14" MacBook Pro
Former LiveCode developer.
Now recovering.

TKYTKY
Posts: 46
Joined: Thu Jul 11, 2013 9:25 am

Re: Problem with updating HTML files in LiveCode

Post by TKYTKY » Thu Nov 28, 2013 2:50 am

I have tried your way, but it doesn't replace the old html file to the new one. is it possible to replace the file? :/

Thanks!
Attachments
Screen Shot 2013-11-28 at 10.01.03 AM.png
This is the file name in the "Copy files" place.
Screen Shot 2013-11-28 at 10.02.36 AM.png
This is what is in the folder of "Content" file. I want to replace the "p7.html" file to what is in the link.

TKYTKY
Posts: 46
Joined: Thu Jul 11, 2013 9:25 am

Re: Problem with updating HTML files in LiveCode

Post by TKYTKY » Thu Nov 28, 2013 8:23 am

can anyone help me please? Am a little urgent ><

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Problem with updating HTML files in LiveCode

Post by Jellicle » Thu Nov 28, 2013 8:32 am

You are trying to replace a file that is bundled in the app? Why didn't you say before? That is NOT possible - Apple does not allow apps to be modified while they are running. But if your copy all those files to the Documents folder the first time your app runs then my solution will work. The Documents folder is created outside the app bundle.

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

TKYTKY
Posts: 46
Joined: Thu Jul 11, 2013 9:25 am

Re: Problem with updating HTML files in LiveCode

Post by TKYTKY » Thu Nov 28, 2013 12:43 pm

How do I copy these files to the documents folder first? I really need to update the html files when needed. only those that are for e.g "p7.html","p1.html", which means only the number would be changing only. Thank you so much for helping me.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Problem with updating HTML files in LiveCode

Post by Jellicle » Thu Nov 28, 2013 2:11 pm

TKYTKY wrote:How do I copy these files to the documents folder first? I really need to update the html files when needed. only those that are for e.g "p7.html","p1.html", which means only the number would be changing only. Thank you so much for helping me.
It's very late here. I'll post an example script in the morning.

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

TKYTKY
Posts: 46
Joined: Thu Jul 11, 2013 9:25 am

Re: Problem with updating HTML files in LiveCode

Post by TKYTKY » Thu Nov 28, 2013 10:24 pm

Thank you so much for your help! Really thank you!

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Problem with updating HTML files in LiveCode

Post by Jellicle » Thu Nov 28, 2013 10:28 pm

TKYTKY wrote:How do I copy these files to the documents folder first? I really need to update the html files when needed. only those that are for e.g "p7.html","p1.html", which means only the number would be changing only. Thank you so much for helping me.
For each file do this the FIRST time your app opens on the device:

Code: Select all

on openstack
    if there is not a file (specialFolderPath("Documents") & "/Contents/index.html")  then -- no files installed yet, so copy them from the engine
    
-- html files
    put (specialFolderPath("engine") & "/Content/p1.html") into filePath
    put url ("binfile:" & filePath) into destFilePath
    put destFilePath into url ("binfile:"& (specialFolderPath("Documents") & "/Content/p1.html"))  

    put (specialFolderPath("engine") & "/Content/p2.html") into filePath
    put url ("binfile:" & filePath) into destFilePath
    put destFilePath into url ("binfile:"& (specialFolderPath("Documents") & "/Content/p2.html"))  

-- image files
    put (specialFolderPath("engine") & "Content/images/image1.jpg") into filePath
    put url ("binfile:" & filePath) into destFilePath
    put destFilePath into url ("binfile:"& (specialFolderPath("Documents") & "Content/images/image1.jpg"))  

  end if

end openstack
Do that for each file. This is a brute force method - you could also use a repeat loop for the p*.html files.

Good luck.

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

TKYTKY
Posts: 46
Joined: Thu Jul 11, 2013 9:25 am

Re: Problem with updating HTML files in LiveCode

Post by TKYTKY » Fri Nov 29, 2013 2:12 am

Hmm, I dun get it. Do I need to get the app on my phone to test it? Or it should work fine on the simulator? I can't get it replaced after putting that script on the card.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Problem with updating HTML files in LiveCode

Post by Jellicle » Fri Nov 29, 2013 2:35 am

TKYTKY wrote:Hmm, I dun get it. Do I need to get the app on my phone to test it? Or it should work fine on the simulator? I can't get it replaced after putting that script on the card.
That will work on the simulator too. It'll copy the files to the Documents folder on the simulator. if you reset the simulator of course they will be deleted and next time to install the app on the simulator it'll create the files and folders again, using the original files.

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

TKYTKY
Posts: 46
Joined: Thu Jul 11, 2013 9:25 am

Re: Problem with updating HTML files in LiveCode

Post by TKYTKY » Fri Nov 29, 2013 2:59 am

I tried doing it but it doesn't update/replace the file still. What might be the problem still? :O

Post Reply