| 45 | using std::string; |
| 46 | |
| 47 | static string GetLinksFilePath(const string& configDir) |
| 48 | { |
| 49 | if (!configDir.empty()) { |
| 50 | #ifdef _WIN32 |
| 51 | char buffer[MAX_PATH + 1]; |
| 52 | configDir.copy(buffer, MAX_PATH); |
| 53 | if (PathAppendA(buffer, "ED2KLinks")) { |
| 54 | string strDir; |
| 55 | strDir.assign(buffer); |
| 56 | return strDir; |
| 57 | } |
| 58 | #else |
| 59 | string strDir = configDir; |
| 60 | if (strDir.at(strDir.length() - 1) != '/') { |
| 61 | strDir += '/'; |
| 62 | } |
| 63 | return strDir + "ED2KLinks"; |
| 64 | #endif |
| 65 | } |
| 66 | |
| 67 | |
| 68 | #ifdef __APPLE__ |
| 69 | |
| 70 | // ~/Library/Application Support always exists on macOS >= 10.5 and |
| 71 | // is the user-domain equivalent of FSFindFolder(kUserDomain, |
| 72 | // kApplicationSupportFolderType, ...) that we used to call via the |
| 73 | // Carbon FSRef API (removed in 64-bit macOS). |
| 74 | const char* home = getenv("HOME"); |
| 75 | std::string strDir = (home ? home : ""); |
| 76 | return strDir + "/Library/Application Support/aMule/ED2KLinks"; |
| 77 | |
| 78 | #elif defined(_WIN32) |
| 79 | |
| 80 | std::string strDir; |
| 81 | LPITEMIDLIST pidl; |
| 82 | |
| 83 | HRESULT hr = SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl); |
| 84 | |
| 85 | if (SUCCEEDED(hr)) { |
| 86 | char buffer[MAX_PATH + 1]; |
| 87 | if (SHGetPathFromIDListA(pidl, buffer)) { |
| 88 | if (PathAppendA(buffer, "aMule\\ED2KLinks")) { |
| 89 | strDir.assign(buffer); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | if (pidl) { |
| 95 | LPMALLOC pMalloc; |
| 96 | SHGetMalloc(&pMalloc); |
| 97 | if (pMalloc) { |
| 98 | pMalloc->Free(pidl); |
| 99 | pMalloc->Release(); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | return strDir; |
| 104 | |