--Alle Rechte an SimSoft 2.1 sind "SimlorLP" (oder in Minecraft auch nur "Simlor") vorbehalten.


--SappS Touch

function SappSL(xa, xb, ya, yb, num)

 if x >= xa and x <= xb and y >= ya and y <= yb then
  file = fs.open("SimSoft/Daten/SappS/"..num,"r") 
  local fileData = {}
  local line = file.readLine()
  repeat
  table.insert(fileData,line)
  line = file.readLine()
  until line == nil
  file.close()
  ver = fileData[5]
  if ver == "n" then
  else
   shell.run("SimSoft/SappS/"..ver)
   shell.run("SimSoft/System/Desktop")
  end
 end
end


--Sapps Function

function AppG(name,pos,farbe)

 --Pos

 if pos == "1.0" then
  x = 4
  y = 5
 elseif pos == "2.0" then
  x = 12
  y = 5
 elseif pos == "3.0" then
  x = 20
  y = 5
 elseif pos == "4.0" then
  x = 28
  y = 5
 elseif pos == "5.0" then
  x = 36
  y = 5
 elseif pos == "6.0" then
  x = 4
  y = 9
 elseif pos == "7.0" then
  x = 12
  y = 9
 elseif pos == "8.0" then
  x = 20
  y = 9
 elseif pos == "9.0" then
  x = 28
  y = 9
 elseif pos == "10.0" then
  x = 36
  y = 9
 elseif pos == "11.0" then
  x = 4
  y = 13
 elseif pos == "12.0" then
  x = 12
  y = 13
 elseif pos == "13.0" then
  x = 20
  y = 13
 elseif pos == "14.0" then
  x = 28
  y = 13
 elseif pos == "15.0" then
  x = 36
  y = 13
 end
 
 --Farbe

 TC(256)
 
 if farbe == "1.0" then
  BC(1)
 elseif farbe == "2.0" then
  BC(2048)
 elseif farbe == "3.0" then
  BC(2048)
 elseif farbe == "4.0" then
  BC(8)
 elseif farbe == "5.0" then
  BC(32)
 elseif farbe == "6.0" then
  BC(6)
 elseif farbe == "7.0" then
  BC(2048)
 elseif farbe == "8.0" then
  BC(16)
 elseif farbe == "9.0" then
  BC(1024)
 elseif farbe == "10.0" then
  BC(4069)
 elseif farbe == "11.0" then
  BC(2)
 elseif farbe == "12.0" then
  BC(1024)
 elseif farbe == "13.0" then
  BC(16384)
 elseif farbe == "14.0" then
  BC(8192)
 elseif farbe == "15.0" then
  BC(2)
 elseif farbe == "16.0" then
  BC(4)
 elseif farbe == "17.0" then
  BC(8)
 elseif farbe == "18.0" then
  BC(16)
 elseif farbe == "19.0" then
  BC(32)
 elseif farbe == "20.0" then
  BC(64)
 
 end
 
 --Pos
 
 CP(x,y) --4,6
 print(" ")
 x = (x+1)
 y = (y+1)
 CP(x,y) --5,7
 print(" ")
 y = (y-1)
 
 --Farbe
 
 if farbe == "1.0" then
  BC(32768)
 elseif farbe == "2.0" then
  BC(1)
 elseif farbe == "3.0" then
  BC(32768)
 elseif farbe == "4.0" then
  BC(1)
 elseif farbe == "5.0" then
  BC(32768)
 elseif farbe == "6.0" then
  BC(1)
 elseif farbe == "7.0" then
  BC(16384)
 elseif farbe == "8.0" then
  BC(32)
 elseif farbe == "9.0" then
  BC(32768)
 elseif farbe == "10.0" then
  BC(8192)
 elseif farbe == "11.0" then
  BC(32768)
 elseif farbe == "12.0" then
  BC(4)
 elseif farbe == "13.0" then
  BC(16)
 elseif farbe == "14.0" then
  BC(32)
 elseif farbe == "15.0" then
  BC(64)
 elseif farbe == "16.0" then
  BC(256)
 elseif farbe == "17.0" then
  BC(256)
 elseif farbe == "18.0" then
  BC(512)
 elseif farbe == "19.0" then
  BC(1024)
 elseif farbe == "20.0" then
  BC(8192)
 end
 
 --Pos
 
 CP(x,y) --5,6
 print(" ")
 x = (x-1)
 y = (y+1)
 CP(x,y) --4,7
 print(" ")
 x = (x-2)
 y = (y+1)
 CP(x,y) --2,8
 TC(256)
 BC(128)
 print(name)
end


--Hintergrund erstellung

BC(128)
Clear()

file = fs.open("SimSoft/Daten/User","r")
local fileData = {}
local line = file.readLine()
repeat
table.insert(fileData,line)
line = file.readLine()
until line == nil
file.close()

hint = fileData[4]

if hint == "t" then

 _Background = paintutils.loadImage("SimSoft/Daten/DesktopBG")
 paintutils.drawImage(_Background,1,2)
 
elseif hint == "f" then
end


--Interface und Icons

CP(1,1)
BC(32768)
print("                                                   ")
print("                                                   ")
print("                                                   ")

CP(17,2)
TC(1)
print("SimSoft 2.1 - Desktop")

CP(49,4)
BC(256)
print("   ")
CP(49,5)
print(" @ ")
CP(49,6)
print("   ")
CP(49,7)
print("   ")
CP(49,8)
print("   ")
CP(49,9)
print("   ")
CP(49,10)
print("   ")
CP(49,11)
print("   ")
CP(49,12)
print("   ")
CP(49,13)
print("   ")
CP(49,14)
print("   ")
CP(49,15)
print("   ")
CP(49,16)
print("   ")
CP(49,17)
print("   ")
CP(49,18)
print(" @ ")
CP(49,19)
write("   ")
CP(1,15)

file = fs.open("SimSoft/Daten/SappS/A","r")
local fileData = {}
local line = file.readLine()
repeat
table.insert(fileData,line)
line = file.readLine()
until line == nil
file.close()

sc = fileData[1]

sc = (sc+1)
sc = (sc-1)

if sc >= 16 then
 sc = 15
elseif sc <= -1 then
 sc = 0
end

if sc == 0 then
 shell.run("")
else

 anz = 0

 while true do

  anz = (anz+1)

  file = fs.open("SimSoft/Daten/SappS/"..anz,"r")
  local fileData = {}
  local line = file.readLine()
  repeat
  table.insert(fileData,line)
  line = file.readLine()
  until line == nil
  file.close()

  a = fileData[1]
  b = fileData[2]
  c = fileData[3]

  AppG(a,b,c)
 
  if anz == sc then
   break
  end
 end
end

--Touch

while true do

 event,side,x,y = os.pullEvent()
 if event == "mouse_click" then
  
  --SappS
  
  SappSL(2, 7, 5, 7, 1)
  SappSL(10, 15, 5, 7, 2)
  SappSL(18, 23, 5, 7, 3)
  SappSL(26, 31, 5, 7, 4)
  SappSL(34, 39, 5, 7, 5)
  SappSL(2, 7, 9, 11, 6)
  SappSL(10, 15, 9, 11, 7)
  SappSL(18, 23, 9, 11, 8)
  SappSL(26, 31, 9, 11, 9)
  SappSL(34, 39, 9, 11, 10)
  SappSL(2, 7, 13, 15, 11)
  SappSL(10, 15, 13, 15, 12)
  SappSL(18, 23, 13, 15, 13)
  SappSL(26, 31, 13, 15, 14)
  SappSL(34, 39, 13, 15, 15)
  
  --Balkenleisten
  
  if x >= 1 and x <= 51 and y >= 1 and y <= 3 then
   CP(1,4)
   BC(128)
   TC(1)
   print("                                                ")
   print("                                                ")
   print("                                                ")
   print("                                                ")
   print("                                                ")
   print("                                                ")
   print("                                                ")
   print("                                                ")
   print("                                                ")
   print("                                                ")
   print("                                                ")
   print("                                                ")
   print("                                                ")
   print("                                                ")
   print("                                                ")
   write("                                                ")
   
   TC(1)
   CP(10,5)
   print("System")
   
   --Version
   TC(32768)
   CP(4,8)
   write("OS version - ")
   TC(256)
   Version()
   print(SS2V)
   
   --by
   CP(4,10)
   TC(32768)
   write("Copyright - ")
   TC(256)
   print("SimlorLP")
   
   while true do
   
   --Pass
   BC(128)
   CP(4,12)
   TC(1)
   print("Edit password")
   
   file = fs.open("SimSoft/Daten/User","r")
   local fileData = {}
   local line = file.readLine()
   repeat
   table.insert(fileData,line)
   line = file.readLine()
   until line == nil
   file.close()
   name = fileData[1]
   pass = fileData[2]
   hin = fileData[3]
   hinz = fileData[4]
   
   if hin == "t" then
    CP(26,12)
	BC(2048)
	write("  ")
	BC(32768)
	print(" ")
   else
    CP(26,12)
	BC(32768)
	write(" ")
	BC(256)
	print("  ")
   end
   
   --Pass
   BC(128)
   CP(4,14)
   TC(1)
   print("Edit name")
   
   --Hintergrund
   CP(4,16)
   TC(1)
   print("Edit background")
   
   --Update Anzeige
   UpdataC()
   
   if UpdataCV == false then
    CP(24,8)
	TC(32768)
	write("- ")
	TC(16384)
	print("Update available")
   end
   
   TC(1)
   
   if hinz == "t" then
    CP(26,16)
	BC(2048)
	write("  ")
	BC(32768)
	print(" ")
   else
    CP(26,16)
	BC(32768)
	write(" ")
	BC(256)
	print("  ")
   end
   --While true do steht oben!
    event,side,x,y = os.pullEvent()
	if event == "mouse_click" then
	 
	 if x >= 4 and x <= 22 and y == 12 then
	  BC(128)
	  CP(4,12)
	  print("                      ")
	  CP(4,12)
	  npass = read()
   
      Version()
   
      local file = fs.open("SimSoft/Daten/User","w")
      file.close()
   
      local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(name)
      file.close()
   
      local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(npass)
      file.close()
	  
	  local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(hin)
      file.close()
   
      local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(hinz)
      file.close()
	  
	  local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(SS2V)
      file.close()
	  
	  TC(128)
	  CP(4,12)
	  print("                      ")
	  CP(4,12)
	  TC(32)
	  print("Saved!")
	  sleep(0.2)
	  TC(1)
	 end
	  
	 if x >= 4 and x <= 18 and y == 14 then
	  BC(128)
	  CP(4,14)
	  print("                      ")
	  CP(4,14)
	  nname = read()
   
      Version()
   
      local file = fs.open("SimSoft/Daten/User","w")
      file.close()
   
      local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(nname)
      file.close()

      local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(pass)
      file.close()
	  
	  local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(hin)
      file.close()
   
      local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(hinz)
      file.close()
	  
	  local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(SS2V)
      file.close()

	  os.setComputerLabel(nname)
	 
	  TC(128)
	  CP(4,14)
	  print("                      ")
	  CP(4,14)
	  TC(32)
	  print("Saved!")
	  sleep(0.2)
	  TC(1)
     end
	  
	 if x >= 4 and x <= 24 and y == 16 then
	  shell.run("paint SimSoft/Daten/DesktopBG")
	  shell.run("SimSoft/System/Desktop")
	 end
	 
	 --
	 
	 if x >= 26 and x <= 28 and y == 12 then
   
      Version()
   
      local file = fs.open("SimSoft/Daten/User","w")
      file.close()
   
      local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(name)
      file.close()
   
      local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(pass)
      file.close()
	  
	  if hin == "t" then
	   hin = "f"
	  elseif hin == "f" then
	   hin = "t"
	  end
	  
	  local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(hin)
      file.close()
   
      local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(hinz)
      file.close()
	  
	  local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(SS2V)
      file.close()
	 end
	 
	if x >= 26 and x <= 28 and y == 16 then
   
      Version()
   
      local file = fs.open("SimSoft/Daten/User","w")
      file.close()
   
      local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(name)
      file.close()
   
      local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(pass)
      file.close()
	  
	  if hinz == "t" then
	   hinz = "f"
	  elseif hinz == "f" then
	   hinz = "t"
	  end
	  
	  local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(hin)
      file.close()
   
      local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(hinz)
      file.close()
	  
	  local file = fs.open("SimSoft/Daten/User","a")
      file.writeLine(SS2V)
      file.close()
	 end
	 
	 if x >= 1 and x <= 51 and y >= 1 and y <= 3 then
	  shell.run("SimSoft/System/Desktop")
	  break
	 end
	 
	 if x >= 49 and x <= 51 and y >= 4 and y <= 19 then
	  shell.run("SimSoft/System/Desktop")
	  break
	 end
    end 
   end 
   break   
  end   
  
  if x >= 49 and x <= 51 and y >= 4 and y <= 19 then
   CP(37,4)
   BC(256)
   TC(1)
   write("               ")
   CP(37,5)
   write(" @             ")
   CP(37,6)
   write("               ")
   CP(37,7)
   write("               ")
   CP(37,8)
   write("               ")
   CP(37,9)
   write("               ")
   CP(37,10)
   write("               ")
   CP(37,11)
   write("               ")
   CP(37,12)
   write("               ")
   CP(37,13)
   write("               ")
   CP(37,14)
   write("               ")
   CP(37,15)
   write("               ")
   CP(37,16)
   write("               ")
   CP(37,17)
   write("               ")
   CP(37,18)
   write(" @             ")
   CP(37,19)
   write("               ")
   
   CP(40,18)
   TC(128)
   print("by SimlorLP")
   
   CP(40,5)
   TC(32768)
   print("SimSoft 2.1")
   
   CP(37,7)
   TC(256)
   BC(128)
   print("   Log off     ")
   
   CP(37,8)
   TC(128)
   BC(256)
   print("   Shutdown    ")
   
   CP(37,9)
   TC(256)
   BC(128)
   print("   Restart     ")
   
   CP(37,10)
   TC(128)
   BC(256)
   print("   SappS Store ")
   
   CP(37,11)
   TC(256)
   BC(128)
   print("   Delete      ")
   
   CP(37,12)
   TC(128)
   BC(256)
   print("   OS updates  ")
   
   while true do
    event,side,x,y = os.pullEvent()
    if event == "mouse_click" then
     
     if x >= 37 and x <= 51 and y == 7 then
      shell.run("SimSoft/System/SystemStart")
      break
	 end
	  
     if x >= 37 and x <= 51 and y == 8 then
      os.shutdown()
      break
	 end
      
     if x >= 37 and x <= 51 and y == 9 then
      os.reboot()
      break
	 end
     
     if x >= 37 and x <= 51 and y == 10 then
      shell.run("SimSoft/System/SappS")
      break
	 end
	 
	 if x >= 37 and x <= 51 and y == 11 then
      shell.run("SimSoft/System/SappSLoeschen")
      break
	 end
	 
	 if x >= 37 and x <= 51 and y == 12 then
      shell.run("SimSoft/System/SystemUpdate")
      break
	 end
	  
     --Seitenleiste aus
     
     if x >= 1 and x <= 36 and y >= 4 and y <= 19 then
      shell.run("SimSoft/System/Desktop")
      break   	  
     end
	 if x >= 1 and x <= 51 and y >= 1 and y <= 3 then
	  shell.run("SimSoft/System/Desktop")
      break   	  
     end
	end
   end
   break
  end
 end
end