Helops

Untitled

Jul 1st, 2020
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.16 KB | None | 0 0
  1. import getpass
  2. import os
  3. import shutil
  4. import urllib
  5. import zipfile
  6. import wget
  7.  
  8. vw_path = f"C:/Users/{getpass.getuser()}/AppData/Roaming/.vimeworld"
  9.  
  10.  
  11. def removeData():
  12.     try:
  13.         data = os.path.join(os.path.abspath(os.path.dirname(__file__)), f"{vw_path}/.data")
  14.         shutil.rmtree(data)
  15.     except FileNotFoundError:
  16.         pass
  17.  
  18.  
  19. os.system("title Created by Helops - https://vk.com/id214066309")
  20.  
  21. # Удаляем папку .data
  22. removeData()
  23.  
  24. # Скачиваем архив с темой (.data)
  25. print("-> | Скачивание темы")
  26. try:
  27.     wget.download("https://vimetheme.at.ua/themeV2.zip", f"{vw_path}/theme.zip")
  28. except urllib.error.URLError:
  29.     print("-> | Ошибка при скачивании темы. Попробуйте ещё раз.")
  30.     os.system("pause")
  31.     raise SystemExit
  32.  
  33. os.system("cls")
  34. print("-> | Тема скачана\n")
  35. print("-> | Установка темы")
  36.  
  37. # Распаковываем скачаный архив
  38. theme = zipfile.ZipFile(f"{vw_path}/theme.zip", 'r')
  39. theme.extractall(vw_path)
  40. theme.close()
  41.  
  42. # Удаляем архив
  43. try:
  44.     theme_zip = os.path.join(os.path.abspath(os.path.dirname(__file__)), f"{vw_path}/theme.zip")
  45.     os.remove(theme_zip)
  46. except FileNotFoundError:
  47.     pass
  48.  
  49. # Изменяем текущую тему в config
  50. try:
  51.     with open(f"{vw_path}/config", "r") as file:
  52.         text = file.read()
  53.         textToLine = text.split("\n")
  54. except FileNotFoundError:
  55.     print("-> | Не удалось найти файл config")
  56.     removeData()
  57.     os.system("pause")
  58.     raise SystemExit
  59.  
  60. themeLine = None
  61. for index in range(len(textToLine)):
  62.     line = textToLine[index].split(":")
  63.     if line[0] == "theme":
  64.         themeLine = index
  65.  
  66. if themeLine is None:
  67.     print("-> | Не удалось найти параметр 'theme' в config")
  68.     removeData()
  69.     os.system("pause")
  70.     raise SystemExit
  71.  
  72. with open(f"{vw_path}/config", "w") as file:
  73.     file.write(text.replace(textToLine[themeLine], "theme:discord"))
  74.  
  75. print("-> | Тема установлена. Запустите VimeWorld.")
  76. os.system("pause")
  77. raise SystemExit
Add Comment
Please, Sign In to add comment