Check Version In Store

Using either the Plugin Name (title) or Plugin Filename retrieves the current Plugin Store version.
The current plugin filename can be obtained using fhGetContextInfo(‘CI_PLUGIN_NAME’)

Requires: luacom

Code

require('luacom')

function checkVersionInStore(type,value)
--[[
@description: Checks the version in the plugin store by name or id
@Parms:
1: String, must be either 'name' or 'file'
2: String
@Returns:
1: nil where value not found or parameter 1 is invalid,
     or the value of the plugin version field
2: the value of the plugin id number
]]
    local function httpRequest(strRequest)
        local http = luacom.CreateObject("winhttp.winhttprequest.5.1")
        http:Open("GET",strRequest,false)
        http:Send()
        return http.Responsebody
    end -- local function httpRequest

    if type ~= 'name' and type ~= 'file' then
        return nil
    end
    if value then
        local strRequest ='http://www.family-historian.co.uk/lnk/checkpluginversion.php?'..type..'='..value
        local isOK, strReturn = pcall(httpRequest,strRequest)
        if not isOK then
            fhMessageBox(strReturn.."\n The Internet appears to be inaccessible at present. ")
            return nil
        end
        local ver = ''
        local ref = ''
        if strReturn ~= nil then
            ver,ref = strReturn:match('([%d%.]*),(%d*)') -- Version digits & dots then comma and Id digits 
        end
        return ver,ref
    else
        return nil
    end
end -- function checkVersionInStore

 

Usage

pluginname = fhGetContextInfo('CI_PLUGIN_NAME')..'.fh_lua'
version,reference = checkVersionInStore('file',pluginname)
print(pluginname,version,reference)			-->>	Timeline Chart.fh_lua	1.4	199

print(checkVersionInStore('id',199))			-->>	1.4	199
print(checkVersionInStore('name','Timeline Chart'))	-->>	1.4	199