From 37c404603d79642abad19207a5d7173ab24bd533 Mon Sep 17 00:00:00 2001 From: Zacharias Date: Tue, 6 May 2025 14:47:51 +0200 Subject: [PATCH] Created a test for downloading the core with the core. added some safe checks in the core --- core.lua | 11 ++++++++++- downloadCore.lua | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 downloadCore.lua diff --git a/core.lua b/core.lua index 9e10f70..fab84ac 100644 --- a/core.lua +++ b/core.lua @@ -98,8 +98,17 @@ function Core:download(file) return false, "Invalid type: "..textutils.serialiseJSON(data) end + if fs.exists(file) then + fs.delete(file); + end + local fileStream = io.open(file, "w"); - fileStream:write(data.fileContent); + + if not fileStream then + return false, "Failed to open fileStream" + end + + fileStream:write(data.data); fileStream:close(); return true, "Success" diff --git a/downloadCore.lua b/downloadCore.lua new file mode 100644 index 0000000..66f4355 --- /dev/null +++ b/downloadCore.lua @@ -0,0 +1,9 @@ +require("core") + +local core = Core.new(); + +core:connect(); + +core:download("core.lua"); + +core:disconnect(); \ No newline at end of file