Andy73

AndyCode Archiver v.0.4

Apr 21st, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.85 KB | None | 0 0
  1. --[[
  2. Pure Lua archiver made by Andy73 a.k.a. viluon
  3.  
  4. Copyright 2014
  5. version 0.4 BETA (6th public release)
  6.  
  7. usage: archiver <compress|extract|help> <file input path> <file output path>
  8.  
  9. CAN CONTAIN SOME BUGS :/ I was kinda hurrying to release it in time
  10. ]]
  11.  
  12. local s="?"
  13. local tArgs={...}
  14. local t=nil
  15. local tOrigin={}
  16. local tDictionaryA={
  17. "@",
  18. "#",
  19. "$",
  20. "*",
  21. "&",
  22. "/",
  23. "~",
  24. "|",
  25. "!",
  26. "•",
  27. "√",
  28. "π",
  29. "÷",
  30. "×",
  31. "£",
  32. "¢",
  33. "€",
  34. "°",
  35. "_",
  36. "™",
  37. "®",
  38. "©",
  39. "¶",
  40. "^", }
  41. local tDictionaryB={
  42. "á",
  43. "à",
  44. "â",
  45. "ä",
  46. "æ",
  47. "ã",
  48. "å",
  49. "ā",
  50. "ě",
  51. "é",
  52. "è",
  53. "ê",
  54. "ë",
  55. "ę",
  56. "ė",
  57. "ē",
  58. "ï",
  59. "î",
  60. "í",
  61. "ī",
  62. "ì",
  63. "į",
  64. "ò",
  65. "ô",
  66. "ö",
  67. "ó",
  68. "ō",
  69. "ø",
  70. "œ",
  71. "õ",
  72. "ů",
  73. "ú",
  74. "û",
  75. "ü",
  76. "ù",
  77. "ū",
  78. "ý",
  79. "ÿ",
  80.  
  81. "ř",
  82. "ť",
  83. "ź",
  84. "ž",
  85. "ż",
  86. "š",
  87. "ß",
  88. "ś",
  89. "ď",
  90. "ć",
  91. "č",
  92. "ç",
  93. "ń",
  94. "ň",
  95. "ñ",
  96. "`", }
  97.  
  98.  
  99. local function help()
  100. print("Pure Lua archiver by Andy a.k.a. viluon copyright 2014")
  101. print("version 0.4 BETA")
  102. print("")
  103. print("Current dictionary size: "..s.." keywords")
  104. print("") term.setBackgroundColor(colors.cyan)
  105. print(string.rep("-",term.getSize())) term.setTextColor(colors.black)
  106. print("FAQ: I am getting an error when accessing a file in ../ directory")
  107. print("  Yes, that is a common problem, I am working on a fix now. Please use the current directory until I fix this (some weird behaviour in shell.resolve :( )") term.setBackgroundColor(colors.black);term.setTextColor(colors.white)
  108. print("Please note:Beta versions can cause unexpected data changes. Andy is not responsible for any data corruption or removals caused by this program. Use at your own risk.")
  109. end
  110.  
  111. local function usage()
  112. print("Usage:")
  113. print(" archiver <compress|extract|help> <file input path> <file output path>")
  114. print("'compress','extract' or 'help' can be shortened to 'c','e' or '?'")
  115. end
  116.  
  117. local function loadOrg()
  118. local iorg=0
  119. local org=fs.open(shell.resolve(".").."/org","r")
  120. if org then
  121. line=org.readLine()
  122. while line do
  123. iorg=iorg+1
  124. table.insert(tOrigin,iorg,line)
  125. line=org.readLine()
  126. --print(iorg)
  127. end
  128. org:close()
  129. s=iorg
  130. else
  131. error("Origin file doesn't exist (\"./org\").")
  132. end
  133. end
  134.  
  135. local function r(a,b)
  136. t=string.gsub(t,a,b)
  137. end
  138.  
  139. --COMPRESS
  140. local function compress(...)
  141. local args={...}--ARGS ARE SOLVED BEFORE!!!
  142. local file=fs.open(shell.resolve(tostring(args[1])),"r")
  143. print("FileSize original:"..fs.getSize(shell.resolve(tostring(args[1])))) --print("asd")
  144. if file then t=file.readAll() else error("Can't open:Requested source file doesn't exist.") end
  145. file:close()
  146. local b=0
  147. for a=1,#tDictionaryA do
  148.     for index=1,#tDictionaryB do
  149.      b=b+1
  150.      if b>#tOrigin then break end
  151.      
  152.      r(tostring(tOrigin[b]),tostring(tDictionaryA[a])..tostring(tDictionaryB[index]))
  153.     end
  154.    end
  155.  
  156. local target=fs.open(shell.resolve(tostring(args[2])),"w")
  157. if not target then error("Can't write:Taget path is invalid. Check the help for more info.") end
  158. target.write(t)
  159. target:close()
  160.  
  161. print("FileSize comprimed:"..fs.getSize(shell.resolve(args[2])))
  162. local one=tonumber(fs.getSize(shell.resolve(args[1])))/100
  163. local size=fs.getSize(shell.resolve(args[2]))
  164. local calc=tonumber(size/one)
  165.  
  166. --[[DEBUG
  167. print("fs.getSize(...):"..fs.getSize(shell.resolve(tostring(args[1]))))
  168. print("one:"..one)
  169. print("size:"..size)
  170. print("size/one:"..tonumber(size/one))
  171. print("calc:"..calc)
  172. --/DEBUG]]
  173.  
  174. print("comprimed by "..(100-tonumber(calc)).."%")
  175. end
  176.  
  177. --EXTRACT
  178. local function extract(...)
  179. local args={...}--ARGS ARE SOLVED BEFORE!!!
  180. local file=fs.open(shell.resolve(tostring(args[1])),"r") --print("asd")
  181. if file then t=file.readAll() else error("Can't open:Requested source file doesn't exist.") end
  182. file:close()
  183.  
  184. local b=0
  185.    for a=1,#tDictionaryA do
  186.     for index=1,#tDictionaryB do
  187.      b=b+1
  188.      if b>#tOrigin then break end
  189.      r(tostring(tDictionaryA[a])..tostring(tDictionaryB[index]),tostring(tOrigin[b]))
  190.     end
  191.    end
  192.  
  193. local target=fs.open(shell.resolve(tostring(args[2])),"w")
  194. if not target then error("Can't write:Taget path is invalid. Check the help for more info.") end
  195. target.write(t)
  196. target:close()
  197.  
  198. print("done!")
  199. end
  200.  
  201. local function main()
  202. if not fs.exists(shell.resolve(".").."/org") then
  203.   pcall(function() print("Attempting to download origin file...") shell.run("pastebin","get","xj4ZABRH","org") end)
  204. end
  205. loadOrg()
  206. if tostring(tArgs[1])=="compress" or tostring(tArgs[1])=="c" then
  207. compress(tArgs[2],tArgs[3])
  208. elseif tostring(tArgs[1])=="extract" or tostring(tArgs[1])=="e" then
  209. extract(tArgs[2],tArgs[3])
  210. elseif tostring(tArgs[1])=="help" or tostring(tArgs[1])=="?" then
  211. help()
  212. else
  213. usage()
  214. end
  215. end
  216. ------------------------------------------------------------------------------------------------------------
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223. main()
Advertisement
Add Comment
Please, Sign In to add comment