Skip to content

Commit bae0247

Browse files
committed
Fix a bug on first startup
+ some brushup
1 parent 28f6d02 commit bae0247

File tree

4 files changed

+48
-284
lines changed

4 files changed

+48
-284
lines changed

Charu3.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,6 @@ bool CCharu3App::init()
267267
CString strText;
268268
strText.Format(_T("start \"%s\"\n"),ABOUT_NAME);
269269
CGeneral::writeLog(m_ini.m_strDebugLog,strText,_ME_NAME_,__LINE__);
270-
strText.Format(_T("ini file name \"%s\"\n"), m_ini.m_strIniFile.GetString());
271-
CGeneral::writeLog(m_ini.m_strDebugLog,strText,_ME_NAME_,__LINE__);
272270
}
273271

274272
m_pTree->setPlugin(m_ini.m_strRwPluginFolder);

Charu3Tree.cpp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,8 @@ void CCharu3Tree::setPlugin(CString strPath)
8989

9090
if (pInitDLL && pEndDLL && pReadData && pWriteData && pGetFormatName && pGetExtension) {
9191
TCHAR tcFormat[256], tcExt[256];
92-
// NOTE: We need to pass the size of the buffer minus
93-
// one character as the second argument.
94-
// This is because the existing plugins are badly
95-
// implemented (or the plugin specification is badly
96-
// designed) and will copy the string to be copied if
97-
// the size of the string to be copied is less than
98-
// or EQUAL TO the size of the buffer. They do not
99-
// take into account the extra storage for the string
100-
// terminator character.
101-
pGetExtension(tcExt, sizeof tcExt - sizeof(TCHAR));
102-
pGetFormatName(tcFormat, sizeof tcFormat - sizeof(TCHAR));
92+
pGetExtension(tcExt, sizeof tcExt);
93+
pGetFormatName(tcFormat, sizeof tcFormat);
10394
RW_PLUGIN plugin(filefind.GetFilePath(), tcFormat, tcExt);
10495
m_rwPlugin.push_back(plugin);
10596

@@ -723,16 +714,7 @@ bool CCharu3Tree::convertMacroPlugin(STRING_DATA* SourceData, CString* strRet, C
723714

724715
if(pConvertMacro) {
725716
int nSize = SourceData->m_strData.GetLength()*10+10240;
726-
// NOTE: The buffer needs to be one character larger
727-
// than the buffer size to give the plugin.
728-
// This is because the existing plugins are badly
729-
// implemented (or the plugin specification is badly
730-
// designed) and will copy the string to be copied if
731-
// the size of the string to be copied is less than
732-
// or EQUAL TO the size of the buffer.They do not
733-
// take into account the extra storage for the string
734-
// terminator character.
735-
szRet = new TCHAR[nSize + 1];
717+
szRet = new TCHAR[nSize];
736718
if(szRet) {
737719
isRet = pConvertMacro((TCHAR*)LPCTSTR(SourceData->m_strData),szRet,nSize,
738720
(TCHAR*)LPCTSTR(strSelect),(TCHAR*)LPCTSTR(strClip));

Init.cpp

Lines changed: 7 additions & 237 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ CInit::CInit()
5050
, m_nSearchTarget(0)
5151
, m_nSearchLogic(0)
5252
, m_bReadOnly(false)
53-
, m_strIniFile(_T(""))
5453
, m_strStateFile(_T(""))
5554
, m_strSettingsFile(_T(""))
5655
, m_hHookDLL(nullptr)
@@ -68,7 +67,9 @@ CInit::CInit()
6867
//---------------------------------------------------
6968
CInit::~CInit()
7069
{
71-
if(m_hHookDLL) unHook();
70+
if (m_hHookDLL) {
71+
unHook();
72+
}
7273
}
7374

7475
//---------------------------------------------------
@@ -85,7 +86,7 @@ void CInit::initialize()
8586

8687
// user name
8788
DWORD dwSize = _countof(buf);
88-
if(::GetUserName(buf, &dwSize)) {
89+
if (::GetUserName(buf, &dwSize)) {
8990
m_strUserName = CString(buf);
9091
}
9192
else {
@@ -108,7 +109,6 @@ void CInit::initialize()
108109
}
109110

110111
// file paths for state, settings and log
111-
m_strIniFile = m_strAppDataPath + "\\" + INI_FILE;
112112
m_strStateFile = m_strAppDataPath + "\\" + STATE_FILE;
113113
m_strSettingsFile = m_strAppDataPath + "\\" + SETTINGS_FILE;
114114
m_strDebugLog = m_strAppDataPath + "\\" + DEBUGLOG_FILE;
@@ -117,182 +117,6 @@ void CInit::initialize()
117117
try { m_state = nlohmann::json::parse(std::ifstream(m_strStateFile)); }
118118
catch (...) {}
119119

120-
// read settings
121-
try { m_settings = nlohmann::json::parse(std::ifstream(m_strSettingsFile)); }
122-
catch (...) {}
123-
124-
//if(m_strIniFile == "") return;
125-
126-
//int i;
127-
////int nKetsetCount;
128-
//CString strKeyBuff,StringBuff;
129-
//CString strRes;
130-
//CHANGE_KEY key;
131-
//TCHAR strBuff[1024],*szName,*szKind,*szMacro;
132-
133-
//一般設定
134-
//m_etc.m_nActiveTime = setIniFileInt(REGKEY_ETC,_T("ActiveTime"),400); //監視タイマー
135-
//m_etc.m_nCopyRetryTimes = setIniFileInt(REGKEY_ETC,_T("CopyWaitCnt"),5);
136-
//m_etc.m_nPasteRetryTimes = setIniFileInt(REGKEY_ETC,_T("PasteWaitCnt"),10);
137-
138-
//m_pop.m_nDCKeyPopTime = setIniFileInt(REGKEY_POPUP,_T("DCPopupKeyTime"),250);
139-
//m_pop.m_nDCKeyFifoTime = setIniFileInt(REGKEY_POPUP,_T("DCFifoKeyTime"),250);
140-
141-
//m_nToolTipTime = setIniFileInt(REGKEY_ENV, _T("ToolTipTime"), 30000);
142-
//m_nToolTipDelay = setIniFileInt(REGKEY_ENV, _T("ToolTipDelay"), 300);
143-
144-
//履歴FIFO設定
145-
//m_fifo.m_nFifo = setIniFileInt(REGKEY_FIFO,_T("FifoSW"),1); //履歴動作中はCtrl+Vで貼り付ける文字列を先入れ先出しにする 0NON 1FIFO 2RIFO
146-
//m_fifo.m_strCopySound = setIniFileString(REGKEY_FIFO,_T("WaveName"),_T("pu.wav"));
147-
//m_fifo.m_nOffClear = setIniFileInt(REGKEY_FIFO,_T("OffClear"),0); //履歴OFF時に一時項目をクリア
148-
//m_fifo.m_nAllClearOff = setIniFileInt(REGKEY_FIFO,_T("AllClearOff"),1);//一時履歴が空になったら履歴モードをOFFにする
149-
//m_fifo.m_nDuplication = setIniFileInt(REGKEY_FIFO,_T("Duplication"),1);
150-
151-
////仮想キー設定
152-
//WINDOWS_MESSAGE winMessage;
153-
//// m_key.m_defKeySet.m_nMessage = setIniFileInt(REGKEY_KEY,_T("isMessage"),0); // obsolete
154-
//m_key.m_defKeySet.m_nMessage = 0; //メッセージ方式
155-
//m_key.m_defKeySet.m_uMod_Paste = setIniFileInt(REGKEY_KEY,_T("ModPaste"),MOD_CONTROL); //貼り付け特殊キー
156-
//m_key.m_defKeySet.m_uVK_Paste = setIniFileInt(REGKEY_KEY,_T("VKPaste"),'V'); //貼り付けキー
157-
//m_key.m_defKeySet.m_uMod_Copy = setIniFileInt(REGKEY_KEY,_T("ModCopy"),MOD_CONTROL); //コピー特殊キー
158-
//m_key.m_defKeySet.m_uVK_Copy = setIniFileInt(REGKEY_KEY,_T("VkCopy"),'C'); //コピーキー
159-
//m_key.m_defKeySet.m_nCopyWait = setIniFileInt(REGKEY_KEY,_T("CopyWait"),50); //コピー待ち時間
160-
//m_key.m_defKeySet.m_nPasteWait = setIniFileInt(REGKEY_KEY,_T("PasteWait"),50); //ペースト待ち時間
161-
////メッセージ
162-
//strKeyBuff = setIniFileString(REGKEY_KEY,_T("CopyMessage"),_T("301,0,0"));
163-
//_stscanf_s(LPCTSTR(strKeyBuff),_T("%x,%x,%x"),&winMessage.Msg,&winMessage.wParam,&winMessage.lParam);
164-
//m_key.m_defKeySet.m_copyMessage = winMessage;
165-
166-
//strKeyBuff = setIniFileString(REGKEY_KEY,_T("PasteMessage"),_T("302,0,0"));
167-
//_stscanf_s(LPCTSTR(strKeyBuff),_T("%x,%x,%x"),&winMessage.Msg,&winMessage.wParam,&winMessage.lParam);
168-
//m_key.m_defKeySet.m_pasteMessage = winMessage;
169-
////クリップボード容量制限
170-
//m_key.m_nHistoryLimit = setIniFileInt(REGKEY_KEY,_T("HistoryLimit"),-1);
171-
172-
////固有キー設定を読む
173-
//nKetsetCount = setIniFileInt(REGKEY_KEY,_T("KeySetCount"),0);
174-
//m_key.m_KeyList.clear();
175-
//for(i = 0; i < nKetsetCount; i++){
176-
// StringBuff.Format(_T("KeySetTitle_%d"),i);
177-
// //ウィンドウキャプション
178-
// key.m_strTitle = setIniFileString(REGKEY_KEY,StringBuff,_T(""));
179-
// //マッチ方法
180-
// StringBuff.Format(_T("KeySetMatch_%d"),i);
181-
// key.m_nMatch = setIniFileInt(REGKEY_KEY,StringBuff,0);
182-
// //キーコード
183-
// StringBuff.Format(_T("KeySetCode_%d"),i);
184-
// strKeyBuff = setIniFileString(REGKEY_KEY,StringBuff,"");
185-
// _stscanf_s(LPCTSTR(strKeyBuff),_T("%d,%d,%d,%d")
186-
// ,&key.m_sCopyPasteKey.m_uMod_Copy,&key.m_sCopyPasteKey.m_uVK_Copy
187-
// ,&key.m_sCopyPasteKey.m_uMod_Paste,&key.m_sCopyPasteKey.m_uVK_Paste);
188-
// StringBuff.Format(_T("KeyCopyWait_%d"),i);
189-
// key.m_sCopyPasteKey.m_nCopyWait = setIniFileInt(REGKEY_KEY,StringBuff,100); //コピー待ち時間
190-
// StringBuff.Format(_T("KeyPasteWait_%d"),i);
191-
// key.m_sCopyPasteKey.m_nPasteWait = setIniFileInt(REGKEY_KEY,StringBuff,100); //ペースト待ち時間
192-
193-
// StringBuff.Format(_T("KeyMessage_%d"),i);
194-
// key.m_sCopyPasteKey.m_nMessage = setIniFileInt(REGKEY_KEY,StringBuff,0); //方式
195-
196-
// //メッセージ
197-
// StringBuff.Format(_T("CopyMessage_%d"),i);
198-
// strKeyBuff = setIniFileString(REGKEY_KEY,StringBuff,_T("301,0,0"));
199-
// _stscanf_s(LPCTSTR(strKeyBuff),_T("%x,%x,%x"),&winMessage.Msg,&winMessage.wParam,&winMessage.lParam);
200-
// key.m_sCopyPasteKey.m_copyMessage = winMessage;
201-
//
202-
// StringBuff.Format(_T("PasteMessage_%d"),i);
203-
// strKeyBuff = setIniFileString(REGKEY_KEY,StringBuff,_T("302,0,0"));
204-
// _stscanf_s(LPCTSTR(strKeyBuff),_T("%x,%x,%x"),&winMessage.Msg,&winMessage.wParam,&winMessage.lParam);
205-
// key.m_sCopyPasteKey.m_pasteMessage = winMessage;
206-
// //クリップボード容量制限
207-
// StringBuff.Format(_T("HistoryLimit_%d"),i);
208-
// key.m_nHistoryLimit = setIniFileInt(REGKEY_KEY,StringBuff,-1);
209-
//
210-
// m_key.m_KeyList.insert(m_key.m_KeyList.end(),key);//設定に追加
211-
//}
212-
213-
//一般環境設定
214-
//m_strDataPath = setIniFileString(REGKEY_ENV,_T("DataFile"),"");
215-
216-
//m_strRwPluginFolder = setIniFileString(REGKEY_ENV,_T("RwPluginFolder"),m_strAppPath + _T("RW_Plugin"));
217-
//m_strPluginName = setIniFileString(REGKEY_ENV,_T("DataFormat"),DAT_FORMAT);
218-
//m_strMacroPluginName = setIniFileString(REGKEY_ENV,_T("MacroPlugin"),DAT_FORMAT);
219-
//m_nSelectID = setIniFileInt(REGKEY_ENV,_T("SelectID"),-1);
220-
//time_t lTime;
221-
//m_nTreeID = setIniFileInt(REGKEY_ENV,_T("TreeID"),time(&lTime));
222-
//m_nRecNumber = setIniFileInt(REGKEY_ENV,_T("RecNumber"),0);
223-
//m_nDebug = setIniFileInt(REGKEY_ENV,_T("Debug"),0) != 0;
224-
//m_strDebugLog = setIniFileString(REGKEY_ENV,_T("LogfileName"),_T("Charu3.log"));
225-
226-
//ウィンドウ設定
227-
//m_DialogSize.x = setIniFileInt(REGKEY_WINDOW,_T("PopupSizeX"),250);
228-
//m_DialogSize.y = setIniFileInt(REGKEY_WINDOW,_T("PopupSizeY"),350);
229-
230-
//検索設定
231-
//m_nSearchTarget = setIniFileInt(REGKEY_SERCH,_T("SerchKind"),0);
232-
//m_nSearchLogic = setIniFileInt(REGKEY_SERCH,_T("SerchLogic"),0);
233-
//m_strSearchKey = setIniFileString(REGKEY_SERCH,_T("SerchKey"),_T(""));
234-
235-
//マクロテンプレート
236-
//for(i = 0; i <= 99; i++) { // TODO: magic number
237-
// strRes.LoadString(APP_INF_MACRO_TEMPLATE01+i);
238-
// if(strRes == _T("end")) break;
239-
//}
240-
//int nStringCnt = i;
241-
MACRO_STRUCT macroData;
242-
CString strMacro;
243-
//m_vctMacro.clear();
244-
//m_vctMacro.reserve(99); // TODO: magic number
245-
//for(i = 1; i <= 99; i++) { // TODO: magic number
246-
// StringBuff.Format(_T("Macro_%02d"),i);
247-
// ::GetPrivateProfileString(REGKEY_MACRO,StringBuff,_T(""),strBuff,_countof(strBuff),m_strIniFile);
248-
// if (_tcsclen(strBuff) == 0 && i <= nStringCnt) {
249-
// strRes.LoadString(APP_INF_MACRO_TEMPLATE01 + i -1);
250-
// writeProfileString(REGKEY_MACRO,StringBuff,strRes);
251-
// strMacro = strRes;
252-
// _tcscpy_s(strBuff,LPCTSTR(strRes));
253-
// }
254-
// if(_tcsclen(strBuff) == 0) break;
255-
// if(UStringWork::splitString(strBuff,_T('@'),&szName,&szKind,&szMacro,NULL) == 3) {
256-
// macroData.m_strName = szName;
257-
// if(*szKind == _T('D')) macroData.m_cKind = KIND_DATA_ALL;
258-
// else if(*szKind == _T('F')) macroData.m_cKind = KIND_FOLDER_ALL;
259-
// else macroData.m_cKind = 0xff;
260-
// macroData.m_strMacro = szMacro;
261-
// m_vctMacro.push_back(macroData);
262-
// }
263-
//}
264-
265-
//拡張マクロテンプレート R履歴フォルダ Fフォルダ A全て Dデータ
266-
//for(i = 0; i <= 99; i++) { // TODO: magic number
267-
// strRes.LoadString(APP_INF_EXMACRO_TEMPLATE01+i);
268-
// if(strRes == "end") break;
269-
//}
270-
//int nStringCnt = i;
271-
//m_vctDataMacro.clear();
272-
//m_vctDataMacro.reserve(99); // TODO: magic number
273-
//for(i = 1; i <= 99; i++) { // TODO: magic number
274-
// StringBuff.Format(_T("DataMacro_%02d"),i);
275-
// ::GetPrivateProfileString(REGKEY_MACRO,StringBuff,_T(""),strBuff,_countof(strBuff),m_strIniFile);
276-
// if (_tcsclen(strBuff) == 0 && i <= nStringCnt) {
277-
// strRes.LoadString(APP_INF_EXMACRO_TEMPLATE01 + i -1);
278-
// writeProfileString(REGKEY_MACRO,StringBuff,strRes);
279-
// strMacro = strRes;
280-
// _tcscpy_s(strBuff,LPCTSTR(strRes));
281-
// }
282-
// if(_tcsclen(strBuff) == 0) break;
283-
// if(UStringWork::splitString(strBuff,'@',&szName,&szKind,&szMacro,NULL) == 3) {
284-
// macroData.m_strName = szName;
285-
//if(*szKind == 'D') macroData.m_cKind = KIND_DATA_ALL;
286-
//else if(*szKind == 'R') macroData.m_cKind = KIND_RIREKI;
287-
//else if(*szKind == 'F') macroData.m_cKind = KIND_FOLDER_ALL;
288-
//else macroData.m_cKind = 0xff;
289-
// macroData.m_strMacro = szMacro;
290-
// m_vctDataMacro.push_back(macroData);
291-
// }
292-
//}
293-
294-
// read state
295-
296120
m_strDataPath = CGeneral::getSettingCString(m_state, "data.path", _T(""));
297121
m_strDataFormat = CGeneral::getSettingCString(m_state, "data.format", DAT_FORMAT);
298122
m_bReadOnly = CGeneral::getSettingBool(m_state, "data.readOnly", false);
@@ -309,6 +133,8 @@ void CInit::initialize()
309133
m_nRecNumber = static_cast<int>(CGeneral::getSettingNumber(m_state, "internal.recordNumber", 0));
310134

311135
// read settings
136+
try { m_settings = nlohmann::json::parse(std::ifstream(m_strSettingsFile)); }
137+
catch (...) {}
312138

313139
m_etc.m_bPutBackClipboard = CGeneral::getSettingBool(m_settings, "clipboard.putBackAfterPasting", false);
314140
m_nClipboardOpenDelay = static_cast<int>(CGeneral::getSettingNumber(m_settings, "clipboard.openDelay", 0));
@@ -375,18 +201,16 @@ void CInit::initialize()
375201
m_key.m_KeyList.push_back(node);
376202
}
377203
m_key.m_defKeySet = COPYPASTE_KEY(m_settings["keyEvent.default"]);
378-
m_key.m_nHistoryLimit = m_settings["keyEvent.default.copyLimit"];
204+
m_key.m_nHistoryLimit = static_cast<int>(CGeneral::getSettingNumber(m_settings, "keyEvent.default.copyLimit", -1));
379205

380206
SaveSettings();
381207

382208
// read snippets
383-
384209
m_vctMacro.clear();
385210
ReadPredefined(m_vctMacro, m_strAppPath + "_locale\\" + m_locale + "\\snippets.json");
386211
ReadPredefined(m_vctMacro, m_strAppDataPath + "\\snippets.json");
387212

388213
// read options
389-
390214
m_vctDataMacro.clear();
391215
ReadPredefined(m_vctDataMacro, m_strAppPath + "_locale\\" + m_locale + "\\options.json");
392216
}
@@ -498,60 +322,6 @@ void CInit::writeEnvInitData()
498322
try { std::ofstream(m_strStateFile) << m_state.dump(1, '\t') << "\n"; } catch (...) {}
499323
}
500324

501-
502-
//---------------------------------------------------
503-
//関数名 setIniFileInt()
504-
//機能 設定ファイルを読む
505-
//---------------------------------------------------
506-
int CInit::setIniFileInt(const TCHAR* szSection,const TCHAR* szKey,int nDefault)
507-
{
508-
int n = (int)::GetPrivateProfileInt(szSection,szKey,-1,m_strIniFile);
509-
if(n == -1) {
510-
n = nDefault;
511-
writeProfileInt(szSection,szKey,n);
512-
}
513-
return n;
514-
}
515-
516-
//---------------------------------------------------
517-
//関数名 setIniFileString()
518-
//機能 設定ファイルを読む
519-
//---------------------------------------------------
520-
CString CInit::setIniFileString(const TCHAR* szSection,const TCHAR* szKey,CString strDefault)
521-
{
522-
TCHAR strBuff[1024];
523-
CString strRet;
524-
::GetPrivateProfileString(szSection,szKey,_T(""),strBuff,_countof(strBuff),m_strIniFile);
525-
strRet = strBuff;
526-
if (strRet == "") {
527-
// Use default if empty
528-
writeProfileString(szSection,szKey,strDefault);
529-
strRet = strDefault;
530-
}
531-
return strRet;
532-
}
533-
534-
//---------------------------------------------------
535-
//関数名 writeProfileInt()
536-
//機能 設定ファイルを書き込み
537-
//---------------------------------------------------
538-
void CInit::writeProfileInt(const TCHAR* szSection,const TCHAR* szKey,int nValue)
539-
{
540-
TCHAR strBuff[1024];
541-
_stprintf_s(strBuff,_T("%d"),nValue);
542-
WritePrivateProfileString(szSection,szKey,strBuff,m_strIniFile);
543-
}
544-
545-
//---------------------------------------------------
546-
//関数名 writeProfileString()
547-
//機能 設定ファイルを書き込み
548-
//---------------------------------------------------
549-
void CInit::writeProfileString(const TCHAR* szSection,const TCHAR* szKey,CString strValue)
550-
{
551-
WritePrivateProfileString(szSection,szKey,_T("\"") + strValue + _T("\""),m_strIniFile);
552-
auto err = GetLastError();
553-
}
554-
555325
//---------------------------------------------------
556326
//関数名 getPasteHotKey
557327
//機能 貼り付け系キー設定を取得

0 commit comments

Comments
 (0)