@@ -92,10 +92,20 @@ bool CSkinFile::Load(const wstring& skin_name)
9292 file_path = theApp.m_skin_path + skin_name + L" \\ skin.ini" ;
9393 CFilePathHelper file_path_helper{ file_path };
9494 wstring ext = file_path_helper.GetFileExtension ();
95+ m_is_error = false ;
9596 if (ext == L" ini" )
97+ {
9698 LoadFromIni (file_path);
99+ }
97100 else
98- LoadFromXml (file_path);
101+ {
102+ if (!LoadFromXml (file_path))
103+ {
104+ LoadFromIni (std::wstring ());
105+ m_skin_info.text_color = { RGB (255 , 255 , 255 ) };
106+ m_is_error = true ;
107+ }
108+ }
99109
100110 CSkinManager::SkinSettingDataFronSkin (m_setting_data, *this );
101111
@@ -144,7 +154,7 @@ bool CSkinFile::Load(const wstring& skin_name)
144154 return CCommon::FileExist (file_path.c_str ());
145155}
146156
147- void CSkinFile::LoadFromXml (const wstring& file_path)
157+ bool CSkinFile::LoadFromXml (const wstring& file_path)
148158{
149159 m_skin_info = SkinInfo ();
150160 m_layout_info = LayoutInfo ();
@@ -255,6 +265,11 @@ void CSkinFile::LoadFromXml(const wstring& file_path)
255265 }
256266 });
257267 }
268+ else
269+ {
270+ // xml解析失败
271+ return false ;
272+ }
258273
259274 // 载入显示文本
260275 for (const auto & display_text_item : display_text_map)
@@ -282,7 +297,7 @@ void CSkinFile::LoadFromXml(const wstring& file_path)
282297 }
283298 }
284299 }
285-
300+ return true ;
286301}
287302
288303void CSkinFile::LoadFromIni (const wstring& file_path)
@@ -402,130 +417,136 @@ void CSkinFile::DrawPreview(CDC* pDC, CRect rect)
402417 draw.Create (pDC, nullptr );
403418 // 设置字体
404419 draw.SetFont (&m_font);
405- // 绘制背景
406- CRect rect_s (CPoint (m_preview_info.s_pos .x , m_preview_info.s_pos .y ), CSize (m_layout_info.layout_s .width , m_layout_info.layout_s .height ));
407- CRect rect_l (CPoint (m_preview_info.l_pos .x , m_preview_info.l_pos .y ), CSize (m_layout_info.layout_l .width , m_layout_info.layout_l .height ));
408- if (IsPNG ()) // png背景使用GDI+绘制
420+ if (m_is_error)
409421 {
410- CDrawCommonEx gdiplus_drawer (pDC);
411- gdiplus_drawer.DrawImage (m_background_png_s, rect_s.TopLeft (), rect_s.Size (), IDrawCommon::StretchMode::STRETCH);
412- gdiplus_drawer.DrawImage (m_background_png_l, rect_l.TopLeft (), rect_l.Size (), IDrawCommon::StretchMode::STRETCH);
422+ // 显示错误信息
423+ draw.DrawWindowText (rect, CCommon::LoadText (IDS_SKIN_FILE_ERROR_INFO), RGB (252 , 128 , 45 ));
413424 }
414425 else
415426 {
416- if (m_background_s.IsNull ())
417- draw.FillRect (rect_s, RGB (230 , 230 , 230 ));
427+ // 绘制背景
428+ CRect rect_s (CPoint (m_preview_info.s_pos .x , m_preview_info.s_pos .y ), CSize (m_layout_info.layout_s .width , m_layout_info.layout_s .height ));
429+ CRect rect_l (CPoint (m_preview_info.l_pos .x , m_preview_info.l_pos .y ), CSize (m_layout_info.layout_l .width , m_layout_info.layout_l .height ));
430+ if (IsPNG ()) // png背景使用GDI+绘制
431+ {
432+ CDrawCommonEx gdiplus_drawer (pDC);
433+ gdiplus_drawer.DrawImage (m_background_png_s, rect_s.TopLeft (), rect_s.Size (), IDrawCommon::StretchMode::STRETCH);
434+ gdiplus_drawer.DrawImage (m_background_png_l, rect_l.TopLeft (), rect_l.Size (), IDrawCommon::StretchMode::STRETCH);
435+ }
418436 else
419- draw.DrawBitmap (m_background_s, rect_s.TopLeft (), rect_s.Size ());
420- if (m_background_l.IsNull ())
421- draw.FillRect (rect_l, RGB (230 , 230 , 230 ));
422- draw.DrawBitmap (m_background_l, rect_l.TopLeft (), rect_l.Size ());
423- }
424-
425- std::set<CommonDisplayItem> all_skin_items;
426- GetSkinDisplayItems (all_skin_items);
427-
428- // 获取每个项目显示的文本
429- std::map<DisplayItem, DrawStr> map_str;
430- for (auto iter = all_skin_items.begin (); iter != all_skin_items.end (); ++iter)
431- {
432- if (iter->IsPlugin ())
433- continue ;
434- DrawStr draw_str;
435- draw_str.value = CommonDisplayItem (iter->ItemType ()).GetItemValueSampleText (true );
436- if (!m_layout_info.no_label )
437437 {
438- if (m_setting_data. disp_str . IsInvalid ())
439- draw_str. label = iter-> DefaultString ( true ). c_str ( );
438+ if (m_background_s. IsNull ())
439+ draw. FillRect (rect_s, RGB ( 230 , 230 , 230 ) );
440440 else
441- draw_str.label = m_setting_data.disp_str .GetConst (*iter).c_str ();
441+ draw.DrawBitmap (m_background_s, rect_s.TopLeft (), rect_s.Size ());
442+ if (m_background_l.IsNull ())
443+ draw.FillRect (rect_l, RGB (230 , 230 , 230 ));
444+ draw.DrawBitmap (m_background_l, rect_l.TopLeft (), rect_l.Size ());
442445 }
443- map_str[iter->ItemType ()] = draw_str;
444- }
445446
446- // 获取文本颜色
447- std::map<CommonDisplayItem, COLORREF> text_colors{};
448- if (m_setting_data.specify_each_item_color )
449- {
450- text_colors = m_setting_data.text_colors ;
451- }
452- else if (!m_setting_data.text_colors .empty ())
453- {
454- for (const auto & item : all_skin_items)
447+ std::set<CommonDisplayItem> all_skin_items;
448+ GetSkinDisplayItems (all_skin_items);
449+
450+ // 获取每个项目显示的文本
451+ std::map<DisplayItem, DrawStr> map_str;
452+ for (auto iter = all_skin_items.begin (); iter != all_skin_items.end (); ++iter)
455453 {
456- text_colors[item] = m_setting_data.text_colors .begin ()->second ;
454+ if (iter->IsPlugin ())
455+ continue ;
456+ DrawStr draw_str;
457+ draw_str.value = CommonDisplayItem (iter->ItemType ()).GetItemValueSampleText (true );
458+ if (!m_layout_info.no_label )
459+ {
460+ if (m_setting_data.disp_str .IsInvalid ())
461+ draw_str.label = iter->DefaultString (true ).c_str ();
462+ else
463+ draw_str.label = m_setting_data.disp_str .GetConst (*iter).c_str ();
464+ }
465+ map_str[iter->ItemType ()] = draw_str;
457466 }
458- }
459467
460- // 绘制预览图文本
461- auto drawPreviewText = [&](Layout& layout, const PreviewInfo::Pos& pos)
462- {
463- for (auto iter = map_str.begin (); iter != map_str.end (); ++iter)
468+ // 获取文本颜色
469+ std::map<CommonDisplayItem, COLORREF> text_colors{};
470+ if (m_setting_data.specify_each_item_color )
464471 {
465- if (layout.layout_items [iter->first ].show )
472+ text_colors = m_setting_data.text_colors ;
473+ }
474+ else if (!m_setting_data.text_colors .empty ())
475+ {
476+ for (const auto & item : all_skin_items)
466477 {
467- CPoint point;
468- point.SetPoint (layout.layout_items [iter->first ].x , layout.layout_items [iter->first ].y );
469- point.Offset (pos.x , pos.y );
470- CRect rect (point, CSize (layout.layout_items [iter->first ].width , m_layout_info.text_height ));
471- COLORREF text_color{};
472- text_color = text_colors[iter->first ];
473- DrawSkinText (draw, iter->second , rect, text_color, layout.layout_items [iter->first ].align );
478+ text_colors[item] = m_setting_data.text_colors .begin ()->second ;
474479 }
475480 }
476481
477- // 绘制插件项目
478- for (const auto & plugin_item : theApp.m_plugins .GetPluginItems ())
479- {
480- LayoutItem layout_item = layout.GetItem (plugin_item);
481- if (layout_item.show )
482+ // 绘制预览图文本
483+ auto drawPreviewText = [&](Layout& layout, const PreviewInfo::Pos& pos) {
484+ for (auto iter = map_str.begin (); iter != map_str.end (); ++iter)
482485 {
483- COLORREF cl{};
484- auto iter = text_colors.find (plugin_item);
485- if (iter != text_colors.end ())
486- cl = iter->second ;
487- else if (!text_colors.empty ())
488- cl = text_colors.begin ()->second ;
489- // 矩形区域
490- CPoint point;
491- point.SetPoint (layout_item.x , layout_item.y );
492- point.Offset (pos.x , pos.y );
493- CRect rect (point, CSize (layout_item.width , m_layout_info.text_height ));
494- ITMPlugin* plugin = theApp.m_plugins .GetPluginByItem (plugin_item);
495- if (plugin != nullptr && plugin->GetAPIVersion () >= 2 )
486+ if (layout.layout_items [iter->first ].show )
496487 {
497- plugin->OnExtenedInfo (ITMPlugin::EI_DRAW_TASKBAR_WND, L" 0" );
488+ CPoint point;
489+ point.SetPoint (layout.layout_items [iter->first ].x , layout.layout_items [iter->first ].y );
490+ point.Offset (pos.x , pos.y );
491+ CRect rect (point, CSize (layout.layout_items [iter->first ].width , m_layout_info.text_height ));
492+ COLORREF text_color{};
493+ text_color = text_colors[iter->first ];
494+ DrawSkinText (draw, iter->second , rect, text_color, layout.layout_items [iter->first ].align );
498495 }
499- if (plugin_item->IsCustomDraw ())
496+ }
497+
498+ // 绘制插件项目
499+ for (const auto & plugin_item : theApp.m_plugins .GetPluginItems ())
500+ {
501+ LayoutItem layout_item = layout.GetItem (plugin_item);
502+ if (layout_item.show )
500503 {
501- int brightness{ (GetRValue (cl) + GetGValue (cl) + GetBValue (cl)) / 2 };
504+ COLORREF cl{};
505+ auto iter = text_colors.find (plugin_item);
506+ if (iter != text_colors.end ())
507+ cl = iter->second ;
508+ else if (!text_colors.empty ())
509+ cl = text_colors.begin ()->second ;
510+ // 矩形区域
511+ CPoint point;
512+ point.SetPoint (layout_item.x , layout_item.y );
513+ point.Offset (pos.x , pos.y );
514+ CRect rect (point, CSize (layout_item.width , m_layout_info.text_height ));
515+ ITMPlugin* plugin = theApp.m_plugins .GetPluginByItem (plugin_item);
502516 if (plugin != nullptr && plugin->GetAPIVersion () >= 2 )
503517 {
504- plugin->OnExtenedInfo (ITMPlugin::EI_VALUE_TEXT_COLOR, std::to_wstring (cl).c_str ());
518+ plugin->OnExtenedInfo (ITMPlugin::EI_DRAW_TASKBAR_WND, L" 0" );
519+ }
520+ if (plugin_item->IsCustomDraw ())
521+ {
522+ int brightness{ (GetRValue (cl) + GetGValue (cl) + GetBValue (cl)) / 2 };
523+ if (plugin != nullptr && plugin->GetAPIVersion () >= 2 )
524+ {
525+ plugin->OnExtenedInfo (ITMPlugin::EI_VALUE_TEXT_COLOR, std::to_wstring (cl).c_str ());
526+ }
527+ draw.GetDC ()->SetTextColor (cl);
528+ plugin_item->DrawItem (draw.GetDC ()->GetSafeHdc (), point.x , point.y , layout_item.width , m_layout_info.text_height , brightness >= 128 );
505529 }
506- draw.GetDC ()->SetTextColor (cl);
507- plugin_item->DrawItem (draw.GetDC ()->GetSafeHdc (), point.x , point.y , layout_item.width , m_layout_info.text_height , brightness >= 128 );
508- }
509- else
510- {
511- // 绘制文本
512- DrawStr draw_str;
513- if (m_skin_info.display_text .IsInvalid ())
514- draw_str.label = plugin_item->GetItemLableText ();
515530 else
516- draw_str.label = m_skin_info.display_text .GetConst (plugin_item).c_str ();
517- draw_str.value = plugin_item->GetItemValueSampleText ();
518- DrawSkinText (draw, draw_str, rect, cl, layout_item.align );
531+ {
532+ // 绘制文本
533+ DrawStr draw_str;
534+ if (m_skin_info.display_text .IsInvalid ())
535+ draw_str.label = plugin_item->GetItemLableText ();
536+ else
537+ draw_str.label = m_skin_info.display_text .GetConst (plugin_item).c_str ();
538+ draw_str.value = plugin_item->GetItemValueSampleText ();
539+ DrawSkinText (draw, draw_str, rect, cl, layout_item.align );
540+ }
519541 }
520542 }
521- }
543+ };
522544
523- };
524-
525- // 绘制小预览图文本
526- drawPreviewText (m_layout_info.layout_s , m_preview_info.s_pos );
527- // 绘制大预览图文本
528- drawPreviewText (m_layout_info.layout_l , m_preview_info.l_pos );
545+ // 绘制小预览图文本
546+ drawPreviewText (m_layout_info.layout_s , m_preview_info.s_pos );
547+ // 绘制大预览图文本
548+ drawPreviewText (m_layout_info.layout_l , m_preview_info.l_pos );
549+ }
529550}
530551
531552void CSkinFile::DrawInfo (CDC* pDC, bool show_more_info)
0 commit comments