Skip to content

Commit fd7b11d

Browse files
steampp: use std::filesystem non-throwing overloads everywhere
1 parent 9ca94ed commit fd7b11d

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

src/steampp/steampp.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,25 @@ namespace {
2727

2828
bool isAppUsingSourceEnginePredicate(std::string_view installDir) {
2929
std::filesystem::directory_iterator dirIterator{installDir, std::filesystem::directory_options::skip_permission_denied};
30-
return std::any_of(std::filesystem::begin(dirIterator), std::filesystem::end(dirIterator), [](const auto& entry){
31-
return entry.is_directory() && std::filesystem::exists(entry.path() / "gameinfo.txt");
30+
std::error_code ec;
31+
return std::any_of(std::filesystem::begin(dirIterator), std::filesystem::end(dirIterator), [&ec](const auto& entry){
32+
return entry.is_directory(ec) && std::filesystem::exists(entry.path() / "gameinfo.txt", ec);
3233
});
3334
}
3435

3536
bool isAppUsingSource2EnginePredicate(std::string_view installDir) {
3637
std::filesystem::directory_iterator dirIterator{installDir, std::filesystem::directory_options::skip_permission_denied};
37-
return std::any_of(std::filesystem::begin(dirIterator), std::filesystem::end(dirIterator), [](const auto& entry) {
38-
if (!entry.is_directory()) {
38+
std::error_code ec;
39+
return std::any_of(std::filesystem::begin(dirIterator), std::filesystem::end(dirIterator), [&ec](const auto& entry) {
40+
if (!entry.is_directory(ec)) {
3941
return false;
4042
}
41-
if (std::filesystem::exists(entry.path() / "gameinfo.gi")) {
43+
if (std::filesystem::exists(entry.path() / "gameinfo.gi", ec)) {
4244
return true;
4345
}
4446
std::filesystem::directory_iterator subDirIterator{entry.path(), std::filesystem::directory_options::skip_permission_denied};
45-
return std::any_of(std::filesystem::begin(subDirIterator), std::filesystem::end(subDirIterator), [](const auto& entry_) {
46-
return entry_.is_directory() && std::filesystem::exists(entry_.path() / "gameinfo.gi");
47+
return std::any_of(std::filesystem::begin(subDirIterator), std::filesystem::end(subDirIterator), [&ec](const auto& entry_) {
48+
return entry_.is_directory(ec) && std::filesystem::exists(entry_.path() / "gameinfo.gi", ec);
4749
});
4850
});
4951
}
@@ -200,11 +202,10 @@ Steam::Steam() {
200202
}
201203
libraryFolderPath /= "steamapps";
202204

203-
this->libraryDirs.push_back(libraryFolderPath.string());
204-
205-
if (!std::filesystem::exists(libraryFolderPath)) {
205+
if (!std::filesystem::exists(libraryFolderPath, ec)) {
206206
continue;
207207
}
208+
this->libraryDirs.push_back(libraryFolderPath.string());
208209

209210
for (const auto& entry : std::filesystem::directory_iterator{libraryFolderPath, std::filesystem::directory_options::skip_permission_denied}) {
210211
auto entryName = entry.path().filename().string();
@@ -233,9 +234,9 @@ Steam::Steam() {
233234
}
234235

235236
this->gameDetails[std::stoi(std::string{appID.getValue()})] = GameInfo{
236-
.name = std::string{appName.getValue()},
237-
.installDir = std::string{appInstallDir.getValue()},
238-
.libraryInstallDirsIndex = this->libraryDirs.size() - 1,
237+
.name = std::string{appName.getValue()},
238+
.installDir = std::string{appInstallDir.getValue()},
239+
.libraryInstallDirsIndex = this->libraryDirs.size() - 1,
239240
};
240241
}
241242
}

0 commit comments

Comments
 (0)