#include <string>
#include <vector>
#include <functional>
+#include <map>
#ifndef PATH_SEPARATOR
#define PATH_SEPARATOR '/'
std::string Basename (const std::string& path);
bool EndWithIgnoreCase (const std::string& str1, const std::string& str2, std::string& filename);
void AssembliesInDirectory(const std::vector<std::string>& directories, std::string& tpaList);
+
bool FileNotExist(const std::string& path);
std::string JoinStrings(const std::vector<std::string>& strings, const char* const delimeter);
-typedef std::function<void (const char*)> FileReader;
+typedef std::function<void (const char*, const char*)> FileReader;
void ScanFilesInDir(const char* directory, FileReader reader, unsigned int depth);
#endif // __UTILS_H__
}
else
{
- std::vector<std::string> tpaDir = {
- RuntimeDir, DeviceAPIDir
- };
+ // search dlls in the application directory first, to use application dlls
+ // instead of system dlls when proceeding NI
+ std::vector<std::string> tpaDir;
+ if (app_path != NULL)
+ {
+ std::string path(app_path);
+ std::string::size_type prev_pos = 0, pos = 0;
+ while((pos = path.find(':', pos)) != std::string::npos)
+ {
+ std::string substring(path.substr(prev_pos, pos - prev_pos));
+ tpaDir.push_back(substring);
+ prev_pos = ++pos;
+ }
+ std::string substring(path.substr(prev_pos, pos - prev_pos));
+ tpaDir.push_back(substring);
+ }
+ tpaDir.push_back(RuntimeDir);
+ tpaDir.push_back(DeviceAPIDir);
+
std::string tpa;
AssembliesInDirectory(tpaDir, tpa);
if (app_paths.back() == ':')
app_paths.pop_back();
- auto convert = [&app_paths, ignores, igcount, &cb](const char* path)
+ auto convert = [&app_paths, ignores, igcount, &cb](const char* path, const char* name)
{
for (int i=0; i<igcount; i++)
{
{
std::string npath(path);
if (path.size() < 5) return npath;
- if (strncasecmp(path.c_str() + path.size() - 4, ".dll", 4))
+ if (!strncasecmp(path.c_str() + path.size() - 4, ".dll", 4))
{
npath = path.substr(0, path.size()-4);
- }else if (strncasecmp(path.c_str() + path.size() - 4, ".exe", 4))
+ }else if (!strncasecmp(path.c_str() + path.size() - 4, ".exe", 4))
{
npath = path.substr(0, path.size()-4);
}
- if (strncasecmp(npath.c_str() + npath.size() - 3, ".ni", 3))
+ if (!strncasecmp(npath.c_str() + npath.size() - 3, ".ni", 3))
{
return npath.substr(0, npath.size()-3);
}
void AssembliesInDirectory(const std::vector<std::string>& directories, std::string& tpaList)
{
- std::unordered_map<AssemblyFile, bool> addedAssemblies;
+ std::map<std::string, std::string> assemblyList;
+ std::map<std::string, std::string> tmpList;
- auto reader = [&addedAssemblies] (const char* path)
+ auto reader = [&assemblyList, &tmpList] (const char* path, const char* name)
{
std::string _path(path);
-
- std::string::size_type dotp = _path.rfind('.');
- std::string ext = dotp != std::string::npos ? _path.substr(dotp) : "";
- std::string noext;
- bool ni = false;
-
if (IsManagedAssembly(_path))
{
- if (IsNativeImage(_path))
- {
- noext = _path.substr(0, _path.size()-7);
- ni = true;
- }
- else
- {
- noext = _path.substr(0, _path.size()-4);
- }
-
- AssemblyFile f = {noext, ext};
- if (addedAssemblies.find(f) == addedAssemblies.end())
+ std::string dll_name = StripNIDLL(name);
+ std::pair<std::map<std::string, std::string>::iterator, bool> ret;
+ ret = tmpList.insert(std::pair<std::string, std::string>(dll_name, _path));
+ if (ret.second == false)
{
- addedAssemblies[f] = ni;
- }
- else
- {
- addedAssemblies[f] |= ni;
+ if (IsNativeImage(_path))
+ {
+ tmpList[dll_name] = _path;
+ }
}
}
};
for (auto directory : directories)
{
ScanFilesInDir(directory.c_str(), reader, 1);
+ // merge scaned dll list to tpa list.
+ // if the dll is already exist in the list, that is skipped.
+ assemblyList.insert(tmpList.begin(), tmpList.end());
}
- for (auto kv : addedAssemblies)
+ std::map<std::string, std::string>::iterator it;
+ for (it = assemblyList.begin(); it != assemblyList.end(); it++)
{
- tpaList += kv.first.noext + (kv.second ? ".ni" : "") + kv.first.ext + ':';
+ tpaList += it->second + ':';
}
-
if (tpaList.back() == ':')
+ {
tpaList.pop_back();
+ }
}
void ScanFilesInDir(const char* directory, FileReader reader, unsigned int depth)
}
if (!isDir)
{
- reader(path.c_str());
+ reader(path.c_str(), entry->d_name);
}
else if (depth > 1 && strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))
{