1
0
mirror of https://github.com/anope/anope.git synced 2026-06-26 17:16:39 +02:00

Moved some global functions to be member functions and misc cleanup

This commit is contained in:
Adam
2011-04-25 03:16:57 -04:00
parent 6922bd239c
commit 076ebafa1b
30 changed files with 229 additions and 306 deletions
-100
View File
@@ -179,106 +179,6 @@ int Module::DelCommand(BotInfo *bi, Command *c)
return MOD_ERR_OK;
}
/*******************************************************************************
* Module Callback Functions
*******************************************************************************/
/* Check the current version of anope against a given version number
* Specifiying -1 for minor,patch or build
* @param major The major version of anope, the first part of the verison number
* @param minor The minor version of anope, the second part of the version number
* @param patch The patch version of anope, the third part of the version number
* @param build The build revision of anope from SVN
* @return True if the version newer than the version specified.
**/
bool moduleMinVersion(int major, int minor, int patch, int build)
{
bool ret = false;
if (Anope::VersionMajor() > major) /* Def. new */
ret = true;
else if (Anope::VersionMajor() == major) /* Might be newer */
{
if (minor == -1)
return true; /* They dont care about minor */
if (Anope::VersionMinor() > minor) /* Def. newer */
ret = true;
else if (Anope::VersionMinor() == minor) /* Might be newer */
{
if (patch == -1)
return true; /* They dont care about patch */
if (Anope::VersionPatch() > patch)
ret = true;
else if (Anope::VersionPatch() == patch)
{
#if 0
// XXX
if (build == -1)
return true; /* They dont care about build */
if (Anope::VersionBuild >= build)
ret = true;
#endif
}
}
}
return ret;
}
void ModuleRunTimeDirCleanUp()
{
Anope::string dirbuf = services_dir + "/modules/runtime";
Log(LOG_DEBUG) << "Cleaning out Module run time directory (" << dirbuf << ") - this may take a moment please wait";
#ifndef _WIN32
DIR *dirp = opendir(dirbuf.c_str());
if (!dirp)
{
Log(LOG_DEBUG) << "Cannot open directory (" << dirbuf << ")";
return;
}
struct dirent *dp;
while ((dp = readdir(dirp)))
{
if (!dp->d_ino)
continue;
if (Anope::string(dp->d_name).equals_cs(".") || Anope::string(dp->d_name).equals_cs(".."))
continue;
Anope::string filebuf = dirbuf + "/" + dp->d_name;
DeleteFile(filebuf.c_str());
}
closedir(dirp);
#else
Anope::string szDir = dirbuf + "/*";
WIN32_FIND_DATA FileData;
HANDLE hList = FindFirstFile(szDir.c_str(), &FileData);
if (hList != INVALID_HANDLE_VALUE)
{
bool fFinished = false;
while (!fFinished)
{
if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
Anope::string filebuf = dirbuf + "/" + FileData.cFileName;
if (!DeleteFile(filebuf.c_str()))
Log(LOG_DEBUG) << "Error deleting file " << filebuf << " - GetLastError() reports " << Anope::LastError();
}
if (!FindNextFile(hList, &FileData))
{
if (GetLastError() == ERROR_NO_MORE_FILES)
fFinished = true;
}
}
}
else
Log(LOG_DEBUG) << "Invalid File Handle. GetLastError() reports "<< static_cast<int>(GetLastError());
FindClose(hList);
#endif
Log(LOG_DEBUG) << "Module run time directory has been cleaned out";
}
void Module::SendMessage(CommandSource &source, const char *fmt, ...)
{
Anope::string language = (source.u && source.u->Account() ? source.u->Account()->language : "");