AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
|
03-06-2015
, 10:58
Re: [Search] auto plugin adder
|
#14
|
Well, here is final code:
PHP Code:
/* Copyleft 2015 @ HamletEagle
Auto plugin adder to file 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.
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 Auto plugin adder; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <amxmodx>
#define Plugin "Auto plugin adder" #define Version "0.0.2" #define Author "HamletEagle"
new Trie:TriePluginsFromFile new Array:ArrayPlugins
new HandleDir new CurrentDir[80] new CurrentFileName[100]
public plugin_init() { register_plugin ( .plugin_name = Plugin, .version = Version, .author = Author )
TriePluginsFromFile = TrieCreate() ArrayPlugins = ArrayCreate(120) ReadPluginsFolder() }
ReadPluginsFolder() { get_localinfo("amxx_pluginsdir", CurrentDir, charsmax(CurrentDir)) HandleDir = open_dir(CurrentDir, CurrentFileName, charsmax(CurrentFileName)) if(HandleDir) { while(next_file(HandleDir, CurrentFileName, charsmax(CurrentFileName))) { ArrayPushString(ArrayPlugins, CurrentFileName) } close_dir(HandleDir) ParsePluginsFiles() } else { log_error(AMX_ERR_NATIVE, "Plugins folder could not be found") pause("a") } }
ParsePluginsFiles() { //Step 1: parse plugins.ini file get_localinfo("amxx_plugins", CurrentDir, charsmax(CurrentDir)) ReadFile(fopen(CurrentDir, "rt")) //Step 2: parse plugins-.ini files get_localinfo("amxx_configsdir", CurrentDir, charsmax(CurrentDir)) HandleDir = open_dir(CurrentDir, CurrentFileName, charsmax(CurrentFileName)) if(HandleDir) { while(next_file(HandleDir, CurrentFileName, charsmax(CurrentFileName))) { if(equal(CurrentFileName, "plugins-", 8)) { format(CurrentFileName, charsmax(CurrentFileName), "%s/%s", CurrentDir, CurrentFileName) ReadFile(fopen(CurrentFileName, "rt")) } } close_dir(HandleDir) } //Step 3: parse custom configuration per map name new const MapFile[] = "maps" format(CurrentDir, charsmax(CurrentDir), "%s/%s", CurrentDir, MapFile)
HandleDir = open_dir(CurrentDir, CurrentFileName, charsmax(CurrentFileName)) if(HandleDir) { while(next_file(HandleDir, CurrentFileName, charsmax(CurrentFileName))) { if(equal(CurrentFileName, "plugins_", 8)) { format(CurrentFileName, charsmax(CurrentFileName), "%s/%s", CurrentDir, CurrentFileName) ReadFile(fopen(CurrentFileName, "rt")) } } close_dir(HandleDir) } AddPlugins() }
ReadFile(FilePointer) { if(FilePointer) { new FileData[128], Needed[64], UnNeeded[64] while(!feof(FilePointer)) { fgets(FilePointer, FileData, charsmax(FileData)) trim(FileData) if(FileData[0] != EOS) { parse(FileData, Needed, charsmax(Needed), UnNeeded, charsmax(UnNeeded)) if(Needed[0] == ';' && Needed[1] != EOS) { copy(Needed, charsmax(Needed), Needed[1]) } TrieSetCell(TriePluginsFromFile, Needed, 0) } } fclose(FilePointer) } }
AddPlugins() { new Array:FinalArray = ArrayCreate(120), Size = ArraySize(ArrayPlugins), PluginName[120], i for(i = 0; i < Size; i++) { ArrayGetString(ArrayPlugins, i, PluginName, charsmax(PluginName)) if(!TrieKeyExists(TriePluginsFromFile, PluginName)) { ArrayPushString(FinalArray, PluginName) } }
ArrayDestroy(ArrayPlugins) TrieDestroy(TriePluginsFromFile)
Size = ArraySize(FinalArray) if(Size) { get_localinfo("amxx_plugins", CurrentDir, charsmax(CurrentDir)) new FilePointer = fopen(CurrentDir, "a") if(FilePointer) { for(i = 0; i < Size; i++) { ArrayGetString(FinalArray, i, PluginName, charsmax(PluginName)) if(strlen(PluginName) > 5) //prevent invalid entries { fprintf(FilePointer, "%s^n", PluginName) } } fclose(FilePointer) } } ArrayDestroy(FinalArray) }
It search for custom plugin configuration(per map or per mod configurations). Any plugin that is in a custom plugins file won't be added to plugins.ini
Quote:
Originally Posted by fysiks
This is not a good idea. If you ever need to use map specific plugin files, your idea would load them on EVERY map and not just the ones that are configured to do so.
Simply edit plugins.ini manually.
|
This is now properly handled.
OP, can you please test this version ? From my tests it's working fine, but I would like to have a second opinion.
__________________
Last edited by HamletEagle; 03-07-2015 at 06:29.
|
|