testingの成果をマージ
This commit is contained in:
parent
45b1b767ac
commit
45d6b9f3c8
1 changed files with 66 additions and 28 deletions
|
@ -11,7 +11,6 @@ import string
|
|||
import random
|
||||
import tkinter
|
||||
import threading
|
||||
import signal
|
||||
import sys
|
||||
import shutil
|
||||
import time
|
||||
|
@ -361,24 +360,73 @@ class Help(customtkinter.CTkToplevel):
|
|||
def handler_close(self):
|
||||
self.destroy()
|
||||
|
||||
class Monitor():
|
||||
|
||||
class Stop():
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def start(self):
|
||||
monitor_thread = threading.Thread(target=self.run)
|
||||
monitor_thread.start()
|
||||
def run(self):
|
||||
stop_thread = threading.Thread(target=self.stop)
|
||||
stop_thread.run()
|
||||
|
||||
def signal_handler(self):
|
||||
def delete_appdata(self, **kwargs):
|
||||
process_name = kwargs["process_name"]
|
||||
dir_path = kwargs["dir_path"]
|
||||
|
||||
if not os.path.exists(dir_path):
|
||||
print(f"エラー: 指定されたディレクトリ {dir_path} が存在しません。")
|
||||
return 1
|
||||
|
||||
i = 0
|
||||
i_max = 10
|
||||
result = 1
|
||||
while i != i_max:
|
||||
i += 1
|
||||
try:
|
||||
# プロセスの終了
|
||||
subprocess.run(['taskkill', '/f', '/t', '/im', process_name])
|
||||
print(f"{process_name} を終了しました。")
|
||||
time.sleep(0.1)
|
||||
# ディレクトリの削除
|
||||
shutil.rmtree(dir_path)
|
||||
if os.path.isdir(dir_path):
|
||||
pass
|
||||
else:
|
||||
print(f"{dir_path} を削除しました。")
|
||||
result = 0
|
||||
i = i_max
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"プロセス終了エラー: {e}")
|
||||
|
||||
except PermissionError as e:
|
||||
print(f"権限エラー: {e}")
|
||||
|
||||
except Exception as e:
|
||||
print("エラーが発生しました。\nエラー内容:")
|
||||
print(f"エラータイプ: {e.__class__.__name__}")
|
||||
print(f"エラー引数: {e.args}")
|
||||
print(f"エラーメッセージ: {str(e)}")
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def shutdown(self):
|
||||
shutdown_command = subprocess.run(['shutdown', '/s', '/t', '1'])
|
||||
|
||||
def stop(self):
|
||||
print("停止処理を実行。")
|
||||
appdata_local = os.path.expandvars("%LOCALAPPDATA%")
|
||||
appdata_roaming = os.path.expandvars("%APPDATA%")
|
||||
epic_del = app.delete_appdata(process_name="EpicGamesLauncher.exe", dir_path=f"{appdata_local}\\EpicGamesLauncher\\Saved")
|
||||
chrome_del = app.delete_appdata(process_name="chrome.exe", dir_path=f"{appdata_local}\\Google\\Chrome\\User Data")
|
||||
discord_del = app.delete_appdata(process_name="discord.exe", dir_path=f"{appdata_roaming}\\discord")
|
||||
steam_del = app.delete_appdata(process_name="steam.exe", dir_path=f"{appdata_local}\\Steam")
|
||||
ea_del = app.delete_appdata(process_name="EADesktop.exe", dir_path=f"{appdata_local}\\Electronic Arts")
|
||||
riot_del = app.delete_appdata(process_name="RiotClientServices.exe", dir_path=f"{appdata_local}\\Riot Games\\Riot Client")
|
||||
if client_config["eraser"] == 1:
|
||||
appdata_local = os.path.expandvars("%LOCALAPPDATA%")
|
||||
appdata_roaming = os.path.expandvars("%APPDATA%")
|
||||
epic_del = app.delete_appdata(process_name="EpicGamesLauncher.exe", dir_path=f"{appdata_local}\\EpicGamesLauncher\\Saved")
|
||||
chrome_del = app.delete_appdata(process_name="chrome.exe", dir_path=f"{appdata_local}\\Google\\Chrome\\User Data")
|
||||
discord_del = app.delete_appdata(process_name="discord.exe", dir_path=f"{appdata_roaming}\\discord")
|
||||
steam_del = app.delete_appdata(process_name="steam.exe", dir_path=f"{appdata_local}\\Steam")
|
||||
ea_del = app.delete_appdata(process_name="EADesktop.exe", dir_path=f"{appdata_local}\\Electronic Arts")
|
||||
riot_del = app.delete_appdata(process_name="RiotClientServices.exe", dir_path=f"{appdata_local}\\Riot Games\\Riot Client")
|
||||
else:
|
||||
print("削除処理をスキップ。")
|
||||
stop_url = client_config["auth_host_url"] + "/stop"
|
||||
stop_json = {
|
||||
"pc_number": int(client_config["pc_number"])
|
||||
|
@ -389,20 +437,11 @@ class Monitor():
|
|||
print("停止処理は成功しました。")
|
||||
else:
|
||||
print("内部エラーにより停止処理に失敗しました。")
|
||||
result_msgbox = tkinter.messagebox.showwarning(title=f"{app_name} | エラー", message=f"内部エラーにより停止処理に失敗しました。\nDiscordサーバーの指示に従って、停止処理を自身で行ってください。")
|
||||
except:
|
||||
print("ネットワークエラーにより停止処理に失敗しました。")
|
||||
result_msgbox = tkinter.messagebox.showwarning(title=f"{app_name} | エラー", message=f"ネットワークエラーにより停止処理に失敗しました。\nDiscordサーバーの指示に従って、停止処理を自身で行ってください。")
|
||||
finally:
|
||||
self.shutdown()
|
||||
|
||||
def shutdown(self):
|
||||
shutdown_command = subprocess.run(['shutdown', '/s', '/t', '1'])
|
||||
|
||||
|
||||
def run(self):
|
||||
signal.signal(signal.SIGTERM, self.signal_handler)
|
||||
|
||||
|
||||
def master_password_gen():
|
||||
numbers = string.digits # (1)
|
||||
|
@ -418,13 +457,12 @@ if __name__ == '__main__':
|
|||
if args[1] == "stop":
|
||||
init_result = init()
|
||||
if init_result == 1:
|
||||
warning_msgbox = tkinter.messagebox.showwarning(title=f"{app_name} | 多重起動エラー", message=f"もう終了処理を行っています。\nPCがシャットダウンするまで、もう少しお待ちください。")
|
||||
print("多重起動エラー。")
|
||||
elif init_result == 2:
|
||||
pass
|
||||
else:
|
||||
app = App()
|
||||
monitor = Monitor()
|
||||
monitor.signal_handler()
|
||||
stop = Stop()
|
||||
stop.run()
|
||||
elif args[1] == "setup":
|
||||
init_result = init(pc_number=args[2])
|
||||
if init_result == 1:
|
||||
|
|
Loading…
Reference in a new issue