| 866 | } |
| 867 | |
| 868 | void 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(); |
nothing calls this directly
no test coverage detected