hasher.lua 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. require 'love.filesystem'
  2. require 'love.timer'
  3. local sha1 = require 'lib/deps/sha1/sha1'
  4. local out = love.thread.getChannel('hasher.out')
  5. local sleep = .001
  6. local hashes = {}
  7. local ignore = {'.git', '.DS_Store', 'error.log', '.swp', '.swo', 'playedBefore', 'user.json', 'patch.zip'}
  8. local function halp(base)
  9. for _, file in ipairs(love.filesystem.getDirectoryItems(base)) do
  10. local path = base .. '/' .. file
  11. local ignored = false
  12. for _, name in pairs(ignore) do
  13. if path:find(name) then ignored = true end
  14. end
  15. if not ignored then
  16. if love.filesystem.isDirectory(path) then
  17. halp(path)
  18. else
  19. local entry = {path = path, hash = sha1(love.filesystem.read(path))}
  20. table.insert(hashes, entry)
  21. out:push(entry)
  22. end
  23. end
  24. love.timer.sleep(sleep)
  25. end
  26. end
  27. halp('')
  28. table.sort(hashes, function(a, b) return a.path < b.path end)
  29. for key, entry in pairs(hashes) do
  30. hashes[key] = entry.hash
  31. end
  32. local gameHash = sha1(table.concat(hashes, ''))
  33. out:push('done')
  34. out:push(gameHash)