Skip to content

Commit

Permalink
Fixed non ASCII characters in loose file extension causing crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
hakasapl committed Jul 23, 2024
1 parent 5da06ce commit a120764
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 36 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [0.4.4] - UNRELEASED

- Fixed non ASCII characters in loose file extension causing crashes

## [0.4.3] - 2024-07-22

- Fixed parallax being applied on soft and rim lighting
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set(PROJECT_NAME "ParallaxGen")
set(PROJECT_URI "com.github.hakasapl.ParallaxGen")

# Initialize Project
set(PARALLAXGEN_VERSION 0.4.3)
set(PARALLAXGEN_VERSION 0.4.4)
project(${PROJECT_NAME} VERSION ${PARALLAXGEN_VERSION})

# Define preprocessor macro with the version number
Expand Down
10 changes: 5 additions & 5 deletions include/BethesdaDirectory/BethesdaDirectory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class BethesdaDirectory {
// any file that ends with these strings will be ignored
// allowed BSAs etc. to be hidden from the file map since this object is an abstraction
// of the data directory that no longer factors BSAs for downstream users
std::vector<std::string> extension_blocklist = {
".bsa",
".esp",
".esl",
".esm"
std::vector<std::wstring> extension_blocklist = {
L".bsa",
L".esp",
L".esl",
L".esm"
};

public:
Expand Down
29 changes: 11 additions & 18 deletions src/BethesdaDirectory/BethesdaDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,27 +202,20 @@ void BethesdaDirectory::addLooseFilesToMap()
}

for (const auto& entry : fs::recursive_directory_iterator(data_dir, fs::directory_options::skip_permission_denied)) {
try{
if (entry.is_regular_file()) {
const fs::path file_path = entry.path();
fs::path relative_path = file_path.lexically_relative(data_dir);

// check type of file, skip BSAs and ESPs
if (!file_allowed(file_path)) {
continue;
}

if (logging) {
spdlog::trace(L"Adding loose file to map: {}", relative_path.wstring());
}
if (entry.is_regular_file()) {
const fs::path file_path = entry.path();
fs::path relative_path = file_path.lexically_relative(data_dir);

updateFileMap(relative_path, nullptr);
// check type of file, skip BSAs and ESPs
if (!file_allowed(file_path)) {
continue;
}
} catch (const std::exception& e) {

if (logging) {
spdlog::warn(L"Failed to add loose file to map, skipping {}: {}", entry.path().wstring(), convertToWstring(e.what()));
spdlog::trace(L"Adding loose file to map: {}", relative_path.wstring());
}
continue;

updateFileMap(relative_path, nullptr);
}
}
}
Expand Down Expand Up @@ -523,7 +516,7 @@ vector<wstring> BethesdaDirectory::findBSAFilesFromPluginName(const vector<wstri

bool BethesdaDirectory::file_allowed(const fs::path file_path) const
{
string file_extension = file_path.extension().string();
wstring file_extension = file_path.extension().wstring();
boost::algorithm::to_lower(file_extension);
if (std::find(extension_blocklist.begin(), extension_blocklist.end(), file_extension) != extension_blocklist.end()) {
//elem exists in the vector
Expand Down
28 changes: 16 additions & 12 deletions src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,13 @@ filesystem::path getExecutablePath() {
exitWithUserInput(1);
}

try {
filesystem::path out_path = filesystem::path(buffer);
filesystem::path out_path = filesystem::path(buffer);

if (filesystem::exists(out_path)) {
return out_path;
}
else {
cout << "Error getting executable path: path does not exist\n";
exitWithUserInput(1);
}
if (filesystem::exists(out_path)) {
return out_path;
}
catch(const filesystem::filesystem_error& ex) {
cout << "Error getting executable path: " << ex.what() << "\n";
else {
cout << "Error getting executable path: path does not exist\n";
exitWithUserInput(1);
}

Expand Down Expand Up @@ -97,7 +91,8 @@ const unordered_map<string, BethesdaGame::GameType> GAME_TYPE_MAP = {
{"enderalse", BethesdaGame::GameType::ENDERAL_SE}
};

int main(int argc, char** argv) {
void mainRunner(int argc, char** argv)
{
// Find location of ParallaxGen.exe
const filesystem::path EXE_PATH = getExecutablePath().parent_path();

Expand Down Expand Up @@ -280,3 +275,12 @@ int main(int argc, char** argv) {
// Close Console
exitWithUserInput(0);
}

int main(int argc, char** argv) {
try {
mainRunner(argc, argv);
} catch (const exception& ex) {
spdlog::critical("An unhandled exception occured, provide this message in your bug report: {}", ex.what());
exitWithUserInput(1);
}
}

0 comments on commit a120764

Please sign in to comment.