• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

'Check for Updates' Script

Scheduled Pinned Locked Moved Developers' Forum
15 Posts 8 Posters 1.1k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    JonD
    last edited by 2 Nov 2010, 21:46

    Has anyone had any luck making a script that automatically updates. I would like to somehow check the script version against my website and offer to download an update if one exists. My initial thought was to have a text file on the website that contains a version number. The script would check the version number in the text file when it loads (if online) and then prompt the user to download the updated files directly into the plugins folder. I am sure it is not as easy I am making it sound...

    Has anyone tried this? If so, please share!

    Thanks,
    Jon

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 2 Nov 2010, 22:04

      None in existence so far.
      But I've started to sketch out a system.

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • H Offline
        honoluludesktop
        last edited by 3 Nov 2010, 00:33

        JonD, Not automatic, but look at Dxf_In . If you do, select a file to open, then select Help Options. It links to the "Su plugin topic".

        1 Reply Last reply Reply Quote 0
        • C Offline
          Chris Fullmer
          last edited by 3 Nov 2010, 01:26

          smustard offers it. Its part of the smustard toolbar. You can download that script and look at it I think. But I think there might be more happening on the back end than in that script. But it might be worth looking at.

          Chris

          Lately you've been tan, suspicious for the winter.
          All my Plugins I've written

          1 Reply Last reply Reply Quote 0
          • D Offline
            Dan Rathbun
            last edited by 3 Nov 2010, 11:41

            My preference is either RubyGems, or RVM (for OSX,) and pik (for Win32.)

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • J Offline
              JonD
              last edited by 3 Nov 2010, 15:49

              Thanks all, I have check these out and post what I come up with.

              Jon

              1 Reply Last reply Reply Quote 0
              • W Offline
                Whaat
                last edited by 5 Nov 2010, 04:13

                @jond said:

                Has anyone had any luck making a script that automatically updates. I would like to somehow check the script version against my website and offer to download an update if one exists. My initial thought was to have a text file on the website that contains a version number. The script would check the version number in the text file when it loads (if online) and then prompt the user to download the updated files directly into the plugins folder. I am sure it is not as easy I am making it sound...

                Has anyone tried this? If so, please share!

                Thanks,
                Jon

                Yes, I've done exactly this in SkIndigo and it seems to work well.

                @mat_editor.add_action_callback("check_current_version") {|d,p|
                		version=p.to_s
                		current=SkIndigo;;VERSION.to_s
                		if version>current
                			text="A newer version of SkIndigo is available. Would you like to update?  (Click 'No' to be reminded in two weeks.)"
                			result=UI.messagebox(text,MB_YESNO)
                			if result==6 #yes
                				UI.openURL("http://www.indigorenderer.com/documentation/sketchup")
                			else
                				time=Time.now.to_i
                				Sketchup.write_default("SkIndigo","LastUpdateCheck",time)
                			end
                		end
                	}
                
                def check_for_updates()
                
                last_update_check=Sketchup.read_default("SkIndigo","LastUpdateCheck",0)
                current_time=Time.now.to_i
                update_check_period=1209600
                
                if current_time-last_update_check>update_check_period  #check for updates every 2 weeks
                	@mat_editor.execute_script("check_current_version();")
                end
                
                end
                

                Javascript in the webdialog initiates in the version check using jquery:

                function check_current_version() {
                	$.get("http://www.indigorenderer.com/dist/exporters/skindigo/skindigo_current_version.txt", function(data){
                		window.location='skp;check_current_version@'+data;
                	});
                	
                }
                

                SketchUp Plugins for Professionals

                1 Reply Last reply Reply Quote 0
                • J Offline
                  JonD
                  last edited by 6 Nov 2010, 13:02

                  That is perfect! Thanks for the post.

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    JonD
                    last edited by 12 Nov 2010, 22:38

                    Thanks for the direction. Here is how I ended up doing it - very close to Whaat's method. The main difference is I am loading a very small page in the web dialog, not getting the contents of the text file. I had trouble getting the $.get method to work...javascript newbie, I am...

                    This is the code in the ruby script. I basically open the webdialog during the startup of Sketchup. The web page loaded in the dialog (from my server) just returns the current build code. I had to add the UI.start_timer to pause a second to let the javascript happen, then close the web dialog

                    
                    	current = $current.to_s
                    	if Sketchup.is_online
                    		ssupdate = UI;;WebDialog.new("Check for Updates", false, "Check for Updates", 200, 200, 200, 200, true)
                    		ssupdate.add_action_callback("check_current_version") {|d,p|
                    			version=p.to_s
                    			
                    			if version>current
                    				text="A newer version of Lakefront Layout is available. Would you like to update?"
                    				result=UI.messagebox(text,MB_YESNO)
                    				if result==6 #yes
                    					UI.openURL("http://www.shorestation.com/")
                    				end
                    			end
                    		}
                    		ssupdate.set_url("http://www.shorestation.com/IPADock/Sketchup/checkupdate.html")
                    		ssupdate.show
                    		
                    		id = UI.start_timer(1, false){ssupdate.close}
                    	end#if
                    
                    
                    

                    Here is the html file I have on y website:

                    the 20111112 is the date code of the latest build. This is what I edit when I want to push a new update.

                    
                    <html>
                    <script>
                    function check_current_version() {
                    	
                    	window.location='skp;check_current_version@'+20101112;
                       
                    }
                    window.onload = check_current_version()
                    </script>
                    <body>
                    </body>
                    </html>
                    
                    
                    

                    I am sure this is not the greatest approach, but it is working. Again, thanks for the help -great forum!

                    Jon

                    1 Reply Last reply Reply Quote 0
                    • fredo6F Offline
                      fredo6
                      last edited by 13 Nov 2010, 15:20

                      Jon,

                      It is relatively easy to perform the check of whether the version on the web (and then comare with the one currently installed locally).

                      The real difficulty is to download the file and install it when it is in binary format (for instance a Zip file). It is possible for a .rb file which is plain text however.

                      Fredo

                      PS: I would use Whaat's method, which is to check periodically, even letting the user set the next date. If all scripts do their check at each SU statup, then it would take too long.

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        thomthom
                        last edited by 13 Nov 2010, 16:41

                        @unknownuser said:

                        If all scripts do their check at each SU statup, then it would take too long.

                        A menu to trigger the check would also work. Or a button if the plugins preference/option dialog if it has one.

                        Thomas Thomassen — SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 Reply Last reply Reply Quote 0
                        • J Offline
                          Jim
                          last edited by 13 Nov 2010, 17:04

                          If you all agree on an API, there could be a single "Update All Plugins" option.

                          Hi

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            thomthom
                            last edited by 13 Nov 2010, 18:29

                            @jim said:

                            If you all agree on an API, there could be a single "Update All Plugins" option.

                            I got some notes done for this...

                            Thomas Thomassen — SketchUp Monkey & Coding addict
                            List of my plugins and link to the CookieWare fund

                            1 Reply Last reply Reply Quote 0
                            • fredo6F Offline
                              fredo6
                              last edited by 13 Nov 2010, 22:57

                              Here is what I would propose, and which I will do for my own scripts whenever I have time.

                              1. I will Build a module CheckForUpdate
                                It will take care of displaying a window showing the status of plugins.

                              2. A plugin can register to CheckForUpdateby just invoking the following (for instance in its startup section)

                              
                              CheckForUpdate.register(plugin_name, url) { |text| my_own_check(text) } if defined?(CheckForUpdate)
                              
                              

                              where

                              • plugin_name is the unique name of the plugin
                              • url is the address of the page where the plugin is available for download (for instance Sketchucation, which keeps the page url quite stable)
                              • the dynamic method will receive the whole HTML page as a string (argument text) and will be responsible for parsing it the way it likes, and return three information as [outdated, new_version, url_details].
                                • outdated is true if the plugin is not up to date
                                • new_version is a text to be displayed, encoding the new version and date (and whatever additional comment)
                                • url_details is simply a url where the detail of the updated version can be displayed. If nil, then url is used instead.

                              In the case of my plugins, I will probably use the title of the first post to be parsed: like [Plugin] FredoScale 2.0i - 26 Nov 09.

                              This API is neutral as it does not make any hypothesis on how the version and dates are coded in the HTML page or text file pointed to by the URL.

                              Note that the above is only for check for update. Downloading and installing the plugin is another story.

                              By the way, at Sketchucation, we can probably optimize the process by having a special private page, which is refreshed by a robot every night, where the header of the first post {plugin xxx] are collected 'a little bit like Jim's page on plugin). The benefit is that there is a single url for all pulgins published at Skecthucation, and the url fetching is done once.

                              Fredo

                              1 Reply Last reply Reply Quote 0
                              • J Offline
                                JonD
                                last edited by 16 Nov 2010, 03:36

                                @unknownuser said:

                                Jon,

                                It is relatively easy to perform the check of whether the version on the web (and then comare with the one currently installed locally).

                                The real difficulty is to download the file and install it when it is in binary format (for instance a Zip file). It is possible for a .rb file which is plain text however.

                                Fredo

                                PS: I would use Whaat's method, which is to check periodically, even letting the user set the next date. If all scripts do their check at each SU statup, then it would take too long.

                                You are right on with the downloading difficulty. I originally wanted to have each 'dependent' represented in the version string so I could only download the file that needed updating. Unfortunately, I could not find a clean way to initiate a download of a .rb or .rbs file into the plugins directory. I have resorted to having the link point directly to a download of an installer (.exe) and the installer is handling the file moves to the plugins folder. It is an acceptable solution for me.

                                I have changed my script so that the update is user initiated through the plugin commands. Again, thanks to all for the help.

                                Jon

                                1 Reply Last reply Reply Quote 0
                                • 1 / 1
                                1 / 1
                                • First post
                                  2/15
                                  Last post
                                Buy SketchPlus
                                Buy SUbD
                                Buy WrapR
                                Buy eBook
                                Buy Modelur
                                Buy Vertex Tools
                                Buy SketchCuisine
                                Buy FormFonts

                                Advertisement