mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 14:13:30 -07:00
Only restore from saved units if they are valid in the current available units.
This commit is contained in:
parent
957da712ff
commit
e6a80f28eb
1 changed files with 21 additions and 4 deletions
|
@ -403,12 +403,29 @@ void UnitConverter::RestoreUserPreferences(const wstring& userPreferences)
|
|||
}
|
||||
|
||||
vector<wstring> outerTokens = StringToVector(userPreferences, L"|");
|
||||
if (outerTokens.size() == 3)
|
||||
if (outerTokens.size() != 3)
|
||||
{
|
||||
m_fromType = StringToUnit(outerTokens[0]);
|
||||
m_toType = StringToUnit(outerTokens[1]);
|
||||
m_currentCategory = StringToCategory(outerTokens[2]);
|
||||
return;
|
||||
}
|
||||
auto fromType = StringToUnit(outerTokens[0]);
|
||||
auto toType = StringToUnit(outerTokens[1]);
|
||||
m_currentCategory = StringToCategory(outerTokens[2]);
|
||||
|
||||
// Only restore from the saved units if they are valid in the current available units.
|
||||
auto itr = m_categoryToUnits.find(m_currentCategory);
|
||||
if (itr != m_categoryToUnits.end())
|
||||
{
|
||||
auto curUnits = itr->second;
|
||||
if (find(curUnits.begin(), curUnits.end(), fromType) != curUnits.end())
|
||||
{
|
||||
m_fromType = fromType;
|
||||
}
|
||||
if (find(curUnits.begin(), curUnits.end(), toType) != curUnits.end())
|
||||
{
|
||||
m_toType = toType;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue