Andy73

AndyCode Archiver v.0.4b ALPHA

Apr 20th, 2014
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.48 KB | None | 0 0
  1. --[[
  2. Pure Lua archiver made by Andy73 a.k.a. viluon
  3.  
  4. Copyright 2014
  5. version 0.4b ALPHA (5th public release)
  6.  
  7. usage: archiver <compress|extract|help> <file input path> <file output path>
  8.  
  9. WIP
  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.4b ALPHA")
  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(args[2]))
  162. one=tonumber(fs.getSize(shell.resolve(args[1])))/100
  163. size=fs.getSize(args[2])
  164. --[[DEBUG
  165. print("fs.getSize(...):"..fs.getSize(args[1]))
  166. print("one:"..one)
  167. print("size:"..size)
  168. --/DEBUG]]
  169. percent=100-(size/one)
  170. print("comprimed by "..percent.."%")
  171. end
  172.  
  173. --EXTRACT
  174. local function extract(...)
  175. local args={...}--ARGS ARE SOLVED BEFORE!!!
  176. local file=fs.open(shell.resolve(tostring(args[1])),"r") --print("asd")
  177. if file then t=file.readAll() else error("Can't open:Requested source file doesn't exist.") end
  178. file:close()
  179.  
  180. local b=0
  181.    for a=1,#tDictionaryA do
  182.     for index=1,#tDictionaryB do
  183.      b=b+1
  184.      if b>#tOrigin then break end
  185.      r(tostring(tDictionaryA[a])..tostring(tDictionaryB[index]),tostring(tOrigin[b]))
  186.     end
  187.    end
  188.  
  189. local target=fs.open(shell.resolve(tostring(args[2])),"w")
  190. if not target then error("Can't write:Taget path is invalid. Check the help for more info.") end
  191. target.write(t)
  192. target:close()
  193.  
  194. print("done!")
  195. end
  196.  
  197. local function main()
  198. loadOrg()
  199. if tostring(tArgs[1])=="compress" or tostring(tArgs[1])=="c" then
  200. compress(tArgs[2],tArgs[3])
  201. elseif tostring(tArgs[1])=="extract" or tostring(tArgs[1])=="e" then
  202. extract(tArgs[2],tArgs[3])
  203. elseif tostring(tArgs[1])=="help" or tostring(tArgs[1])=="?" then
  204. help()
  205. else
  206. usage()
  207. end
  208. end
  209. ------------------------------------------------------------------------------------------------------------
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216. main()
Advertisement
Add Comment
Please, Sign In to add comment