forked from Aloshi/EmulationStation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameData.cpp
More file actions
61 lines (53 loc) · 1.43 KB
/
GameData.cpp
File metadata and controls
61 lines (53 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "GameData.h"
#include <boost/filesystem.hpp>
#include <iostream>
bool GameData::isFolder() { return false; }
std::string GameData::getName() { return mName; }
std::string GameData::getPath() { return mPath; }
std::string GameData::getDescription() { return mDescription; }
std::string GameData::getImagePath() { return mImagePath; }
GameData::GameData(SystemData* system, std::string path, std::string name)
{
mSystem = system;
mPath = path;
mName = name;
mDescription = "";
mImagePath = "";
}
std::string GameData::getBashPath()
{
//a quick and dirty way to insert a backslash before most characters that would mess up a bash path
std::string path = mPath;
const char* invalidChars = " '\"\\!$^&*(){}[]?;<>";
for(unsigned int i = 0; i < path.length(); i++)
{
char c;
unsigned int charNum = 0;
do {
c = invalidChars[charNum];
if(path[i] == c)
{
path.insert(i, "\\");
i++;
break;
}
charNum++;
} while(c != '\0');
}
return path;
}
//returns the boost::filesystem stem of our path - e.g. for "/foo/bar.rom" returns "bar"
std::string GameData::getBaseName()
{
boost::filesystem::path path(mPath);
return path.stem().string();
}
void GameData::set(std::string name, std::string description, std::string imagePath)
{
if(!name.empty())
mName = name;
if(!description.empty())
mDescription = description;
if(!imagePath.empty() && boost::filesystem::exists(imagePath))
mImagePath = imagePath;
}