Skip to content

Commit

Permalink
Merge pull request #348 from udoe/master
Browse files Browse the repository at this point in the history
Properly handle the case where no Sources child node is present in the config xml
  • Loading branch information
janwilmans committed Mar 3, 2019
2 parents b343dae + b6fbed1 commit 291309a
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions DebugView++/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,34 +947,38 @@ void CMainFrame::LoadConfiguration(const std::wstring& fileName)
CloseView(i);
}

auto sourcesPt = pt.get_child("DebugViewPP.Sources");
std::vector<SourceInfoHelper> sources;
for (const auto& item : sourcesPt)
// The Sources child might not be present!
auto sourcesPt = pt.get_child_optional("DebugViewPP.Sources");
if (sourcesPt)
{
if (item.first == "Source")
std::vector<SourceInfoHelper> sources;
for (const auto& item : *sourcesPt)
{
auto& sourcePt = item.second;
int index = sourcePt.get<int>("Index");
SourceType::type type = StringToSourceType(sourcePt.get<std::string>("SourceType"));
std::wstring description = WStr(sourcePt.get<std::string>("Description"));
SourceInfoHelper helper(index, description, type);
helper.sourceInfo.address = WStr(sourcePt.get<std::string>("Address")).str();
helper.sourceInfo.port = sourcePt.get<int>("Port");
helper.sourceInfo.enabled = sourcePt.get<bool>("Enabled");
sources.push_back(helper);
if (item.first == "Source")
{
auto& sourcePt = item.second;
int index = sourcePt.get<int>("Index");
SourceType::type type = StringToSourceType(sourcePt.get<std::string>("SourceType"));
std::wstring description = WStr(sourcePt.get<std::string>("Description"));
SourceInfoHelper helper(index, description, type);
helper.sourceInfo.address = WStr(sourcePt.get<std::string>("Address")).str();
helper.sourceInfo.port = sourcePt.get<int>("Port");
helper.sourceInfo.enabled = sourcePt.get<bool>("Enabled");
sources.push_back(helper);
}
}
}

std::sort(sources.begin(), sources.end(), [](const SourceInfoHelper& si1, const SourceInfoHelper& si2) { return si1.index < si2.index; });
std::sort(sources.begin(), sources.end(), [](const SourceInfoHelper& si1, const SourceInfoHelper& si2) { return si1.index < si2.index; });

std::vector<SourceInfo> sourceInfos;
for (const auto& helper : sources)
{
sourceInfos.push_back(helper.sourceInfo);
}
UpdateLogSources(sourceInfos);
std::vector<SourceInfo> sourceInfos;
for (const auto& helper : sources)
{
sourceInfos.push_back(helper.sourceInfo);
}
UpdateLogSources(sourceInfos);

m_sourceInfos = sourceInfos;
m_sourceInfos = sourceInfos;
}
}

void CMainFrame::SaveConfiguration(const std::wstring& fileName)
Expand Down

0 comments on commit 291309a

Please sign in to comment.