| 102 | } |
| 103 | |
| 104 | void SystemData::populateFolder(FolderData* folder) |
| 105 | { |
| 106 | std::string folderPath = folder->getPath(); |
| 107 | if(!fs::is_directory(folderPath)) |
| 108 | { |
| 109 | LOG(LogWarning) << "Error - folder with path \"" << folderPath << "\" is not a directory!"; |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | //make sure that this isn't a symlink to a thing we already have |
| 114 | if(fs::is_symlink(folderPath)) |
| 115 | { |
| 116 | //if this symlink resolves to somewhere that's at the beginning of our path, it's gonna recurse |
| 117 | if(folderPath.find(fs::canonical(folderPath).string()) == 0) |
| 118 | { |
| 119 | LOG(LogWarning) << "Skipping infinitely recursive symlink \"" << folderPath << "\""; |
| 120 | return; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | for(fs::directory_iterator end, dir(folderPath); dir != end; ++dir) |
| 125 | { |
| 126 | fs::path filePath = (*dir).path(); |
| 127 | |
| 128 | if(filePath.stem().string().empty()) |
| 129 | continue; |
| 130 | |
| 131 | //this is a little complicated because we allow a list of extensions to be defined (delimited with a space) |
| 132 | //we first get the extension of the file itself: |
| 133 | std::string extension = filePath.extension().string(); |
| 134 | std::string chkExt; |
| 135 | size_t extPos = 0; |
| 136 | |
| 137 | //folders *can* also match the extension and be added as games - this is mostly just to support higan |
| 138 | //see issue #75: https://github.com/Aloshi/EmulationStation/issues/75 |
| 139 | bool isGame = false; |
| 140 | do { |
| 141 | //now we loop through every extension in the list |
| 142 | size_t cpos = extPos; |
| 143 | extPos = mSearchExtension.find(" ", extPos); |
| 144 | chkExt = mSearchExtension.substr(cpos, ((extPos == std::string::npos) ? mSearchExtension.length() - cpos: extPos - cpos)); |
| 145 | |
| 146 | //if it matches, add it |
| 147 | if(chkExt == extension) |
| 148 | { |
| 149 | GameData* newGame = new GameData(this, filePath.generic_string(), filePath.stem().string()); |
| 150 | folder->pushFileData(newGame); |
| 151 | isGame = true; |
| 152 | break; |
| 153 | }else if(extPos != std::string::npos) //if not, add one to the "next position" marker to skip the space when reading the next extension |
| 154 | { |
| 155 | extPos++; |
| 156 | } |
| 157 | |
| 158 | } while(extPos != std::string::npos && chkExt != "" && chkExt.find(".") != std::string::npos); |
| 159 | |
| 160 | //add directories that also do not match an extension as folders |
| 161 | if(!isGame && fs::is_directory(filePath)) |
nothing calls this directly
no test coverage detected