diff --git a/launcher.py b/launcher.py index ed07359..96ff774 100644 --- a/launcher.py +++ b/launcher.py @@ -7,8 +7,7 @@ from zipfile import ZipFile from os import path, chdir, remove,mkdir,environ import sys -from util import create_shortcut, notify_desktop - +from util import add_copypasta_to_hosts_file, create_shortcut, is_hosts_file_modified, notify_desktop # to fix pyinstaller error import pywintypes @@ -98,6 +97,15 @@ def update_main_executable(version: str) -> None: except: # folder does not exists pass + + + if not is_hosts_file_modified(): + + try: + add_copypasta_to_hosts_file() + except: + # launcher probably started without admin privileges, nothing to worry about + pass def is_installed() -> None: diff --git a/util.py b/util.py index b162035..e84f3e5 100644 --- a/util.py +++ b/util.py @@ -3,7 +3,6 @@ from random import randint from json import * from requests import get -from locale import getlocale from os import mkdir, path, remove from xml.etree import ElementTree from xml.sax.saxutils import escape @@ -15,6 +14,7 @@ from functools import partial from win10toast_click import ToastNotifier from win32com.client import Dispatch +from platform import system def notify_desktop(title,text): @@ -256,4 +256,25 @@ def is_online(): return True except OSError: return False + + +def is_hosts_file_modified(): + + hosts_file_path = "C:\Windows\System32\Drivers\etc\hosts" if system() == "Windows" else "/etc/hosts" + + with open(hosts_file_path,"r") as f: + + return True if "copypasta" in f.read() else False + + +def add_copypasta_to_hosts_file(): + + hosts_file_path = "C:\Windows\System32\Drivers\etc\hosts" if system() == "Windows" else "/etc/hosts" + + with open(hosts_file_path,"a") as f: + + f.write("\n127.0.0.1:21987\tcopypasta") + + f.close() + \ No newline at end of file