Skip to content

Commit c11b9ec

Browse files
authored
Merge pull request #794 from cmitu/del2-metadata
gamelists: remove scraped files when removing game
2 parents 7e02b26 + df9fa3b commit c11b9ec

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

es-app/src/views/gamelist/BasicGameListView.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,53 @@ void BasicGameListView::launch(FileData* game)
115115
void BasicGameListView::remove(FileData *game, bool deleteFile)
116116
{
117117
if (deleteFile)
118+
{
118119
Utils::FileSystem::removeFile(game->getPath()); // actually delete the file on the filesystem
120+
121+
// we want to delete related/scraped files, but check first if resources are shared with another game
122+
bool keepVideo = game->getVideoPath().empty();
123+
bool keepMarquee = game->getMarqueePath().empty();
124+
bool keepThumbnail = game->getThumbnailPath().empty();
125+
bool keepImage = game->getImagePath().empty();
126+
127+
for (auto system : SystemData::sSystemVector)
128+
{
129+
// skip checking if we determined we need to keep the resources
130+
if (keepVideo && keepMarquee && keepImage && keepThumbnail)
131+
break;
132+
133+
if (!system->isGameSystem() || system->isCollection())
134+
continue;
135+
136+
for (auto entry : system->getRootFolder()->getChildren()) {
137+
if (entry == game) // skip the game's own entry
138+
continue;
139+
140+
if (!keepVideo && (game->getVideoPath() == entry->getVideoPath()))
141+
keepVideo = true;
142+
143+
if (!keepMarquee && (game->getMarqueePath() == entry->getMarqueePath()))
144+
keepMarquee = true;
145+
146+
// Thumbnail/Image can be used inter-changeably, so check for both in game's resources
147+
if (!keepThumbnail && (game->getThumbnailPath() == entry->getThumbnailPath() || game->getThumbnailPath() == entry->getImagePath()))
148+
keepThumbnail = true;
149+
150+
if (!keepImage && (game->getImagePath() == entry->getImagePath() || game->getImagePath() == entry->getThumbnailPath()))
151+
keepImage = true;
152+
}
153+
}
154+
155+
// delete the resources that are not shared
156+
if (!keepVideo)
157+
Utils::FileSystem::removeFile(game->getVideoPath());
158+
if (!keepImage)
159+
Utils::FileSystem::removeFile(game->getImagePath());
160+
if (!keepThumbnail)
161+
Utils::FileSystem::removeFile(game->getThumbnailPath());
162+
if (!keepMarquee)
163+
Utils::FileSystem::removeFile(game->getMarqueePath());
164+
}
119165
FileData* parent = game->getParent();
120166
if (getCursor() == game) // Select next element in list, or prev if none
121167
{

0 commit comments

Comments
 (0)