-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesgo_cli.py
More file actions
executable file
·391 lines (332 loc) · 18.2 KB
/
Copy pathesgo_cli.py
File metadata and controls
executable file
·391 lines (332 loc) · 18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT-only
# Copyright (c) 2026 ByPythonCoder / ESGO Launcher. All rights reserved.
import sys
import argparse
from typing import Optional, List, Dict
from esgo.core import logger
from esgo.core.config import load_config
from esgo.core.library import load_games
def handle_platform_cli(platform_name: str, plat_instance: object, args: argparse.Namespace) -> None:
"""
Belirtilen oyun platformu için (Epic, GOG vb.) CLI işlemlerini yönetir.
Bu fonksiyon, gelen argümanlara göre giriş yapma (login), çıkış yapma (logout),
oyunları listeleme veya kurulu oyunları içe aktarma işlemlerini ilgili platform
sınıfına devreder.
Args:
platform_name (str): İşlem yapılan platformun okunaklı adı (örn: "Epic Games").
plat_instance (object): İşlemleri yürütecek platform sınıfının bir örneği (instance).
args (argparse.Namespace): Kullanıcının komut satırından girdiği argümanlar.
Returns:
None: Fonksiyon bir değer döndürmez, işlemleri gerçekleştirir ve ekrana çıktı verir.
"""
if args.login:
plat_instance.login()
elif args.logout:
plat_instance.logout()
elif args.list:
games = plat_instance.get_games()
if not games:
print("[BİLGİ] Kütüphane boş veya giriş yapılmamış.")
else:
print(f"\n--- {platform_name} Kütüphanesi ({len(games)} Oyun) ---")
for i, g in enumerate(games):
print(f"{i+1}) {g.get('title')} ({g.get('app_name')})")
elif hasattr(args, 'import_games') and args.import_games:
games = load_games()
if platform_name == "Epic Games":
from esgo.cli.installed_games import import_epic_games
import_epic_games(games)
elif platform_name == "GOG":
from esgo.cli.installed_games import import_gog_games
import_gog_games(games)
else:
print(f"[UYARI] {platform_name} için içe aktarma desteği henüz yok.")
else:
msg = "[UYARI] Lütfen bir işlem seçin: --login, --logout, --list"
if hasattr(args, 'import_games'):
msg += ", --import"
print(msg)
def main() -> None:
"""
ESGO Launcher komut satırı arayüzünün (CLI) ana giriş noktasıdır.
Bu fonksiyon, argparse kullanarak terminal üzerinden girilen tüm komutları (run, setting, list, vb.)
ayrıştırır ve ilgili modüllere yönlendirir. Hiçbir argüman verilmezse etkileşimli ana menüyü başlatır.
Args:
None
Returns:
None: Fonksiyon bir değer döndürmez, gerekirse doğrudan işletim sistemine çıkış yapar (sys.exit).
"""
config = load_config() # i18n ve genel ayarları yükle
parser = argparse.ArgumentParser(
description="ESGO Launcher CLI - Oyunlarınızı terminalden yönetin.",
epilog="Örnekler:\n python esgo_cli.py run 1\n python esgo_cli.py setting 1\n python esgo_cli.py list\n python esgo_cli.py doctor",
formatter_class=argparse.RawDescriptionHelpFormatter
)
subparsers = parser.add_subparsers(dest="command", help="Kullanılabilir Komutlar")
# Run komutu
run_parser = subparsers.add_parser("run", help="Belirtilen oyunu başlatır (ID veya İsim)")
run_parser.add_argument("query", help="Oyun numarası (list çıktısındaki) veya oyunun tam/kısmi ismi")
run_parser.add_argument("--log", action="store_true", help="Oyunun çıktısını log dosyasına kaydeder")
run_parser.add_argument("--prefixclear", action="store_true", help="Oyunun prefix dizinini temizler ve yeniden oluşturur")
run_parser.add_argument("--exe", help="Oyunun kendi EXE'si yerine başka bir EXE çalıştırır (Yama vb. için)")
run_parser.add_argument("--dry-run", action="store_true", help="Oyunu başlatmadan kullanılacak komut ve ortamı gösterir")
# Settings komutu (oyun bazlı)
set_parser = subparsers.add_parser("setting", help="Bir oyunun ayarlarını düzenler")
set_parser.add_argument("index", type=int, help="Düzenlenecek oyunun numarası (list çıktısındaki)")
set_parser.add_argument("--name", help="Oyunun adını değiştirir")
set_parser.add_argument("--exe", help="Oyunun EXE dosya yolunu değiştirir")
set_parser.add_argument("--proton", help="Özel Proton/Wine yolunu değiştirir")
set_parser.add_argument("--prefix", help="Özel Prefix (Wine ortamı) yolunu değiştirir")
set_parser.add_argument("--args", help="Başlatma parametrelerini değiştirir")
set_parser.add_argument("--env", help="Çevre değişkenlerini değiştirir (Örn: 'DXVK_HUD=1')")
set_parser.add_argument("--umu-id", help="ProtonFixes için UMU Veritabanı ID'sini değiştirir")
set_parser.add_argument("--sandbox", action="store_true", help="Oyunu korumalı alanda (Firejail) başlatmayı aktif eder")
set_parser.add_argument("--no-sandbox", action="store_true", help="Oyunun korumalı alan (Firejail) ayarını devre dışı bırakır")
set_parser.add_argument("--prefixclear", action="store_true", help="Özel prefix yolunu temizler")
# Settings komutu (genel ayarlar)
subparsers.add_parser("settings", help="ESGO genel ayarlarını açar")
# Uninstall komutu
un_parser = subparsers.add_parser("uninstall", help="Bir oyunu kütüphaneden ve diskten kaldırır")
un_parser.add_argument("index", type=int, help="Kaldırılacak oyunun numarası (list çıktısındaki)")
un_parser.add_argument("--force", action="store_true", help="Kütüphane ve Prefix'i onay sormadan siler")
un_parser.add_argument("--delete-files", action="store_true", help="Oyunun asıl dosyalarını (exe klasörü) diskten siler")
# Verify komutu
vf_parser = subparsers.add_parser("verify", help="Bir oyunun dosya bütünlüğünü doğrular (Şimdilik sadece Epic)")
vf_parser.add_argument("index", type=int, help="Doğrulanacak oyunun numarası (list çıktısındaki)")
# List komutu
subparsers.add_parser("list", help="Kütüphanedeki tüm oyunları numaralarıyla listeler")
# Add komutu
subparsers.add_parser("add", help="Yeni bir oyunu manuel olarak eklemek için sihirbazı başlatır")
# Doctor komutu
subparsers.add_parser("doctor", help="Kurulum, araçlar ve yollar için sağlık kontrolü yapar")
# Kill komutu
kill_parser = subparsers.add_parser("kill", help="ESGO tarafından başlatılan oyunları listele/sonlandır")
kill_parser.add_argument("target", nargs="?", help="Sonlandırılacak oyunun adı (kısmi), PID numarası veya 'all'")
kill_parser.add_argument("--list", "-l", action="store_true", dest="kill_list", help="Aktif/yetim oyunları listele")
kill_parser.add_argument("--force", "-f", action="store_true", help="Onay sormadan sonlandır")
# Update Tools komutu
up_parser = subparsers.add_parser("update-tools", aliases=["update-package"], help="Gerekli araçları (legendary, nile vb.) indirir ve günceller")
up_parser.add_argument("name", nargs="?", help="Güncellenecek aracın adı (boş bırakılırsa hepsi güncellenir)")
# Epic komutu
epic_parser = subparsers.add_parser("epic", help="Epic Games (Legendary) işlemlerini yönetir")
epic_parser.add_argument("--login", action="store_true", help="Epic Games hesabına giriş yapar")
epic_parser.add_argument("--logout", action="store_true", help="Epic Games hesabından çıkış yapar")
epic_parser.add_argument("--list", action="store_true", help="Kütüphanedeki tüm oyunları listeler")
epic_parser.add_argument("--import", dest="import_games", action="store_true", help="Kurulu olan Epic oyunlarını ESGO'ya aktarır")
# GOG komutu
gog_parser = subparsers.add_parser("gog", help="GOG (gogdl) işlemlerini yönetir")
gog_parser.add_argument("--login", action="store_true", help="GOG hesabına giriş yapar")
gog_parser.add_argument("--logout", action="store_true", help="GOG hesabından çıkış yapar")
gog_parser.add_argument("--list", action="store_true", help="Kütüphanedeki oyunları listeler")
gog_parser.add_argument("--import", dest="import_games", action="store_true", help="Kurulu olan GOG oyunlarını ESGO'ya aktarır")
# Amazon komutu
amazon_parser = subparsers.add_parser("amazon", aliases=["nile"], help="Amazon Games (Nile) işlemlerini yönetir")
amazon_parser.add_argument("--login", action="store_true", help="Amazon hesabına giriş yapar")
amazon_parser.add_argument("--logout", action="store_true", help="Amazon hesabından çıkış yapar")
amazon_parser.add_argument("--list", action="store_true", help="Kütüphanedeki oyunları listeler")
# Itch komutu
itch_parser = subparsers.add_parser("itch", help="Itch.io (Butler) işlemlerini yönetir")
itch_parser.add_argument("--login", action="store_true", help="Itch.io hesabına giriş yapar")
itch_parser.add_argument("--logout", action="store_true", help="Itch.io hesabından çıkış yapar")
itch_parser.add_argument("--list", action="store_true", help="Kütüphanedeki oyunları listeler")
# Menu komutu
menu_parser = subparsers.add_parser("menu", help="Bir oyunun aksiyon menüsünü doğrudan açar")
menu_parser.add_argument("index", type=int, help="Oyunun numarası (list çıktısındaki)")
# Help komutu (manuel)
help_parser = subparsers.add_parser("help", help="Bu yardım mesajını gösterir veya bir komut hakkında detaylı bilgi verir")
help_parser.add_argument("subcommand", nargs="?", help="Yardım alınacak alt komut (örn: run, setting, uninstall)")
# Dead komutu (temizlik)
dead_parser = subparsers.add_parser("dead", help="ESGO'nun tüm verilerini (ayarlar, araçlar, kütüphane) siler")
dead_parser.add_argument("--force", "-f", action="store_true", help="Onay sormadan temizle")
dead_parser.add_argument("--include-games", action="store_true", help="Oyun indirme ve prefix klasörlerini de sil")
args = parser.parse_args()
if args.command == "help":
if args.subcommand:
sub = parser._subparsers._group_actions[0].choices.get(args.subcommand)
if sub:
sub.print_help()
else:
print(f"[HATA] Bilinmeyen komut: {args.subcommand}")
sys.exit(0)
parser.print_help()
sys.exit(0)
if args.command == "run":
games = load_games()
target = None
query_clean = args.query.strip()
if not query_clean:
print("[HATA] Boş sorgu girdiniz.")
sys.exit(1)
if query_clean.isdigit():
idx = int(query_clean) - 1
if 0 <= idx < len(games):
target = games[idx]
else:
query = query_clean.lower()
for game in games:
if query in game.name.lower():
target = game
break
if target:
is_patch = False
if args.exe:
target.exe_path = args.exe
is_patch = True
from esgo.runners.executor import launch_game
launch_game(target, config, use_logging=args.log, clear_prefix=args.prefixclear, dry_run=args.dry_run, is_patch=is_patch)
else:
print(f"[HATA] Oyun bulunamadı: {args.query}")
sys.exit(1)
elif args.command == "setting":
games = load_games()
idx = args.index - 1
if 0 <= idx < len(games):
game = games[idx]
# CLI üzerinden gelen argümanlar var mı kontrol et (is not None ile boş stringleri de kabul ediyoruz)
cli_params = [args.name, args.exe, args.proton, args.prefix, args.args, args.env, args.umu_id]
has_cli_update = any(p is not None for p in cli_params) or args.prefixclear or args.sandbox or args.no_sandbox
if has_cli_update:
if args.name is not None: game.name = args.name
if args.exe is not None: game.exe_path = args.exe
if args.proton is not None: game.custom_wine = args.proton
if args.prefix is not None: game.custom_prefix = args.prefix
if args.args is not None: game.arguments = args.args
if args.env is not None: game.env_vars = args.env
if args.umu_id is not None: game.umu_id = args.umu_id
if args.prefixclear: game.custom_prefix = ""
if args.sandbox: game.use_sandbox = True
if args.no_sandbox: game.use_sandbox = False
print(f"[BAŞARILI] '{game.name}' ayarları güncellendi.")
from esgo.core.library import save_games
save_games(games)
else:
# Argüman yoksa interaktif menüyü aç
from esgo.cli.installed_games import edit_game_ui
edit_game_ui(game)
from esgo.core.library import save_games
save_games(games)
else:
print(f"[HATA] Geçersiz oyun numarası: {args.index}")
elif args.command == "uninstall":
games = load_games()
idx = args.index - 1
if 0 <= idx < len(games):
from esgo.cli.installed_games import uninstall_game
uninstall_game(games, idx, force=args.force, delete_files=args.delete_files)
else:
print(f"[HATA] Geçersiz oyun numarası: {args.index}")
elif args.command == "verify":
games = load_games()
idx = args.index - 1
if 0 <= idx < len(games):
game = games[idx]
if game.source == "epic" and game.platform_id:
from esgo.platforms.epic import EpicPlatform
EpicPlatform().verify_game(game.platform_id)
else:
print("[HATA] Şu anda sadece Epic Games (Legendary) oyunları doğrulanabilir.")
else:
print(f"[HATA] Geçersiz oyun numarası: {args.index}")
elif args.command == "list":
games = load_games()
print(f"\n--- ESGO Oyun Kütüphanesi ({len(games)} Oyun) ---")
for i, game in enumerate(games):
print(f"{i+1}) {game.name} [{game.source.upper()}]")
elif args.command == "add":
from esgo.cli.installed_games import menu_add_game_manual
games = load_games()
menu_add_game_manual(games)
elif args.command == "doctor":
from esgo.cli.doctor import run_doctor
run_doctor()
elif args.command == "kill":
from esgo.core.game_tracker import list_active_games, kill_game_by_pid_file
active = list_active_games()
if args.kill_list or (not args.target and not active):
if not active:
print("[BİLGİ] ESGO tarafından başlatılmış aktif oyun bulunamadı.")
else:
print(f"\n--- ESGO Aktif Oyunlar ({len(active)}) ---")
for g in active:
orphan_tag = "[YETİM] " if g.get("orphan") else ""
alive_tag = "[ÇALIŞIYOR]" if g.get("alive") else "[KAPANDI]"
print(f" {orphan_tag}{g['name']} {alive_tag}")
print(f" PID dosyası: {g['pid_file']}")
sys.exit(0)
if not active:
print("[BİLGİ] Sonlandırılacak aktif oyun bulunamadı.")
sys.exit(0)
targets = []
if args.target == "all":
targets = active
else:
q = args.target.lower()
for g in active:
if q in g["name"].lower() or q in g["pid_file"]:
targets.append(g)
if not targets:
print(f"[HATA] '{args.target}' ile eşleşen oyun bulunamadı.")
sys.exit(1)
for g in targets:
name = g["name"]
if not args.force:
ans = input(f"'{name}' sonlandırılsın mı? (e/H): ").strip().lower()
if ans != 'e':
print(f"[İPTAL] '{name}' atlandı.")
continue
killed = kill_game_by_pid_file(g["pid_file"])
print(f"[SONLANDIRILDI] '{name}' — {killed} süreç öldürüldü.")
elif args.command == "epic":
from esgo.platforms.epic import EpicPlatform
handle_platform_cli("Epic Games", EpicPlatform(), args)
elif args.command == "gog":
from esgo.platforms.gog import GogPlatform
handle_platform_cli("GOG", GogPlatform(), args)
elif args.command in ["amazon", "nile"]:
from esgo.platforms.nile import NilePlatform
handle_platform_cli("Amazon Games", NilePlatform(), args)
elif args.command == "itch":
from esgo.platforms.itch import ItchPlatform
handle_platform_cli("Itch.io", ItchPlatform(), args)
elif args.command == "settings":
from esgo.cli.settings import menu_settings
menu_settings()
elif args.command == "dead":
from esgo.cli.dead import run_dead
run_dead(force=args.force, include_games=args.include_games)
elif args.command == "menu":
games = load_games()
games.sort(key=lambda x: x.name.lower())
idx = args.index - 1
if 0 <= idx < len(games):
from esgo.cli.installed_games import _game_actions_menu
_game_actions_menu(games, idx)
from esgo.core.library import save_games
save_games(games)
else:
print(f"[HATA] Geçersiz oyun numarası: {args.index}. Toplam {len(games)} oyun var.")
sys.exit(1)
elif args.command in ["update-tools", "update-package", "setup-tools"]:
from esgo.core.tool_downloader import download_tool
print("\n=== ESGO Araç Güncelleme Merkezi ===")
if args.name:
download_tool(args.name)
else:
tools = ["legendary", "nile", "butler", "gogdl", "soda", "proton"]
for t in tools:
download_tool(t)
print("\n[TAMAMLANDI] Araçlar kontrol edildi ve güncellendi.")
else:
# Argüman yoksa klasik menüyü başlat
logger.info("ESGO Launcher menü modu başlatıldı.")
try:
from esgo.cli.main_menu import show_main_menu
show_main_menu()
except KeyboardInterrupt:
print("\nÇıkış yapılıyor...")
logger.info("Kullanici tarafindan (Ctrl+C) kapatildi.")
sys.exit(0)
logger.info("ESGO Launcher kapatildi.")
if __name__ == "__main__":
main()