diff --git a/src/main/resources/assets/opencomputers/loot/openos/lib/core/install_basics.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/core/install_basics.lua index a193b7cdf..67d218fdd 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/lib/core/install_basics.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/core/install_basics.lua @@ -89,12 +89,10 @@ for dev, path in pairs(devices) do end local target = targets[1] -if #targets ~= 1 then - utils = loadfile(utils_path, "bt", _G) - target = utils("select", "targets", options, targets) +-- if there is only 1 target, the source selection cannot include it +if #targets == 1 then + devices[targets[1].dev] = nil end -if not target then return end -devices[target.dev] = nil for dev, path in pairs(devices) do local address = dev.address @@ -127,13 +125,29 @@ for dev, path in pairs(devices) do end end +-- Ask the user to select a source local source = sources[1] if #sources ~= 1 then - utils = utils or loadfile(utils_path, "bt", _G) + utils = loadfile(utils_path, "bt", _G) source = utils("select", "sources", options, sources) end if not source then return end +-- Remove the source from the target options +for index,entry in ipairs(targets) do + if entry.dev == source.dev then + table.remove(targets, index) + target = targets[1] + end +end + +-- Ask the user to select a target +if #targets ~= 1 then + utils = utils or loadfile(utils_path, "bt", _G) + target = utils("select", "targets", options, targets) +end +if not target then return end + options = { from = source.path .. '/', diff --git a/src/main/resources/assets/opencomputers/loot/openos/lib/core/install_utils.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/core/install_utils.lua index 0e376abfd..a5704a684 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/lib/core/install_utils.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/core/install_utils.lua @@ -53,6 +53,20 @@ if cmd == "select" then end os.exit(1) end + local index_of_rw_source + for index,entry in ipairs(devices) do + if not entry.dev.isReadOnly() then + if index_of_rw_source then + -- this means there was another rw source, no special action required + index_of_rw_source = nil + break + end + index_of_rw_source = index + end + end + if index_of_rw_source then + table.remove(devices, index_of_rw_source) + end return select_prompt(devices, "What do you want to install?") elseif arg == "targets" then if #devices == 0 then