mirror of
https://codeberg.org/spire/sm_whitelist.git
synced 2026-06-03 10:14:07 +02:00
don't download existing whitelists, download to tmp file
This commit is contained in:
parent
6a1837dbd4
commit
333c506551
2 changed files with 29 additions and 15 deletions
Binary file not shown.
|
|
@ -7,7 +7,7 @@ public Plugin:myinfo = {
|
|||
name = "whitelist.tf downloader",
|
||||
author = "Icewind",
|
||||
description = "Download whitelists from whitelist.tf",
|
||||
version = "0.2",
|
||||
version = "0.3",
|
||||
url = "https://whitelist.tf"
|
||||
};
|
||||
|
||||
|
|
@ -54,7 +54,8 @@ public Action:DownloadWhiteListAction(client, args) {
|
|||
|
||||
public DownloadWhiteList(String:whiteListId[128], bool:exec) {
|
||||
decl String:fullUrl[512];
|
||||
decl String:targetPath[128];
|
||||
decl String:targetPath[PLATFORM_MAX_PATH];
|
||||
decl String:downloadPath[PLATFORM_MAX_PATH];
|
||||
decl String:BaseUrl[128];
|
||||
GetConVarString(g_hCvarUrl, BaseUrl, sizeof(BaseUrl));
|
||||
new Handle:curl = curl_easy_init();
|
||||
|
|
@ -63,10 +64,15 @@ public DownloadWhiteList(String:whiteListId[128], bool:exec) {
|
|||
Format(fullUrl, sizeof(fullUrl), "%s/%s.txt", BaseUrl, whiteListId);
|
||||
|
||||
Format(targetPath, sizeof(targetPath), "cfg/%s.txt", whiteListId);
|
||||
if (FileExists(targetPath)) {
|
||||
execWhiteList(whiteListId);
|
||||
return;
|
||||
}
|
||||
|
||||
Format(downloadPath, sizeof(downloadPath), "cfg/%s.txt.part", whiteListId);
|
||||
new Handle:output_file = INVALID_HANDLE;
|
||||
|
||||
output_file = curl_OpenFile(targetPath, "w");
|
||||
output_file = curl_OpenFile(downloadPath, "w");
|
||||
|
||||
new Handle:hDLPack = CreateDataPack();
|
||||
WritePackCell(hDLPack, _:output_file);
|
||||
|
|
@ -75,16 +81,25 @@ public DownloadWhiteList(String:whiteListId[128], bool:exec) {
|
|||
|
||||
curl_easy_setopt_handle(curl, CURLOPT_WRITEDATA, output_file);
|
||||
curl_easy_setopt_string(curl, CURLOPT_URL, fullUrl);
|
||||
|
||||
WritePackString(hDLPack, downloadPath);
|
||||
WritePackString(hDLPack, targetPath);
|
||||
|
||||
|
||||
curl_easy_perform_thread(curl, onComplete, hDLPack);
|
||||
}
|
||||
|
||||
public onComplete(Handle:hndl, CURLcode:code, any hDLPack) {
|
||||
decl String:whiteListId[128];
|
||||
decl String:targetPath[PLATFORM_MAX_PATH];
|
||||
decl String:downloadPath[PLATFORM_MAX_PATH];
|
||||
|
||||
ResetPack(hDLPack);
|
||||
CloseHandle(Handle:ReadPackCell(hDLPack)); // output_file
|
||||
ReadPackString(hDLPack, whiteListId, sizeof(whiteListId));
|
||||
bool exec = ReadPackCell(hDLPack);
|
||||
ReadPackString(hDLPack, downloadPath, sizeof(downloadPath));
|
||||
ReadPackString(hDLPack, targetPath, sizeof(targetPath));
|
||||
|
||||
CloseHandle(hDLPack);
|
||||
|
||||
|
|
@ -98,6 +113,7 @@ public onComplete(Handle:hndl, CURLcode:code, any hDLPack) {
|
|||
|
||||
if (status_code == 200) {
|
||||
ok = true;
|
||||
RenameFile(downloadPath, targetPath);
|
||||
if (exec) {
|
||||
execWhiteList(whiteListId);
|
||||
}
|
||||
|
|
@ -112,9 +128,7 @@ public onComplete(Handle:hndl, CURLcode:code, any hDLPack) {
|
|||
CloseHandle(hndl);
|
||||
|
||||
if (!ok) {
|
||||
decl String:targetPath[128];
|
||||
Format(targetPath, sizeof(targetPath), "cfg/%s.txt", whiteListId);
|
||||
DeleteFile(targetPath);
|
||||
DeleteFile(downloadPath);
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue