std::string ResolveIgniteHome(const std::string* path, bool* found) { if (path) // 1. Check passed argument. return ResolveIgniteHome0(*path, false, found); else { // 2. Check environment variable. bool envFound; std::string env = GetEnv(IGNITE_HOME, &envFound); if (envFound) return ResolveIgniteHome0(env, false, found); // 3. Check current work dir. const DWORD curDirLen = GetCurrentDirectory(0, NULL); char* curDir = new char[curDirLen]; GetCurrentDirectoryA(curDirLen, curDir); std::string curDirStr = curDir; delete[] curDir; return ResolveIgniteHome0(curDirStr, true, found); } }
std::string ResolveIgniteHome(const std::string& path) { // 1. Check passed argument. if (IsValidDirectory(path)) return path; // 2. Check environment variable. std::string home = GetEnv(IGNITE_HOME); if (IsValidDirectory(home)) return home; // 3. Check current work dir. DWORD curDirLen = GetCurrentDirectoryA(0, NULL); if (!curDirLen) return std::string(); FixedSizeArray<char> curDir(curDirLen); curDirLen = GetCurrentDirectoryA(curDir.GetSize(), curDir.GetData()); if (!curDirLen) return std::string(); std::string curDirStr(curDir.GetData()); return ResolveIgniteHome0(curDirStr); }
/** * Helper function for Ignite home resolution. * Goes upwards in directory hierarchy and checks whether certain * folders exist in the path. * * @param path Path to evaluate. * @return res Resolved directory. Empty string if not found. */ std::string ResolveIgniteHome0(const std::string& path) { if (!IsValidDirectory(path)) return std::string(); // Remove trailing slashes, otherwise we will have an infinite loop. size_t last = path.find_last_not_of("/\\ "); if (last == std::string::npos) return std::string(); std::string path0(path, 0, last + 1); if (LooksLikeBinaryReleaseHome(path0) || LooksLikeSourceReleaseHome(path0)) return path0; // Evaluate parent directory. size_t slashPos = path0.find_last_of("/\\"); if (slashPos == std::string::npos) return std::string(); std::string parent(path0, 0, slashPos); return ResolveIgniteHome0(parent); }
/** * Helper function for GG home resolution. Checks whether certain folders * exist in the path. Optionally goes upwards in directory hierarchy. * * @param path Path to evaluate. * @param up Whether to go upwards. * @res Resolution result. * @return Resolved directory. */ std::string ResolveIgniteHome0(const std::string& path, bool up, bool* res) { DWORD attrs = GetFileAttributesA(path.c_str()); if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) { // Remove trailing slashes, otherwise we will have an infinite loop. std::string path0 = path; while (true) { char lastChar = *path0.rbegin(); if (lastChar == '/' || lastChar == '\\' || lastChar == ' ') { size_t off = path0.find_last_of(lastChar); path0.erase(off, 1); } else break; } std::string binStr = path0 + PROBE_BIN; DWORD binAttrs = GetFileAttributesA(binStr.c_str()); std::string examplesStr = path0 + PROBE_EXAMPLES; DWORD examplesAttrs = GetFileAttributesA(examplesStr.c_str()); if (binAttrs != INVALID_FILE_ATTRIBUTES && (binAttrs & FILE_ATTRIBUTE_DIRECTORY) && examplesAttrs != INVALID_FILE_ATTRIBUTES && (examplesAttrs & FILE_ATTRIBUTE_DIRECTORY)) { SetBoolResult(true, res); return std::string(path0); } if (up) { // Evaluate parent directory. size_t slashPos = path0.find_last_of("/\\"); if (slashPos != std::string::npos) { std::string parent = path0.substr(0, slashPos); return ResolveIgniteHome0(parent, true, res); } } } SetBoolResult(false, res); return std::string(); }
std::string ResolveIgniteHome(const std::string& path) { // 1. Check passed argument. if (IsValidDirectory(path)) return path; // 2. Check environment variable. std::string home = GetEnv(IGNITE_HOME); if (IsValidDirectory(home)) return home; // 3. Check current work dir. FixedSizeArray<char> curDir(1024 * 16); char* res = getcwd(curDir.GetData(), curDir.GetSize()); if (!res) return std::string(); std::string curDirStr(curDir.GetData()); return ResolveIgniteHome0(curDirStr); }