From 487dfbd96d95eaf16fad98a532a4a65e07c30ad9 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Fri, 6 Sep 2024 14:47:31 +0900 Subject: [PATCH 01/10] =?UTF-8?q?delete=5Fappdata=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E3=82=92testing=E3=81=8B=E3=82=89=E3=82=82=E3=81=A3?= =?UTF-8?q?=E3=81=A6=E3=81=8F=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_client.py | 51 +++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/dislocker_client.py b/dislocker_client.py index 79c5bd7..f2e68fc 100644 --- a/dislocker_client.py +++ b/dislocker_client.py @@ -14,6 +14,8 @@ import threading import signal import sys import shutil +import time + app_name = "Dislocker" dislocker_dir = os.path.dirname(os.path.abspath(sys.argv[0])) @@ -98,28 +100,37 @@ class App(customtkinter.CTk): print(f"エラー: 指定されたディレクトリ {dir_path} が存在しません。") return 1 - try: - # プロセスの終了 - subprocess.run(['taskkill', '/f', '/t', '/im', process_name]) - print(f"{process_name} を終了しました。") + 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 - # ディレクトリの削除 - shutil.rmtree(dir_path) - print(f"{dir_path} を削除しました。") + 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 0 - except subprocess.CalledProcessError as e: - print(f"プロセス終了エラー: {e}") - return 1 - except PermissionError as e: - print(f"権限エラー: {e}") - return 1 - except Exception as error: - print("エラーが発生しました。\nエラー内容:") - print(f"エラータイプ: {error.__class__.__name__}") - print(f"エラー引数: {error.args}") - print(f"エラーメッセージ: {str(error)}") - return 1 def block_key(self): block_keys = ['ctrl', 'alt', 'windows', 'shift', 'delete'] From 5a709197e79b7d23a3c0814400dc9f43848bc511 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sun, 8 Sep 2024 15:03:16 +0900 Subject: [PATCH 02/10] =?UTF-8?q?config=E3=81=AE=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E3=82=92testing=E3=81=8B=E3=82=89=E3=82=82=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=8F=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dislocker.py b/dislocker.py index 7da40da..03a3cbc 100644 --- a/dislocker.py +++ b/dislocker.py @@ -48,7 +48,10 @@ class DL(): "search_frequency": 1, "allowable_time": 180, "fstop_time": "21:00:00" - } + }, + "preset_games": ["TEST1", "TEST2", "TEST3", "TEST4", "TEST5"], + "admin_user_id": "TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!)", + "debug": False } } From c08afa08c3cd52d8cd26135e4f25450ca1e47f65 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sun, 8 Sep 2024 15:14:06 +0900 Subject: [PATCH 03/10] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9B=AE=E7=9A=84?= =?UTF-8?q?=E3=81=AE=E3=83=97=E3=83=AA=E3=82=BB=E3=83=83=E3=83=88=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/dislocker.py b/dislocker.py index 03a3cbc..7e98f04 100644 --- a/dislocker.py +++ b/dislocker.py @@ -77,6 +77,7 @@ class DL(): cursor = self.db.cursor() self.pc_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + self.preset_games = self.server_config["bot"]["preset_games"] cursor.execute("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'club_member')") find_club_member_table = cursor.fetchall() @@ -625,6 +626,9 @@ class Bot(discord.Client): pc_number = custom_id_split[1] device_number = custom_id_split[2] reason_register_view = View(timeout=15) + for i in dislocker.preset_games: + reason_quick_button = reason_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i)}", custom_id=f"reasonregister_{str(pc_number)}_{str(device_number)}_quick_{str(i)}") + reason_register_view.add_item(reason_quick_button) reason_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="使用目的を入力する", custom_id=f"reasonregister_{str(pc_number)}_{str(device_number)}") reason_register_view.add_item(reason_button) @@ -633,8 +637,31 @@ class Bot(discord.Client): elif custom_id_split[0] == "reasonregister": pc_number = custom_id_split[1] device_number = custom_id_split[2] - reason_input_form = Reason(title="Dislocker | 登録", pc_number=str(pc_number), device_number=str(device_number)) - await interaction.response.send_modal(reason_input_form) + + if len(custom_id_split) >= 4: + if custom_id_split[3] == "quick": + reason = custom_id_split[4] + device_number = custom_id_split[2] + register = bot.register(user_id=interaction.user.id, name=interaction.user.name, display_name=interaction.user.display_name, pc_number=pc_number, device_number=device_number, detail=reason) + print(register["result"]) + + if register["result"] == "ok": + await interaction.response.send_message(f":white_check_mark: 使用が開始されました。\n>>> # パスワード | {register["password"]}\n## PC番号 | {pc_number}\n## デバイス番号 | {device_number}\n## 使用目的 | {reason}", ephemeral=True) + await bot.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(f':white_check_mark: {register["name"]} さんがPC {pc_number} の使用を開始しました。') + elif register["result"] == "pc_already_in_use_by_you": + await interaction.response.send_message(f"# :exploding_head: あなたはPCをもう使用されているようです。\n使用状態を解除するには 終了ボタン で使用終了をお知らせください。\n>>> # PC番号 | {register["pc_number"]}\n# デバイス番号 | {register["device_number"]}\n# 使用開始時刻 | {register["start_time"]}\n# 使用目的 | {register["detail"]}", ephemeral=True) + elif register["result"] == "pc_already_in_use_by_other": + await interaction.response.send_message(f"# :man_gesturing_no: そのPCは他のメンバーによって使用されています。\n別のPC番号を指定して、再度お試しください。", ephemeral=True) + elif register["result"] == "user_data_not_found": + await interaction.response.send_message("# :dizzy_face: ユーザーとして登録されていないようです。\n最初にサーバーで登録を行ってください。", ephemeral=True) + else: + await interaction.response.send_message("# :skull_crossbones: 登録できませんでした。\n内部エラーが発生しています。", ephemeral=True) + else: + reason_input_form = Reason(title="Dislocker | 登録", pc_number=str(pc_number), device_number=str(device_number)) + await interaction.response.send_modal(reason_input_form) + else: + reason_input_form = Reason(title="Dislocker | 登録", pc_number=str(pc_number), device_number=str(device_number)) + await interaction.response.send_modal(reason_input_form) elif custom_id_split[0] == "stop": print("STOP running") From cf47a5b2adae16747c1b6bc2f2e37b980dd176ad Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Mon, 9 Sep 2024 14:04:19 +0900 Subject: [PATCH 04/10] =?UTF-8?q?=E8=87=AA=E5=89=8D=E3=81=AE=E3=83=9C?= =?UTF-8?q?=E3=82=BF=E3=83=B3=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/dislocker.py b/dislocker.py index 7e98f04..64de3fa 100644 --- a/dislocker.py +++ b/dislocker.py @@ -619,6 +619,8 @@ class Bot(discord.Client): for i in range(1, 11): device_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{i}", custom_id=f"deviceregister_{str(pc_number)}_{i}") device_register_view.add_item(device_register_button) + device_own_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="自前", custom_id=f"device_register_{str(pc_number)}_own") + device_register_view.add_item(device_own_register_button) await interaction.response.send_message(f"# :keyboard: デバイス番号を選んでください!\n>>> # PC番号 | {str(pc_number)}", view=device_register_view, ephemeral=True) @@ -641,7 +643,11 @@ class Bot(discord.Client): if len(custom_id_split) >= 4: if custom_id_split[3] == "quick": reason = custom_id_split[4] - device_number = custom_id_split[2] + if device_number == "own": + device_number = 0 + else: + device_number = custom_id_split[2] + register = bot.register(user_id=interaction.user.id, name=interaction.user.name, display_name=interaction.user.display_name, pc_number=pc_number, device_number=device_number, detail=reason) print(register["result"]) @@ -800,7 +806,11 @@ class Reason(Modal): print(custom_id) custom_id_split = custom_id.split("_") pc_number = custom_id_split[1] - device_number = custom_id_split[2] + if device_number == "own": + device_number = 0 + else: + device_number = custom_id_split[2] + register = bot.register(user_id=interaction.user.id, name=interaction.user.name, display_name=interaction.user.display_name, pc_number=pc_number, device_number=device_number, detail=self.reason_input_form.value) print(register["result"]) From 8ade781d4b5aa1a3ad5af8d345c359b588d54d55 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Mon, 9 Sep 2024 14:20:26 +0900 Subject: [PATCH 05/10] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=90=86=E7=94=B1?= =?UTF-8?q?=E3=81=8C=E8=81=9E=E3=81=8B=E3=82=8C=E3=81=AA=E3=81=84=E3=83=90?= =?UTF-8?q?=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dislocker.py b/dislocker.py index 64de3fa..b051213 100644 --- a/dislocker.py +++ b/dislocker.py @@ -619,7 +619,7 @@ class Bot(discord.Client): for i in range(1, 11): device_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{i}", custom_id=f"deviceregister_{str(pc_number)}_{i}") device_register_view.add_item(device_register_button) - device_own_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="自前", custom_id=f"device_register_{str(pc_number)}_own") + device_own_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="自前", custom_id=f"deviceregister_{str(pc_number)}_own") device_register_view.add_item(device_own_register_button) await interaction.response.send_message(f"# :keyboard: デバイス番号を選んでください!\n>>> # PC番号 | {str(pc_number)}", view=device_register_view, ephemeral=True) From 8658955998636a0b36e0c9add2970d042b9d9af4 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Tue, 10 Sep 2024 18:12:40 +0900 Subject: [PATCH 06/10] =?UTF-8?q?temp=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF?= =?UTF-8?q?=E3=83=88=E3=83=AA=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- temp/client_playground.py | 40 ---------------- temp/csv_test.py | 77 ------------------------------- temp/kill.py | 22 --------- temp/password.py | 16 ------- temp/password.txt | 0 temp/powershell.py | 9 ---- temp/test.py | 41 ----------------- temp/xcel.py | 97 --------------------------------------- 8 files changed, 302 deletions(-) delete mode 100644 temp/client_playground.py delete mode 100644 temp/csv_test.py delete mode 100644 temp/kill.py delete mode 100644 temp/password.py delete mode 100644 temp/password.txt delete mode 100644 temp/powershell.py delete mode 100644 temp/test.py delete mode 100644 temp/xcel.py diff --git a/temp/client_playground.py b/temp/client_playground.py deleted file mode 100644 index f0a4879..0000000 --- a/temp/client_playground.py +++ /dev/null @@ -1,40 +0,0 @@ -import os -import subprocess -import shutil - -def delete_appdata(**kwargs): - process_name = kwargs["process_name"] - dir_path = kwargs["dir_path"] - - if not os.path.exists(dir_path): - print(f"エラー: 指定されたディレクトリ {dir_path} が存在しません。") - return 1 - - try: - # プロセスの終了 - subprocess.run(['taskkill', '/f', '/t', '/im', process_name]) - print(f"{process_name} を終了しました。") - - # ディレクトリの削除 - shutil.rmtree(dir_path) - print(f"{dir_path} を削除しました。") - - return 0 - except subprocess.CalledProcessError as e: - print(f"プロセス終了エラー: {e}") - return 1 - except PermissionError as e: - print(f"権限エラー: {e}") - return 1 - except Exception as error: - print("エラーが発生しました。\nエラー内容:") - print(f"エラータイプ: {error.__class__.__name__}") - print(f"エラー引数: {error.args}") - print(f"エラーメッセージ: {str(error)}") - return 1 - -appdata_local = os.path.expandvars("%LOCALAPPDATA%") -appdata_roaming = os.path.expandvars("%APPDATA%") -print(appdata_local, appdata_roaming) -print(f"{appdata_local}\\Steam") -steam_del = delete_appdata(process_name="steam.exe", dir_path=f"{appdata_local}\\Steam") \ No newline at end of file diff --git a/temp/csv_test.py b/temp/csv_test.py deleted file mode 100644 index 9b30aa8..0000000 --- a/temp/csv_test.py +++ /dev/null @@ -1,77 +0,0 @@ -import psycopg2 -import csv -from psycopg2 import sql -from datetime import datetime - -def format_datetime(value): - if isinstance(value, datetime): - return value.strftime('%Y-%m-%d %H:%M:%S') - return value - -def export_table_to_csv(host, port, database, user, password, main_table, related_table, related_column, csv_file_path): - try: - # データベースに接続 - conn = psycopg2.connect( - host=host, - port=port, - database=database, - user=user, - password=password - ) - - cur = conn.cursor() - - # メインテーブルの列情報を取得(user_idを除く) - cur.execute(sql.SQL("SELECT * FROM {} LIMIT 0").format(sql.Identifier(main_table))) - main_columns = [desc[0] for desc in cur.description if desc[0] != 'member_id'] - - # クエリを作成(列名を明確に指定) - query = sql.SQL(""" - SELECT {main_columns}, {related_table}.name - FROM {main_table} - LEFT JOIN {related_table} ON {main_table}.member_id = {related_table}.id - """).format( - main_columns=sql.SQL(', ').join([sql.SQL("{}.{}").format(sql.Identifier(main_table), sql.Identifier(col)) for col in main_columns]), - main_table=sql.Identifier(main_table), - related_table=sql.Identifier(related_table) - ) - - cur.execute(query) - - # 列名を再構成(nameを2番目に配置) - column_names = [main_columns[0], 'name'] + main_columns[1:] - - rows = cur.fetchall() - - with open(csv_file_path, 'w', newline='', encoding='utf-8-sig') as csvfile: - csvwriter = csv.writer(csvfile) - csvwriter.writerow(column_names) - - for row in rows: - # nameを2番目に移動 - formatted_row = [format_datetime(row[0])] + [row[-1]] + [format_datetime(field) if field is not None else '' for field in row[1:-1]] - csvwriter.writerow(formatted_row) - - print(f"テーブル '{main_table}' の内容を '{csv_file_path}' に出力しました。") - - except (Exception, psycopg2.Error) as error: - print("エラーが発生しました:", error) - - finally: - if conn: - cur.close() - conn.close() - print("データベース接続を閉じました。") - -# 使用例 -host = "192.168.1.220" -port = "12245" -database = "dislocker" -user = "suti7" -password = "Testing1234" -main_table = "pc_usage_history" -related_table = "club_member" -related_column = "name" # 例: 登録者の名前を表示したい場合 -csv_file_path = "output.csv" - -export_table_to_csv(host, port, database, user, password, main_table, related_table, related_column, csv_file_path) diff --git a/temp/kill.py b/temp/kill.py deleted file mode 100644 index 2c68cbf..0000000 --- a/temp/kill.py +++ /dev/null @@ -1,22 +0,0 @@ -import wmi -import asyncio - -async def watcher(): - c=wmi.WMI() - cre_process_watcher=c.Win32_Process.watch_for("creation") - del_process_watcher=c.Win32_Process.watch_for("deletion") - - while True: - new_cre_process=cre_process_watcher() - new_del_process=del_process_watcher() - print(new_cre_process.Caption+" has been created") - print(new_del_process.Caption+" has been deleted ") - -async def main(): - kill_task = asyncio.TaskGroup(watcher()) - print('hello world') - await asyncio.sleep(1) - print('1sec') - await kill_task - -asyncio.run(main()) diff --git a/temp/password.py b/temp/password.py deleted file mode 100644 index 6d1c9d7..0000000 --- a/temp/password.py +++ /dev/null @@ -1,16 +0,0 @@ -import random -import string -# パスワードをファイルから読み込む - -with open('password.txt', 'r') as f: - secret = f.read() - -check=int(input("password :")) - -if check==int(secret): - print("ok") - secret=0 - with open('password.txt', 'w') as file: - file.write('') -else: - print("out") \ No newline at end of file diff --git a/temp/password.txt b/temp/password.txt deleted file mode 100644 index e69de29..0000000 diff --git a/temp/powershell.py b/temp/powershell.py deleted file mode 100644 index 97f65f6..0000000 --- a/temp/powershell.py +++ /dev/null @@ -1,9 +0,0 @@ -import os - -# PowerShellコマンドを実行する関数 -def run_powershell_command(command): - # PowerShellコマンドを実行 - os.system(f"powershell -Command {command}") - -# 例としてGet-Dateコマンドを実行して現在の日時を取得 -run_powershell_command("Get-Date") diff --git a/temp/test.py b/temp/test.py deleted file mode 100644 index 03e0e7b..0000000 --- a/temp/test.py +++ /dev/null @@ -1,41 +0,0 @@ - -import discord -import string -import random - -# Intentsの設定 -intents = discord.Intents.default() -intents.message_content = True - -# 接続に必要なオブジェクトを生成 -client = discord.Client(intents=intents) - -# 起動時に動作する処理 -@client.event -async def on_ready(): - # 起動したらターミナルにログイン通知が表示される - print('ログインしました') - -# メッセージ受信時に動作する処理 -@client.event -async def on_message(message): - # メッセージ送信者がBotだった場合は無視する - if message.author.bot: - return - # 「/neko」と発言したら「にゃーん」が返る処理 - if message.content == "/neko": - await message.channel.send('にゃーん') - - if message.content == '/password': - secret=password_generator_n(4) - await message.channel.send(str(secret)) - with open('password.txt', 'a') as file: - file.write(secret) - -def password_generator_n(length): - numbers = string.digits # (1) - password = ''.join(random.choice(numbers) for _ in range(length)) # (2) - return password - -# Botの起動とDiscordサーバーへの接続 -client.run('MTI0NzA1Mzc1NzUxOTM2NDEyNw.Gh5gIt.kz1acBMxphff9mEZLLWrEdEoVD4RJwgBW5P14o') diff --git a/temp/xcel.py b/temp/xcel.py deleted file mode 100644 index 684cfc7..0000000 --- a/temp/xcel.py +++ /dev/null @@ -1,97 +0,0 @@ -import psycopg2 -import csv -from psycopg2 import sql -from datetime import datetime -from openpyxl import Workbook -from openpyxl.utils import get_column_letter - -def format_datetime(value): - if isinstance(value, datetime): - return value.strftime('%Y-%m-%d %H:%M:%S') - return value - -def export_table_to_excel(host, port, database, user, password, main_table, related_table, excel_file_path): - try: - conn = psycopg2.connect( - host=host, - port=port, - database=database, - user=user, - password=password - ) - - cur = conn.cursor() - - # メインテーブルの列情報を取得(member_idを除く) - cur.execute(sql.SQL("SELECT * FROM {} LIMIT 0").format(sql.Identifier(main_table))) - main_columns = [desc[0] for desc in cur.description if desc[0] != 'member_id'] - - # クエリを作成(列名を明確に指定) - query = sql.SQL(""" - SELECT {main_columns}, {related_table}.name - FROM {main_table} - LEFT JOIN {related_table} ON {main_table}.member_id = {related_table}.id - """).format( - main_columns=sql.SQL(', ').join([sql.SQL("{}.{}").format(sql.Identifier(main_table), sql.Identifier(col)) for col in main_columns]), - main_table=sql.Identifier(main_table), - related_table=sql.Identifier(related_table) - ) - - cur.execute(query) - - # 列名を再構成(nameを2番目に配置) - column_names = [main_columns[0], 'name'] + main_columns[1:] - - rows = cur.fetchall() - - # Excelワークブックを作成 - wb = Workbook() - ws = wb.active - - # 列名を書き込み - ws.append(column_names) - - # データを書き込み - for row in rows: - # nameを2番目に移動 - formatted_row = [format_datetime(row[0])] + [row[-1]] + [format_datetime(field) if field is not None else '' for field in row[1:-1]] - ws.append(formatted_row) - - # 列幅を自動調整 - for col in ws.columns: - max_length = 0 - column = col[0].column_letter - for cell in col: - try: - if len(str(cell.value)) > max_length: - max_length = len(str(cell.value)) - except: - pass - adjusted_width = (max_length + 2) * 1.2 - ws.column_dimensions[column].width = adjusted_width - - # Excelファイルを保存 - wb.save(excel_file_path) - - print(f"テーブル '{main_table}' の内容を '{excel_file_path}' に出力しました。") - - except (Exception, psycopg2.Error) as error: - print("エラーが発生しました:", error) - - finally: - if conn: - cur.close() - conn.close() - print("データベース接続を閉じました。") - -# 使用例 -host = "192.168.1.220" -port = "12245" -database = "dislocker" -user = "suti7" -password = "Testing1234" -main_table = "pc_usage_history" -related_table = "club_member" -excel_file_path = "output.xlsx" - -export_table_to_excel(host, port, database, user, password, main_table, related_table, excel_file_path) From 45b1b767acccdeff1f52c6b4fc104706082b4253 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Tue, 10 Sep 2024 18:13:10 +0900 Subject: [PATCH 07/10] =?UTF-8?q?temp=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF?= =?UTF-8?q?=E3=83=88=E3=83=AA=E3=81=AF=E8=BF=BD=E8=B7=A1=E5=A4=96=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f5c0150..541d26b 100644 --- a/.gitignore +++ b/.gitignore @@ -164,4 +164,5 @@ config/ db/ test.py data/ -export/ \ No newline at end of file +export/ +temp/ \ No newline at end of file From 45d6b9f3c833aff8d1bd36f3a32f21a438e47163 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Tue, 10 Sep 2024 18:17:00 +0900 Subject: [PATCH 08/10] =?UTF-8?q?testing=E3=81=AE=E6=88=90=E6=9E=9C?= =?UTF-8?q?=E3=82=92=E3=83=9E=E3=83=BC=E3=82=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_client.py | 94 +++++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 28 deletions(-) diff --git a/dislocker_client.py b/dislocker_client.py index f2e68fc..568b4d4 100644 --- a/dislocker_client.py +++ b/dislocker_client.py @@ -11,7 +11,6 @@ import string import random import tkinter import threading -import signal import sys import shutil import time @@ -360,25 +359,74 @@ 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,19 +437,10 @@ 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(): @@ -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: From 9389441262137068364b5c19c4087acc298a8fa7 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Tue, 10 Sep 2024 18:30:33 +0900 Subject: [PATCH 09/10] =?UTF-8?q?config=E3=81=ABstop=E7=94=A8=E3=81=AEeras?= =?UTF-8?q?er=E3=82=AD=E3=83=BC=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dislocker_client.py b/dislocker_client.py index 568b4d4..da9b9e1 100644 --- a/dislocker_client.py +++ b/dislocker_client.py @@ -33,7 +33,8 @@ if not os.path.isfile(client_config_path): "auth_host_url": "http://localhost", "pc_number": 1, "master_password_hash": "", - "testing": 0 + "testing": 0, + "eraser": 1 } elif os.path.isfile(client_config_path): From 84d1b0cb5908b06457f2afe1c3bf8f4a7eb37041 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Tue, 17 Sep 2024 14:02:14 +0900 Subject: [PATCH 10/10] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9B=AE=E7=9A=84?= =?UTF-8?q?=E3=81=8C=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0=E3=81=A7=E9=80=81?= =?UTF-8?q?=E4=BF=A1=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=84=E3=83=90=E3=82=B0?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dislocker.py b/dislocker.py index b051213..fcb0401 100644 --- a/dislocker.py +++ b/dislocker.py @@ -806,6 +806,8 @@ class Reason(Modal): print(custom_id) custom_id_split = custom_id.split("_") pc_number = custom_id_split[1] + device_number = custom_id_split[2] + if device_number == "own": device_number = 0 else: