MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / iterateObjectFolder

Function iterateObjectFolder

src/OpenLoco/src/Objects/ObjectIndex.cpp:96–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94 // func takes a const fs::directory_entry parameter and returns false to stop iteration
95 template<typename Func>
96 static void iterateObjectFolder(fs::path path, bool shouldRecurse, Func&& func)
97 {
98 if (!fs::exists(path))
99 {
100 return;
101 }
102 auto f = [&func](const fs::directory_entry& file) {
103 if (!file.is_regular_file())
104 {
105 return true;
106 }
107 const auto extension = file.path().extension().u8string();
108 if (!Utility::iequals(extension, ".DAT"))
109 {
110 return true;
111 }
112 return func(file);
113 };
114
115 if (shouldRecurse)
116 {
117 for (const auto& file : fs::recursive_directory_iterator(path, fs::directory_options::skip_permission_denied))
118 {
119 if (!f(file))
120 {
121 break;
122 }
123 }
124 }
125 else
126 {
127 for (const auto& file : fs::directory_iterator(path, fs::directory_options::skip_permission_denied))
128 {
129 if (!f(file))
130 {
131 break;
132 }
133 }
134 }
135 }
136
137 // 0x00470F3C
138 static ObjectFolderState getCurrentObjectFolderState(fs::path path, bool shouldRecurse)

Callers 2

addObjectsInFolderFunction · 0.85

Calls 1

iequalsFunction · 0.85

Tested by

no test coverage detected