handle new settings file and not deleting legacy config

This commit is contained in:
Mikayla Fischler 2023-10-03 23:11:52 -04:00
parent ebabd99f2b
commit 5d7a0b266a

View File

@ -18,7 +18,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
local function println(message) print(tostring(message)) end local function println(message) print(tostring(message)) end
local function print(message) term.write(tostring(message)) end local function print(message) term.write(tostring(message)) end
local CCMSI_VERSION = "v1.10" local CCMSI_VERSION = "v1.11"
local install_dir = "/.install-cache" local install_dir = "/.install-cache"
local manifest_path = "https://mikaylafischler.github.io/cc-mek-scada/manifests/" local manifest_path = "https://mikaylafischler.github.io/cc-mek-scada/manifests/"
@ -158,7 +158,7 @@ local function _clean_dir(dir, tree)
if fs.isDir(path) then if fs.isDir(path) then
_clean_dir(path, tree[val]) _clean_dir(path, tree[val])
if #fs.list(path) == 0 then fs.delete(path);println("deleted " .. path) end if #fs.list(path) == 0 then fs.delete(path);println("deleted " .. path) end
elseif not _in_array(val, tree) then elseif (not _in_array(val, tree)) and (val ~= "config.lua" ) then ---@fixme remove condition after migration to settings files
fs.delete(path) fs.delete(path)
println("deleted " .. path) println("deleted " .. path)
end end
@ -172,7 +172,7 @@ local function clean(manifest)
table.insert(tree, "install_manifest.json") table.insert(tree, "install_manifest.json")
table.insert(tree, "ccmsi.lua") table.insert(tree, "ccmsi.lua")
table.insert(tree, "log.txt") -- this won't necessarily work correctly table.insert(tree, "log.txt") ---@fixme fix after migration to settings files?
lgray() lgray()
@ -203,8 +203,8 @@ if #opts == 0 or opts[1] == "help" then
yellow() yellow()
println(" ccmsi check <branch> for target") println(" ccmsi check <branch> for target")
lgray() lgray()
println(" install - fresh install, overwrites config") println(" install - fresh install, overwrites config.lua")
println(" update - update files EXCEPT for config/logs") println(" update - update files EXCEPT for config.lua")
println(" uninstall - delete files INCLUDING config/logs") println(" uninstall - delete files INCLUDING config/logs")
white();println("<app>");lgray() white();println("<app>");lgray()
println(" reactor-plc - reactor PLC firmware") println(" reactor-plc - reactor PLC firmware")
@ -543,28 +543,38 @@ elseif mode == "uninstall" then
local file_list = manifest.files local file_list = manifest.files
local dependencies = manifest.depends[app] local dependencies = manifest.depends[app]
local config_file = app .. "/config.lua"
table.insert(dependencies, app) table.insert(dependencies, app)
-- delete log file -- delete log file
local log_deleted = false
local settings_file = app .. ".settings"
local legacy_config_file = app .. "/config.lua"
lgray() lgray()
if fs.exists(config_file) then if fs.exists(legacy_config_file) then
local log_deleted = pcall(function () log_deleted = pcall(function ()
local config = require(app .. ".config") local config = require(app .. ".config")
if fs.exists(config.LOG_PATH) then if fs.exists(config.LOG_PATH) then
fs.delete(config.LOG_PATH) fs.delete(config.LOG_PATH)
println("deleted log file " .. config.LOG_PATH) println("deleted log file " .. config.LOG_PATH)
end end
end) end)
elseif fs.exists(settings_file) and settings.load(settings_file) then
if not log_deleted then local log = settings.get("LogPath")
red();println("Failed to delete log file.") if log ~= nil and fs.exists(log) then
white();println("press any key to continue...") log_deleted = true
any_key();lgray() fs.delete(log)
println("deleted log file " .. log)
end end
end end
if not log_deleted then
red();println("Failed to delete log file.")
white();println("press any key to continue...")
any_key();lgray()
end
-- delete all installed files -- delete all installed files
for _, dependency in pairs(dependencies) do for _, dependency in pairs(dependencies) do
local files = file_list[dependency] local files = file_list[dependency]
@ -584,6 +594,11 @@ elseif mode == "uninstall" then
end end
end end
if fs.exists(settings_file) then
fs.delete(settings_file)
println("deleted " .. settings_file)
end
fs.delete("install_manifest.json") fs.delete("install_manifest.json")
println("deleted install_manifest.json") println("deleted install_manifest.json")