Raised This Month: $51 Target: $400
 12% 

[Search] auto plugin adder


Post New Thread Reply   
 
Thread Tools Display Modes
Giass
Member
Join Date: Aug 2011
Location: {Israel}
Old 03-04-2015 , 15:22   Re: [Search] auto plugin adder
Reply With Quote #11

Quote:
Originally Posted by HamletEagle View Post
It uses another file, mine just edit plugins.ini
TY MAN
Quote:
Originally Posted by ANTICHRISTUS View Post


EHH i know what to do but im lazy
THATS WHAT I HAD
__________________
All you need is carb
Giass is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-04-2015 , 15:28   Re: [Search] auto plugin adder
Reply With Quote #12

So, did you test mine ? It's working as you want ?
__________________
HamletEagle is offline
Giass
Member
Join Date: Aug 2011
Location: {Israel}
Old 03-04-2015 , 15:52   Re: [Search] auto plugin adder
Reply With Quote #13

Quote:
Originally Posted by HamletEagle View Post
So, did you test mine ? It's working as you want ?
Works perfect.
__________________
All you need is carb
Giass is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-06-2015 , 10:58   Re: [Search] auto plugin adder
Reply With Quote #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"CurrentDircharsmax(CurrentDir))
    
HandleDir open_dir(CurrentDirCurrentFileNamecharsmax(CurrentFileName))
    
    if(
HandleDir)
    {
        while(
next_file(HandleDirCurrentFileNamecharsmax(CurrentFileName)))
        {
            
ArrayPushString(ArrayPluginsCurrentFileName)
        }
        
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"CurrentDircharsmax(CurrentDir))
    
ReadFile(fopen(CurrentDir"rt"))
    
    
//Step 2: parse plugins-.ini files
    
get_localinfo("amxx_configsdir"CurrentDircharsmax(CurrentDir))
    
    
HandleDir open_dir(CurrentDirCurrentFileNamecharsmax(CurrentFileName))
    if(
HandleDir)
    {
        while(
next_file(HandleDirCurrentFileNamecharsmax(CurrentFileName)))
        {
            if(
equal(CurrentFileName"plugins-"8))
            {
                
format(CurrentFileNamecharsmax(CurrentFileName), "%s/%s"CurrentDirCurrentFileName)
                
ReadFile(fopen(CurrentFileName"rt"))
            }
        }
        
close_dir(HandleDir)
    }
    
    
//Step 3: parse custom configuration per map name
    
new const MapFile[] = "maps"
    
format(CurrentDircharsmax(CurrentDir), "%s/%s"CurrentDirMapFile)

    
HandleDir open_dir(CurrentDirCurrentFileNamecharsmax(CurrentFileName))
    if(
HandleDir)
    {
        while(
next_file(HandleDirCurrentFileNamecharsmax(CurrentFileName)))
        {
            if(
equal(CurrentFileName"plugins_"8))
            {
                
format(CurrentFileNamecharsmax(CurrentFileName), "%s/%s"CurrentDirCurrentFileName)
                
ReadFile(fopen(CurrentFileName"rt"))
            }
        }
        
close_dir(HandleDir)
    }
    
    
AddPlugins()
}

ReadFile(FilePointer)
{
    if(
FilePointer)
    {
        new 
FileData[128], Needed[64], UnNeeded[64]
        while(!
feof(FilePointer))
        {
            
fgets(FilePointerFileDatacharsmax(FileData))
            
trim(FileData)
            
            if(
FileData[0] != EOS)
            {
                
parse(FileDataNeededcharsmax(Needed), UnNeededcharsmax(UnNeeded))
                
                if(
Needed[0] == ';' && Needed[1] != EOS)
                {
                    
copy(Neededcharsmax(Needed), Needed[1])
                }
                
TrieSetCell(TriePluginsFromFileNeeded0)
            }
        }
        
fclose(FilePointer)
    }
}

AddPlugins()
{    
    new Array:
FinalArray ArrayCreate(120), Size ArraySize(ArrayPlugins), PluginName[120], i
    
for(0Sizei++)
    {
        
ArrayGetString(ArrayPluginsiPluginNamecharsmax(PluginName))
        if(!
TrieKeyExists(TriePluginsFromFilePluginName))
        {    
            
ArrayPushString(FinalArrayPluginName)
        }
    }

    
ArrayDestroy(ArrayPlugins)
    
TrieDestroy(TriePluginsFromFile)

    
Size ArraySize(FinalArray)
    if(
Size)
    {
        
get_localinfo("amxx_plugins"CurrentDircharsmax(CurrentDir))
        new 
FilePointer fopen(CurrentDir"a")
        if(
FilePointer)
        {
            for(
0Sizei++)
            {
                
ArrayGetString(FinalArrayiPluginNamecharsmax(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 View Post
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.
HamletEagle is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:57.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode