installer.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. --The OS Installer
  2. local devmode = (love.filesystem.getInfo("/devmode.txt") and true or false) or (_LVer.tag == "DEV")
  3. local HandledAPIS, osName, update = ...
  4. local Title = ""
  5. if update then
  6. Title = "=--------< Updating "..osName.." >--------="
  7. else
  8. Title = "=-------< Installing "..osName.." >-------="
  9. devmode = false
  10. end
  11. local GPU = HandledAPIS.GPU
  12. local CPU = HandledAPIS.CPU
  13. local fs = HandledAPIS.HDD
  14. local sw,sh = GPU.screenSize()
  15. local tw,th = GPU.termSize()
  16. local fw,fh = GPU.fontSize()
  17. --Draws the progress bar, takes a value between 0 and 1, nil for no progress bar.
  18. local function drawProgress(float)
  19. if devmode then return end
  20. GPU.rect(0,sh-9, sw,9, false, 7) --Draw the bar
  21. if not float then return end --If no progress value then we are done.
  22. --The progress bar "=" chars
  23. local progChars = math.floor(float*32+0.5)
  24. local progStr = string.rep("=", progChars)..string.rep(" ", 32-progChars)
  25. --The % percentage.
  26. local precent = tostring(math.floor(float*100+0.5))
  27. precent = string.rep(" ",3-precent:len())..precent
  28. --Draw the text.
  29. GPU.color(0) GPU.print("["..progStr.."]"..precent.."%",1, sh-7)
  30. end
  31. if not devmode then
  32. --Draw the GUI
  33. GPU.clear(5) --Clear the screen
  34. GPU.rect(0,0,sw,9, false, 7) --The top bar
  35. GPU.color(0) GPU.print(Title, 1,2, sw, "center") --Draw the title.
  36. drawProgress(1) --Draw the bottom bar.
  37. end
  38. --Display a log message
  39. local function display(text)
  40. if devmode then return end
  41. --Push the text up
  42. GPU.screenshot(0,9+fh+2,sw,sh-9-fh-2-9):image():draw(0,9)
  43. --Clear the last line
  44. GPU.rect(0,sh-8-fh-3,sw,fh+2,false,5)
  45. --Display the new message
  46. GPU.color(6) GPU.print(tostring(text),1,sh-9-fh-2)
  47. --Make sure that it's shown to the user
  48. GPU.flip()
  49. end
  50. if update then
  51. display("Indexing Files")
  52. local function index(path, list)
  53. local path = path or "/OS/DiskOS/"
  54. local list = list or {}
  55. local items = love.filesystem.getDirectoryItems(path)
  56. for id, item in ipairs(items) do
  57. if love.filesystem.getInfo(path..item,"directory") then
  58. table.insert(list,path..item)
  59. index(path..item.."/", list)
  60. else
  61. table.insert(list,path..item)
  62. end
  63. end
  64. return list
  65. end
  66. local OSPath = "/OS/"..osName.."/"
  67. local OSPathLen = OSPath:len()
  68. local OSFiles = index("/OS/"..osName.."/")
  69. drawProgress(0)
  70. display("Updating Files...")
  71. for k, path in ipairs(OSFiles) do
  72. local HDDPath = "C:/"..path:sub(OSPathLen+1,-1)
  73. if fs.exists(HDDPath) then
  74. local info = love.filesystem.getInfo(path,"file")
  75. if info then
  76. local newDate = assert(info.modtime,"failed to get mod time")
  77. local oldDate = assert(fs.getLastModified(HDDPath))
  78. if newDate > oldDate then
  79. local data = love.filesystem.read(path)
  80. fs.write(HDDPath,data)
  81. display("Updated File: "..HDDPath)
  82. end
  83. end
  84. else --New File/Directory
  85. if love.filesystem.getInfo(path,"directory") then
  86. fs.newDirectory(HDDPath)
  87. display("New Directory: "..HDDPath)
  88. else
  89. local data = love.filesystem.read(path)
  90. fs.write(HDDPath,data)
  91. display("New File: "..HDDPath)
  92. end
  93. end
  94. drawProgress(k/#OSFiles)
  95. end
  96. else ---INSTALL--------------------------------------------
  97. display("Indexing Files")
  98. local function index(path, list)
  99. local path = path or "/OS/DiskOS/"
  100. local list = list or {}
  101. local items = love.filesystem.getDirectoryItems(path)
  102. for id, item in ipairs(items) do
  103. if love.filesystem.getInfo(path..item,"directory") then
  104. table.insert(list,path..item)
  105. index(path..item.."/", list)
  106. else
  107. table.insert(list,path..item)
  108. end
  109. end
  110. return list
  111. end
  112. local OSPath = "/OS/"..osName.."/"
  113. local OSPathLen = OSPath:len()
  114. local OSFiles = index("/OS/"..osName.."/")
  115. drawProgress(0)
  116. for k, path in ipairs(OSFiles) do
  117. local HDDPath = "C:/"..path:sub(OSPathLen+1,-1)
  118. if love.filesystem.getInfo(path,"directory") then
  119. fs.newDirectory(HDDPath)
  120. display("Directory: "..HDDPath)
  121. else
  122. local data = love.filesystem.read(path)
  123. fs.write(HDDPath,data)
  124. display("File: "..HDDPath)
  125. end
  126. drawProgress(k/#OSFiles)
  127. end
  128. end
  129. GPU.clear(0)