local login = 0
local ds = 1
local x = 1
local userI = ""
local vyhledat = "run command"
--os.loadAPI ("/system/api/run")
local passI = ""
local userO = ""
local passO = ""
local data = ""
local user = 0
local pass = ""
local vyhledatold = ""
local sDrive = nil
local tArgs = { ... }
local nastaveni={barva=colors.blue}
        local f=fs.open("system/.core/colors","r")
        local cnt=f.readAll()
        f.close()
        local nastaveni=textutils.unserialize(cnt)
local f=fs.open("system/.core/textcol","r")
local tnt=f.readAll()
f.close()
local text=textutils.unserialize(tnt)

fs.delete ("/system/.core/Build")
local na=fs.open("/system/.core/Build","w")
na.writeLine ("Verua Pro")
na.writeLine ("1631")
na.close ()
data = fs.open ("/system/.core/Build", "r")
verze = data.readLine ()
build = data.readLine ()
data.close ()
           
if not fs.exists ("/system/.core/lsprogram") then
        local data = fs.open ("/system/.core/lsprogram", "w")
        data.writeLine("Pmanager")
        data.writeLine()
        data.writeLine("FileX")
        data.writeLine("/system/programs/FileX")
        data.writeLine("Firewolf")
        data.writeLine("/system/api/internet")
        data.writeLine("")
        data.writeLine()
        data.writeLine("")
        data.writeLine()
        data.writeLine("")
        data.writeLine()
        data.writeLine("Setting")
        data.writeLine("/system/programs/setting")
        data.close ()
        end
                    
if fs.exists ("/system/.core/defuser") then
local na=fs.open("/system/.core/defuser","r")
    user = na.readLine ()
    userI = user
    na.close()
    data = fs.open("/system/.ucet/"..userI.."/.data","r")
    user = data.readLine ()
    passI = data.readLine ()
    data.close()
end

if fs.exists ("/system/RAM/user") then
	data = fs.open ("/system/RAM/user", "r")
	user = data.readLine ()
	pass = data.readLine ()
	userI = user
	data.close ()
	end


if not fs.exists ("/system/RAM/"..user) then
    data = fs. open ("/system/RAM/"..user, "w")
    data.close ()
    end

local function prc(text, y)
  local w = term.getSize()
  local _, cy = term.getCursorPos()
  term.setCursorPos(math.ceil((w-#text)/2), y or cy)
  write(text)
end


	
function clear()
  term.clear()
  term.setBackgroundColor(colors.white)
  for i=1,w do
    for j=1,h do
      term.setCursorPos(i,j)
      write(" ")
    end
  end
end

	
local function plocha ()
    if fs.exists ("/system/RAM/desk") then
    local data = fs.open("/system/RAM/desk", "r")
    ds = data.readLine()
    data.close ()
    
    if ds >= "0" then
        ds = ds-"1"
        else
        ds = "1"
        end
    end 
                   
        if ds < 0 then
            
            ds = 0
            end
            
o=fs.open ("/system/RAM/setting", "w")
o.writeLine (userI)
o.writeLine (passI)
o.close ()
        
 if fs.exists ("/system/Local/"..user.."/desktop/.list"..ds) then
 data = fs.open("/system/Local/"..user.."/desktop/.list"..ds, "r")
            fpath1 = data.readLine ()
            fname1 = data.readLine ()
            ftype1 = data.readLine ()
            fpath2 = data.readLine ()
            fname2 = data.readLine ()
            ftype2 = data.readLine ()
            fpath3 = data.readLine ()
            fname3 = data.readLine ()
            ftype3 = data.readLine ()
            fpath4 = data.readLine ()
            fname4 = data.readLine ()
            ftype4 = data.readLine ()
            fpath5 = data.readLine ()
            fname5 = data.readLine ()
            ftype5 = data.readLine ()
            fpath6 = data.readLine ()
            fname6 = data.readLine ()
            ftype6 = data.readLine ()
            fpath7 = data.readLine ()
            fname7 = data.readLine ()
            ftype7 = data.readLine ()
            fpath8 = data.readLine ()
            fname8 = data.readLine ()
            ftype8 = data.readLine ()
            fpath9 = data.readLine ()
            fname9 = data.readLine ()
            ftype9 = data.readLine ()
            data.close()        
     end
     
local f=fs.open("system/.core/colors","r")
local cnt=f.readAll()
f.close()
local nastaveni=textutils.unserialize(cnt)

local f=fs.open("system/.core/textcol","r")
local tnt=f.readAll()
f.close()
local text=textutils.unserialize(tnt)

if fs.exists ("/system/RAM/online") then
   internetcon = ""
   else
   internetcon = " No internet connect!"
   end
   
data = fs.open ("/system/RAM/user", "r")
	user = data.readLine ()
	pass = data.readLine ()
	userI = user
	data.close ()

min1 = ""
min2 = ""
min3 = ""


if fs.exists ("/system/RAM/m1") then
	data = fs.open ("/system/RAM/m1", "r")
	min1 = data.readLine ()
    data.close ()
	end
if fs.exists ("/system/RAM/m2") then
	data = fs.open ("/system/RAM/m2", "r")
	min2 = data.readLine ()
    data.close ()
	end
if fs.exists ("/system/RAM/m3") then
	data = fs.open ("/system/RAM/m3", "r")
	min3 = data.readLine ()
    data.close ()
	end

if fs.exists ("/system/.ucet/"..user.."/bar.nfp") then
		local image = paintutils.loadImage("/system/.ucet/"..user.."/bar.nfp")
		paintutils.drawImage(image, 1, 1)
    else
		local myWindow = window.create(term.current(),1,1,51,19)
		myWindow.setBackgroundColor(colors.cyan)
		myWindow.clear()
	end

	term.setTextColor(text.barva)
    paintutils.drawLine(1, 19, 51, 19, nastaveni.barva)
	term.setCursorPos(1,19)
	term.write (verze.." "..build)
	local time = os.time()
	local formattedTime = textutils.formatTime(time, true)
	term.setCursorPos(46,19)
	term.write(formattedTime)
    term.setCursorPos(30,18)
    print (internetcon)
    term.setCursorPos(1,13)
    term.setTextColor(colors.white)
    term.setBackgroundColor(colors.red)
    term.setCursorPos(1,18)
    print ">"
	term.setBackgroundColor(nastaveni.barva)
	term.setTextColor(text.barva)
	term.setCursorPos(51,18)
	print "<"
    paintutils.drawPixel (51,19, colors.lightBlue)
	term.setTextColor(colors.white)
    if #tArgs > 0 then
    sDrive = tostring( tArgs[1] )
end

data = fs.open ("/system/RAM/explorer", "w")
data.writeLine(".list"..ds)
data.writeLine (user)
    data.close ()
    
    
function cteni ()
    data = fs.open ("/system/RAM/explorer", "r")
local ds = data.readLine ()
local user = data.readLine ()
    data.close ()

if fs.exists ("/system/local/"..user.."/desktop/"..ds) then
    data = fs.open ("/system/local/"..user.."/desktop/"..ds, "r")
        path1 = data.readLine ()
        name1 = data.readLine ()
        typ1 = data.readLine ()  
    path2 = data.readLine ()
    name2 = data.readLine ()
    typ2 = data.readLine ()
        path3 = data.readLine ()
        name3 = data.readLine ()
        typ3 = data.readLine ()
    path4 = data.readLine ()
    name4 = data.readLine ()
    typ4 = data.readLine ()
        path5 = data.readLine ()
        name5 = data.readLine ()
        typ5 = data.readLine ()
    path6 = data.readLine ()
    name6 = data.readLine ()
    typ6 = data.readLine ()
        path7 = data.readLine ()
        name7 = data.readLine ()
        typ7 = data.readLine ()
    path8 = data.readLine ()
    name8 = data.readLine ()
    typ8 = data.readLine ()
        path9 = data.readLine ()
        name9 = data.readLine ()
        typ9 = data.readLine ()
    data.close ()
    vypis ()
    end 
end

function vypis ()
    if typ1 == "folder" then
        local ikona = paintutils.loadImage("/system/.core/ikon/folder.nft")
        paintutils.drawImage(ikona, 5, 1)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(5,5)
    print (name1)
    elseif typ1 == "file" then
        local ikona = paintutils.loadImage("/system/.core/ikon/file.nft")
        paintutils.drawImage(ikona, 5, 1)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(5,5)
    print (name1)
    end
    
    if typ2 == "folder" then
        local ikona = paintutils.loadImage("/system/.core/ikon/folder.nft")
        paintutils.drawImage(ikona, 22, 1)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(22,5)
    print (name2)
    elseif typ2 == "file" then
        local ikona = paintutils.loadImage("/system/.core/ikon/file.nft")
        paintutils.drawImage(ikona, 22, 1)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(22,5)
    print (name2)
    end
    
    if typ3 == "folder" then
        local ikona = paintutils.loadImage("/system/.core/ikon/folder.nft")
        paintutils.drawImage(ikona, 39, 1)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(39,5)
    print (name3)
    elseif typ3 == "file" then
        local ikona = paintutils.loadImage("/system/.core/ikon/file.nft")
        paintutils.drawImage(ikona, 39, 1)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(39,5)
    print (name3)
    end
    
    if typ4 == "folder" then
        local ikona = paintutils.loadImage("/system/.core/ikon/folder.nft")
        paintutils.drawImage(ikona, 5, 7)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(5,11)
    print (name4)
    elseif typ4 == "file" then
        local ikona = paintutils.loadImage("/system/.core/ikon/file.nft")
        paintutils.drawImage(ikona, 5, 7)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(5,11)
    print (name4)
    end
    
    if typ5 == "folder" then
        local ikona = paintutils.loadImage("/system/.core/ikon/folder.nft")
        paintutils.drawImage(ikona, 22, 7)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(22,11)
    print (name5)
    elseif typ5 == "file" then
        local ikona = paintutils.loadImage("/system/.core/ikon/file.nft")
        paintutils.drawImage(ikona, 22, 7)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(22,11)
    print (name5)
    end
    
    if typ6 == "folder" then
        local ikona = paintutils.loadImage("/system/.core/ikon/folder.nft")
        paintutils.drawImage(ikona, 39, 7)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(39,11)
    print (name6)
    elseif typ6 == "file" then
        local ikona = paintutils.loadImage("/system/.core/ikon/file.nft")
        paintutils.drawImage(ikona, 39, 7)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(39,11)
    print (name6)
    end
    
    if typ7 == "folder" then
        local ikona = paintutils.loadImage("/system/.core/ikon/folder.nft")
        paintutils.drawImage(ikona, 5, 13)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(5,17)
    print (name7)
    elseif typ7 == "file" then
        local ikona = paintutils.loadImage("/system/.core/ikon/file.nft")
        paintutils.drawImage(ikona, 5, 13)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(5,17)
    print (name7)
    end
    
    if typ8 == "folder" then
        local ikona = paintutils.loadImage("/system/.core/ikon/folder.nft")
        paintutils.drawImage(ikona, 22, 13)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(22,17)
    print (name8)
    elseif typ8 == "file" then
        local ikona = paintutils.loadImage("/system/.core/ikon/file.nft")
        paintutils.drawImage(ikona, 22, 13)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(22,17)
    print (name8)
    end
    
    if typ9 == "folder" then
        local ikona = paintutils.loadImage("/system/.core/ikon/folder.nft")
        paintutils.drawImage(ikona, 39, 13)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(39,17)
    print (name9)
    elseif typ9 == "file" then
        local ikona = paintutils.loadImage("/system/.core/ikon/file.nft")
        paintutils.drawImage(ikona, 39, 13)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(39,17)
    print (name9)
    end
end

cteni ()

term.setBackgroundColor(nastaveni.barva)
term.setTextColor(text.barva)
term.setCursorPos(51,2)
print ">"
term.setCursorPos(1,2)
print "<"
if ds == 0 then
prc ("Apps for Pepdroll", 18)
elseif ds > 0 then
prc ("Desktop "..ds, 18)
end

term.setBackgroundColor(colors.lightBlue)
if fs.exists ("/system/RAM/m1") then
if not min1 == "" then
term.setCursorPos(15,19)
write "          "
end
term.setCursorPos(15,19)
write (min1)
end
if fs.exists ("/system/RAM/m2") then
term.setBackgroundColor(colors.lightGray)
if not min2 == "" then
term.setCursorPos(25,19)
write "          "
end
term.setCursorPos(25,19)
write (min2)
end
if fs.exists ("/system/RAM/m3") then
term.setBackgroundColor(colors.cyan)
if not min3 == "" then
term.setCursorPos(35,19)
write "          "
end
term.setCursorPos(35,19)
write (min3)
end

local smodem = peripheral.find("modem")

if not smodem then
  paintutils.drawPixel (45,19, colors.red)
  	term.setCursorPos(45,19)
	term.write ("M")
    else
    paintutils.drawPixel (45,19, colors.lime)
    	term.setCursorPos(45,19)
	term.write ("M")
end

if rednet.isOpen('back') == true then
a = 1
elseif rednet.isOpen('left') == true then
b = 1
elseif rednet.isOpen('right') == true then
c = 1
elseif rednet.isOpen('top') == true then
d = 1
elseif rednet.isOpen('bottom') == true then
e = 1
elseif rednet.isOpen('front') == true then
f = 1
else
a = 0
b = 0
c = 0
d = 0
e = 0
f = 0
end

if a == 1 then
    pripojeni = 1
elseif b == 1 then
    pripojeni = 1
elseif c == 1 then
    pripojeni = 1
elseif d == 1 then
    pripojeni = 1
elseif e == 1 then
    pripojeni = 1
elseif f == 1 then
    pripojeni = 1
else
    pripojeni = 0
end

if pripojeni == 0 then
  paintutils.drawPixel (44,19, colors.red)
  	term.setCursorPos(44,19)
	term.write ("W")
    W = 0
elseif pripojeni == 1 then
  if not smodem then
  paintutils.drawPixel (44,19, colors.red)
  	term.setCursorPos(44,19)
	term.write ("W")
    W = 0
    else
    paintutils.drawPixel (44,19, colors.lime)
    term.setCursorPos(44,19)
	term.write ("W")
    W = 1
end
end

local label = os.getComputerLabel()
if label then
  paintutils.drawPixel (43,19, colors.lime)
  	term.setCursorPos(43,19)
	term.write ("L")
  elseif not label then
  paintutils.drawPixel (43,19, colors.red)
    term.setCursorPos(43,19)
	term.write ("L")
end
    while true do
        
        local event, button, x, y = os.pullEvent("mouse_click")
        xy = x..","..y
		
		if x == 51 and y == 18 and button == 1 then
			local myWindow = window.create(term.current(),40,12,12,7)
		myWindow.setBackgroundColor(nastaveni.barva)
		myWindow.clear()
        myWindow.setCursorPos(3,1)
        myWindow.setTextColor(text.barva)
        myWindow.write ("Network")
		myWindow.setCursorPos(12,7)
		print ">"
		local myWindow = window.create(term.current(),41,13,10,6)
		myWindow.setBackgroundColor(colors.gray)
		myWindow.clear()
        myWindow.setCursorPos(2,3)
        myWindow.setTextColor(colors.white)
        myWindow.write( "Label:" )
						if sDrive == nil then
					myWindow.setCursorPos(2,2)
					myWindow.setTextColor(colors.white)
					print( "ID "..os.getComputerID() )
					
					local label = os.getComputerLabel()
					if label then
					myWindow.setCursorPos(2,4)
					myWindow.setTextColor(colors.lime)
						myWindow.write( "Labeled" )
                    myWindow.setTextColor(colors.white)
						myWindow.setCursorPos(2,5)
						myWindow.write(label)
                    else
                    myWindow.setCursorPos(2,4)
					myWindow.setTextColor(colors.red)
				    myWindow.write( "Unlabeled" )
                    myWindow.setTextColor(colors.white)
					end

				else
					local bData = disk.hasData( sDrive )
					if not bData then
						print( "No disk in drive "..sDrive )
						return
					end
					
					print( "The disk is #"..disk.getID( sDrive ) )

					local label = disk.getLabel( sDrive )
					if label then
						print( "The disk is labelled \""..label.."\"" )
					end
					end
					
	while true do
        local event, button, x, y = os.pullEvent("mouse_click")
        xy = x..","..y
		
		if x >= 41 and x <= 50 and y >= 17 and y <= 18 and button == 1 then
		myWindow.setCursorPos(1,5)
        term.setBackgroundColor(colors.lightGray)
		print "          "
		myWindow.setCursorPos(2,5)
		spojnice = read ()
    if spojnice == "" then
        os.setComputerLabel()
    elseif spojnice == " " then
        os.setComputerLabel()
    else
        os.setComputerLabel(spojnice)
    end
    
		plocha ()
		else
		plocha ()
		end
	end
        elseif x == 51 and y == 19 and button == 1 then
            shell.run ("/system/desktop")  
        elseif x == 45 and y == 19 and button == 1 then
            if not smodem then
			term.setCursorPos(28,1)
			term.setBackgroundColor(colors.white)
			term.setTextColor(colors.red)
			print "  Modem is not connected"
				else
			term.setCursorPos(28,1)
			term.setBackgroundColor(colors.white)
			term.setTextColor(colors.lime)
			print "      Modem is connected"
			end
    elseif x == 44 and y == 19 and button == 1 then
            if W == 0 then
			term.setCursorPos(28,1)
			term.setBackgroundColor(colors.white)
			term.setTextColor(colors.red)
			print "      Wireless disconect"
			sleep (0.5)
			pruvodcepr ()
				else
			term.setCursorPos(28,1)
			term.setBackgroundColor(colors.white)
			term.setTextColor(colors.lime)
			print "      Wireless connected"
			end
elseif x == 43 and y == 19 and button == 1 then
            if not label then
			term.setCursorPos(28,1)
			term.setBackgroundColor(colors.white)
			term.setTextColor(colors.red)
			print " Computer is not labeled"
			sleep (0.5)
			propojeni ()
				else
			term.setCursorPos(28,1)
			term.setBackgroundColor(colors.white)
			term.setTextColor(colors.lime)
			print "       Computer is label"
			end
        elseif x == 1 and y == 18 and button == 1 then
        menu ()
        elseif x == 51 and y == 19 and button == 1 then
        plocha ()
        elseif x >= 15 and x <= 24 and y == 19 and button == 1 then
            if fs.exists ("/system/RAM/m1") then
                data = fs.open ("/system/RAM/m1", "r")
                maxim = data.readLine ()
                data.close ()
				fs.delete ("/system/RAM/m1")
        if fs.exists ("/system/.core/.registry/"..maxim..".regs") then
        data = fs.open ("/system/.core/.registry/"..maxim..".regs", "r")
        filename = data.readLine ()
        path = data.readLine ()
        data.close ()
        shell.run (path)
        else
        term.setBackgroundColor(colors.white)
        term.setTextColor(colors.red)
        term.setCursorPos(31,1)
        print " Registry not found! "
        sleep (0.5)
        plocha ()
        end
            else
            return
                plocha ()
                end
        elseif x >= 25 and x <= 34 and y == 19 and button == 1 then
            if fs.exists ("/system/RAM/m2") then
                data = fs.open ("/system/RAM/m2", "r")
                maxim = data.readLine ()
                data.close ()
				fs.delete ("/system/RAM/m2")
        if fs.exists ("/system/.core/.registry/"..maxim..".regs") then
        data = fs.open ("/system/.core/.registry/"..maxim..".regs", "r")
        filename = data.readLine ()
        path = data.readLine ()
        data.close ()
        shell.run (path)
        else
        term.setBackgroundColor(colors.white)
        term.setTextColor(colors.red)
        term.setCursorPos(31,1)
        print " Registry not found! "
        sleep (0.5)
        plocha ()
        end
            else
            return
                plocha ()
                end
        elseif x >= 35 and x <= 44 and y == 19 and button == 1 then
            if fs.exists ("/system/RAM/m3") then
                data = fs.open ("/system/RAM/m3", "r")
                maxim = data.readLine ()
                data.close ()
				fs.delete ("/system/RAM/m3")
        if fs.exists ("/system/.core/.registry/"..maxim..".regs") then
        data = fs.open ("/system/.core/.registry/"..maxim..".regs", "r")
        filename = data.readLine ()
        path = data.readLine ()
        data.close ()
        shell.run (path)
        else
        term.setBackgroundColor(colors.white)
        term.setTextColor(colors.red)
        term.setCursorPos(31,1)
        print " Registry not found! "
        sleep (0.5)
        plocha ()
        end
                 else
                 return
                plocha ()
                end
        elseif x == 51 and y == 2 and button == 1 then
                ds = ds+1
                local data = fs.open("/system/RAM/desk", "w")
            data.writeLine (ds+"1")
                data.close ()
                plocha ()
        elseif x == 1 and y == 2 and button == 1 then
                ds = ds-1
                local data = fs.open("/system/RAM/desk", "w")
            data.writeLine (ds+"1")
                data.close ()
                plocha ()   
        elseif x >= 29 and x <= 32 and y == 18 and button == 1 then
            term.setBackgroundColor(nastaveni.barva)
            term.setTextColor(text.barva)
            term.setCursorPos(29,18)
            print " "
            term.setCursorPos(29,18)
            lds = ds
            ds = read ()
            
            if ds >= "0" or not ds == nil then
                local data = fs.open("/system/RAM/desk", "w")
                data.writeLine (ds+"1")
                data.close ()
                plocha ()
            elseif not ds == "0" then
                ds = "1"
            else
                ds = lds
                plocha ()
            end
            
        elseif x >= 5 and x <= 15 and y >= 1 and y <= 5 and button == 1 then
           if ftype1 == "file" then
           if fs.exists (fpath1) then
        local data = fs.open ("/system/RAM/startprogram", "w")
        data.writeLine (fname1)
        data.writeLine (fpath1)
        data.close ()
               shell.exit ()
               shell.run ("/system/api/startprogram")
               else
               plocha ()
               end
               end
        elseif x >= 22 and x <= 32 and y >= 1 and y <= 5 and button == 1 then
           if ftype2 == "file" then
           if fs.exists (fpath2) then
        local data = fs.open ("/system/RAM/startprogram", "w")
        data.writeLine (fname2)
        data.writeLine (fpath2)
        data.close ()
               shell.exit ()
               shell.run ("/system/api/startprogram")
               else
               plocha ()
               end
               end
         elseif x >= 39 and x <= 49 and y >= 1 and y <= 5 and button == 1 then
           if ftype3 == "file" then
           if fs.exists (fpath3) then
        local data = fs.open ("/system/RAM/startprogram", "w")
        data.writeLine (fname3)
        data.writeLine (fpath3)
        data.close ()
               shell.exit ()
               shell.run ("/system/api/startprogram")
               else
               plocha ()
               end
               end
               
               
        elseif x >= 5 and x <= 15 and y >= 7 and y <= 12 and button == 1 then
           if ftype4 == "file" then
           if fs.exists (fpath4) then
        local data = fs.open ("/system/RAM/startprogram", "w")
        data.writeLine (fname4)
        data.writeLine (fpath4)
        data.close ()
               shell.exit ()
               shell.run ("/system/api/startprogram")
               else
               plocha ()
               end
               end
        elseif x >= 22 and x <= 32 and y >= 7 and y <= 12 and button == 1 then
           if ftype5 == "file" then
           if fs.exists (fpath5) then
        local data = fs.open ("/system/RAM/startprogram", "w")
        data.writeLine (fname5)
        data.writeLine (fpath5)
        data.close ()
               shell.exit ()
               shell.run ("/system/api/startprogram")
               else
               plocha ()
               end
               end
         elseif x >= 39 and x <= 49 and y >= 7 and y <= 12 and button == 1 then
           if ftype6 == "file" then
           if fs.exists (fpath6) then
        local data = fs.open ("/system/RAM/startprogram", "w")
        data.writeLine (fname6)
        data.writeLine (fpath6)
        data.close ()
               shell.exit ()
               shell.run ("/system/api/startprogram")
               else
               plocha ()
               end
               end
               
        elseif x >= 5 and x <= 15 and y >= 13 and y <= 18 and button == 1 then
           if ftype7 == "file" then
           if fs.exists (fpath7) then
        local data = fs.open ("/system/RAM/startprogram", "w")
        data.writeLine (fname7)
        data.writeLine (fpath7)
        data.close ()
               shell.exit ()
               shell.run ("/system/api/startprogram")
               else
               plocha ()
               end
               end      
        elseif x >= 22 and x <= 32 and y >= 13 and y <= 18 and button == 1 then
           if ftype8 == "file" then
           if fs.exists (fpath8) then
        local data = fs.open ("/system/RAM/startprogram", "w")
        data.writeLine (fname8)
        data.writeLine (fpath8)
        data.close ()
               shell.exit ()
               shell.run ("/system/api/startprogram")
               else
               plocha ()
               end
               end     
         elseif x >= 39 and x <= 49 and y >= 13 and y <= 18 and button == 1 then
           if ftype9 == "file" then
           if fs.exists (fpath9) then
        local data = fs.open ("/system/RAM/startprogram", "w")
        data.writeLine (fname9)
        data.writeLine (fpath9)
        data.close ()
               shell.exit ()
               shell.run ("/system/api/startprogram")
               else
               plocha ()
               end   
               end
               
        elseif button == 2 then
            if x >= 41 then
                x = 40
                end
            if y >= 15 then
                y = 14
                end
                
            local myWindow = window.create(term.current(),x,y,12,4)
            myWindow.setBackgroundColor(colors.white)
            myWindow.clear()
            paintutils.drawLine(x, y, x, y+3, nastaveni.barva)
            paintutils.drawLine(x, y-1, x+11, y-1, nastaveni.barva)
            term.setTextColor(text.barva)
            term.setCursorPos (x,y)
            write ">"
            term.setCursorPos (x,y+1)
            write ">"
            term.setCursorPos (x,y+2)
            write ">"
            term.setCursorPos (x,y+3)
            write ">"
            term.setBackgroundColor(colors.white)
            term.setTextColor(colors.black)
            term.setCursorPos (x+1,y)
            write "New Folder"
            term.setCursorPos (x+1,y+1)
            write "New File"
            term.setCursorPos (x+1,y+2)
            write "Delete"
            term.setCursorPos (x+1,y+3)
            write "Theme"
            PosX = x
            PosY = y
      while true do
        local event, button, x, y = os.pullEvent("mouse_click")
        xy = x..","..y
		
        if x >= PosX and x <= PosX+10 and y == PosY and button == 1 then
            local myWindow = window.create(term.current(),PosX,PosY-1,12,7)
            myWindow.setBackgroundColor(colors.black)
            myWindow.clear()
            local myWindow = window.create(term.current(),PosX+1,PosY,10,5)
            myWindow.setBackgroundColor(colors.white)
            myWindow.clear()
            term.setCursorPos (PosX+1,PosY+1)
            term.setBackgroundColor(colors.yellow)
            term.setTextColor(colors.black)
            print "Fold. name"
            term.setBackgroundColor(colors.gray)
            term.setTextColor(colors.white)
            term.setCursorPos (PosX+1,PosY+3)
            print "          "
            term.setCursorPos (PosX+1,PosY+3)
            novaslozka = nil
            novaslozka = read ()
            if novaslozka == "" then
                plocha ()
                else
            fs.delete ("/system/RAM/novydokument")
            local data = fs.open("/system/RAM/novydokument", "w")
            data.writeLine ("/system/local/"..user.."/desktop/"..novaslozka)
            data.writeLine (novaslozka)
            data.writeLine ("folder")
            data.writeLine (user)
            data.writeLine (ds+"1")
                data.close ()

            shell.run ("/system/api/novydok")
                end
		elseif x >= PosX and x <= PosX+10 and y == PosY+1 and button == 1 then
            local myWindow = window.create(term.current(),PosX,PosY-1,12,7)
            myWindow.setBackgroundColor(colors.black)
            myWindow.clear()
            local myWindow = window.create(term.current(),PosX+1,PosY,10,5)
            myWindow.setBackgroundColor(colors.white)
            myWindow.clear()
            term.setCursorPos (PosX+1,PosY+1)
            term.setBackgroundColor(colors.yellow)
            term.setTextColor(colors.black)
            print "File name "
            term.setBackgroundColor(colors.lightGray)
            term.setTextColor(colors.white)
            term.setCursorPos (PosX+1,PosY+3)
            print "          "
            term.setCursorPos (PosX+1,PosY+3)
            novysoubor = nil
            novysoubor = read ()
            if novysoubor == "" then
                plocha ()
            elseif novysoubor == " " then
                plocha ()
            else
            fs.delete ("/system/RAM/novydokument")
            local data = fs.open("/system/RAM/novydokument", "w")
            data.writeLine ("/system/local/"..user.."/desktop/"..novysoubor)
            data.writeLine (novysoubor)
            data.writeLine ("file")
            data.writeLine (user)
            data.writeLine (ds+"1")
            data.close ()
                
            shell.run ("/system/api/novydok")
            end
        elseif x >= PosX and x <= PosX+10 and y == PosY+2 and button == 1 then
            local myWindow = window.create(term.current(),PosX,PosY-1,12,7)
            myWindow.setBackgroundColor(colors.black)
            myWindow.clear()
            local myWindow = window.create(term.current(),PosX+1,PosY,10,5)
            myWindow.setBackgroundColor(colors.white)
            myWindow.clear()
            term.setCursorPos (PosX+1,PosY+1)
            term.setBackgroundColor(colors.yellow)
            term.setTextColor(colors.black)
            print " Filename "
            term.setCursorPos (PosX+1,PosY+3)
            print "File      "
            term.setCursorPos (PosX+1,PosY+4)
            print "Folder    "
            term.setBackgroundColor(colors.lightGray)
            term.setTextColor(colors.white)
            term.setCursorPos (PosX+1,PosY+2)
            print "          "
            term.setCursorPos (PosX+1,PosY+2)
            smazat = nil
            smazat = read ()
            if smazat == "" then
                plocha ()
            elseif smazat == " " then
                plocha ()
            end
            
            while true do
                
            	local event, button, x, y = os.pullEvent("mouse_click")
                    xy = x..","..y
            		
            		if x >= PosX+1 and x <= PosX+10 and y == PosY+3 and button == 1 then
                            typ = "file"
                    elseif x >= PosX+1 and x <= PosX+10 and y == PosY+4 and button == 1 then
            		        typ = "folder"
                    end
                    
            local data = fs.open("/system/RAM/delete", "w")
            data.writeLine (smazat)
            data.writeLine (user)
            data.writeLine (typ)
            data.writeLine (ds+"1")
                data.close ()
                
                local data = fs.open("/system/RAM/deletes", "w")
            data.writeLine (smazat)
            data.writeLine (user)
            data.writeLine (typ)
            data.writeLine (ds+"1")
                data.close ()
            shell.run ("/system/api/delete")
            end
        elseif x >= PosX and x <= PosX+10 and y == PosY+3 and button == 1 then
            local data = fs.open ("/system/RAM/setdata", "w")
        	data.writeLine("theme")
        	data.close ()
        local data = fs.open ("/system/RAM/startprogram", "w")
        data.writeLine ("setting")
        data.writeLine ("/system/programs/setting")
        data.close ()    
        o=fs.open ("/system/RAM/setting", "w")
        o.writeLine (userI)
        o.writeLine (passI)
        o.close ()   
        shell.run ("/system/api/startprogram")
        else
        plocha ()
            end
            end
            else
            plocha ()
		end
	end
end

function maximalizace ()
    if fs.exists ("/system/.core/.registry/"..maxim..".regs") then
        data = fs.open ("/system/.core/.registry/"..maxim..".regs", "r")
        filename = data.readLine ()
        path = data.readLine ()
        data.close ()
        shell.run (path)
        else
        term.setBackgroundColor(colors.white)
        term.setTextColor(colors.red)
        term.setCursorPos(31,1)
        print " Registry not found! "
        sleep (0.5)
        plocha ()
        end
        end
               
function pruvodcepr ()
	local myWindow = window.create(term.current(),17,7,22,10)
    myWindow.setBackgroundColor(colors.gray)
    myWindow.clear()
    local myWindow = window.create(term.current(),16,6,22,10)
    myWindow.setBackgroundColor(colors.lime)
    myWindow.clear()
    local myWindow = window.create(term.current(),17,7,20,8)
    myWindow.setBackgroundColor(colors.white)
    myWindow.clear()
    paintutils.drawPixel (37,6, colors.red)
    term.setCursorPos(37,6)
    print "*"
	
	term.setBackgroundColor(colors.lightGray)
	if pripojka == "top" then
		myWindow.setCursorPos(2,4)
		print "Top"
	else
	term.setBackgroundColor(colors.gray)
	myWindow.setCursorPos(4,8)
	print " Auto  Repair "
	term.setBackgroundColor(colors.white)
	term.setTextColor(colors.black)
	myWindow.setCursorPos(2,1)
	print "Connection Manager"
	myWindow.setCursorPos(2,3)
	print "  Manual connect  "
	myWindow.setCursorPos(2,4)
	print "Top         Bottom"
	myWindow.setCursorPos(2,5)
	print "Left         Right"
	myWindow.setCursorPos(2,6)
	print "Front         Back"
	end
	
	while true do
	local event, button, x, y = os.pullEvent("mouse_click")
        xy = x..","..y
		
		if x >= 37 and x <= 37 and y == 6 and button == 1 then
		plocha ()
		elseif x >= 18 and x <= 20 and y == 10 and button == 1 then
		pripojka = "top"
		connecting ()
		elseif x >= 18 and x <= 21 and y == 11 and button == 1 then
		pripojka = "left"
		connecting ()
		elseif x >= 18 and x <= 21 and y == 12 and button == 1 then
		pripojka = "front"
		connecting ()
		elseif x >= 30 and x <= 36 and y == 10 and button == 1 then
		pripojka = "bottom"
		connecting ()
		elseif x >= 31 and x <= 36 and y == 11 and button == 1 then
		pripojka = "right"
		connecting ()
		elseif x >= 32 and x <= 36 and y == 12 and button == 1 then
		pripojka = "back"
		connecting ()
		elseif x >= 20 and x <= 33 and y == 14 and button == 1 then
		
		local function openRednet()
  for _,side in ipairs({"top", "bottom", "back", "left", "right", "front"}) do
        if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
          rednet.open(side)
          return side
        end
  end
end

modemSide = openRednet()
if modemSide == nil then
	term.setCursorPos(18,13)
		term.setTextColor(colors.red)
		print "No modem found!"
		sleep (1)
		plocha ()
else
  term.setCursorPos(17,13)
		term.setTextColor(colors.lime)
		print ("Connected on: "..modemSide)
		sleep (1)
		plocha ()
end

		end
	end
	
end

function connecting ()
	local function openRednet()
  for _,side in ipairs({pripojka}) do
        if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
          rednet.open(side)
          return side
        end
  end
end

modemSide = openRednet()
if modemSide == nil then
  term.setCursorPos(18,13)
		term.setTextColor(colors.red)
		print "Error - Bad modem!"
		sleep (1)
		plocha ()
else
		term.setCursorPos(18,13)
		term.setTextColor(colors.lime)
		print "Successful"
		sleep (1)
		plocha ()
end
    end

function propojeni()
	local myWindow = window.create(term.current(),17,7,22,10)
    myWindow.setBackgroundColor(colors.gray)
    myWindow.clear()
    local myWindow = window.create(term.current(),16,6,22,10)
    myWindow.setBackgroundColor(colors.lime)
    myWindow.clear()
    local myWindow = window.create(term.current(),17,7,20,8)
    myWindow.setBackgroundColor(colors.white)
    myWindow.clear()
    paintutils.drawPixel (37,6, colors.red)
    term.setCursorPos(37,6)
    print "*"
	
	term.setBackgroundColor(colors.gray)
	myWindow.setCursorPos(4,8)
	print "   Set Label  "
	term.setBackgroundColor(colors.white)
	term.setTextColor(colors.black)
	myWindow.setCursorPos(2,1)
	print "Connection Manager"
	myWindow.setCursorPos(2,3)
	print "  Manual label  "
	myWindow.setCursorPos(2,5)
	term.setTextColor(colors.white)
	term.setBackgroundColor(colors.lightGray)
	print "                  "
	myWindow.setCursorPos(3,5)
	print (spojovak)
	
	while true do
	local event, button, x, y = os.pullEvent("mouse_click")
        xy = x..","..y
		
		if x >= 37 and x <= 37 and y == 6 and button == 1 then
		plocha ()
		elseif x >= 18 and x <= 36 and y == 11 and button == 1 then
		myWindow.setCursorPos(2,5)
        term.setBackgroundColor(colors.gray)
		print "                  "
		myWindow.setCursorPos(3,5)
		spojovak = read ()
		elseif x >= 20 and x <= 33 and y == 14 and button == 1 then
    if spojovak == "" then
		os.setComputerLabel()
    elseif spojovak == " " then
        os.setComputerLabel()
    else
        os.setComputerLabel(spojovak)
    end
	plocha ()
end
end
end
	
function menu ()
    if fs.exists ("/system/.core/lsprogram") then
        local data = fs.open ("/system/.core/lsprogram", "r")
                menu1 = data.readLine ()
                path1 = data.readLine ()
                menu2 = data.readLine ()
                path2 = data.readLine ()
                menu3 = data.readLine ()
                path3 = data.readLine ()
                menu4 = data.readLine ()
                path4 = data.readLine ()
                menu5 = data.readLine ()
                path5 = data.readLine ()
                menu6 = data.readLine ()
                path6 = data.readLine ()
                menu7 = data.readLine ()
                path7 = data.readLine ()
    		data.close ()
        end
    local myWindow = window.create(term.current(),1,8,15,19)
    myWindow.setBackgroundColor(colors.gray)
    myWindow.clear()
    term.setCursorPos(1,18)
    term.setBackgroundColor(colors.white)
    term.setTextColor(colors.lightGray)
    write "           "
    term.setCursorPos(1,18)
    write (vyhledatold)
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.white)
    term.setCursorPos(2,19)
    write "Power"
     term.setCursorPos(13,18)
    write "->"
    term.setCursorPos(4,8)
    print (user)
    term.setCursorPos(2,10)
    print (menu1)
    term.setCursorPos(2,11)
    print (menu2)
    term.setCursorPos(2,12)
    print (menu3)
    term.setCursorPos(2,13)
    print (menu4)
    term.setCursorPos(2,14)
    print (menu5)
    term.setCursorPos(2,15)
    print (menu6)
    term.setCursorPos(2,16)
    print (menu7)
    term.setTextColor(colors.lightGray)
    term.setCursorPos(1,17)
    print "Managment"
    term.setCursorPos(1,9)
    print "Menu"
    
    while true do 
    local event, button, x, y = os.pullEvent("mouse_click")
    xy = x..","..y
    
        if x == 2 and y >= 2 and y <= 7 and button == 1 then
        plocha ()
        elseif x >= 1 and x <= 15 and y == 10 and button == 1 then
		if menu1 == "" then
		plocha ()
		else
        path = menu1
        pathr = path1
		end
        elseif x >= 1 and x <= 15 and y == 11 and button == 1 then
		if menu2 == "" then
		plocha ()
		else
        path = menu2
        pathr = path2
		end
        elseif x >= 1 and x <= 15 and y == 12 and button == 1 then
		if menu3 == "" then
		plocha ()
		else
        path = menu3
        pathr = path3
		end
        elseif x >= 1 and x <= 15 and y == 13 and button == 1 then
		if menu4 == "" then
		plocha ()
		else
        path = menu4
        pathr = path4
		end
        elseif x >= 1 and x <= 15 and y == 14 and button == 1 then
		if menu5 == "" then
		plocha ()
		else
        path = menu5
        pathr = path5
		end
        elseif x >= 1 and x <= 15 and y == 15 and button == 1 then
		if menu6 == "" then
		plocha ()
		else
        path = menu6
        pathr = path6
		end
        elseif x >= 1 and x <= 15 and y == 16 and button == 1 then
		if menu7 == "" then
		plocha ()
		else
        path = menu7
        pathr = path7
		end
        elseif x >= 1 and x <= 15 and y == 19 and button == 1 then
        local myWindow = window.create(term.current(),2,17,8,19)
        myWindow.setBackgroundColor(colors.lightGray)
        myWindow.clear()
        term.setBackgroundColor(colors.lightGray)
        term.setCursorPos(2,17)
        write " Sleep    "
        term.setCursorPos(2,18)
        write " Restart  "
        term.setCursorPos(2,19)
        write " Shutdown "
        while true do 
        local event, button, x, y = os.pullEvent("mouse_click")
        xy = x..","..y
        
        if x >= 2 and x <= 11 and y == 17 and button == 1 then
        spanek ()
        elseif x >= 2 and x <= 11 and y == 18 and button == 1 then
        fs.makeDir("/system/RAM/restart")
        shell.run ("/system/api/modes")
        elseif x >= 2 and x <= 11 and y == 19 and button == 1 then
        fs.makeDir("/system/RAM/vypnout")
        shell.run ("/system/api/modes")
        else
        plocha ()
        end
        end
        elseif x >= 1 and x <= 11 and y == 18 and button == 1 then
        term.setCursorPos(1,18)
        term.setBackgroundColor(colors.white)
        write "           "
        term.setCursorPos(1,18)
        vyhledat = read ()
            if vyhledat == "cmd" then
                shell.run ("/system/api/commander")
            elseif vyhledat == "net" then
                shell.run ("/system/api/internet")
            elseif vyhledat == "shut" then
                fs.makeDir("/system/RAM/vypnout")
                shell.run ("/system/api/modes")
            elseif vyhledat == "hshut" then
                os.shutdown ()
            elseif vyhledat == "hrest" then
                os.reboot ()
                shell.run ("/system/api/modes")
            elseif vyhledat == "rest" then
                fs.makeDir("/system/RAM/restart")
                shell.run ("/system/api/modes")
            elseif vyhledat == "setting" then
                shell.run ("/system/local/programs/setting")
            else
        vyhledatold = vyhledat
        vyhledat = nil
        plocha ()
        end
        end
		
		if path == "" then
			plocha ()
		elseif path == nil then
			plocha ()
		end
	   
local data = fs.open ("/system/RAM/startprogram", "w")
        data.writeLine (path)
        data.writeLine (pathr)
        data.close ()
        path = nil
        pathr = nil
        spustit ()
        
        
end
end

function chyba ()
           term.setBackgroundColor(colors.red)
	term.setTextColor(colors.white)
	prc ("   Error = Program not found   ", 9)
    sleep (0.5)
    plocha ()
    end
    
menuname = nil
pathr = nil

function spustit ()
term.setBackgroundColor(colors.white)
local image = paintutils.loadImage("/system/.core/ikon/logo.nft")
    term.setBackgroundColor(colors.white)
    term.setTextColor (colors.black)
    term.clear ()
    paintutils.drawImage(image, 12, 4)
    term.setBackgroundColor(colors.white)
    prc ("Loading program ...", 15)
	term.setCursorPos(1,17)
    
    local data = fs.open ("/system/RAM/startprogram", "r")
        menuname = data.readLine ()
        pathr = data.readLine ()
        data.close ()
		fs.delete ("/system/RAM/startprogram")
    
        
   if not menuname == nil then
       chyba ()
   end
   
   if not fs.exists ("/system/.core/.registry/"..menuname..".regs") then
       if fs.exists (pathr) then
           sleep (0.3)
        shell.run (pathr)
        else
        chyba ()
        end
      chyba ()
   end
       
     local data = fs.open ("/system/.core/.registry/"..menuname..".regs", "r")
        filename = data.readLine ()
        cesta = data.readLine ()
        pastebincode = data.readLine ()
        menuname = data.readLine ()
        poradi = data.readLine ()
    data.close ()
    sleep (0.3)
    shell.run (cesta)
    shell.run ("/system/api/bluescreen")
    
end   
    
function spanek ()
term.setBackgroundColor(colors.lightGray)
term.clear()
sleep (0.1)
term.setBackgroundColor(colors.gray)
term.clear()
sleep (0.1)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.black)
term.clear()
while true do
  local event, button, xPos, yPos = os.pullEvent("mouse_click")
  plocha ()
end
end

plocha ()