added request amb251
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40749
This commit is contained in:
parent
8137f2d29d
commit
7013072236
@ -637,6 +637,72 @@ static cell_t smn_KvSetEscapeSequences(IPluginContext *pCtx, const cell_t *param
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t smn_KvDeleteThis(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
KeyValueStack *pStk;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
if (pStk->pCurRoot.size() < 2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
KeyValues *pValues = pStk->pCurRoot.front();
|
||||
pStk->pCurRoot.pop();
|
||||
pStk->pCurRoot.front()->RemoveSubKey(pValues);
|
||||
pValues->deleteThis();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t smn_KvDeleteKey(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
KeyValueStack *pStk;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
if (pStk->pCurRoot.size() < 2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *keyName;
|
||||
pContext->LocalToString(params[2], &keyName);
|
||||
|
||||
KeyValues *pRoot = pStk->pCurRoot.front();
|
||||
KeyValues *pValues = pRoot->FindKey(keyName);
|
||||
if (!pValues)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pRoot->RemoveSubKey(pValues);
|
||||
pValues->deleteThis();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static KeyValueNatives s_KeyValueNatives;
|
||||
|
||||
REGISTER_NATIVES(keyvaluenatives)
|
||||
@ -663,5 +729,7 @@ REGISTER_NATIVES(keyvaluenatives)
|
||||
{"KeyValuesToFile", smn_KeyValuesToFile},
|
||||
{"FileToKeyValues", smn_FileToKeyValues},
|
||||
{"KvSetEscapeSequences", smn_KvSetEscapeSequences},
|
||||
{"KvDeleteThis", smn_KvDeleteThis},
|
||||
{"KvDeleteKey", smn_KvDeleteKey},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
@ -192,6 +192,26 @@ native bool:KvJumpFirstSubKey(Handle:kv);
|
||||
*/
|
||||
native bool:KvJumpNextSubKey(Handle:kv);
|
||||
|
||||
/**
|
||||
* Removes the given key from the current position.
|
||||
*
|
||||
* @param kv KeyValues Handle.
|
||||
* @param key Name of the key.
|
||||
* @return True on success, false if key did not exist.
|
||||
* @error Invalid Handle.
|
||||
*/
|
||||
native bool:KvDeleteKey(Handle:kv, const String:key[]);
|
||||
|
||||
/**
|
||||
* Removes the current sub-key and jumps back one position, using the previous
|
||||
* position as the search point. This will not work if used on the root node.
|
||||
*
|
||||
* @param kv KeyValues Handle.
|
||||
* @return True on success, false if there was no sub key.
|
||||
* @error Invalid Handle.
|
||||
*/
|
||||
native bool:KvDeleteThis(Handle:kv);
|
||||
|
||||
/**
|
||||
* Jumps back to the previous position. Returns false if there are no
|
||||
* previous positions (i.e., at the root node). This should be called
|
||||
|
Loading…
Reference in New Issue
Block a user