sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Cleanup Old Plugin Versions?

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 5 Posters 619 Views 5 Watching
    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
      Jim
      last edited by

      What's a good strategy to automatically cleanup old versions of a plugin when a new version has been installed?

      I am going to try to cleanup my plugins and consolidate them into a single folder rather than have them all directly in the Plugins folder. This would mean renaming or deleting many of the old files. I plan on converting them all to .rbz archives to ease installation and upgrades.

      Is it OK to just delete the old files?

      Hi

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        I have done that with a number of my tools.
        Let's say I had an old version named xxxx.rb previously auto-loading from within the Plugins folder, but my new equivalent file [perhaps with the same name] is now installed inside its own tool's subfolder and loaded by some new xxxx_loader.rb script that is installed in Plugins, that does auto-load.
        I don't want the old version of the file to auto-load because it might break/overwrite the new files functions or add outdated methods etc.
        Although I can tell users to remove this old version, some users just won't !
        So I need to auto-run some code in the 'loader' script to find the old file, and if it exists delete it. My tool then pops up a UI.dialog saying what it's deleted the old file. This only happens once because the next time it loads it doesn't find anything to delete... After a while the 'find/deletion code' could perhaps be commented out of any newer versions of the loader as most users will have updated previously...

        Incidentally, there are sometimes problems when a user messes up an install and manually moves a tool's .rb files from the tool's subfolder into the Plugins folder, which then auto-load incorrectly at startup...
        I was wondering if naming all of the script files with a tool's subfolder, as say ' xxxx.rb**~**', would be a better protocol; they won't auto-load when misplaced bay a kack-handed newbie, and if in the wrong folder they can be more readily found in the Plugins folder by sorting a listing by type, and they can still be required or loaded etc from another scripts, by using their subfolder in the path.
        I suggest .rb**~** because I already rename files within my Plugins folder as .rb**!** to stop then auto-loading; and using .txt or other common 'extnames' would preclude a simple finding of misplaced files 'by type'...

        TIG

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          I am not sure about using a tilde character is wise. Windows uses it for contracted directory names, and Unix-like systems use it for a contracted HOME path.

          Another unique character that is valid on both systems ?

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            I only plan on distributing and supporting .rbz archives, in which case botched installs should not be a problem.

            Hi

            1 Reply Last reply Reply Quote 0
            • K Offline
              ktkoh
              last edited by

              I was looking at releasing a new version of my plugin comp2layerScene with new features and considering to make the dir and file names compatible with the SU Warehouse specifications. Thus I would need the new version to delete the old version.
              Could you show a sample code used to delete/clean up old files & dir? as I am not sure how to do this.

              Thanks Keith

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                @ktkoh said:

                I was looking at releasing a new version of my plugin comp2layerScene with new features and considering to make the dir and file names compatible with the SU Warehouse specifications. Thus I would need the new version to delete the old version.
                Could you show a sample code used to delete/clean up old files & dir? as I am not sure how to do this.

                Thanks Keith
                You don't need to do that as the [reworded] loader can remain as 'K2WS_Comp2LayerScene_ext.rb' [overwriting the old version] and its new subfolder [now referred to i it's code] should be 'K2WS_Comp2LayerScene_ext'.

                The old 'K2WS' subfolder becomes redundant / unused by the new loader.

                If you really want to tidy up...
                To remove an entire folder you need to first delete is contents...
                FileUtils can do that for you BUT it is unlikely to be installed for every user...
                So you probably need to add an extra rb file into your new subfolder, which then auto-runs from the ext-loader...
                Add this just below the other 'require' lines in the Plugins folder's 'ext-loader' K2WS_Comp2LayerScene_ext.rb...
                require(File.join(File.dirname(__FILE__), 'K2WS_Comp2LayerScene_ext', 'deleteK2WS.rb'))
                Then deleteK2WS.rb contains this code:

                module K2WS
                 def self.delete_folder(d)
                  return nil unless File.directory?(d)
                  Dir.entries(d).each{|f|
                    next if f=='.' || f=='..'
                    x=File.join(d, f)
                    if File.directory?(x)
                      self.delete_folder(x)
                    else ### file
                      File.delete(x)
                    end
                  }
                  begin
                    Dir.delete(d)
                  rescue ### fails if it's not empty!
                    self.delete_folder(d)
                  end
                 end#def
                 ### auto-start process with K2WS subfolder
                 self.delete_folder(File.join(File.dirname(File.dirname(__FILE__)), 'K2WS'))
                 ###
                end#module
                
                

                Untested - USE WITH CAUTION !
                Perhaps get it to 'puts' the info rather than delete things, when first testing it 🤓
                On subsequent startups after the deletions, the K2WS folder doesn't exist, so it returns nil at the start of the processing.

                TIG

                1 Reply Last reply Reply Quote 0
                • K Offline
                  ktkoh
                  last edited by

                  Thanks I will work on that this afternoon.

                  Keith

                  1 Reply Last reply Reply Quote 0
                  • K Offline
                    ktkoh
                    last edited by

                    I worked with the code yesterday and this am. I found it worked well if the file was in the plugin directory. However I had no success when I tried to run the file from the directory Plugins/k2ws_Comp2LayerScene directory. I tried changing the line replacing the FILE with a filename that was in the Plugins

                    self.delete_folder(File.join(File.dirname(__FILE__), 'K2WS'))
                    
                    self.delete_folder(File.join(File.dirname("k2ws_Comp2LayerScene.rb"), 'K2WS'))
                    

                    but that made the folder ./K2WS and thus it was not found. I read some more on ruby but none of the things I tried fixed this.

                    I looks like I would need to add the clean up code to the end of the file that creates the extension so it would start from the correct directory and I am not sure this is allowed in the warehouse.

                    Keith

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      Aerilius
                      last edited by

                      The first line gives you the (incomplete) directory path Plugins/k2ws_Comp2LayerScene/K2WS.

                      The second line gives you correctly ./K2WS because "k2ws_Comp2LayerScene.rb" has no file path. Nobody can no where this file name is flying around, and so Ruby does not know as well. If no absolute path is provided, it is interpreted as a relative path to the current directory ( ./) which is then joined with K2WS.

                      Using the dynamic variable __FILE__ is absolutely fine (at was probably not written here as a placeholder). This variable will always be the file path of the file that is being loaded.

                      1 Reply Last reply Reply Quote 0
                      • TIGT Offline
                        TIG Moderator
                        last edited by

                        If you read the code it never said that.
                        It said:
                        self.delete_folder(File.join(File.dirname(File.dirname(__FILE__)), 'K2WS'))Assuming that the rb doing the deletion is in the K2WS_Comp2LayerScene_ext subfolder.
                        The path finds the dirname of its folder and then the dirname of that folder's folder - which should typically be Plugins...

                        TIG

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

                        Advertisement