Skip to content

Commit c1d1d00

Browse files
committed
DispStrings结构中只读的Get函数改为GetConst,以避免对DispStrings结构造成意外的修改,保存到每个皮肤的显示文本只包含该皮肤有的显示项目
1 parent ff2d4d0 commit c1d1d00

File tree

7 files changed

+53
-44
lines changed

7 files changed

+53
-44
lines changed

TrafficMonitor/CommonData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ wstring& DispStrings::Get(CommonDisplayItem item)
6060
return map_str[item];
6161
}
6262

63-
const wstring& DispStrings::Get(CommonDisplayItem item) const
63+
const wstring& DispStrings::GetConst(CommonDisplayItem item) const
6464
{
6565
auto iter = map_str.find(item);
6666
if (iter != map_str.end())

TrafficMonitor/CommonData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct DispStrings //显示的文本
6666
public:
6767
//获取一个显示的文本
6868
wstring& Get(CommonDisplayItem item);
69-
const wstring& Get(CommonDisplayItem item) const;
69+
const wstring& GetConst(CommonDisplayItem item) const;
7070

7171
const std::map<CommonDisplayItem, wstring>& GetAllItems() const;
7272

TrafficMonitor/DisplayTextSettingDlg.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ BOOL CDisplayTextSettingDlg::OnInitDialog()
7070
m_display_texts = DispStrings();
7171
for (const auto& display_item : all_skin_items)
7272
{
73-
m_display_texts.Get(display_item) = temp.Get(display_item);
73+
m_display_texts.Get(display_item) = temp.GetConst(display_item);
7474
}
7575
}
7676

@@ -129,7 +129,7 @@ void CDisplayTextSettingDlg::OnBnClickedRestoreDefaultButton()
129129
for (int i{}; i < item_count; i++)
130130
{
131131
CommonDisplayItem display_item = GetDisplayItem(i);
132-
std::wstring default_text = skin_setting_data.disp_str.Get(display_item);
132+
std::wstring default_text = skin_setting_data.disp_str.GetConst(display_item);
133133
m_list_ctrl.SetItemText(i, 1, default_text.c_str());
134134
}
135135
}

TrafficMonitor/IniHelper.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -373,19 +373,26 @@ void CIniHelper::LoadDisplayStr(const wchar_t* AppName, DispStrings& disp_str, b
373373

374374
void CIniHelper::SaveDisplayStr(const wchar_t* AppName, const DispStrings& disp_str)
375375
{
376-
WriteString(AppName, _T("up_string"), disp_str.Get(TDI_UP));
377-
WriteString(AppName, _T("down_string"), disp_str.Get(TDI_DOWN));
378-
WriteString(AppName, _T("total_speed_string"), disp_str.Get(TDI_TOTAL_SPEED));
379-
WriteString(AppName, _T("cpu_string"), disp_str.Get(TDI_CPU));
380-
WriteString(AppName, _T("memory_string"), disp_str.Get(TDI_MEMORY));
381-
WriteString(AppName, _T("gpu_string"), disp_str.Get(TDI_GPU_USAGE));
382-
WriteString(AppName, _T("cpu_temp_string"), disp_str.Get(TDI_CPU_TEMP));
383-
WriteString(AppName, _T("cpu_freq_string"), disp_str.Get(TDI_CPU_FREQ));
384-
WriteString(AppName, _T("gpu_temp_string"), disp_str.Get(TDI_GPU_TEMP));
385-
WriteString(AppName, _T("hdd_temp_string"), disp_str.Get(TDI_HDD_TEMP));
386-
WriteString(AppName, _T("main_board_temp_string"), disp_str.Get(TDI_MAIN_BOARD_TEMP));
387-
WriteString(AppName, _T("hdd_string"), disp_str.Get(TDI_HDD_USAGE));
388-
WriteString(AppName, _T("today_traffic_string"), disp_str.Get(TDI_TODAY_TRAFFIC));
376+
auto writeDisplayString = [&](const wchar_t* key_name, DisplayItem display_item) {
377+
if (disp_str.GetAllItems().find(display_item) != disp_str.GetAllItems().end())
378+
{
379+
WriteString(AppName, key_name, disp_str.GetConst(display_item));
380+
}
381+
};
382+
383+
writeDisplayString(_T("up_string"), TDI_UP);
384+
writeDisplayString(_T("down_string"), TDI_DOWN);
385+
writeDisplayString(_T("total_speed_string"), TDI_TOTAL_SPEED);
386+
writeDisplayString(_T("cpu_string"), TDI_CPU);
387+
writeDisplayString(_T("memory_string"), TDI_MEMORY);
388+
writeDisplayString(_T("gpu_string"), TDI_GPU_USAGE);
389+
writeDisplayString(_T("cpu_temp_string"), TDI_CPU_TEMP);
390+
writeDisplayString(_T("cpu_freq_string"), TDI_CPU_FREQ);
391+
writeDisplayString(_T("gpu_temp_string"), TDI_GPU_TEMP);
392+
writeDisplayString(_T("hdd_temp_string"), TDI_HDD_TEMP);
393+
writeDisplayString(_T("main_board_temp_string"), TDI_MAIN_BOARD_TEMP);
394+
writeDisplayString(_T("hdd_string"), TDI_HDD_USAGE);
395+
writeDisplayString(_T("today_traffic_string"), TDI_TODAY_TRAFFIC);
389396
}
390397

391398
void CIniHelper::LoadPluginDisplayStr(const wchar_t* AppName, DispStrings& disp_str)
@@ -400,7 +407,8 @@ void CIniHelper::SavePluginDisplayStr(const wchar_t* AppName, const DispStrings&
400407
{
401408
for (const auto& plugin : theApp.m_plugins.GetPluginItems())
402409
{
403-
WriteString(AppName, plugin->GetItemId(), disp_str.Get(plugin));
410+
if (disp_str.GetAllItems().find(plugin) != disp_str.GetAllItems().end())
411+
WriteString(AppName, plugin->GetItemId(), disp_str.GetConst(plugin));
404412
}
405413
}
406414

TrafficMonitor/SkinFile.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -434,14 +434,14 @@ void CSkinFile::DrawPreview(CDC* pDC, CRect rect)
434434
draw_str.value = _T("99");
435435
break;
436436
}
437-
if (m_skin_info.display_text.Get(*iter) == NONE_STR)
438-
m_skin_info.display_text.Get(*iter) = theApp.m_main_wnd_data.disp_str.Get(*iter);
437+
if (m_skin_info.display_text.GetConst(*iter) == NONE_STR)
438+
m_skin_info.display_text.Get(*iter) = theApp.m_main_wnd_data.disp_str.GetConst(*iter);
439439
if (!m_layout_info.no_label)
440440
{
441441
if (m_skin_info.display_text.IsInvalid())
442442
draw_str.label = DispStrings::DefaultString(*iter, true).c_str();
443443
else
444-
draw_str.label = m_skin_info.display_text.Get(*iter).c_str();
444+
draw_str.label = m_skin_info.display_text.GetConst(*iter).c_str();
445445
}
446446
map_str[*iter] = draw_str;
447447
}
@@ -520,7 +520,7 @@ void CSkinFile::DrawPreview(CDC* pDC, CRect rect)
520520
if (m_skin_info.display_text.IsInvalid())
521521
draw_str.label = plugin_item->GetItemLableText();
522522
else
523-
draw_str.label = m_skin_info.display_text.Get(plugin_item).c_str();
523+
draw_str.label = m_skin_info.display_text.GetConst(plugin_item).c_str();
524524
draw_str.value = plugin_item->GetItemValueSampleText();
525525
DrawSkinText(draw, draw_str, rect, cl, layout_item.align);
526526
}
@@ -609,19 +609,19 @@ void CSkinFile::DrawItemsInfo(IDrawCommon& drawer, Layout& layout, CFont& font)
609609
std::map<DisplayItem, DrawStr> map_str;
610610
if (!m_layout_info.no_label)
611611
{
612-
map_str[TDI_UP].label = theApp.m_main_wnd_data.disp_str.Get(TDI_UP).c_str();
613-
map_str[TDI_DOWN].label = theApp.m_main_wnd_data.disp_str.Get(TDI_DOWN).c_str();
614-
map_str[TDI_TOTAL_SPEED].label = theApp.m_main_wnd_data.disp_str.Get(TDI_TOTAL_SPEED).c_str();
615-
map_str[TDI_CPU].label = theApp.m_main_wnd_data.disp_str.Get(TDI_CPU).c_str();
616-
map_str[TDI_MEMORY].label = theApp.m_main_wnd_data.disp_str.Get(TDI_MEMORY).c_str();
617-
map_str[TDI_GPU_USAGE].label = theApp.m_main_wnd_data.disp_str.Get(TDI_GPU_USAGE).c_str();
618-
map_str[TDI_HDD_USAGE].label = theApp.m_main_wnd_data.disp_str.Get(TDI_HDD_USAGE).c_str();
619-
map_str[TDI_CPU_TEMP].label = theApp.m_main_wnd_data.disp_str.Get(TDI_CPU_TEMP).c_str();
620-
map_str[TDI_CPU_FREQ].label = theApp.m_main_wnd_data.disp_str.Get(TDI_CPU_FREQ).c_str();
621-
map_str[TDI_GPU_TEMP].label = theApp.m_main_wnd_data.disp_str.Get(TDI_GPU_TEMP).c_str();
622-
map_str[TDI_HDD_TEMP].label = theApp.m_main_wnd_data.disp_str.Get(TDI_HDD_TEMP).c_str();
623-
map_str[TDI_MAIN_BOARD_TEMP].label = theApp.m_main_wnd_data.disp_str.Get(TDI_MAIN_BOARD_TEMP).c_str();
624-
map_str[TDI_TODAY_TRAFFIC].label = theApp.m_main_wnd_data.disp_str.Get(TDI_TODAY_TRAFFIC).c_str();
612+
map_str[TDI_UP].label = theApp.m_main_wnd_data.disp_str.GetConst(TDI_UP).c_str();
613+
map_str[TDI_DOWN].label = theApp.m_main_wnd_data.disp_str.GetConst(TDI_DOWN).c_str();
614+
map_str[TDI_TOTAL_SPEED].label = theApp.m_main_wnd_data.disp_str.GetConst(TDI_TOTAL_SPEED).c_str();
615+
map_str[TDI_CPU].label = theApp.m_main_wnd_data.disp_str.GetConst(TDI_CPU).c_str();
616+
map_str[TDI_MEMORY].label = theApp.m_main_wnd_data.disp_str.GetConst(TDI_MEMORY).c_str();
617+
map_str[TDI_GPU_USAGE].label = theApp.m_main_wnd_data.disp_str.GetConst(TDI_GPU_USAGE).c_str();
618+
map_str[TDI_HDD_USAGE].label = theApp.m_main_wnd_data.disp_str.GetConst(TDI_HDD_USAGE).c_str();
619+
map_str[TDI_CPU_TEMP].label = theApp.m_main_wnd_data.disp_str.GetConst(TDI_CPU_TEMP).c_str();
620+
map_str[TDI_CPU_FREQ].label = theApp.m_main_wnd_data.disp_str.GetConst(TDI_CPU_FREQ).c_str();
621+
map_str[TDI_GPU_TEMP].label = theApp.m_main_wnd_data.disp_str.GetConst(TDI_GPU_TEMP).c_str();
622+
map_str[TDI_HDD_TEMP].label = theApp.m_main_wnd_data.disp_str.GetConst(TDI_HDD_TEMP).c_str();
623+
map_str[TDI_MAIN_BOARD_TEMP].label = theApp.m_main_wnd_data.disp_str.GetConst(TDI_MAIN_BOARD_TEMP).c_str();
624+
map_str[TDI_TODAY_TRAFFIC].label = theApp.m_main_wnd_data.disp_str.GetConst(TDI_TODAY_TRAFFIC).c_str();
625625
}
626626

627627
//上传/下载
@@ -741,7 +741,7 @@ void CSkinFile::DrawItemsInfo(IDrawCommon& drawer, Layout& layout, CFont& font)
741741

742742
//绘制文本
743743
DrawStr draw_str;
744-
draw_str.label = theApp.m_main_wnd_data.disp_str.Get(plugin_item).c_str();
744+
draw_str.label = theApp.m_main_wnd_data.disp_str.GetConst(plugin_item).c_str();
745745
draw_str.value = plugin_item->GetItemValueText();
746746
DrawSkinText(drawer, draw_str, rect, cl, layout_item.align);
747747
}

TrafficMonitor/SkinManager.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,20 @@ void CSkinManager::SkinSettingDataFronSkin(SkinSettingData& skin_setting_data, c
153153
if (skin_file.GetSkinInfo().font_info.size >= MIN_FONT_SIZE && skin_file.GetSkinInfo().font_info.size <= MAX_FONT_SIZE)
154154
skin_setting_data.font.size = skin_file.GetSkinInfo().font_info.size;
155155

156+
//获取皮肤所有显示项目
157+
std::set<CommonDisplayItem> skin_all_items;
158+
skin_file.GetSkinDisplayItems(skin_all_items);
156159
//获取项目的显示文本
157160
if (!skin_file.GetLayoutInfo().no_label)
158161
{
159162
if (!skin_file.GetSkinInfo().display_text.IsInvalid())
160163
{
161-
skin_setting_data.disp_str = skin_file.GetSkinInfo().display_text;
164+
for (const auto& display_item : skin_all_items)
165+
skin_setting_data.disp_str.Get(display_item) = skin_file.GetSkinInfo().display_text.GetConst(display_item);
162166
}
163167
//获取皮肤默认的显示文本
164168
else
165169
{
166-
//获取皮肤所有显示项目
167-
std::set<CommonDisplayItem> skin_all_items;
168-
skin_file.GetSkinDisplayItems(skin_all_items);
169170
//获取所有显示项目的默认显示文本
170171
for (const auto& display_item : skin_all_items)
171172
skin_setting_data.disp_str.Get(display_item) = DispStrings::DefaultString(display_item, true);

TrafficMonitor/TaskBarDlg.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ void CTaskBarDlg::DrawDisplayItem(IDrawCommon& drawer, DisplayItem type, CRect r
364364
//绘制标签
365365
if (label_width > 0)
366366
{
367-
wstring str_label = theApp.m_taskbar_data.disp_str.Get(type);
367+
wstring str_label = theApp.m_taskbar_data.disp_str.GetConst(type);
368368
//if (theApp.m_taskbar_data.swap_up_down)
369369
//{
370370
// if (type == TDI_UP)
@@ -570,7 +570,7 @@ void CTaskBarDlg::DrawPluginItem(IDrawCommon& drawer, IPluginItem* item, CRect r
570570
}
571571
}
572572
//画标签
573-
CString lable_text = theApp.m_taskbar_data.disp_str.Get(item).c_str();
573+
CString lable_text = theApp.m_taskbar_data.disp_str.GetConst(item).c_str();
574574
lable_text += L' ';
575575
drawer.DrawWindowText(rect_label, lable_text, label_text_color, (vertical ? Alignment::CENTER : Alignment::LEFT));
576576
//画数值
@@ -927,7 +927,7 @@ void CTaskBarDlg::CalculateWindowSize()
927927
}
928928
else
929929
{
930-
CString lable_text = theApp.m_taskbar_data.disp_str.Get(plugin).c_str();
930+
CString lable_text = theApp.m_taskbar_data.disp_str.GetConst(plugin).c_str();
931931
if (!lable_text.IsEmpty())
932932
lable_text += L' ';
933933
label_width = m_pDC->GetTextExtent(lable_text).cx;
@@ -936,7 +936,7 @@ void CTaskBarDlg::CalculateWindowSize()
936936
}
937937
else
938938
{
939-
item_widths[*iter].label_width = m_pDC->GetTextExtent(theApp.m_taskbar_data.disp_str.Get(*iter).c_str()).cx;
939+
item_widths[*iter].label_width = m_pDC->GetTextExtent(theApp.m_taskbar_data.disp_str.GetConst(*iter).c_str()).cx;
940940
}
941941
}
942942

0 commit comments

Comments
 (0)