Fighting with boost::filesystem::directory_iterator
This commit is contained in:
parent
7551006102
commit
4ab4a9afe8
@ -98,11 +98,11 @@ std::vector<std::string> scan_serial_ports()
|
|||||||
#else
|
#else
|
||||||
// UNIX and OS X
|
// UNIX and OS X
|
||||||
std::initializer_list<const char*> prefixes { "ttyUSB" , "ttyACM", "tty.", "cu.", "rfcomm" };
|
std::initializer_list<const char*> prefixes { "ttyUSB" , "ttyACM", "tty.", "cu.", "rfcomm" };
|
||||||
for (auto &file : boost::filesystem::directory_iterator(boost::filesystem::path("/dev"))) {
|
for (auto &dir_entry : boost::filesystem::directory_iterator(boost::filesystem::path("/dev"))) {
|
||||||
std::string name = it->path().filename().string();
|
std::string name = dir_entry.path().filename().string();
|
||||||
for (const char *prefix : prefixes) {
|
for (const char *prefix : prefixes) {
|
||||||
if (boost::starts_with(name, prefix)) {
|
if (boost::starts_with(name, prefix)) {
|
||||||
out.emplace_back(it->path().string());
|
out.emplace_back(dir_entry.path().string());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,14 +241,14 @@ void PresetCollection::load_presets(const std::string &dir_path, const std::stri
|
|||||||
m_dir_path = dir.string();
|
m_dir_path = dir.string();
|
||||||
m_presets.erase(m_presets.begin()+1, m_presets.end());
|
m_presets.erase(m_presets.begin()+1, m_presets.end());
|
||||||
t_config_option_keys keys = this->default_preset().config.keys();
|
t_config_option_keys keys = this->default_preset().config.keys();
|
||||||
for (auto &file : boost::filesystem::directory_iterator(dir))
|
for (auto &dir_entry : boost::filesystem::directory_iterator(dir))
|
||||||
if (boost::filesystem::is_regular_file(file.status()) && boost::algorithm::iends_with(file.path().filename().string(), ".ini")) {
|
if (boost::filesystem::is_regular_file(dir_entry.status()) && boost::algorithm::iends_with(dir_entry.path().filename().string(), ".ini")) {
|
||||||
std::string name = file.path().filename().string();
|
std::string name = dir_entry.path().filename().string();
|
||||||
// Remove the .ini suffix.
|
// Remove the .ini suffix.
|
||||||
name.erase(name.size() - 4);
|
name.erase(name.size() - 4);
|
||||||
try {
|
try {
|
||||||
Preset preset(m_type, name, false);
|
Preset preset(m_type, name, false);
|
||||||
preset.file = file.path().string();
|
preset.file = dir_entry.path().string();
|
||||||
preset.load(keys);
|
preset.load(keys);
|
||||||
m_presets.emplace_back(preset);
|
m_presets.emplace_back(preset);
|
||||||
} catch (const boost::filesystem::filesystem_error &err) {
|
} catch (const boost::filesystem::filesystem_error &err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user