1.1 --- a/core-legacy/sourcemm.cpp Mon Nov 24 04:13:35 2008 -0600
1.2 +++ b/core-legacy/sourcemm.cpp Mon Nov 24 07:25:46 2008 -0600
1.3 @@ -118,12 +118,11 @@
1.4 mmBaseDir = GetMetamodBaseDir();
1.5 }
1.6
1.7 - char full_path[260];
1.8 + char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
1.9
1.10 - g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s", g_ModPath.c_str(), pluginFile);
1.11 - LoadPluginsFromFile(full_path);
1.12 - g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s", g_ModPath.c_str(), mmBaseDir);
1.13 - LookForVDFs(full_path);
1.14 + g_SmmAPI.PathFormat(filepath, sizeof(filepath), "%s/%s", g_ModPath.c_str(), pluginFile);
1.15 + g_SmmAPI.PathFormat(vdfpath, sizeof(vdfpath), "%s/%s", g_ModPath.c_str(), mmBaseDir);
1.16 + LoadPlugins(filepath, vdfpath);
1.17 }
1.18
1.19 SMM_API void *
1.20 @@ -344,7 +343,7 @@
1.21 g_SourceHook.CompleteShutdown();
1.22 }
1.23
1.24 -void LoadFromVDF(const char *file)
1.25 +bool LoadFromVDF(const char *file, bool &skipped)
1.26 {
1.27 PluginId id;
1.28 bool already, kvfileLoaded;
1.29 @@ -367,13 +366,15 @@
1.30 if (!kvfileLoaded)
1.31 {
1.32 pValues->deleteThis();
1.33 - return;
1.34 + skipped = false;
1.35 + return false;
1.36 }
1.37
1.38 if ((plugin_file = pValues->GetString("file", NULL)) == NULL)
1.39 {
1.40 pValues->deleteThis();
1.41 - return;
1.42 + skipped = false;
1.43 + return false;
1.44 }
1.45
1.46 if ((alias = pValues->GetString("alias", NULL)) != NULL)
1.47 @@ -406,18 +407,25 @@
1.48 }
1.49
1.50 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
1.51 + skipped = already;
1.52 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1.53 {
1.54 LogMessage("[META] Failed to load plugin %s: %s", plugin_file, error);
1.55 + return false;
1.56 }
1.57
1.58 pValues->deleteThis();
1.59 + return true;
1.60 }
1.61
1.62 -void LookForVDFs(const char *dir)
1.63 +int LoadVDFPluginsFromDir(const char *dir, int &skipped)
1.64 {
1.65 + bool success, skip;
1.66 + int total = 0;
1.67 char path[MAX_PATH];
1.68
1.69 + skipped = 0;
1.70 +
1.71 #if defined _MSC_VER
1.72 HANDLE hFind;
1.73 WIN32_FIND_DATA fd;
1.74 @@ -428,7 +436,7 @@
1.75 {
1.76 DWORD dw = GetLastError();
1.77 if (dw == ERROR_FILE_NOT_FOUND)
1.78 - return;
1.79 + return 0;
1.80
1.81 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
1.82 NULL,
1.83 @@ -438,13 +446,17 @@
1.84 sizeof(error),
1.85 NULL);
1.86 LogMessage("[META] Could not open folder \"%s\" (%s)", dir, error);
1.87 - return;
1.88 + return 0;
1.89 }
1.90
1.91 do
1.92 {
1.93 g_SmmAPI.PathFormat(path, sizeof(path), "%s\\%s", dir, fd.cFileName);
1.94 - LoadFromVDF(path);
1.95 + success = LoadFromVDF(path, skip);
1.96 + if (skip)
1.97 + skipped++;
1.98 + else if (success)
1.99 + total++;
1.100 } while (FindNextFile(hFind, &fd));
1.101
1.102 FindClose(hFind);
1.103 @@ -456,7 +468,7 @@
1.104 if ((pDir = opendir(dir)) == NULL)
1.105 {
1.106 LogMessage("[META] Could not open folder \"%s\" (%s)", dir, strerror(errno));
1.107 - return;
1.108 + return 0;
1.109 }
1.110
1.111 while ((pEnt = readdir(pDir)) != NULL)
1.112 @@ -472,11 +484,17 @@
1.113 continue;
1.114 }
1.115 g_SmmAPI.PathFormat(path, sizeof(path), "%s/%s", dir, pEnt->d_name);
1.116 - LoadFromVDF(path);
1.117 + success = LoadFromVDF(path, skip);
1.118 + if (skip)
1.119 + skipped++;
1.120 + else if (success)
1.121 + total++;
1.122 }
1.123
1.124 closedir(pDir);
1.125 #endif
1.126 +
1.127 + return total;
1.128 }
1.129
1.130 bool KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID)
1.131 @@ -509,21 +527,22 @@
1.132 return retOK;
1.133 }
1.134
1.135 -int LoadPluginsFromFile(const char *_file)
1.136 +int LoadPluginsFromFile(const char *filepath, int &skipped)
1.137 {
1.138 FILE *fp;
1.139 - int total = 0, skipped=0;
1.140 + int total = 0;
1.141 PluginId id;
1.142 bool already;
1.143
1.144 - fp = fopen(_file, "rt");
1.145 + skipped = 0;
1.146 +
1.147 + fp = fopen(filepath, "rt");
1.148 if (!fp)
1.149 {
1.150 - LogMessage("[META] Could not open plugins file %s\n", _file);
1.151 - return -1;
1.152 + return 0;
1.153 }
1.154
1.155 - char buffer[255], error[255], full_path[255];
1.156 + char buffer[255], error[255], full_path[PATH_SIZE];
1.157 const char *ptr, *ext, *file;
1.158 size_t length;
1.159 while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
1.160 @@ -646,16 +665,27 @@
1.161 }
1.162 fclose(fp);
1.163
1.164 - if (skipped)
1.165 - {
1.166 - LogMessage("[META] Loaded %d plugins from file (%d already loaded)", total, skipped);
1.167 - }
1.168 - else
1.169 - {
1.170 - LogMessage("[META] Loaded %d plugins from file.", total);
1.171 - }
1.172 + return total;
1.173 +}
1.174
1.175 - return total;
1.176 +int LoadPlugins(const char *filepath, const char *vdfpath)
1.177 +{
1.178 + int total, skipped, fskipped, vskipped;
1.179 + const char *s = "";
1.180 +
1.181 + total = LoadPluginsFromFile(filepath, fskipped);
1.182 + total += LoadVDFPluginsFromDir(vdfpath, vskipped);
1.183 + skipped = fskipped + vskipped;
1.184 +
1.185 + if (total == 0 || total > 1)
1.186 + s = "s";
1.187 +
1.188 + if (skipped)
1.189 + LogMessage("[META] Loaded %d plugin%s (%d already loaded)", total, s, skipped);
1.190 + else
1.191 + LogMessage("[META] Loaded %d plugin%s.", total, s);
1.192 +
1.193 + return total;
1.194 }
1.195
1.196 void LogMessage(const char *msg, ...)
1.197 @@ -682,13 +712,11 @@
1.198 {
1.199 if (!bInFirstLevel)
1.200 {
1.201 - char full_path[255];
1.202 + char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
1.203
1.204 - g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s", g_ModPath.c_str(), GetPluginsFile());
1.205 - LoadPluginsFromFile(full_path);
1.206 -
1.207 - g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s", g_ModPath.c_str(), GetMetamodBaseDir());
1.208 - LookForVDFs(full_path);
1.209 + g_SmmAPI.PathFormat(filepath, sizeof(filepath), "%s/%s", g_ModPath.c_str(), GetPluginsFile());
1.210 + g_SmmAPI.PathFormat(vdfpath, sizeof(vdfpath), "%s/%s", g_ModPath.c_str(), GetMetamodBaseDir());
1.211 + LoadPlugins(filepath, vdfpath);
1.212 }
1.213 else
1.214 {