Jump to content




Forcing all OS files to be installed in a specific folder


4 replies to this topic

#1 Windows10User

  • Members
  • 62 posts
  • LocationC:\Minecraft\saves\stuff\computer

Posted 30 May 2018 - 01:12 PM

So, right now I have this code:

local nOption = 1

function drawMenu()
   term.clear()
   term.setCursorPos(1, 1)
   paintutils.drawFilledBox(0, 0, 51, 19, colors.cyan)
   term.setCursorPos(1, 1)
   term.setBackgroundColor(colors.blue)
   term.setTextColor(colors.white)
   for i=1, 51 do
	  term.write(" ")
   end

   printCentered("BIOS SETUP UTILITY")
   print("")
   term.setCursorPos(3, 3)
   term.setBackgroundColor(colors.cyan)
   printStayX(nOption == 1 and "[ Set Default OS ]" or "Set Default OS")
   printStayX("")
   printStayX(nOption == 2 and "[ Install Pastebin OS ]" or "Install Pastebin OS")
   printStayX("")
   printStayX(nOption == 3 and "[ Exit and Reboot ]" or "Exit and Reboot")
   term.setCursorPos(30, 3)
   printStayX(textutils.formatTime(os.time()))
   printStayX("")
   printStayX("Free Space: "..math.ceil(fs.getFreeSpace("/") / 1024).." KB")
end

drawMenu()

function pasteget(code, file)
   local response = http.get("https://pastebin.com/raw/"..textutils.urlEncode(code))

   if response then
	  local data = response.readAll()
	  response.close()
	  local hfile = fs.open(file, "w")
	  hfile.write(data)
	  hfile.close()
	  return true
   else
	  return false
   end
end

function pastebinMenu()
   term.setBackgroundColor(colors.black)
   term.clear()
   term.setCursorPos(1, 1)
   print("OS name:")
   local name = read()
   print("OS Pastebin code:")
   local code = read()

   if pasteget(code, "bios/"..name.."/installer") then
	  print("Installer successfully downloaded, about to install...")
	  local oldpath = shell.path()
	  shell.setPath(oldpath..":bios/"..name)
	  shell.run("bios/"..name.."/installer")
	  shell.setPath(oldpath)
   end
end

while true do
   local event, key, _ = os.pullEvent("key")
   if key == keys.up then
	  if nOption > 1 then
		 nOption = nOption - 1
		 drawMenu()
	  end
   elseif key == keys.down then
	  if nOption < 3 then
		 nOption = nOption + 1
		 drawMenu()
	  end
   elseif key == keys.enter then
	  if nOption == 3 then
		 sleep(1)
		 os.reboot()
	  elseif nOption == 2 then
		 pastebinMenu()
	  end
   end
end

When I go install an OS, it installs fine, but even though I used setPath, it copies the files into the root directory.

Is there any way around this?

#2 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 30 May 2018 - 01:43 PM

shell.setPath doesn't have any impact on where the files are installed, it just changes what folders the shell will look in when trying to find a program. You probably meant to use shell.setDir instead. That being said, that will have little effect on many installers as they'll be using the fs API directly. You're probably better off creating a filesystem sandbox which operates within a sub-directory. It might be worth checking out something like Wilma's VirtualOS.

#3 Windows10User

  • Members
  • 62 posts
  • LocationC:\Minecraft\saves\stuff\computer

Posted 30 May 2018 - 01:56 PM

 SquidDev, on 30 May 2018 - 01:43 PM, said:

shell.setPath doesn't have any impact on where the files are installed, it just changes what folders the shell will look in when trying to find a program. You probably meant to use shell.setDir instead. That being said, that will have little effect on many installers as they'll be using the fs API directly. You're probably better off creating a filesystem sandbox which operates within a sub-directory. It might be worth checking out something like Wilma's VirtualOS.

Will overwriting the fs functions to the same things, but adding bios/name to their beginnings work?

#4 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 30 May 2018 - 02:27 PM

 Windows10User, on 30 May 2018 - 01:56 PM, said:

Will overwriting the fs functions to the same things, but adding bios/name to their beginnings work?
Technically yes. However, it's generally best to avoid it as there's all sorts of ways it can go wrong: you have to restore the previous handle between event yields and after your program exists (even in the event of a crash) in order to prevent breaking the computer for everyone else.

#5 Windows10User

  • Members
  • 62 posts
  • LocationC:\Minecraft\saves\stuff\computer

Posted 30 May 2018 - 07:33 PM

 SquidDev, on 30 May 2018 - 02:27 PM, said:

 Windows10User, on 30 May 2018 - 01:56 PM, said:

Will overwriting the fs functions to the same things, but adding bios/name to their beginnings work?
Technically yes. However, it's generally best to avoid it as there's all sorts of ways it can go wrong: you have to restore the previous handle between event yields and after your program exists (even in the event of a crash) in order to prevent breaking the computer for everyone else.

Then what do I do?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users