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

Function createGameFromPath

src/XMLReader.cpp:30–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30GameData* createGameFromPath(std::string gameAbsPath, SystemData* system)
31{
32 std::string gamePath = gameAbsPath;
33 std::string sysPath = system->getStartPath();
34
35 //strip out the system path stuff so it's relative to the system root folder
36 unsigned int i = 0;
37 while(i < gamePath.length() && i < sysPath.length() && gamePath[i] == sysPath[i])
38 i++;
39
40 gamePath = gamePath.substr(i, gamePath.length() - i);
41
42
43 if(gamePath[0] != '/')
44 gamePath.insert(0, "/");
45
46
47 //make our way through the directory tree finding each folder in our path or creating it if it doesn't exist
48 FolderData* folder = system->getRootFolder();
49
50 size_t separator = 0;
51 size_t nextSeparator = 0;
52 unsigned int loops = 0;
53 while(nextSeparator != std::string::npos)
54 {
55 //determine which chunk of the path we're testing right now
56 nextSeparator = gamePath.find('/', separator + 1);
57 if(nextSeparator == std::string::npos)
58 break;
59
60 std::string checkName = gamePath.substr(separator + 1, nextSeparator - separator - 1);
61 separator = nextSeparator;
62
63 //see if the folder already exists
64 bool foundFolder = false;
65 for(unsigned int i = 0; i < folder->getFileCount(); i++)
66 {
67 FileData* checkFolder = folder->getFile(i);
68 if(checkFolder->isFolder() && checkFolder->getName() == checkName)
69 {
70 folder = (FolderData*)checkFolder;
71 foundFolder = true;
72 break;
73 }
74 }
75
76 //the folder didn't already exist, so create it
77 if(!foundFolder)
78 {
79 FolderData* newFolder = new FolderData(system, folder->getPath() + "/" + checkName, checkName);
80 folder->pushFileData(newFolder);
81 folder = newFolder;
82 }
83
84 //if for some reason this function is broken, break out of this while instead of freezing
85 if(loops > gamePath.length() * 2)
86 {
87 LOG(LogError) << "createGameFromPath breaking out of loop for path \"" << gamePath << "\" to prevent infinite loop (please report this)";

Callers 1

parseGamelistFunction · 0.85

Calls 8

getStartPathMethod · 0.80
getRootFolderMethod · 0.80
findMethod · 0.80
getFileCountMethod · 0.80
getFileMethod · 0.80
getNameMethod · 0.80
pushFileDataMethod · 0.80
isFolderMethod · 0.45

Tested by

no test coverage detected