77from . import config
88from . import utils
99
10+
1011def get_latest_version ():
1112 url = f"https://api.github.com/repos/{ config .GITHUB_REPO } /releases/latest"
1213 try :
@@ -15,53 +16,100 @@ def get_latest_version():
1516 tag = response .json ()["tag_name" ]
1617 return tag .lstrip ("v" )
1718 except requests .exceptions .RequestException as e :
18- utils .log_error (config .error_log , f"GitHub API'ye bağlanırken hata: { e } " )
19- utils .show_notification ("anitr-cli" , "Güncelleme kontrolü başarısız oldu: Ağ hatası." , "critical" )
19+ utils .log_error (config .error_log ,
20+ f"GitHub API'ye bağlanırken hata: { e } " )
21+ utils .show_notification (
22+ "anitr-cli" , "Güncelleme kontrolü başarısız oldu: Ağ hatası." , "critical" )
2023 return config .CURRENT_VERSION
2124
25+
2226def download_and_replace_binary ():
2327 print ("📦 Güncelleme başlatılıyor..." )
2428
25- install_dir = os .path .join (os .getenv ("LOCALAPPDATA" ), "Programs" , "anitr-cli" )
26- os .makedirs (install_dir , exist_ok = True )
27- exe_path = os .path .join (install_dir , "anitr-cli.exe" )
29+ install_dir = os .path .join (
30+ os .getenv ("LOCALAPPDATA" ), "Programs" , "anitr-cli-windows" )
31+ bin_dir = os .path .join (os .getenv ("LOCALAPPDATA" ), "Programs" , "bin" )
32+ zip_path = os .path .join (os .getenv ("TEMP" ), "anitr-cli.zip" )
33+ bat_filename = "anitr-cli.bat"
34+ bat_source = os .path .join (install_dir , bat_filename )
35+ bat_dest = os .path .join (bin_dir , bat_filename )
2836
2937 latest = get_latest_version ()
30- download_url = f"https://github.com/{ config .GITHUB_REPO } /releases/download/v{ latest } /anitr-cli.exe"
38+ download_url = f"https://github.com/{
39+ config .GITHUB_REPO } /archive/refs/tags/v{ latest } .zip"
3140
3241 try :
3342 print (f"{ download_url } adresinden indiriliyor..." )
3443 response = requests .get (download_url , timeout = 15 )
3544 response .raise_for_status ()
3645
37- with open (exe_path , "wb" ) as f :
46+ # ZIP dosyasını geçici dizine yaz
47+ with open (zip_path , "wb" ) as f :
3848 f .write (response .content )
3949
40- print (f"\033 [32mYeni sürüm { exe_path } konumuna yüklendi.\033 [0m" )
50+ # Mevcut kurulu klasörü sil (önceki dosyaları temizlemek için)
51+ if os .path .exists (install_dir ):
52+ shutil .rmtree (install_dir )
53+
54+ # Zip'i aç
55+ shutil .unpack_archive (zip_path , install_dir )
56+
57+ # GitHub ZIP içindeki alt klasörü bul (örnek: anitr-cli-0.1.2)
58+ extracted_root = next ((os .path .join (install_dir , d ) for d in os .listdir (install_dir )
59+ if os .path .isdir (os .path .join (install_dir , d ))), None )
60+
61+ if not extracted_root :
62+ raise Exception ("ZIP içeriği beklenmedik şekilde eksik." )
63+
64+ # İçeriği doğrudan install_dir'e taşı
65+ for item in os .listdir (extracted_root ):
66+ s = os .path .join (extracted_root , item )
67+ d = os .path .join (install_dir , item )
68+ shutil .move (s , d )
69+
70+ shutil .rmtree (extracted_root )
4171
42- # PATH içinde mi kontrolü
72+ # bin klasörünü oluştur
73+ os .makedirs (bin_dir , exist_ok = True )
74+
75+ # .bat dosyasını hedefe taşı
76+ if os .path .exists (bat_source ):
77+ shutil .copy2 (bat_source , bat_dest )
78+ print (f"\033 [32m{ bat_filename } başarıyla {
79+ bat_dest } konumuna kopyalandı.\033 [0m" )
80+ else :
81+ print (
82+ f"\033 [91m{ bat_filename } bulunamadı. Lütfen elle kontrol edin.\033 [0m" )
83+
84+ # PATH kontrolü
4385 path_env = os .environ .get ("PATH" , "" )
44- if install_dir .lower () not in [p .strip ().lower () for p in path_env .split (";" )]:
45- print (f"\033 [93mUyarı: { install_dir } dizini PATH ortam değişkeninde bulunmuyor.\033 [0m" )
46- print ("anitr-cli komutunu doğrudan kullanmak için bu dizini PATH'e ekleyin." )
47- utils .show_notification ("anitr-cli" , "Yükleme başarılı ancak PATH'e ekli değil." , "normal" )
86+ if bin_dir .lower () not in [p .strip ().lower () for p in path_env .split (";" )]:
87+ print (f"\033 [93mUyarı: { bin_dir } dizini PATH içinde değil.\033 [0m" )
88+ print ("anitr-cli komutunu çalıştırmak için bu dizini PATH'e ekleyin." )
89+ utils .show_notification (
90+ "anitr-cli" , "Kurulum başarılı ama PATH'e ekli değil." , "normal" )
4891 else :
49- print ("\033 [32manitr-cli komutu artık doğrudan kullanılabilir.\033 [0m" )
50- utils .show_notification ("anitr-cli" , "Güncelleme tamamlandı." , "normal" )
92+ print (
93+ "\033 [32manitr-cli komutu artık doğrudan kullanılabilir.\033 [0m" )
94+ utils .show_notification (
95+ "anitr-cli" , "Güncelleme tamamlandı." , "normal" )
5196
52- except requests . exceptions . RequestException as e :
53- print (f"\033 [91mİndirme hatası: { e } \033 [0m" )
97+ except Exception as e :
98+ print (f"\033 [91mKurulum hatası: { e } \033 [0m" )
5499 utils .log_error (config .error_log , f"Güncelleme indirilemedi: { e } " )
55- utils .show_notification ("anitr-cli" , "Güncelleme indirilemedi." , "critical" )
100+ utils .show_notification (
101+ "anitr-cli" , "Kurulum başarısız oldu." , "critical" )
102+
56103
57104def check_update_notice ():
58105 try :
59106 latest = get_latest_version ()
60107 if version .parse (latest ) > version .parse (config .CURRENT_VERSION ):
61108 notice = f"Yeni bir anitr-cli sürümü mevcut: \033 [31mv{ config .CURRENT_VERSION } \033 [0m → \033 [32mv{ latest } \033 [0m\n " \
62- f"Güncellemek için şunu çalıştırın: anitr-cli --update"
109+ f"Güncellemek için şunu çalıştırın: anitr-cli --update"
63110 return notice
64111 except Exception as e :
65- utils .log_error (config .error_log , f"Güncelleme bildirimi kontrol edilirken hata: { e } " )
112+ utils .log_error (config .error_log ,
113+ f"Güncelleme bildirimi kontrol edilirken hata: { e } " )
66114 pass
67115 return None
0 commit comments