Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from muwenyan521/main
Browse files Browse the repository at this point in the history
更改外观,增加功能
  • Loading branch information
ikun0014 authored Sep 21, 2024
2 parents 0557c56 + 299fdda commit e773cd0
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 79 deletions.
19 changes: 13 additions & 6 deletions common/get_steam_path.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import winreg

from pathlib import Path

def get_steam_path():
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Valve\Steam')
steam_path = Path(winreg.QueryValueEx(key, 'SteamPath')[0])
return steam_path

steam_path = get_steam_path()
try:
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Valve\Steam') as key:
steam_path = Path(winreg.QueryValueEx(key, 'SteamPath')[0])
return steam_path
except FileNotFoundError:
print("未找到 Steam 安装路径,请确保 Steam 已安装。")
return None
except Exception as e:
print(f"发生错误: {e}")
return None

steam_path = get_steam_path()

26 changes: 16 additions & 10 deletions common/show_messagebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ def show_messagebox(parent, title, message, type="info"):
:param type: 消息框类型(info, warning, error, yesno)
:return: None 或 bool(仅在 yesno 类型时返回)
"""
# 创建一个新的顶层窗口并隐藏
messagebox_window = tk.Toplevel(parent)
messagebox_window.withdraw() # 隐藏主窗口
messagebox_window.withdraw()
messagebox_window.attributes("-topmost", True) # 确保置顶

if type == "info":
messagebox.showinfo(title, message, parent=messagebox_window)
elif type == "warning":
messagebox.showwarning(title, message, parent=messagebox_window)
elif type == "error":
messagebox.showerror(title, message, parent=messagebox_window)
elif type == "yesno":
return messagebox.askyesno(title, message, parent=messagebox_window)
# 根据消息框类型显示相应的消息框
messagebox_func = {
"info": messagebox.showinfo,
"warning": messagebox.showwarning,
"error": messagebox.showerror,
"yesno": messagebox.askyesno,
}.get(type)

messagebox_window.destroy()
if messagebox_func:
result = messagebox_func(title, message, parent=messagebox_window)
# 如果是 yesno 类型,返回结果
if type == "yesno":
return result

messagebox_window.destroy()
232 changes: 170 additions & 62 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,101 +4,209 @@
import sv_ttk
from common.get_steam_path import steam_path
from common.show_messagebox import show_messagebox
# 游戏路径常量定义
STPLUG_PATH = steam_path / 'config' / 'stplug-in'
GREENLUMA_PATH = steam_path / 'AppList'

# 固定每页显示的游戏数量
PAGE_SIZE = 14 # 设置为固定值
current_page = 0

# 语言变量
LANGUAGE = {
'en': {
'title': "Unlocked Games Manager",
'search': "Search",
'delete': "Delete (Delete)",
'prev_page': "Previous Page",
'next_page': "Next Page",
'warning': "Warning",
'no_selection': "No game selected. Please select a game to delete.",
'success': "Game: {}, Delete Success.",
'error': "Error",
'paths_not_exist': "Both SteamTools and GreenLuma paths do not exist.",
'language_switch': "Switch Language",
'appid': "AppID",
'name': "Name",
'type': "Type"
},
'zh': {
'title': "解锁游戏管理器",
'search': "搜索",
'delete': "删除(Delete)",
'prev_page': "上一页",
'next_page': "下一页",
'warning': "警告",
'no_selection': "未选择游戏。请选择要删除的游戏。",
'success': "游戏: {}, 删除成功。",
'error': "错误",
'paths_not_exist': "SteamTools 和 GreenLuma 路径都不存在。",
'language_switch': "切换语言",
'appid': "AppID",
'name': "名称",
'type': "类型"
}
}

current_lang = 'zh' # 默认语言

# 界面设置
root = tk.Tk()
root.title(LANGUAGE[current_lang]['title'])
root.geometry("800x600")

def load_unlocked_games():
games = []
search_var = tk.StringVar()
search_entry = ttk.Entry(root, textvariable=search_var)
search_entry.pack(pady=10)

if os.path.exists(stplug_path):
for filename in os.listdir(stplug_path):
if filename.endswith('.st'):
appid = filename.replace('.st', '')
games.append({"appid": appid, "name": f"Game {appid}", "type": "SteamTools"})
else:
print(f"Path not found: {stplug_path}")

if os.path.exists(greenluma_path):
for filename in os.listdir(greenluma_path):
if filename.endswith('.txt'):
appid = filename.replace('.txt', '')
games.append({"appid": appid, "name": f"Game {appid}", "type": "GreenLuma"})
search_button = ttk.Button(root, text=LANGUAGE[current_lang]['search'], command=lambda: filter_games())
search_button.pack()

columns = ("AppID", "Name", "Type")
tree = ttk.Treeview(root, columns=columns, show="headings")
tree.heading("AppID", text=LANGUAGE[current_lang]['appid'])
tree.heading("Name", text=LANGUAGE[current_lang]['name'])
tree.heading("Type", text=LANGUAGE[current_lang]['type'])
tree.pack(expand=True, fill="both")

delete_button = ttk.Button(root, text=LANGUAGE[current_lang]['delete'], command=lambda: on_delete())
delete_button.pack(pady=10)

prev_button = ttk.Button(root, text=LANGUAGE[current_lang]['prev_page'], command=lambda: prev_page())
prev_button.pack(side=tk.LEFT, padx=10)

next_button = ttk.Button(root, text=LANGUAGE[current_lang]['next_page'], command=lambda: next_page())
next_button.pack(side=tk.RIGHT, padx=10)

# 添加语言切换按钮
language_button = ttk.Button(root, text=LANGUAGE[current_lang]['language_switch'], command=lambda: switch_language())
language_button.pack(pady=10)

# 添加标签来指示当前页码
page_label = ttk.Label(root, text=f"{current_page + 1}/1") # 初始化为当前页/总页数
page_label.pack(pady=10)

def load_games_from_directory(directory, extension, game_type):
games = []
if os.path.exists(directory):
for filename in os.listdir(directory):
if filename.endswith(extension):
appid = filename.replace(extension, '')
games.append({"appid": appid, "name": f"Game {appid}", "type": game_type})
else:
print(f"Path not found: {greenluma_path}")

print(f"Path not found: {directory}")
return games

def filter_games():
search_term = search_var.get().lower()
def load_unlocked_games():
games = load_games_from_directory(STPLUG_PATH, '.st', 'SteamTools')
games += load_games_from_directory(GREENLUMA_PATH, '.txt', 'GreenLuma')
return games

def display_games(page):
global page_label
start_index = page * PAGE_SIZE
end_index = start_index + PAGE_SIZE

for row in tree.get_children():
tree.delete(row)
for game in unlocked_games:
if search_term in game["appid"].lower() or search_term in game["name"].lower() or search_term in game["type"].lower():
tree.insert("", "end", values=(game["appid"], game["name"], game["type"]))

for game in unlocked_games[start_index:end_index]:
tree.insert("", "end", values=(game["appid"], game["name"], game["type"]))

# 计算总页数
total_pages = (len(unlocked_games) + PAGE_SIZE - 1) // PAGE_SIZE # 计算总页数
# 更新页码标签
page_label.config(text=f"{current_page + 1}/{total_pages}")

def filter_games():
global current_page
search_term = search_var.get().lower()
filtered_games = [game for game in unlocked_games if any(search_term in game[field].lower() for field in ["appid", "name", "type"])]
display_filtered_games(filtered_games)

def display_filtered_games(filtered_games):
global current_page
if filtered_games:
current_page = 0
global unlocked_games
unlocked_games = filtered_games
display_games(current_page)
else:
for row in tree.get_children():
tree.delete(row)

def delete_game(appid, game_type):
if game_type == "SteamTools":
file_path = os.path.join(stplug_path, f"{appid}.st")
elif game_type == "GreenLuma":
file_path = os.path.join(greenluma_path, f"{appid}.txt")

if os.path.exists(file_path):
os.remove(file_path)
file_path = os.path.join(STPLUG_PATH if game_type == "SteamTools" else GREENLUMA_PATH, f"{appid}{'.st' if game_type == 'SteamTools' else '.txt'}")
try:
if os.path.exists(file_path):
os.remove(file_path)
except Exception as e:
print(f"Error deleting file {file_path}: {e}")
refresh_games()

def refresh_games():
global unlocked_games
unlocked_games = load_unlocked_games()
filter_games()
display_games(current_page)

def on_delete():
selected_item = tree.selection()
if not selected_item:
show_messagebox(root, "Warning", "No game selected. Please select a game to delete.", "warning")
show_messagebox(root, LANGUAGE[current_lang]['warning'], LANGUAGE[current_lang]['no_selection'], "warning")
return
appid = tree.item(selected_item[0], "values")[0]
game_type = tree.item(selected_item[0], "values")[2]
delete_game(appid, game_type)
show_messagebox(root, title="Success", message=f"Game: {appid}, Delete Success.", type="warning")
show_messagebox(root, title="Success", message=LANGUAGE[current_lang]['success'].format(appid), type="info")

def on_key_press(event):
if event.keysym == 'Delete':
on_delete()
elif event.keysym == 'F5':
refresh_games()

root = tk.Tk()
root.title("Unlocked Games Manager")
root.geometry("600x400")

sv_ttk.use_light_theme()

search_var = tk.StringVar()
search_entry = ttk.Entry(root, textvariable=search_var)
search_entry.pack(pady=10)

search_button = ttk.Button(root, text="Search", command=filter_games)
search_button.pack()

columns = ("AppID", "Name", "Type")
tree = ttk.Treeview(root, columns=columns, show="headings")
tree.heading("AppID", text="AppID")
tree.heading("Name", text="Name")
tree.heading("Type", text="Type")
tree.pack(expand=True, fill="both")

delete_button = ttk.Button(root, text="Delete (Delete)", command=on_delete)
delete_button.pack(pady=10)

root.bind('<Delete>', on_key_press)
root.bind('<F5>', on_key_press)
def next_page():
global current_page
if (current_page + 1) * PAGE_SIZE < len(unlocked_games):
current_page += 1
display_games(current_page)

def prev_page():
global current_page
if current_page > 0:
current_page -= 1
display_games(current_page)

def switch_language():
global current_lang
current_lang = 'zh' if current_lang == 'en' else 'en'

# 更新窗口标题
root.title(LANGUAGE[current_lang]['title'])
search_button.config(text=LANGUAGE[current_lang]['search'])
delete_button.config(text=LANGUAGE[current_lang]['delete'])
prev_button.config(text=LANGUAGE[current_lang]['prev_page'])
next_button.config(text=LANGUAGE[current_lang]['next_page'])
language_button.config(text=LANGUAGE[current_lang]['language_switch'])

# 更新表头
tree.heading("AppID", text=LANGUAGE[current_lang]['appid'])
tree.heading("Name", text=LANGUAGE[current_lang]['name'])
tree.heading("Type", text=LANGUAGE[current_lang]['type'])

stplug_path = steam_path / 'config' / 'stplug-in'
greenluma_path = steam_path / 'AppList'
# 更新页面标签
total_pages = (len(unlocked_games) + PAGE_SIZE - 1) // PAGE_SIZE # 计算总页数
page_label.config(text=f"{current_page + 1}/{total_pages}")

if not os.path.exists(stplug_path) and not os.path.exists(greenluma_path):
show_messagebox(root, "Error", "Both SteamTools and GreenLuma paths do not exist.", "error")
if not (os.path.exists(STPLUG_PATH) or os.path.exists(GREENLUMA_PATH)):
show_messagebox(root, LANGUAGE[current_lang]['error'], LANGUAGE[current_lang]['paths_not_exist'], "error")
root.destroy()
else:
unlocked_games = load_unlocked_games()
filter_games()
display_games(current_page)

root.bind('<Delete>', on_key_press)
root.bind('<F5>', on_key_press)

sv_ttk.set_theme("light")
root.mainloop()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "game-uninstaller",
"version": "1.0.0",
"version": "1.0.1",
"description": "删除SteamTools或GreenLuma解锁的游戏",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit e773cd0

Please sign in to comment.