SHARE
TWEET

Untitled

a guest Dec 18th, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import asyncdispatch, httpclient
  3. import zip/zipfiles
  4.  
  5. if os.existsDir(os.CurDir & "/assets/tools/mm2"):
  6.     echo "Assets Already Downloaded"
  7.     quit(0)
  8.  
  9. var client = newAsyncHttpClient()
  10. var target_dir = os.CurDir & "/tmp"
  11. var target_filename = "mm2"
  12. var target_file_extensions = ".zip"
  13. var filename = ""
  14.  
  15. if not os.existsDir(target_dir):
  16.     echo "Create target dir: " & target_dir
  17.     os.createDir(target_dir)
  18.  
  19. proc onProgressChanged(total, progress, speed: BiggestInt) {.async.} =
  20.     echo("Downloaded ", progress, " of ", total)
  21.     echo("Current rate: ", speed div 1000, "kb/s")
  22.  
  23. client.onProgressChanged = onProgressChanged
  24.  
  25. proc asyncProc() {.async.} =
  26.     echo "Downloading mm2"
  27.     when defined(macosx):
  28.         filename = target_filename & "_darwin" & target_file_extensions
  29.         await client.downloadFile("http://195.201.0.6/mm2/mm2-latest-Darwin.zip",
  30.                 target_dir & "/" & filename)
  31.     echo "Downloading Finished"
  32.  
  33. waitFor asyncProc()
  34.  
  35. var z: ZipArchive
  36. echo "Opening: " & target_dir & "/" & filename
  37. if not z.open(target_dir & "/" & filename):
  38.     echo "Opening zip failed"
  39.     quit(1)
  40. z.extractAll(os.CurDir & "/assets/tools/mm2")
  41.  
  42. os.removeDir(target_dir)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top