| 79 | |
| 80 | |
| 81 | std::string getConfigDirName(const char* versionName) { |
| 82 | std::string customConfigDir = configDir(0, NULL); |
| 83 | if (customConfigDir.size() > 0) { |
| 84 | if (versionName) |
| 85 | #if defined(_WIN32) |
| 86 | return customConfigDir + versionName + "\\"; |
| 87 | #else |
| 88 | return customConfigDir + versionName + "/"; |
| 89 | #endif |
| 90 | else { |
| 91 | return customConfigDir; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | #if defined(_WIN32) |
| 96 | std::string name("C:"); |
| 97 | char dir[MAX_PATH]; |
| 98 | ITEMIDLIST* idl; |
| 99 | if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &idl))) { |
| 100 | if (SHGetPathFromIDList(idl, dir)) { |
| 101 | struct stat statbuf; |
| 102 | if (stat(dir, &statbuf) == 0 && (statbuf.st_mode & _S_IFDIR) != 0) { |
| 103 | name = dir; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | IMalloc* shalloc; |
| 108 | if (SUCCEEDED(SHGetMalloc(&shalloc))) { |
| 109 | shalloc->Free(idl); |
| 110 | shalloc->Release(); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // yes your suposed to have the "my" in front of it. I know it's silly, but it's the MS way. |
| 115 | name += "\\My BZFlag Files\\"; |
| 116 | if (versionName) { |
| 117 | name += versionName; |
| 118 | name += "\\"; |
| 119 | } |
| 120 | customConfigDir = name; |
| 121 | return name; |
| 122 | |
| 123 | #elif defined(__APPLE__) |
| 124 | std::string name; |
| 125 | ::FSRef libraryFolder; |
| 126 | ::OSErr err; |
| 127 | err = ::FSFindFolder(::kUserDomain, ::kApplicationSupportFolderType, true, &libraryFolder); |
| 128 | if (err == ::noErr) { |
| 129 | char buff[1024]; |
| 130 | err = ::FSRefMakePath(&libraryFolder, (UInt8*)buff, sizeof(buff)); |
| 131 | if (err == ::noErr) { |
| 132 | std::strcat(buff, "/BZFlag/"); |
| 133 | if (versionName) { |
| 134 | std::strncat(buff, versionName, 1024 - strlen(buff) - 1); |
| 135 | std::strncat(buff, "/", 1024 - strlen(buff) - 1); |
| 136 | } |
| 137 | name = buff; |
| 138 | } |
no test coverage detected