2009-05-18 06:26:13 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2009-07-05 08:49:23 +02:00
|
|
|
* Zombie:Reloaded
|
2009-05-18 06:26:13 +02:00
|
|
|
*
|
2009-06-12 05:51:26 +02:00
|
|
|
* File: downloads.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: Download validation.
|
|
|
|
*
|
2013-01-12 08:47:36 +01:00
|
|
|
* Copyright (C) 2009-2013 Greyscale, Richard Helgeby
|
2009-06-12 05:51:26 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-05-18 06:26:13 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array that stores a list of downloadable files.
|
|
|
|
*/
|
2009-05-29 08:43:15 +02:00
|
|
|
new Handle:arrayDownloads = INVALID_HANDLE;
|
2009-05-18 06:26:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare all model/download data.
|
|
|
|
*/
|
|
|
|
DownloadsLoad()
|
|
|
|
{
|
2009-05-29 08:43:15 +02:00
|
|
|
// Register config file.
|
|
|
|
ConfigRegisterConfig(File_Downloads, Structure_List, CONFIG_FILE_ALIAS_DOWNLOADS);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-18 06:26:13 +02:00
|
|
|
// Get downloads file path.
|
|
|
|
decl String:pathdownloads[PLATFORM_MAX_PATH];
|
|
|
|
new bool:exists = ConfigGetCvarFilePath(CVAR_CONFIG_PATH_DOWNLOADS, pathdownloads);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
// If file doesn't exist, then log and stop.
|
2009-05-18 06:26:13 +02:00
|
|
|
if (!exists)
|
|
|
|
{
|
2009-05-29 08:43:15 +02:00
|
|
|
// Log failure and stop plugin.
|
2009-06-01 23:29:26 +02:00
|
|
|
LogEvent(false, LogType_Fatal, LOG_CORE_EVENTS, LogModule_Downloads, "Config Validation", "Missing downloads file: \"%s\"", pathdownloads);
|
2009-05-18 06:26:13 +02:00
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
// Set the path to the config file.
|
|
|
|
ConfigSetConfigPath(File_Downloads, pathdownloads);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
// Load config from file and create array structure.
|
2009-07-09 23:17:50 +02:00
|
|
|
new bool:success = ConfigLoadConfig(File_Downloads, arrayDownloads, PLATFORM_MAX_PATH);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
// Unexpected error, stop plugin.
|
|
|
|
if (!success)
|
2009-05-18 06:26:13 +02:00
|
|
|
{
|
2009-06-01 23:29:26 +02:00
|
|
|
LogEvent(false, LogType_Fatal, LOG_CORE_EVENTS, LogModule_Downloads, "Config Validation", "Unexpected error encountered loading: %s", pathdownloads);
|
2009-05-18 06:26:13 +02:00
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-18 06:26:13 +02:00
|
|
|
new downloadcount;
|
|
|
|
new downloadvalidcount;
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-18 06:26:13 +02:00
|
|
|
decl String:downloadpath[PLATFORM_MAX_PATH];
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
new downloads = downloadcount = GetArraySize(arrayDownloads);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-18 06:26:13 +02:00
|
|
|
// x = download array index.
|
|
|
|
for (new x = 0; x < downloads; x++)
|
|
|
|
{
|
2009-05-29 08:43:15 +02:00
|
|
|
// Get download path
|
|
|
|
GetArrayString(arrayDownloads, x, downloadpath, sizeof(downloadpath));
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-18 06:26:13 +02:00
|
|
|
// If file doesn't exist, then remove, log, and stop.
|
2016-06-11 23:31:15 +02:00
|
|
|
if (!FileExists(downloadpath, false))
|
2009-05-18 06:26:13 +02:00
|
|
|
{
|
|
|
|
// Remove client from array.
|
2009-05-29 08:43:15 +02:00
|
|
|
RemoveFromArray(arrayDownloads, x);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-18 06:26:13 +02:00
|
|
|
// Subtract one from count.
|
|
|
|
downloads--;
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-18 06:26:13 +02:00
|
|
|
// Backtrack one index, because we deleted it out from under the loop.
|
|
|
|
x--;
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-06-01 23:29:26 +02:00
|
|
|
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Downloads, "Config Validation", "Missing file \"%s\"", downloadpath);
|
2009-05-18 06:26:13 +02:00
|
|
|
continue;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-18 06:26:13 +02:00
|
|
|
// Increment downloadvalidcount
|
|
|
|
downloadvalidcount++;
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-18 06:26:13 +02:00
|
|
|
// Precache model file and add to downloads table.
|
|
|
|
AddFileToDownloadsTable(downloadpath);
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-18 06:26:13 +02:00
|
|
|
// Log model validation info.
|
2009-06-01 23:29:26 +02:00
|
|
|
LogEvent(false, LogType_Normal, LOG_CORE_EVENTS, LogModule_Downloads, "Config Validation", "Total: %d | Successful: %d | Unsuccessful: %d", downloadcount, downloadvalidcount, downloadcount - downloadvalidcount);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-05-18 06:26:13 +02:00
|
|
|
// Set config data.
|
2009-05-29 08:43:15 +02:00
|
|
|
ConfigSetConfigLoaded(File_Downloads, true);
|
|
|
|
ConfigSetConfigReloadFunc(File_Downloads, GetFunctionByName(GetMyHandle(), "DownloadsOnConfigReload"));
|
|
|
|
ConfigSetConfigHandle(File_Downloads, arrayDownloads);
|
2009-05-18 06:26:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when configs are being reloaded.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2009-05-18 06:26:13 +02:00
|
|
|
* @param config The config being reloaded. (only if 'all' is false)
|
|
|
|
*/
|
|
|
|
public DownloadsOnConfigReload(ConfigFile:config)
|
|
|
|
{
|
|
|
|
// Reload download config.
|
2009-05-29 08:43:15 +02:00
|
|
|
DownloadsLoad();
|
2009-06-12 15:52:51 +02:00
|
|
|
}
|