Skip to content

Commit

Permalink
PermissionError 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ajb3296 authored Feb 1, 2020
1 parent 1f8d2fc commit 65b4471
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions Adaway_for_Windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,30 +281,50 @@ def downloadhost():
# Install hosts file
elif choose == "2":
print(installing)
file = open("hosts/hosts", "r", encoding = 'UTF-8')
latesthosts = file.read()
file.close()
file = open("C:\Windows\System32\drivers\etc\hosts", "w", encoding = 'UTF-8')
file.write(latesthosts)
file.close()
print(installfinish)
adawaystatus = adawayon
os.system("cls")
while True:
try:
file = open("hosts/hosts", "r", encoding = 'UTF-8')
except PermissionError:
adawaystatus = "Permission Error. Please restart program"
break
latesthosts = file.read()
file.close()
try:
file = open("C:\Windows\System32\drivers\etc\hosts", "w", encoding = 'UTF-8')
except PermissionError:
adawaystatus = "Permission Error. Please restart program"
break
file.write(latesthosts)
file.close()
print(installfinish)
adawaystatus = adawayon
break

# Restore hosts file
elif choose == "3":
file = open("C:\Windows\System32\drivers\etc\hosts", "w", encoding = 'UTF-8')
file.write(backup)
file.close()
adawaystatus = adawayoff
while True:
try:
file = open("C:\Windows\System32\drivers\etc\hosts", "w", encoding = 'UTF-8')
except PermissionError:
adawaystatus = "Permission Error. Please restart program"
break
file.write(backup)
file.close()
adawaystatus = adawayoff
break

# Open hosts list
elif choose == "4":
os.system("start %s" %hostlist)

# Open host file
elif choose == "5":
os.system("notepad.exe C:\Windows\System32\drivers\etc\hosts")
file = open("C:\Windows\System32\drivers\etc\hosts", "r", encoding = 'UTF-8')
hosts = file.read()
file.close()
os.system("cls")
print("%s\n\n------------------------------------------------------------------------------------------------------------------------\n" %hosts)
os.system("pause")

# Exit
elif choose == "6":
Expand Down

0 comments on commit 65b4471

Please sign in to comment.