Skip to content

Commit 4a33b59

Browse files
committed
Sky: read directory recursively
1 parent 9b500c2 commit 4a33b59

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

  • src/OpenCOVER/plugins/general/Sky

src/OpenCOVER/plugins/general/Sky/Sky.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,28 +178,35 @@ Sky::~Sky()
178178

179179
void Sky::loadSkies()
180180
{
181-
try
181+
std::function<void(const std::filesystem::path &)> read_dir;
182+
read_dir = [&read_dir, this](const std::filesystem::path &path) -> void
182183
{
183-
for (const auto &entry : std::filesystem::directory_iterator(skyPath))
184+
try
184185
{
185-
if (!entry.is_regular_file())
186+
for (const auto &entry : std::filesystem::directory_iterator(path))
186187
{
187-
continue;
188+
if (entry.is_directory())
189+
{
190+
read_dir(entry.path());
191+
}
192+
else if (entry.is_regular_file())
193+
{
194+
const auto &path = entry.path();
195+
addSkyFile(path);
196+
}
188197
}
189-
190-
const auto &path = entry.path();
191-
addSkyFile(path);
192198
}
193-
}
194-
catch (const std::filesystem::filesystem_error &err)
195-
{
196-
std::cerr << "Filesystem error: " << err.what() << std::endl;
197-
}
198-
catch (const std::exception &ex)
199-
{
200-
std::cerr << "General error: " << ex.what() << std::endl;
201-
}
199+
catch (const std::filesystem::filesystem_error &err)
200+
{
201+
std::cerr << "Filesystem error: " << err.what() << std::endl;
202+
}
203+
catch (const std::exception &ex)
204+
{
205+
std::cerr << "General error: " << ex.what() << std::endl;
206+
}
207+
};
202208

209+
read_dir(skyPath);
203210
updateSkyMenu();
204211
}
205212

@@ -248,9 +255,12 @@ void parseExifData(const std::filesystem::path &path, double &longitude, double
248255
std::optional<std::reference_wrapper<SkyEntry>> Sky::addSkyFile(std::filesystem::path path)
249256
{
250257
std::string fileName = path.filename().string();
251-
std::string name = path.stem().string();
252258
std::string extension = path.extension();
253259

260+
auto relative = std::filesystem::relative(path, std::filesystem::path(skyPath)).string();
261+
std::string name = relative.substr(0, relative.length() - extension.length());
262+
name = std::regex_replace(name, std::regex("/"), "");
263+
254264
// Transform extension to lower case
255265
std::transform(extension.begin(), extension.end(), extension.begin(),
256266
[](unsigned char c)

0 commit comments

Comments
 (0)