MCPcopy Create free account
hub / github.com/Aloshi/EmulationStation / populateFolder

Method populateFolder

src/SystemData.cpp:104–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104void 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))

Callers

nothing calls this directly

Calls 6

findMethod · 0.80
stringMethod · 0.80
pathMethod · 0.80
pushFileDataMethod · 0.80
getFileCountMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected