Delete old FH6 Plugin Module Files.fh_lua--[[
@Title: Delete old FH6 Plugin Module Files
@Type: Standard
@Author: Jane Taubman
@Version: 1.0
@Keywords:
@LastUpdated: 16 May 2021
@Licence: This plugin is copyright (c) 2021 Jane Taubman and contributors, and is licensed under the MIT License
which is hereby incorporated by reference (see https://pluginstore.family-historian.co.uk/fh-plugin-licence)
@Description:
Delete all files added by the Load Require option from the Plugins folder in Program Data.
Used to prevent older modules being picked up by FH7.
]]
require 'lfs'
require 'luacom'
require("iuplua");
iup.SetGlobal("CUSTOMQUITMESSAGE","YES");
fhInitialise(7); -- implies users will need version 7 as a minimum; change if that is not the case
local fso = luacom.CreateObject("Scripting.FileSystemObject")
-------------------------------------------------------
-- Clean up all existing modules from old load require option
-------------------------------------------------------
function main()
local a = fhMessageBox("This will uninstall V6 modules from your Plugins folder\nContinue?", "MB_YESNO")
if a == "No" then
return
elseif a == "Yes" then
deleteModule("pl")
deleteModule("md5")
deleteModule("socket")
deleteModule("luasql")
deleteModule("ltn12")
deleteModule("zip")
deleteModule("utf8")
deleteModule("compat53")
end
end
local function httpRequest(url)
local http = luacom.CreateObject("winhttp.winhttprequest.5.1")
http:Open("GET",url,false)
http:Send()
http:WaitForResponse(30)
return http
end -- local function httpRequest
function splitFilename(s)
local d
s =string.gsub(s,'/','\\')
d = string.match(s, "(.-)([^\\]-([^%.]+))$")
d = d:sub(1, #d - 1)
return d
end
function deleteModule(module)
local bmodule = false
filename = module..'.mod'
bmodule = true
local storein = fhGetContextInfo('CI_APP_DATA_FOLDER')..'\\Plugins\\'
local folderList = {}
-- Get file down and install it
local url = "http://www.family-historian.co.uk/lnk/getpluginmodule.php?file="..filename
local isOK, reply = pcall(httpRequest,url)
if not isOK then
fhMessageBox(reply.."\nLoad Require module finds the Internet inaccessible.")
return false
end
local http = reply
local status = http.StatusText
if status == 'OK' then
length = http:GetResponseHeader('Content-Length')
data = http.ResponseBody
if bmodule then
local modlist = load(http.ResponseBody)
for x,y in pairs(modlist()) do
local fileid = storein..y
if fso:FileExists(fileid) then
fso:DeleteFile(fileid)
end
sDir = splitFilename(fileid)
if sDir..'\\' ~= storein then
table.insert(folderList,sDir)
end
end
-- Delete Folders (sort by string length to do the subdirectories first
table.sort(folderList, function(a,b) return #a>#b end)
local last
for i,v in ipairs(folderList) do
if v ~= last then
if fso:FolderExists(v) then
print(v)
fso:DeleteFolder(v)
end
end
last = v
end
return true
else
fhMessageBox('An error occurred in Download, so please try later, or perform a manual download from the FHUG Knowledge Base')
return false
end
end
return true
end
main();
--[[
@Title: Delete old FH6 Plugin Module Files
@Type: Standard
@Author: Jane Taubman
@Version: 1.0
@Keywords:
@LastUpdated: 16 May 2021
@Licence: This plugin is copyright (c) 2021 Jane Taubman and contributors, and is licensed under the MIT License
which is hereby incorporated by reference (see https://pluginstore.family-historian.co.uk/fh-plugin-licence)
@Description:
Delete all files added by the Load Require option from the Plugins folder in Program Data.
Used to prevent older modules being picked up by FH7.
]]
require 'lfs'
require 'luacom'
require("iuplua");
iup.SetGlobal("CUSTOMQUITMESSAGE","YES");
fhInitialise(7); -- implies users will need version 7 as a minimum; change if that is not the case
local fso = luacom.CreateObject("Scripting.FileSystemObject")
-------------------------------------------------------
-- Clean up all existing modules from old load require option
-------------------------------------------------------
function main()
local a = fhMessageBox("This will uninstall V6 modules from your Plugins folder\nContinue?", "MB_YESNO")
if a == "No" then
return
elseif a == "Yes" then
deleteModule("pl")
deleteModule("md5")
deleteModule("socket")
deleteModule("luasql")
deleteModule("ltn12")
deleteModule("zip")
deleteModule("utf8")
deleteModule("compat53")
end
end
local function httpRequest(url)
local http = luacom.CreateObject("winhttp.winhttprequest.5.1")
http:Open("GET",url,false)
http:Send()
http:WaitForResponse(30)
return http
end -- local function httpRequest
function splitFilename(s)
local d
s =string.gsub(s,'/','\\')
d = string.match(s, "(.-)([^\\]-([^%.]+))$")
d = d:sub(1, #d - 1)
return d
end
function deleteModule(module)
local bmodule = false
filename = module..'.mod'
bmodule = true
local storein = fhGetContextInfo('CI_APP_DATA_FOLDER')..'\\Plugins\\'
local folderList = {}
-- Get file down and install it
local url = "http://www.family-historian.co.uk/lnk/getpluginmodule.php?file="..filename
local isOK, reply = pcall(httpRequest,url)
if not isOK then
fhMessageBox(reply.."\nLoad Require module finds the Internet inaccessible.")
return false
end
local http = reply
local status = http.StatusText
if status == 'OK' then
length = http:GetResponseHeader('Content-Length')
data = http.ResponseBody
if bmodule then
local modlist = load(http.ResponseBody)
for x,y in pairs(modlist()) do
local fileid = storein..y
if fso:FileExists(fileid) then
fso:DeleteFile(fileid)
end
sDir = splitFilename(fileid)
if sDir..'\\' ~= storein then
table.insert(folderList,sDir)
end
end
-- Delete Folders (sort by string length to do the subdirectories first
table.sort(folderList, function(a,b) return #a>#b end)
local last
for i,v in ipairs(folderList) do
if v ~= last then
if fso:FolderExists(v) then
print(v)
fso:DeleteFolder(v)
end
end
last = v
end
return true
else
fhMessageBox('An error occurred in Download, so please try later, or perform a manual download from the FHUG Knowledge Base')
return false
end
end
return true
end
main();Source:Delete-old-FH6-Plugin-Module-Files.fh_lua