4
4
#include < StringAlgorithm.hpp>
5
5
#include < WeaselUtility.h>
6
6
#include < WeaselVersion.h>
7
+
8
+ #include < boost/filesystem.hpp>
9
+ #include < map>
7
10
#include < regex>
8
11
#include < rime_api.h>
9
- #include < map>
10
12
11
13
#define TRANSPARENT_COLOR 0x00000000
12
14
#define ARGB2ABGR (value ) ((value & 0xff000000 ) | ((value & 0x000000ff ) << 16 ) | (value & 0x0000ff00 ) | ((value & 0x00ff0000 ) >> 16 ))
@@ -70,10 +72,12 @@ void _RefreshTrayIcon(const UINT session_id, const std::function<void()> _Update
70
72
void RimeWithWeaselHandler::_Setup ()
71
73
{
72
74
RIME_STRUCT (RimeTraits, weasel_traits);
73
- weasel_traits.shared_data_dir = weasel_shared_data_dir ();
74
- weasel_traits.user_data_dir = weasel_user_data_dir ();
75
+ std::string shared_dir = wstring_to_string (WeaselSharedDataPath ().wstring (), CP_UTF8);
76
+ std::string user_dir = wstring_to_string (WeaselUserDataPath ().wstring (), CP_UTF8);
77
+ weasel_traits.shared_data_dir = shared_dir.c_str ();
78
+ weasel_traits.user_data_dir = user_dir.c_str ();
75
79
weasel_traits.prebuilt_data_dir = weasel_traits.shared_data_dir ;
76
- std::string distribution_name ( wstring_to_string (WEASEL_IME_NAME, CP_UTF8) );
80
+ std::string distribution_name = wstring_to_string (WEASEL_IME_NAME, CP_UTF8);
77
81
weasel_traits.distribution_name = distribution_name.c_str ();
78
82
weasel_traits.distribution_code_name = WEASEL_CODE_NAME;
79
83
weasel_traits.distribution_version = WEASEL_VERSION;
@@ -155,7 +159,7 @@ UINT RimeWithWeaselHandler::AddSession(LPWSTR buffer, EatLine eat)
155
159
DLOG (INFO) << " Add session: created session_id = " << session_id;
156
160
_ReadClientInfo (session_id, buffer);
157
161
158
- m_session_status_map[session_id] = SesstionStatus ();
162
+ m_session_status_map[session_id] = SessionStatus ();
159
163
m_session_status_map[session_id].style = m_base_style;
160
164
161
165
RIME_STRUCT (RimeStatus, status);
@@ -512,23 +516,28 @@ void RimeWithWeaselHandler::_UpdateUI(UINT session_id)
512
516
m_option_name.clear ();
513
517
}
514
518
515
- void _LoadIconSettingFromSchema (RimeConfig& config, char *buffer, const int & BUF_SIZE,
516
- const char * key1, const char * key2, const std::wstring& user_dir, const std::wstring& shared_dir, std::wstring& value)
519
+ std::wstring _LoadIconSettingFromSchema (RimeConfig& config,
520
+ const char * key1,
521
+ const char * key2,
522
+ const boost::filesystem::path& user_dir,
523
+ const boost::filesystem::path& shared_dir)
517
524
{
518
- memset (buffer, ' \0 ' , (BUF_SIZE+1 ));
519
- if (RimeConfigGetString (&config, key1, buffer, BUF_SIZE) || (key2 != NULL && RimeConfigGetString (&config, key2, buffer, BUF_SIZE))) {
520
- std::wstring tmp = string_to_wstring (buffer, CP_UTF8);
521
- DWORD dwAttrib = GetFileAttributes ((user_dir + L" \\ " + tmp).c_str ());
522
- if (!(INVALID_FILE_ATTRIBUTES != dwAttrib && 0 == (dwAttrib & FILE_ATTRIBUTE_DIRECTORY))) {
523
- dwAttrib = GetFileAttributes ((shared_dir + L" \\ " + tmp).c_str ());
524
- if (!(INVALID_FILE_ATTRIBUTES != dwAttrib && 0 == (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)))
525
- value = L" " ;
526
- else
527
- value = (shared_dir + L" \\ " + tmp);
525
+ const int BUF_SIZE = 255 ;
526
+ char buffer[BUF_SIZE + 1 ];
527
+ memset (buffer, ' \0 ' , (BUF_SIZE + 1 ));
528
+ if (RimeConfigGetString (&config, key1, buffer, BUF_SIZE) ||
529
+ (key2 != NULL && RimeConfigGetString (&config, key2, buffer, BUF_SIZE))) {
530
+ std::wstring resource = string_to_wstring (buffer, CP_UTF8);
531
+ DWORD dwAttrib = GetFileAttributes ((user_dir / resource).c_str ());
532
+ if (INVALID_FILE_ATTRIBUTES != dwAttrib && 0 == (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) {
533
+ return (user_dir / resource).wstring ();
534
+ }
535
+ dwAttrib = GetFileAttributes ((shared_dir / resource).c_str ());
536
+ if (INVALID_FILE_ATTRIBUTES != dwAttrib && 0 == (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) {
537
+ return (shared_dir / resource).wstring ();
528
538
}
529
- else value = user_dir + L" \\ " + tmp;
530
539
}
531
- else value = L" " ;
540
+ return L" " ;
532
541
}
533
542
534
543
void RimeWithWeaselHandler::_LoadSchemaSpecificSettings (UINT session_id, const std::string& schema_id)
@@ -541,7 +550,7 @@ void RimeWithWeaselHandler::_LoadSchemaSpecificSettings(UINT session_id, const s
541
550
_UpdateShowNotifications (&config);
542
551
m_ui->style () = m_base_style;
543
552
_UpdateUIStyle (&config, m_ui, false );
544
- SesstionStatus & session_status = m_session_status_map[session_id];
553
+ SessionStatus & session_status = m_session_status_map[session_id];
545
554
session_status.style = m_ui->style ();
546
555
// load schema color style config
547
556
memset (buffer, ' \0 ' , sizeof (buffer));
@@ -583,12 +592,12 @@ void RimeWithWeaselHandler::_LoadSchemaSpecificSettings(UINT session_id, const s
583
592
}
584
593
// load schema icon start
585
594
{
586
- std::wstring user_dir = string_to_wstring ( weasel_user_data_dir () );
587
- std::wstring shared_dir = string_to_wstring ( weasel_shared_data_dir () );
588
- _LoadIconSettingFromSchema (config, buffer, BUF_SIZE, " schema/icon" , " schema/zhung_icon" , user_dir, shared_dir, session_status. style . current_zhung_icon );
589
- _LoadIconSettingFromSchema (config, buffer, BUF_SIZE, " schema/ascii_icon" , NULL , user_dir, shared_dir, session_status. style . current_ascii_icon );
590
- _LoadIconSettingFromSchema (config, buffer, BUF_SIZE, " schema/full_icon" , NULL , user_dir, shared_dir, session_status. style . current_full_icon );
591
- _LoadIconSettingFromSchema (config, buffer, BUF_SIZE, " schema/half_icon" , NULL , user_dir, shared_dir, session_status. style . current_half_icon );
595
+ auto user_dir = WeaselUserDataPath ( );
596
+ auto shared_dir = WeaselSharedDataPath ( );
597
+ session_status. style . current_zhung_icon = _LoadIconSettingFromSchema (config, " schema/icon" , " schema/zhung_icon" , user_dir, shared_dir);
598
+ session_status. style . current_ascii_icon = _LoadIconSettingFromSchema (config, " schema/ascii_icon" , NULL , user_dir, shared_dir);
599
+ session_status. style . current_full_icon = _LoadIconSettingFromSchema (config, " schema/full_icon" , NULL , user_dir, shared_dir);
600
+ session_status. style . current_half_icon = _LoadIconSettingFromSchema (config, " schema/half_icon" , NULL , user_dir, shared_dir);
592
601
}
593
602
// load schema icon end
594
603
RimeConfigClose (&config);
@@ -602,7 +611,7 @@ void RimeWithWeaselHandler::_LoadAppInlinePreeditSet(UINT session_id, bool ignor
602
611
if (!ignore_app_name && m_last_app_name == app_name)
603
612
return ;
604
613
m_last_app_name = app_name;
605
- SesstionStatus & session_status = m_session_status_map[session_id];
614
+ SessionStatus & session_status = m_session_status_map[session_id];
606
615
bool inline_preedit = session_status.style .inline_preedit ;
607
616
if (!app_name.empty ())
608
617
{
@@ -712,7 +721,7 @@ bool RimeWithWeaselHandler::_Respond(UINT session_id, EatLine eat)
712
721
std::set<std::string> actions;
713
722
std::list<std::string> messages;
714
723
715
- SesstionStatus & session_status = m_session_status_map[session_id];
724
+ SessionStatus & session_status = m_session_status_map[session_id];
716
725
RIME_STRUCT (RimeCommit, commit);
717
726
if (RimeGetCommit (session_id, &commit))
718
727
{
0 commit comments