Advertisement
CaptainSpaceCat

appstore

May 16th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.28 KB | None | 0 0
  1. os.loadAPI("iostabs")
  2. os.loadAPI("iosutils")
  3. os.loadAPI("iostabsinit")
  4. w, h = term.getSize()
  5. term.setBackgroundColor(colors.lightBlue)
  6. term.clear()
  7. iosutils.centerAlign("App Store", 1, colors.white, colors.lightBlue)
  8. iosutils.leftAlign("Image Filename: ", 3, colors.white, colors.lightBlue)
  9. iosutils.leftAlign("Program Filename: ", 4, colors.white, colors.lightBlue)
  10. iosutils.leftAlign("App Name: ", 5, colors.white, colors.lightBlue)
  11. term.setCursorPos(17, 3)
  12. iImage = read()
  13. term.setCursorPos(19, 4)
  14. iProgram = read()
  15. term.setCursorPos(11, 5)
  16. iName = read()
  17. iName = "\"" .. iName .. "\""
  18.  
  19. --ensures that there aren't any broken string errors--
  20. if string.sub(iProgram, 0, 1) ~= "\"" then
  21.   iProgram = "\"" .. iProgram
  22. end
  23. if string.sub(iProgram, string.len(iProgram)) ~= "\"" then
  24.   iProgram = iProgram .. "\""
  25. end
  26. if string.sub(iImage, 0, 1) ~= "\"" then
  27.   iImage = "\"" .. iImage
  28. end
  29. if string.sub(iImage, string.len(iImage)) ~= "\"" then
  30.   iImage = iImage .. "\""
  31. end
  32.  
  33. local error1 = ""
  34. local error2 = ""
  35. if not fs.exists(iProgram) then
  36.   error1 = "ERROR: Program doesn't exist"
  37. end
  38. if not fs.exists(iImage) then
  39.   error2 = "ERROR: Image file doesn't exist"
  40. end
  41. if error1 ~= "" or error2 ~= "" then
  42.   term.setTextColor(colors.red)
  43.   if error1 ~= "" then
  44.     print(error1)
  45.   end
  46.   print(error2)
  47.   sleep(2)
  48.   oos.exit("appstore")
  49. end
  50.  
  51. --collects page number based off the number of apps--
  52. local num = 1
  53. local pagenumcount = 1
  54. local pagenum = 0
  55. local triplenumcount = 1
  56. local triplenum = 0
  57. for i, v in pairs(iostabsinit.appslist) do
  58.   num = num + 1
  59.   pagenumcount = pagenumcount + 1
  60.   triplenumcount = triplenumcount + 1
  61.   if triplenumcount == 4 then
  62.     triplenum = triplenum + 1
  63.     triplenumcount = 1
  64.   end
  65.   if pagenumcount == 10 then
  66.     pagenum = pagenum + 1
  67.     pagenumcount = 1
  68.   end
  69. end
  70.  
  71. --collects image height and width--
  72. local ix = 1
  73. local iy = 1
  74. local ix2 = 0
  75. local iy2 = 0
  76. local ix2max = 0
  77. local iImageInfo = paintutils.loadImage(iImage)
  78. for i, v in pairs(iImageInfo) do
  79.   iy2 = iy2 + 1
  80.   ix2 = 0
  81.   for k, e in pairs(iImageInfo[i]) do
  82.     ix2 = ix2 + 1
  83.     if ix2 > ix2max then
  84.       ix2max = ix2
  85.     end
  86.   end
  87. end
  88.  
  89. if ix2 > 8 or iy2 > 6 then
  90.   term.setTextColor(colors.red)
  91.   print("ERROR: Image is too big, must be 8*6px max")
  92.   sleep(2)
  93.   oos.exit("appstore")
  94. end
  95.  
  96. --sets position for image--
  97. ix2 = ix2max
  98. ixOff = math.floor(4 - ix2 / 2)
  99. iyOff = math.floor(3 - iy2 / 2)
  100. --ix = ix + ((num - 1) % 3) * 9 + ixOff + (page - 1) * w
  101. local xtest = num - triplenum * 3
  102. local ixmultiply = 0
  103. if xtext == 1 then
  104.   ixmultiply = 0
  105. elseif xtest == 2 then
  106.   ixmultiply = 1
  107. elseif xtest == 3 then
  108.   ixmultiply = 2
  109. end
  110. ix = math.floor(ix + ixmultiply * 9 + ixOff + pagenum * w)
  111. ix2 = math.floor(ix2 + ix) - 1
  112. --iy = iy + math.floor((((num - 1) - (page - 1) * 9) / 3) - 0.1) * 7 + iyOff
  113. local ytest = num - pagenum * 9
  114. local iymultiply = 0
  115. if ytest >= 1 and ytest <= 3 then
  116.   iymultiply = 0
  117. elseif ytest >= 4 and ytest <= 6 then
  118.   iymultiply = 1
  119. elseif ytest >= 7 and ytest <= 9 then
  120.   iymultiply = 2
  121. end
  122. iy = math.floor(iy + iymultiply * 7 + iyOff)
  123. iy2 = math.floor(iy2 + iy) - 1
  124.  
  125. --begins writing files--
  126. oTemp = fs.open("temp", "w")
  127. for line in io.lines("iostabsinit") do
  128.   oTemp.writeLine(line)
  129. end
  130. oTemp.writeLine("appslist[" .. num .. "] = " .. iName)
  131. oTemp.flush()
  132. oTemp.close()
  133. shell.run("delete iostabsinit")
  134. shell.run("copy temp iostabsinit")
  135. shell.run("delete temp")
  136. os.loadAPI("iostabsinit")
  137.  
  138. oTemp = fs.open("temp", "w")
  139. for line in io.lines("iostabs") do
  140.   oTemp.writeLine(line)
  141. end
  142. oTemp.writeLine("appsinit[" .. num .. "][1] = " .. ix)
  143. oTemp.writeLine("appsinit[" .. num .. "][2] = " .. iy)
  144. oTemp.writeLine("appsinit[" .. num .. "][3] = " .. ix2)
  145. oTemp.writeLine("appsinit[" .. num .. "][4] = " .. iy2)
  146. oTemp.writeLine("appsinit[" .. num .. "][5] = paintutils.loadImage(" .. iImage .. ")")
  147. oTemp.writeLine("appsinit[" .. num .. "][6] = " .. iProgram)
  148. oTemp.flush()
  149. oTemp.close()
  150. shell.run("delete iostabs")
  151. shell.run("copy temp iostabs")
  152. shell.run("delete temp")
  153. os.loadAPI("iostabs")
  154.  
  155. --completed, finalizing results--
  156. function debugPrint()
  157.   for i, v in pairs(iostabs.appsinit) do
  158.     for k, e in pairs(iostabs.appsinit[i]) do
  159.       print(e)
  160.     end
  161.   end
  162. end
  163. print("App sucessfully installed!")
  164. sleep(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement