Skip to content

Commit

Permalink
adding copypasta to hosts file
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaaoBlues committed Jun 21, 2022
1 parent 864d4fb commit c2f8506
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
12 changes: 10 additions & 2 deletions launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 22 additions & 1 deletion util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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()


0 comments on commit c2f8506

Please sign in to comment.