It is currently March 28th, 2024, 6:21 pm

[Trick | Guide] Auto Updater for your skins

Tips and Tricks from the Rainmeter Community
Post Reply
User avatar
deflore08
Posts: 209
Joined: July 12th, 2020, 7:47 am
Location: Ada, Garden City
Contact:

[Trick | Guide] Auto Updater for your skins

Post by deflore08 »

Helloooooo!

It seems as a big problem to deliver your latest skin's version to a users. Sure, they always might check it on hubs or even find it unintetionaly, but what if?.. :Whistle
So, let's try WebParser plugin and PowerShell combo to check the latest versions, backup configs and install skins automatically.

For the beginning we have to decide where we will place our skin. I will use RM forum and GitHub (as the most convenient thing for storing projects) and show how it works on my own skin as example (but you will not find this module in current version until next release). Let's see:

Code: Select all


; --- We need some variables now. current version, new version and download URL. Also config path, path for backups and where we store updates.

[Variables]
 
 Version                           = 1.2.1a
 New_Version                       = [m.Updater_Parser_Check_Version]
 Download_URL                      = [m.Updater_URL_1][m.Updater_URL_2]
 
 Config                            = YourConfig.inc
 Backup_Config                     = #ADDONSPATH#\YourSkin\Backup
 Update_Folder                     = #ADDONSPATH#\YourSkin\Update

; --- Our WebParser measures. They checking which number written after "AuroraBar " in "LATEST VERSION" string and part of GitHub URL.

; - After check the parent measure comparing string that it get with current skin's version (#Version#) 

; - I do not write or  copy paste whole code, you able to decide yourself what you will do with this matches. In my case if match is false i just notice user and making update button available.

[m.Updater_Parser_Parent]
 Measure                          = WebParser
 URL                              = https://forum.rainmeter.net/viewtopic.php?f=27&p=181424#p181424
 RegExp                           = (?siU)class="postlink">AuroraBar (.*)</a>.* <strong class="text-strong"><a href=(.*) class="postlink">.*https://github.com/deflore08/AuroraBar(.*)"

[m.Updater_Parser_Check_Version]
 Measure                          = WebParser
 URL                              = [m.Updater_Parser_Parent]
 StringIndex                      = 1
 DynamicVariables                 = 1
     ifMatch                      = ^#Version#$
          ifMatchAction           = Do something
          ifNotMatchAction        = Do something
     ifMatchMode                  = 1

[m.Updater_URL_1]
 Measure                          = WebParser
 URL                              = [m.Updater_Parser_Parent]
 StringIndex                      = 2

[m.Updater_URL_2]
 Measure                          = WebParser
 URL                              = [m.Updater_Parser_Parent]
 StringIndex                      = 3

; --- Autoupdates it is cool, but we have to remember, a skin may contain user-variables. You must care about it and store user defined settings in special file, not in one place with basic skin variables and settings. If you did, let's backup it before installing. We will use built-in RM's variable which lead us to %appdata%\Roaming\Rainmeter\Addons. 

; - YOU CANNOT STORE THIS BACKUP IN SKIN FOLDER - IT WILL BE REPLACED

; - ALSO YOU CANNOT USE MERGE EACH UPDATE (but if you want, you're welcome.. :))

; - Also i recommend you always use logs everywhere it possible to catch an errors and to known what happens.

[shell.BACKUP_CONFIG]
 Measure                          = PLUGIN
 Plugin                           = RunCommand
 Program                          = PowerShell
 Parameter                        = Copy-Item -Path #@#\#Config# -Destination #Backup_Config# -Force
 State                            = Hide
 DynamicVariables                 = 1
 OutputType                       = UTF8
 OutputFile                       = your_log_file.log

[shell.RESTORE_CONFIG]
 Measure                          = PLUGIN
 Plugin                           = RunCommand
 Program                          = PowerShell
 Parameter                        = Copy-Item -Path #Backup_Config# -Destination #@#\#Config# -Force
 State                            = Hide
 DynamicVariables                 = 1
 OutputType                       = UTF8
 OutputFile                       = your_log_file.log

; --- Downloader. After download it will begin chain of actions. Backup config and then after short delay it will start installer.

[m.Updater_Downloader]
 Measure                          = PLUGIN
 Plugin                           = RunCommand
 Program                          = PowerShell
 Parameter                        = New-Item -Path #Update_Folder# -ItemType Directory #CRLF# $client = new-object System.Net.WebClient #CRLF# $client.DownloadFile(""#Download_URL#"", """#Update_Folder#\AuroraBar_#New_Version#.rmskin""")
 State                            = Hide
 DynamicVariables                 = 1
 OutputType                       = UTF8
 OutputFile                       = your_log_file.log
 FinishAction                     = [!CommandMeasure shell.BACKUP_CONFIG "Run"][!Delay 1000][!CommandMeasure m.Updater_Skin_Installer "Run"]

[m.Updater_Skin_Installer]
 Measure                          = PLUGIN
 Plugin                           = RunCommand
 Program                          = PowerShell
 Parameter                        = #Update_Folder#\AuroraBar_#New_Version#.rmskin
 State                            = Hide
 DynamicVariables                 = 1
 OutputType                       = UTF8
 OutputFile                       = your_log_file.log

In spite of it is still an experimental function and we keep testing it on animals, it is works good, and almost ready to being tested in real works skins and real users. All what you need now, it is just to make a button with [!CommandMeasure m.Updater_Downloader "Run"] and eat your popcorn. :lol:

As always, glad to serve and waiting for your own improvements. :)

P.S. I don't think I should be saying that, it's kind of obvious, but i do not want to know how many apes you kill with that. Thanks you. :lol:
Last edited by deflore08 on November 13th, 2020, 5:36 am, edited 1 time in total.
User avatar
deflore08
Posts: 209
Joined: July 12th, 2020, 7:47 am
Location: Ada, Garden City
Contact:

Re: [Trick | Guide] Auto Updater for your skins

Post by deflore08 »

Obviously, in your new version should be defined new version variable and bang for restoring config. :oops:
User avatar
limitless
Posts: 76
Joined: January 8th, 2017, 2:31 am
Location: Charlotte, NC
Contact:

Re: [Trick | Guide] Auto Updater for your skins

Post by limitless »

Thank you!!!
User avatar
deflore08
Posts: 209
Joined: July 12th, 2020, 7:47 am
Location: Ada, Garden City
Contact:

Re: [Trick | Guide] Auto Updater for your skins

Post by deflore08 »

limitless wrote: November 14th, 2020, 9:26 pm Thank you!!!
You are welcome, Sir. :)
Post Reply