 
                
                122 posts
                
                    
                        Location
                        gps.locate()
                    
                
             
            
                Posted 25 July 2015 - 02:57 PM
                Hi,
So I have posted my Improved Turtle API but loads of people are complaining why I am not using Pastebin.
Then, someone said, why don't I just create an auto-updater? So I set to work but I am stuck at the thinking process.
Everyone I normally get help from is currently offline (at the time of posting) so I came here.
So, as you have probably gathered, my question is : how do I create an auto-updater for Pastebin?
I already have the version file uploaded to pastebin and the turtle API (not ready for download as of yet).
Any help will be appreciated,
ZiR
                
             
         
        
        
            
            
                
                     
                
                17 posts
                
                    
                        Location
                        Germany
                    
                
             
            
                Posted 25 July 2015 - 03:07 PM
                Maybe you also have a pastebin in which you increase a number every time you update your code and you let your program download it and if the number in this file is higher your program knows it should download your program again so it is a newer version.
Sorry for my English ;-)
ROB
                
             
         
        
        
            
            
                
                     
                
                1426 posts
                
                    
                        Location
                        Does anyone put something serious here?
                    
                
             
            
                Posted 25 July 2015 - 03:07 PM
                Don't. That would be my simple answer. If people want to update they will - and you can provide the utilities to do that. However checking and automatically fetching updates is pain in the neck for both developer and user - if a program takes several seconds to load because it needs to access a remote server then they'll just remove the update part.
I'm going to presume you have a pastebin account - that means you can preserve the same pastebin ID every time. Then you can fetch the paste every time you load the program, and if you cannot find it then just load a cached version. Alternatively you could have a separate paste containing the latest version number and, if it doesn't match the current version number, update.
local update = http.get("http://pastebin.com/raw.php?i=<version_paste_id>")
if update and update.readAll() ~= "<current_version>" then
  update.close()
  shell.run("pastebin get <paste_id> turtleAPI")
end
Edited on 03 August 2015 - 06:11 AM
                
             
         
        
        
            
            
                
                     
                
                122 posts
                
                    
                        Location
                        gps.locate()
                    
                
             
            
                Posted 25 July 2015 - 03:10 PM
                Thank you both for your very quick responses.
I am going to go with SquidDev's response because it is something I do with all my programs, but evidently not this one ^_^/>
Again, thank you both for your responses.
ZiR
                
             
         
        
        
            
            
                
                     
                
                957 posts
                
                    
                        Location
                        Web Development
                    
                
             
            
                Posted 25 July 2015 - 03:26 PM
                
  shell.execute("pastebin get <paste_id> turtleAPI")
You mean 'shell.run'?
 
         
        
        
            
            
                
                     
                
                1426 posts
                
                    
                        Location
                        Does anyone put something serious here?
                    
                
             
            
                Posted 25 July 2015 - 03:28 PM
                
if fs.exists("/apis/turtle") then
  fs.delete("/apis/turtle")
end
shell.run("pastebin get w7DnM2Rt /apis/turtle")
os.loadAPI("/apis/turtle")
One thing I would do which I should have mentioned is not delete the file until you know you can get it:
local response = http and http.get("http://pastebin.com/raw.php?i=w7DnM2Rt")
if response then
  local handle = fs.open("turtleAPI", "w")
  handle.write(response.readAll())
  handle.close()
  response.close()
end
Otherwise if HTTP is disabled or pastebin is down, turtles aren't left disabled. :)/>
You mean 'shell.run'?
That is what I wrote. Totally. (I was probably thinking os.execute() from vanilla Lua - sorry).
Edited on 25 July 2015 - 01:29 PM
                
             
         
        
        
            
            
                
                     
                
                122 posts
                
                    
                        Location
                        gps.locate()
                    
                
             
            
                Posted 25 July 2015 - 04:24 PM
                
if fs.exists("/apis/turtle") then
  fs.delete("/apis/turtle")
end
shell.run("pastebin get w7DnM2Rt /apis/turtle")
os.loadAPI("/apis/turtle")
One thing I would do which I should have mentioned is not delete the file until you know you can get it:
local response = http and http.get("http://pastebin.com/raw.php?i=w7DnM2Rt")
if response then
  local handle = fs.open("turtleAPI", "w")
  handle.write(response.readAll())
  handle.close()
  response.close()
end
Otherwise if HTTP is disabled or pastebin is down, turtles aren't left disabled. :)/>
You mean 'shell.run'?
That is what I wrote. Totally. (I was probably thinking os.execute() from vanilla Lua - sorry).
I will change it now :D/> Thanks for reminding me!!
ZiR
EDIT: Changed the script to allow checking for errors ^_^/>. Thank you SquidDev :D/>
Edited on 25 July 2015 - 02:30 PM
                
             
         
        
        
            
            
                
                     
                
                81 posts
                
             
            
                Posted 26 July 2015 - 12:24 AM
                I believe it had been already mentioned in passing in your API thread, but rather than try to put your a uff on pastebin and then make an installer it was suggested that you simply have the installer on pastebin install the installer you already use. The complaint was not that the API itself was nice t in pastebin, but rather that it was complex to install, compared to pastebin run code