MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / LoadPluginsFromDir

Method LoadPluginsFromDir

core/logic/PluginSys.cpp:868–928  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

866}
867
868void CPluginManager::LoadPluginsFromDir(const char *basedir, const char *localpath)
869{
870 char base_path[PLATFORM_MAX_PATH];
871
872 /* Form the current path to start reading from */
873 if (localpath == NULL)
874 {
875 libsys->PathFormat(base_path, sizeof(base_path), "%s", basedir);
876 } else {
877 libsys->PathFormat(base_path, sizeof(base_path), "%s/%s", basedir, localpath);
878 }
879
880 IDirectory *dir = libsys->OpenDirectory(base_path);
881
882 if (!dir)
883 {
884 char error[256];
885 libsys->GetPlatformError(error, sizeof(error));
886 g_Logger.LogError("[SM] Failure reading from plugins path: %s", localpath);
887 g_Logger.LogError("[SM] Platform returned error: %s", error);
888 return;
889 }
890
891 while (dir->MoreFiles())
892 {
893 if (dir->IsEntryDirectory()
894 && (strcmp(dir->GetEntryName(), ".") != 0)
895 && (strcmp(dir->GetEntryName(), "..") != 0)
896 && (strcmp(dir->GetEntryName(), "disabled") != 0)
897 && (strcmp(dir->GetEntryName(), "optional") != 0))
898 {
899 char new_local[PLATFORM_MAX_PATH];
900 if (localpath == NULL)
901 {
902 /* If no path yet, don't add a former slash */
903 ke::SafeStrcpy(new_local, sizeof(new_local), dir->GetEntryName());
904 } else {
905 libsys->PathFormat(new_local, sizeof(new_local), "%s/%s", localpath, dir->GetEntryName());
906 }
907 LoadPluginsFromDir(basedir, new_local);
908 } else if (dir->IsEntryFile()) {
909 const char *name = dir->GetEntryName();
910 size_t len = strlen(name);
911 if (len >= 4
912 && strcmp(&name[len-4], ".smx") == 0)
913 {
914 /* If the filename matches, load the plugin */
915 char plugin[PLATFORM_MAX_PATH];
916 if (localpath == NULL)
917 {
918 ke::SafeStrcpy(plugin, sizeof(plugin), name);
919 } else {
920 libsys->PathFormat(plugin, sizeof(plugin), "%s/%s", localpath, name);
921 }
922 LoadAutoPlugin(plugin);
923 }
924 }
925 dir->NextEntry();

Callers

nothing calls this directly

Calls 10

PathFormatMethod · 0.80
OpenDirectoryMethod · 0.80
GetPlatformErrorMethod · 0.80
MoreFilesMethod · 0.80
IsEntryDirectoryMethod · 0.80
GetEntryNameMethod · 0.80
IsEntryFileMethod · 0.80
NextEntryMethod · 0.80
CloseDirectoryMethod · 0.80
LogErrorMethod · 0.45

Tested by

no test coverage detected