From 2ac539aa6456ee8db7225acb793fee4b5c6906b4 Mon Sep 17 00:00:00 2001 From: usagisita <40428610+usagisita@users.noreply.github.com> Date: Sun, 27 Sep 2020 09:13:41 +0900 Subject: [PATCH 01/14] =?UTF-8?q?=E3=83=9E=E3=82=AF=E3=83=AD=E3=81=A7?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E9=96=8B=E3=81=8F?= =?UTF-8?q?=E3=83=80=E3=82=A4=E3=82=A2=E3=83=AD=E3=82=B0=E3=81=AE=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB=E5=90=8D=E3=81=A8=E6=8B=A1=E5=BC=B5?= =?UTF-8?q?=E5=AD=90=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=BC=E3=80=81?= =?UTF-8?q?=E3=83=90=E3=83=83=E3=83=95=E3=82=A1=E9=95=B7=E5=88=B6=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・マクロでフォルダを開く初期フォルダ制限 ・pszUserWildCardがSFilePathでMAX_PATH制限 ・CFileExtのExtが短い固定長だったのをwstringへ変更 --- sakura_core/CFileExt.cpp | 36 +++++++++++------------------------- sakura_core/CFileExt.h | 10 +++++----- sakura_core/macro/CMacro.cpp | 12 ++++++++++++ 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/sakura_core/CFileExt.cpp b/sakura_core/CFileExt.cpp index ea08cb42b0..b2ae1a9a5e 100644 --- a/sakura_core/CFileExt.cpp +++ b/sakura_core/CFileExt.cpp @@ -37,7 +37,6 @@ CFileExt::CFileExt() { - m_puFileExtInfo = NULL; m_nCount = 0; m_vstrFilter.resize( 1 ); m_vstrFilter[0] = L'\0'; @@ -49,14 +48,12 @@ CFileExt::CFileExt() CFileExt::~CFileExt() { - if( m_puFileExtInfo ) free( m_puFileExtInfo ); - m_puFileExtInfo = NULL; m_nCount = 0; } bool CFileExt::AppendExt( const WCHAR *pszName, const WCHAR *pszExt ) { - WCHAR szWork[_countof(m_puFileExtInfo[0].m_szExt) + 10]; + WCHAR szWork[MAX_PATH]; if( !CDocTypeManager::ConvertTypesExtToDlgExt( pszExt, NULL, szWork ) ) return false; return AppendExtRaw( pszName, szWork ); @@ -64,26 +61,15 @@ bool CFileExt::AppendExt( const WCHAR *pszName, const WCHAR *pszExt ) bool CFileExt::AppendExtRaw( const WCHAR *pszName, const WCHAR *pszExt ) { - FileExtInfoTag *p; - if( NULL == pszName || pszName[0] == L'\0' ) return false; if( NULL == pszExt || pszExt[0] == L'\0' ) return false; - if( NULL == m_puFileExtInfo ) - { - p = (FileExtInfoTag*)malloc( sizeof( FileExtInfoTag ) * 1 ); - if( NULL == p ) return false; - } - else - { - p = (FileExtInfoTag*)realloc( m_puFileExtInfo, sizeof( FileExtInfoTag ) * ( m_nCount + 1 ) ); - if( NULL == p ) return false; - } - m_puFileExtInfo = p; + SFileExtInfo info; + info.m_sTypeName = pszName; + info.m_sExt = pszExt; - wcscpy( m_puFileExtInfo[m_nCount].m_szName, pszName ); - wcscpy( m_puFileExtInfo[m_nCount].m_szExt, pszExt ); - m_nCount++; + m_vFileExtInfo.push_back(std::move(info)); + m_nCount = static_cast(m_vFileExtInfo.size()); return true; } @@ -92,14 +78,14 @@ const WCHAR *CFileExt::GetName( int nIndex ) { if( nIndex < 0 || nIndex >= m_nCount ) return NULL; - return m_puFileExtInfo[nIndex].m_szName; + return m_vFileExtInfo[nIndex].m_sTypeName.c_str(); } const WCHAR *CFileExt::GetExt( int nIndex ) { if( nIndex < 0 || nIndex >= m_nCount ) return NULL; - return m_puFileExtInfo[nIndex].m_szExt; + return m_vFileExtInfo[nIndex].m_sExt.c_str(); } const WCHAR *CFileExt::GetExtFilter( void ) @@ -113,12 +99,12 @@ const WCHAR *CFileExt::GetExtFilter( void ) for( i = 0; i < m_nCount; i++ ) { // "%s (%s)\0%s\0" - work = m_puFileExtInfo[i].m_szName; + work = m_vFileExtInfo[i].m_sTypeName; work.append(L" ("); - work.append(m_puFileExtInfo[i].m_szExt); + work.append(m_vFileExtInfo[i].m_sExt); work.append(L")"); work.append(L"\0", 1); - work.append(m_puFileExtInfo[i].m_szExt); + work.append(m_vFileExtInfo[i].m_sExt); work.append(L"\0", 1); int i = (int)m_vstrFilter.size(); diff --git a/sakura_core/CFileExt.h b/sakura_core/CFileExt.h index fabfb5f744..a23e2c89a1 100644 --- a/sakura_core/CFileExt.h +++ b/sakura_core/CFileExt.h @@ -60,13 +60,13 @@ class CFileExt private: - typedef struct { - WCHAR m_szName[64]; //名前(64文字以下のはず→m_szTypeName) - WCHAR m_szExt[MAX_TYPES_EXTS*3+1]; //拡張子(64文字以下のはず→m_szTypeExts) なお "*." を追加するのでそれなりに必要 - } FileExtInfoTag; + struct SFileExtInfo { + std::wstring m_sTypeName; //名前 + std::wstring m_sExt; //拡張子 + }; int m_nCount; - FileExtInfoTag *m_puFileExtInfo; + std::vector m_vFileExtInfo; std::vector m_vstrFilter; DISALLOW_COPY_AND_ASSIGN(CFileExt); diff --git a/sakura_core/macro/CMacro.cpp b/sakura_core/macro/CMacro.cpp index e6db099ce5..dbeb58a802 100644 --- a/sakura_core/macro/CMacro.cpp +++ b/sakura_core/macro/CMacro.cpp @@ -1884,6 +1884,14 @@ bool CMacro::HandleFunction(CEditView *View, EFunctionCode ID, const VARIANT *Ar sFilter = Source; // フィルタ文字列 delete[] Source; } + // sDefaultの先はSFilePath型 + if (MAX_PATH <= sDefault.length()) { + return false; + } + // sFilterの先はSFilePath型 + if (MAX_PATH <= sFilter.length()) { + return false; + } CDlgOpenFile cDlgOpenFile; cDlgOpenFile.Create( @@ -1929,6 +1937,10 @@ bool CMacro::HandleFunction(CEditView *View, EFunctionCode ID, const VARIANT *Ar sDefault = Source; // 既定のファイル名 delete[] Source; } + // sDefaultは[MAX_PATH] + if (MAX_PATH <= sDefault.length()) { + return false; + } WCHAR szPath[ _MAX_PATH ]; int nRet = SelectDir( View->GetHwnd(), sMessage.c_str(), sDefault.c_str(), szPath ); From f941df8bb3400b574ce50a00fcdc1a2cacd86878 Mon Sep 17 00:00:00 2001 From: usagisita <40428610+usagisita@users.noreply.github.com> Date: Fri, 12 Mar 2021 19:27:14 +0900 Subject: [PATCH 02/14] =?UTF-8?q?CFileExt=E3=81=AE=E5=8A=A9=E9=95=B7?= =?UTF-8?q?=E3=81=AAm=5FnCount=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sakura_core/CFileExt.cpp | 15 ++++----------- sakura_core/CFileExt.h | 5 ++--- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/sakura_core/CFileExt.cpp b/sakura_core/CFileExt.cpp index b2ae1a9a5e..772afbb25c 100644 --- a/sakura_core/CFileExt.cpp +++ b/sakura_core/CFileExt.cpp @@ -37,7 +37,6 @@ CFileExt::CFileExt() { - m_nCount = 0; m_vstrFilter.resize( 1 ); m_vstrFilter[0] = L'\0'; @@ -46,11 +45,6 @@ CFileExt::CFileExt() // AppendExt( "テキストファイル", "txt" ); } -CFileExt::~CFileExt() -{ - m_nCount = 0; -} - bool CFileExt::AppendExt( const WCHAR *pszName, const WCHAR *pszExt ) { WCHAR szWork[MAX_PATH]; @@ -69,21 +63,20 @@ bool CFileExt::AppendExtRaw( const WCHAR *pszName, const WCHAR *pszExt ) info.m_sExt = pszExt; m_vFileExtInfo.push_back(std::move(info)); - m_nCount = static_cast(m_vFileExtInfo.size()); return true; } const WCHAR *CFileExt::GetName( int nIndex ) { - if( nIndex < 0 || nIndex >= m_nCount ) return NULL; + if( nIndex < 0 || nIndex >= GetCount() ) return NULL; return m_vFileExtInfo[nIndex].m_sTypeName.c_str(); } const WCHAR *CFileExt::GetExt( int nIndex ) { - if( nIndex < 0 || nIndex >= m_nCount ) return NULL; + if( nIndex < 0 || nIndex >= GetCount() ) return NULL; return m_vFileExtInfo[nIndex].m_sExt.c_str(); } @@ -96,7 +89,7 @@ const WCHAR *CFileExt::GetExtFilter( void ) /* 拡張子フィルタの作成 */ m_vstrFilter.resize(0); - for( i = 0; i < m_nCount; i++ ) + for( i = 0; i < GetCount(); i++ ) { // "%s (%s)\0%s\0" work = m_vFileExtInfo[i].m_sTypeName; @@ -111,7 +104,7 @@ const WCHAR *CFileExt::GetExtFilter( void ) m_vstrFilter.resize( i + work.length() ); wmemcpy( &m_vstrFilter[i], &work[0], work.length() ); } - if( 0 == m_nCount ){ + if( 0 == GetCount() ){ m_vstrFilter.push_back( L'\0' ); } m_vstrFilter.push_back( L'\0' ); diff --git a/sakura_core/CFileExt.h b/sakura_core/CFileExt.h index a23e2c89a1..9d2f72abd5 100644 --- a/sakura_core/CFileExt.h +++ b/sakura_core/CFileExt.h @@ -41,7 +41,7 @@ class CFileExt { public: CFileExt(); - ~CFileExt(); + ~CFileExt() = default; bool AppendExt( const WCHAR *pszName, const WCHAR *pszExt ); bool AppendExtRaw( const WCHAR *pszName, const WCHAR *pszExt ); @@ -52,7 +52,7 @@ class CFileExt //2回呼び出すと古いバッファが無効になることがあるのに注意 const WCHAR *GetExtFilter( void ); - int GetCount( void ) { return m_nCount; } + int GetCount() const { return static_cast(m_vFileExtInfo.size()); } protected: // 2014.10.30 syat ConvertTypesExtToDlgExtをCDocTypeManagerに移動 @@ -65,7 +65,6 @@ class CFileExt std::wstring m_sExt; //拡張子 }; - int m_nCount; std::vector m_vFileExtInfo; std::vector m_vstrFilter; From 77b5ee689e68fc6bf83c6eac5b19795bba5ee2db Mon Sep 17 00:00:00 2001 From: usagisita <40428610+usagisita@users.noreply.github.com> Date: Fri, 12 Mar 2021 19:35:00 +0900 Subject: [PATCH 03/14] =?UTF-8?q?CFileExt::GetExtFilter=E3=81=8B=E3=82=89?= =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=BC=E6=96=87=E5=AD=97?= =?UTF-8?q?=E5=88=97=E4=BD=9C=E6=88=90=E3=82=92=E5=88=86=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sakura_core/CFileExt.cpp | 20 ++++++++++++-------- sakura_core/CFileExt.h | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/sakura_core/CFileExt.cpp b/sakura_core/CFileExt.cpp index 772afbb25c..892e72a5d4 100644 --- a/sakura_core/CFileExt.cpp +++ b/sakura_core/CFileExt.cpp @@ -82,12 +82,18 @@ const WCHAR *CFileExt::GetExt( int nIndex ) } const WCHAR *CFileExt::GetExtFilter( void ) +{ + CreateExtFilter(m_vstrFilter); + return m_vstrFilter.data(); +} + +void CFileExt::CreateExtFilter(std::vector& output) const { int i; std::wstring work; /* 拡張子フィルタの作成 */ - m_vstrFilter.resize(0); + output.resize(0); for( i = 0; i < GetCount(); i++ ) { @@ -100,14 +106,12 @@ const WCHAR *CFileExt::GetExtFilter( void ) work.append(m_vFileExtInfo[i].m_sExt); work.append(L"\0", 1); - int i = (int)m_vstrFilter.size(); - m_vstrFilter.resize( i + work.length() ); - wmemcpy( &m_vstrFilter[i], &work[0], work.length() ); + int pos = static_cast(output.size()); + output.resize(pos + work.length()); + wmemcpy(&output[pos], &work[0], work.length()); } if( 0 == GetCount() ){ - m_vstrFilter.push_back( L'\0' ); + output.push_back( L'\0' ); } - m_vstrFilter.push_back( L'\0' ); - - return &m_vstrFilter[0]; + output.push_back( L'\0' ); } diff --git a/sakura_core/CFileExt.h b/sakura_core/CFileExt.h index 9d2f72abd5..5b23ed0cb8 100644 --- a/sakura_core/CFileExt.h +++ b/sakura_core/CFileExt.h @@ -59,6 +59,7 @@ class CFileExt //bool ConvertTypesExtToDlgExt( const WCHAR *pszSrcExt, WCHAR *pszDstExt ); private: + void CreateExtFilter(std::vector& output) const; struct SFileExtInfo { std::wstring m_sTypeName; //名前 From cdb7079d3223352883a8bcb41f6c30715062ffed Mon Sep 17 00:00:00 2001 From: usagisita <40428610+usagisita@users.noreply.github.com> Date: Sun, 27 Sep 2020 09:13:41 +0900 Subject: [PATCH 04/14] =?UTF-8?q?CDlgOpenFile=E3=81=AE=E3=83=AF=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=83=89=E3=82=AB=E3=83=BC=E3=83=89=E9=95=B7=E5=88=B6?= =?UTF-8?q?=E9=99=90=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sakura_core/CFileExt.cpp | 6 +-- .../dlg/CDlgOpenFile_CommonFileDialog.cpp | 16 +++---- .../dlg/CDlgOpenFile_CommonItemDialog.cpp | 6 +-- sakura_core/doc/CDocFileOperation.cpp | 18 ++++---- sakura_core/env/CDocTypeManager.cpp | 42 +++++++++---------- sakura_core/env/CDocTypeManager.h | 2 +- sakura_core/macro/CMacro.cpp | 4 -- 7 files changed, 45 insertions(+), 49 deletions(-) diff --git a/sakura_core/CFileExt.cpp b/sakura_core/CFileExt.cpp index 892e72a5d4..0269fab164 100644 --- a/sakura_core/CFileExt.cpp +++ b/sakura_core/CFileExt.cpp @@ -47,10 +47,10 @@ CFileExt::CFileExt() bool CFileExt::AppendExt( const WCHAR *pszName, const WCHAR *pszExt ) { - WCHAR szWork[MAX_PATH]; + std::wstring workExt; - if( !CDocTypeManager::ConvertTypesExtToDlgExt( pszExt, NULL, szWork ) ) return false; - return AppendExtRaw( pszName, szWork ); + if( !CDocTypeManager::ConvertTypesExtToDlgExt( pszExt, NULL, workExt ) ) return false; + return AppendExtRaw( pszName, workExt.c_str() ); } bool CFileExt::AppendExtRaw( const WCHAR *pszName, const WCHAR *pszExt ) diff --git a/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp b/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp index 1678d39046..b4408164f9 100644 --- a/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp +++ b/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp @@ -93,7 +93,7 @@ struct CDlgOpenFile_CommonFileDialog final : public IDlgOpenFile DLLSHAREDATA* m_pShareData; - SFilePath m_szDefaultWildCard; /* 「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */ + std::wstring m_strDefaultWildCard; /* 「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */ SFilePath m_szInitialDir; /* 「開く」での初期ディレクトリ */ std::vector m_vMRU; @@ -418,7 +418,7 @@ UINT_PTR CALLBACK OFNHookProc( else{ switch( pData->m_pOf->nFilterIndex ){ // 選択されているファイルの種類 case 1: // ユーザー定義 - pszCur = pData->m_pcDlgOpenFile->m_szDefaultWildCard; + pszCur = pData->m_pcDlgOpenFile->m_strDefaultWildCard.data(); while( *pszCur != L'.' && *pszCur != L'\0' ) // '.'まで読み飛ばす pszCur = ::CharNext(pszCur); i = 0; @@ -667,7 +667,7 @@ CDlgOpenFile_CommonFileDialog::CDlgOpenFile_CommonFileDialog() wcscpy( m_szInitialDir, szDrive ); wcscat( m_szInitialDir, szDir ); - wcscpy( m_szDefaultWildCard, L"*.*" ); /*「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */ + m_strDefaultWildCard = L"*.*"; /*「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */ return; } @@ -687,7 +687,7 @@ void CDlgOpenFile_CommonFileDialog::Create( /* ユーザー定義ワイルドカード(保存時の拡張子補完でも使用される) */ if( NULL != pszUserWildCard ){ - wcscpy( m_szDefaultWildCard, pszUserWildCard ); + m_strDefaultWildCard = pszUserWildCard; } /* 「開く」での初期フォルダ */ @@ -722,7 +722,7 @@ bool CDlgOpenFile_CommonFileDialog::DoModal_GetOpenFileName( WCHAR* pszPath, EFi // 2003.05.12 MIK CFileExt cFileExt; - cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME1), m_szDefaultWildCard ); + cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME1), m_strDefaultWildCard.c_str() ); switch( eAddFilter ){ case EFITER_TEXT: @@ -740,7 +740,7 @@ bool CDlgOpenFile_CommonFileDialog::DoModal_GetOpenFileName( WCHAR* pszPath, EFi break; } - if( 0 != wcscmp(m_szDefaultWildCard, L"*.*") ){ + if( 0 != wcscmp(m_strDefaultWildCard.c_str(), L"*.*") ){ cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME3), L"*.*" ); } @@ -815,7 +815,7 @@ bool CDlgOpenFile_CommonFileDialog::DoModal_GetSaveFileName( WCHAR* pszPath ) // 2003.05.12 MIK CFileExt cFileExt; - cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME1), m_szDefaultWildCard ); + cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME1), m_strDefaultWildCard.c_str() ); cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME2), L"*.txt" ); cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME3), L"*.*" ); @@ -979,7 +979,7 @@ bool CDlgOpenFile_CommonFileDialog::DoModalSaveDlg( // 2003.05.12 MIK CFileExt cFileExt; - cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME1), m_szDefaultWildCard ); + cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME1), m_strDefaultWildCard.c_str() ); cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME2), L"*.txt" ); cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME3), L"*.*" ); diff --git a/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp b/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp index f6fea7305b..0e93697ec0 100644 --- a/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp +++ b/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp @@ -700,15 +700,15 @@ bool CDlgOpenFile_CommonItemDialog::DoModalOpenDlg( specs[1].pszName = strs[1].c_str(); specs[1].pszSpec = L"*.txt"; CDocTypeManager docTypeMgr; - WCHAR szWork[_countof(STypeConfigMini::m_szTypeExts) * 3]; + std::wstring worksString; for( int i = 0; i < nTypesCount; i++ ){ const STypeConfigMini* type = NULL; if( !docTypeMgr.GetTypeConfigMini( CTypeConfig(i), &type ) ){ continue; } specs[2 + i].pszName = type->m_szTypeName; - if (CDocTypeManager::ConvertTypesExtToDlgExt(type->m_szTypeExts, NULL, szWork)) { - strs[2 + i] = szWork; + if (CDocTypeManager::ConvertTypesExtToDlgExt(type->m_szTypeExts, NULL, worksString)) { + strs[2 + i] = worksString; specs[2 + i].pszSpec = strs[2 + i].c_str(); } else { diff --git a/sakura_core/doc/CDocFileOperation.cpp b/sakura_core/doc/CDocFileOperation.cpp index 1702593be8..fb775ad704 100644 --- a/sakura_core/doc/CDocFileOperation.cpp +++ b/sakura_core/doc/CDocFileOperation.cpp @@ -225,7 +225,8 @@ bool CDocFileOperation::SaveFileDialog( //拡張子指定 // 一時適用や拡張子なしの場合の拡張子をタイプ別設定から持ってくる // 2008/6/14 大きく改造 Uchi - WCHAR szDefaultWildCard[_MAX_PATH + 10]; // ユーザー指定拡張子 + std::wstring strDefaultWildCard; // ユーザー指定拡張子 + { LPCWSTR szExt; @@ -241,28 +242,27 @@ bool CDocFileOperation::SaveFileDialog( // 基本 if (szExt[0] == L'\0') { // ファイルパスが無いまたは拡張子なし - wcscpy(szDefaultWildCard, L"*.txt"); + strDefaultWildCard = L"*.txt"; } else { // 拡張子あり - wcscpy(szDefaultWildCard, L"*"); - wcscat(szDefaultWildCard, szExt); + strDefaultWildCard = L"*"; + strDefaultWildCard += szExt; } } else { - szDefaultWildCard[0] = L'\0'; - CDocTypeManager::ConvertTypesExtToDlgExt(type.m_szTypeExts, szExt, szDefaultWildCard); + CDocTypeManager::ConvertTypesExtToDlgExt(type.m_szTypeExts, szExt, strDefaultWildCard); } if(!this->m_pcDocRef->m_cDocFile.GetFilePathClass().IsValidPath()){ //「新規から保存時は全ファイル表示」オプション // 2008/6/15 バグフィックス Uchi if( GetDllShareData().m_Common.m_sFile.m_bNoFilterSaveNew ) - wcscat(szDefaultWildCard, L";*.*"); // 全ファイル表示 + strDefaultWildCard += L";*.*"; // 全ファイル表示 } else { //「新規以外から保存時は全ファイル表示」オプション if( GetDllShareData().m_Common.m_sFile.m_bNoFilterSaveFile ) - wcscat(szDefaultWildCard, L";*.*"); // 全ファイル表示 + strDefaultWildCard += L";*.*"; // 全ファイル表示 } } @@ -281,7 +281,7 @@ bool CDocFileOperation::SaveFileDialog( cDlgOpenFile.Create( G_AppInstance(), CEditWnd::getInstance()->GetHwnd(), - szDefaultWildCard, + strDefaultWildCard.c_str(), CSakuraEnvironment::GetDlgInitialDir().c_str(), // 初期フォルダ CMRUFile().GetPathList(), // 最近のファイル CMRUFolder().GetPathList() // 最近のフォルダ diff --git a/sakura_core/env/CDocTypeManager.cpp b/sakura_core/env/CDocTypeManager.cpp index 02e6115f84..a4bf8d1990 100644 --- a/sakura_core/env/CDocTypeManager.cpp +++ b/sakura_core/env/CDocTypeManager.cpp @@ -215,45 +215,45 @@ void CDocTypeManager::GetFirstExt(const WCHAR* pszTypeExts, WCHAR szFirstExt[], } /*! タイプ別設定の拡張子リストをダイアログ用リストに変換する - @param pszSrcExt [in] 拡張子リスト 例「.c .cpp;.h」 - @param pszDstExt [out] 拡張子リスト 例「*.c;*.cpp;*.h」 - @param szExt [in] リストの先頭にする拡張子 例「.h」 + @param pszSrcExt [in] 拡張子リスト 例「.c cpp;.h」(ドットはオプション) + @param szExt [in] リストの先頭にする拡張子 例「.h」(ドット必須) + @param destExt [out] 拡張子リスト 例「*.h;*.c;*.cpp」 @date 2014.12.06 syat CFileExtから移動 */ -bool CDocTypeManager::ConvertTypesExtToDlgExt( const WCHAR *pszSrcExt, const WCHAR* szExt, WCHAR *pszDstExt ) +bool CDocTypeManager::ConvertTypesExtToDlgExt(const WCHAR *pszSrcExt, const WCHAR* szExt, std::wstring& destExt) { - WCHAR *token; - WCHAR *p; - + destExt.resize(0); // 2003.08.14 MIK NULLじゃなくてfalse if( NULL == pszSrcExt ) return false; - if( NULL == pszDstExt ) return false; - - p = _wcsdup( pszSrcExt ); - pszDstExt[0] = L'\0'; if (szExt != NULL && szExt[0] != L'\0') { // ファイルパスがあり、拡張子ありの場合、トップに指定 - wcscpy(pszDstExt, L"*"); - wcscat(pszDstExt, szExt); + destExt.assign(L"*"); + destExt.append(szExt); } - token = _wcstok(p, m_typeExtSeps); + std::wstring strSrcTokens = pszSrcExt; + WCHAR* context = nullptr; + WCHAR* token = wcstok_s(strSrcTokens.data(), m_typeExtSeps, &context); while( token ) { if (szExt == NULL || szExt[0] == L'\0' || wmemicmp(token, szExt + 1) != 0) { - if( pszDstExt[0] != '\0' ) wcscat( pszDstExt, L";" ); + if (0 < destExt.length()) { + destExt.append(L";"); + } // 拡張子指定なし、またはマッチした拡張子でない if (wcspbrk(token, m_typeExtWildcards) == NULL) { - if (L'.' == *token) wcscat(pszDstExt, L"*"); - else wcscat(pszDstExt, L"*."); + if (L'.' == *token) { + destExt.append(L"*"); + } + else { + destExt.append(L"*."); + } } - wcscat(pszDstExt, token); + destExt.append(token); } - - token = _wcstok( NULL, m_typeExtSeps ); + token = wcstok_s(nullptr, m_typeExtSeps, &context); } - free( p ); // 2003.05.20 MIK メモリ解放漏れ return true; } diff --git a/sakura_core/env/CDocTypeManager.h b/sakura_core/env/CDocTypeManager.h index aa3a5edfc0..a0027169c8 100644 --- a/sakura_core/env/CDocTypeManager.h +++ b/sakura_core/env/CDocTypeManager.h @@ -51,7 +51,7 @@ class CDocTypeManager{ static bool IsFileNameMatch(const WCHAR* pszTypeExts, const WCHAR* pszFileName); // タイプ別拡張子にファイル名がマッチするか static void GetFirstExt(const WCHAR* pszTypeExts, WCHAR szFirstExt[], int nBuffSize); // タイプ別拡張子の先頭拡張子を取得する - static bool ConvertTypesExtToDlgExt( const WCHAR *pszSrcExt, const WCHAR* szExt, WCHAR *pszDstExt ); // タイプ別設定の拡張子リストをダイアログ用リストに変換する + static bool ConvertTypesExtToDlgExt(const WCHAR *pszSrcExt, const WCHAR* szExt, std::wstring& destExt); // タイプ別設定の拡張子リストをダイアログ用リストに変換する static const WCHAR* m_typeExtSeps; // タイプ別拡張子の区切り文字 static const WCHAR* m_typeExtWildcards; // タイプ別拡張子のワイルドカード diff --git a/sakura_core/macro/CMacro.cpp b/sakura_core/macro/CMacro.cpp index dbeb58a802..3e822a1f35 100644 --- a/sakura_core/macro/CMacro.cpp +++ b/sakura_core/macro/CMacro.cpp @@ -1888,10 +1888,6 @@ bool CMacro::HandleFunction(CEditView *View, EFunctionCode ID, const VARIANT *Ar if (MAX_PATH <= sDefault.length()) { return false; } - // sFilterの先はSFilePath型 - if (MAX_PATH <= sFilter.length()) { - return false; - } CDlgOpenFile cDlgOpenFile; cDlgOpenFile.Create( From 22aca79a95e5d6217439e683bcfe92ec809c6cac Mon Sep 17 00:00:00 2001 From: usagisita <40428610+usagisita@users.noreply.github.com> Date: Tue, 16 Mar 2021 03:41:41 +0900 Subject: [PATCH 05/14] =?UTF-8?q?CDlgOpenFile=5FCommonItemDialog=E3=81=AEm?= =?UTF-8?q?=5FstrDefaultWildCard=E3=82=92std::wstring=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・バッファオーバーランしていたのを修正 --- sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp b/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp index 0e93697ec0..71fc8e3763 100644 --- a/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp +++ b/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp @@ -77,7 +77,7 @@ struct CDlgOpenFile_CommonItemDialog final DLLSHAREDATA* m_pShareData; - SFilePath m_szDefaultWildCard; /* 「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */ + std::wstring m_strDefaultWildCard; /* 「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */ SFilePath m_szInitialDir; /* 「開く」での初期ディレクトリ */ std::vector m_vMRU; @@ -416,7 +416,7 @@ CDlgOpenFile_CommonItemDialog::CDlgOpenFile_CommonItemDialog() wcscpy( m_szInitialDir, szDrive ); wcscat( m_szInitialDir, szDir ); - wcscpy( m_szDefaultWildCard, L"*.*" ); /*「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */ + m_strDefaultWildCard = L"*.*"; /*「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */ return; } @@ -435,7 +435,7 @@ void CDlgOpenFile_CommonItemDialog::Create( /* ユーザー定義ワイルドカード(保存時の拡張子補完でも使用される) */ if( NULL != pszUserWildCard ){ - wcscpy( m_szDefaultWildCard, pszUserWildCard ); + m_strDefaultWildCard = pszUserWildCard; } /* 「開く」での初期フォルダ */ @@ -465,7 +465,7 @@ bool CDlgOpenFile_CommonItemDialog::DoModal_GetOpenFileName( WCHAR* pszPath, EFi strs.reserve(8); strs.push_back(LS(STR_DLGOPNFL_EXTNAME1)); - specs.push_back(COMDLG_FILTERSPEC{strs.back().c_str(), m_szDefaultWildCard}); + specs.push_back(COMDLG_FILTERSPEC{strs.back().c_str(), m_strDefaultWildCard.c_str()}); switch( eAddFilter ){ case EFITER_TEXT: @@ -484,7 +484,7 @@ bool CDlgOpenFile_CommonItemDialog::DoModal_GetOpenFileName( WCHAR* pszPath, EFi break; } - if( 0 != wcscmp(m_szDefaultWildCard, L"*.*") ){ + if( 0 != wcscmp(m_strDefaultWildCard.c_str(), L"*.*") ){ strs.push_back(LS(STR_DLGOPNFL_EXTNAME3)); specs.push_back(COMDLG_FILTERSPEC{strs.back().c_str(), L"*.*"}); } @@ -747,7 +747,7 @@ HRESULT CDlgOpenFile_CommonItemDialog::DoModalSaveDlgImpl1( strs[1] = LS(STR_DLGOPNFL_EXTNAME2); strs[2] = LS(STR_DLGOPNFL_EXTNAME3); specs[0].pszName = strs[0].c_str(); - specs[0].pszSpec = m_szDefaultWildCard; + specs[0].pszSpec = m_strDefaultWildCard.c_str(); specs[1].pszName = strs[1].c_str(); specs[1].pszSpec = L"*.txt"; specs[2].pszName = strs[2].c_str(); From 4470d7d77e3092edc074c090eec851d21d56529f Mon Sep 17 00:00:00 2001 From: usagisita <40428610+usagisita@users.noreply.github.com> Date: Sun, 21 Mar 2021 16:28:08 +0900 Subject: [PATCH 06/14] =?UTF-8?q?SonarCloud=E4=B8=80=E9=83=A8=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sakura_core/CFileExt.cpp | 11 +++++------ sakura_core/CFileExt.h | 2 +- sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp | 3 +-- sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/sakura_core/CFileExt.cpp b/sakura_core/CFileExt.cpp index 0269fab164..938cc5598f 100644 --- a/sakura_core/CFileExt.cpp +++ b/sakura_core/CFileExt.cpp @@ -49,7 +49,7 @@ bool CFileExt::AppendExt( const WCHAR *pszName, const WCHAR *pszExt ) { std::wstring workExt; - if( !CDocTypeManager::ConvertTypesExtToDlgExt( pszExt, NULL, workExt ) ) return false; + if( !CDocTypeManager::ConvertTypesExtToDlgExt( pszExt, nullptr, workExt ) ) return false; return AppendExtRaw( pszName, workExt.c_str() ); } @@ -69,14 +69,14 @@ bool CFileExt::AppendExtRaw( const WCHAR *pszName, const WCHAR *pszExt ) const WCHAR *CFileExt::GetName( int nIndex ) { - if( nIndex < 0 || nIndex >= GetCount() ) return NULL; + if( nIndex < 0 || nIndex >= GetCount() ) return nullptr; return m_vFileExtInfo[nIndex].m_sTypeName.c_str(); } const WCHAR *CFileExt::GetExt( int nIndex ) { - if( nIndex < 0 || nIndex >= GetCount() ) return NULL; + if( nIndex < 0 || nIndex >= GetCount() ) return nullptr; return m_vFileExtInfo[nIndex].m_sExt.c_str(); } @@ -89,13 +89,12 @@ const WCHAR *CFileExt::GetExtFilter( void ) void CFileExt::CreateExtFilter(std::vector& output) const { - int i; std::wstring work; /* 拡張子フィルタの作成 */ output.resize(0); - for( i = 0; i < GetCount(); i++ ) + for (int i = 0; i < GetCount(); i++) { // "%s (%s)\0%s\0" work = m_vFileExtInfo[i].m_sTypeName; @@ -106,7 +105,7 @@ void CFileExt::CreateExtFilter(std::vector& output) const work.append(m_vFileExtInfo[i].m_sExt); work.append(L"\0", 1); - int pos = static_cast(output.size()); + size_t pos = output.size(); output.resize(pos + work.length()); wmemcpy(&output[pos], &work[0], work.length()); } diff --git a/sakura_core/CFileExt.h b/sakura_core/CFileExt.h index 5b23ed0cb8..9236ebde39 100644 --- a/sakura_core/CFileExt.h +++ b/sakura_core/CFileExt.h @@ -52,7 +52,7 @@ class CFileExt //2回呼び出すと古いバッファが無効になることがあるのに注意 const WCHAR *GetExtFilter( void ); - int GetCount() const { return static_cast(m_vFileExtInfo.size()); } + [[nodiscard]] int GetCount() const { return static_cast(m_vFileExtInfo.size()); } protected: // 2014.10.30 syat ConvertTypesExtToDlgExtをCDocTypeManagerに移動 diff --git a/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp b/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp index b4408164f9..7e4b3d8c17 100644 --- a/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp +++ b/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp @@ -649,6 +649,7 @@ int AddComboCodePages(HWND hdlg, HWND combo, int nSelCode, bool& bInit) @date 2008.05.05 novice GetModuleHandle(NULL)→NULLに変更 */ CDlgOpenFile_CommonFileDialog::CDlgOpenFile_CommonFileDialog() + :m_strDefaultWildCard(L"*.*") //「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) { m_hInstance = NULL; /* アプリケーションインスタンスのハンドル */ m_hwndParent = NULL; /* オーナーウィンドウのハンドル */ @@ -667,8 +668,6 @@ CDlgOpenFile_CommonFileDialog::CDlgOpenFile_CommonFileDialog() wcscpy( m_szInitialDir, szDrive ); wcscat( m_szInitialDir, szDir ); - m_strDefaultWildCard = L"*.*"; /*「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */ - return; } diff --git a/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp b/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp index 71fc8e3763..95c124646c 100644 --- a/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp +++ b/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp @@ -398,6 +398,7 @@ enum CtrlId { }; CDlgOpenFile_CommonItemDialog::CDlgOpenFile_CommonItemDialog() + :m_strDefaultWildCard(L"*.*") //「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) { m_hInstance = NULL; /* アプリケーションインスタンスのハンドル */ m_hwndParent = NULL; /* オーナーウィンドウのハンドル */ @@ -416,7 +417,6 @@ CDlgOpenFile_CommonItemDialog::CDlgOpenFile_CommonItemDialog() wcscpy( m_szInitialDir, szDrive ); wcscat( m_szInitialDir, szDir ); - m_strDefaultWildCard = L"*.*"; /*「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */ return; } From 51f8ab452ed1e3d9e5ea7972a563c62cc8febf37 Mon Sep 17 00:00:00 2001 From: usagisita <40428610+usagisita@users.noreply.github.com> Date: Sun, 21 Mar 2021 16:29:33 +0900 Subject: [PATCH 07/14] =?UTF-8?q?=E4=B8=80=E9=83=A8=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/unittests/test-cdlgopenfile.cpp | 126 +++++++++++++++++++++++++ tests/unittests/test-cfileext.cpp | 91 ++++++++++++++++++ tests/unittests/tests1.vcxproj | 2 + tests/unittests/tests1.vcxproj.filters | 6 ++ 4 files changed, 225 insertions(+) create mode 100644 tests/unittests/test-cdlgopenfile.cpp create mode 100644 tests/unittests/test-cfileext.cpp diff --git a/tests/unittests/test-cdlgopenfile.cpp b/tests/unittests/test-cdlgopenfile.cpp new file mode 100644 index 0000000000..cf09ee64cd --- /dev/null +++ b/tests/unittests/test-cdlgopenfile.cpp @@ -0,0 +1,126 @@ +/*! @file */ +/* + Copyright (C) 2018-2021, Sakura Editor Organization + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; + you must not claim that you wrote the original software. + If you use this software in a product, an acknowledgment + in the product documentation would be appreciated but is + not required. + + 2. Altered source versions must be plainly marked as such, + and must not be misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ +#include +#ifndef STRICT +#define STRICT 1 +#endif +#ifndef NOMINMAX +#define NOMINMAX +#endif /* #ifndef NOMINMAX */ +#include +#include +#include +#include "util/design_template.h" +#include "dlg/CDlgOpenFile.h" + +extern std::shared_ptr New_CDlgOpenFile_CommonFileDialog(); +extern std::shared_ptr New_CDlgOpenFile_CommonItemDialog(); + +TEST(CDlgOpenFile, Construct) +{ + CDlgOpenFile cDlgOpenFile; +} + +TEST(CDlgOpenFile, CommonItemDialogCreate) +{ + std::shared_ptrimpl = New_CDlgOpenFile_CommonItemDialog(); + impl->Create( + GetModuleHandle(nullptr), + nullptr, + L"*.txt", + L"C:\\Windows", + std::vector(), + std::vector() + ); +} + +TEST(CDlgOpenFile, CommonFileDialogCreate) +{ + std::shared_ptrimpl = New_CDlgOpenFile_CommonFileDialog(); + impl->Create( + GetModuleHandle(nullptr), + nullptr, + L"*.txt", + L"C:\\Windows", + std::vector(), + std::vector() + ); +} + +TEST(CDlgOpenFile, CommonItemDialogDefaltFilterLong) +{ + std::shared_ptrimpl = New_CDlgOpenFile_CommonItemDialog(); + // 落ちたり例外にならないこと + impl->Create( + GetModuleHandle(nullptr), + nullptr, + L".extension_250_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_LONG", + L"C:\\Windows", + std::vector(), + std::vector() + ); +} + +TEST(CDlgOpenFile, CommonFileDialogDefaltFilterLong) +{ + std::shared_ptrimpl = New_CDlgOpenFile_CommonFileDialog(); + // 落ちたり例外にならないこと + impl->Create( + GetModuleHandle(nullptr), + nullptr, + L"*.extension_250_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_LONG", + L"C:\\Windows", + std::vector(), + std::vector() + ); +} + +TEST(CDlgOpenFile, CommonFileDialogDefaltFilterMany) +{ + std::shared_ptrimpl = New_CDlgOpenFile_CommonFileDialog(); + // 落ちたり例外にならないこと + impl->Create( + GetModuleHandle(nullptr), + nullptr, + L"*.extension_50_0_long_long_long_long_long_long_LONG;*.extension_50_1_long_long_long_long_long_long_LONG;*.extension_50_2_long_long_long_long_long_long_LONG;*.extension_50_3_long_long_long_long_long_long_LONG;*.extension_50_4_long_long_long_long_long_long_LONG;*.extension_50_5_long_long_long_long_long_long_LONG;*.extension_50_6_long_long_long_long_long_long_LONG;*.extension_50_7_long_long_long_long_long_long_LONG;*.extension_50_8_long_long_long_long_long_long_LONG;*.extension_50_9_long_long_long_long_long_long_LONG", + L"C:\\Windows", + std::vector(), + std::vector() + ); +} + +TEST(CDlgOpenFile, CommonItemDialogDefaltFilterMany) +{ + std::shared_ptrimpl = New_CDlgOpenFile_CommonItemDialog(); + // 落ちたり例外にならないこと + impl->Create( + GetModuleHandle(nullptr), + nullptr, + L"*.extension_50_0_long_long_long_long_long_long_LONG;*.extension_50_1_long_long_long_long_long_long_LONG;*.extension_50_2_long_long_long_long_long_long_LONG;*.extension_50_3_long_long_long_long_long_long_LONG;*.extension_50_4_long_long_long_long_long_long_LONG;*.extension_50_5_long_long_long_long_long_long_LONG;*.extension_50_6_long_long_long_long_long_long_LONG;*.extension_50_7_long_long_long_long_long_long_LONG;*.extension_50_8_long_long_long_long_long_long_LONG;*.extension_50_9_long_long_long_long_long_long_LONG", + L"C:\\Windows", + std::vector(), + std::vector() + ); +} diff --git a/tests/unittests/test-cfileext.cpp b/tests/unittests/test-cfileext.cpp new file mode 100644 index 0000000000..cf65b9fd27 --- /dev/null +++ b/tests/unittests/test-cfileext.cpp @@ -0,0 +1,91 @@ +/*! @file */ +/* + Copyright (C) 2018-2021, Sakura Editor Organization + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; + you must not claim that you wrote the original software. + If you use this software in a product, an acknowledgment + in the product documentation would be appreciated but is + not required. + + 2. Altered source versions must be plainly marked as such, + and must not be misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ +#include + +#ifndef NOMINMAX +#define NOMINMAX +#endif /* #ifndef NOMINMAX */ + +#include +#include "CFileExt.h" + + +static size_t GetFilterLength(const wchar_t* filter) +{ + size_t length = 0; + size_t i = 0; + while (!(filter[i] == L'\0' && filter[i+1] == L'\0')) { + ++i; + } + return i + 2; +} + +TEST(CFileExt, Construct) +{ + CFileExt cFileExt; +} + +TEST(CFileExt, CreateFilter) +{ + wchar_t result[] = L"ユーザー設定 (*.cpp;*.h;*.*)\0*.cpp;*.h;*.*\0テキスト (*.txt)\0*.txt\0すべてのファイル (*.*)\0*.*\0"; + + CFileExt cFileExt; + cFileExt.AppendExtRaw(L"ユーザー設定", L"*.cpp;*.h;*.*"); + cFileExt.AppendExtRaw(L"テキスト", L"*.txt"); + cFileExt.AppendExtRaw(L"すべてのファイル", L"*.*"); + + const wchar_t* filter = cFileExt.GetExtFilter(); + size_t length = GetFilterLength(filter); + std::wstring expected = {result, _countof(result)}; + std::wstring actual = {filter, length}; + EXPECT_EQ(expected, actual); +} + +TEST(CFileExt, RawLongFilter) +{ + CFileExt cFileExt; + cFileExt.AppendExtRaw( + L"ユーザ設定", + L"*.extensin_250_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_longX" + ); +} + +TEST(CFileExt, RawManyFilter) +{ + CFileExt cFileExt; + cFileExt.AppendExtRaw( + L"ユーザ指定", + L"*.extensin_50_0_long_long_long_long_long_long_long_l;*.extensin_50_1_long_long_long_long_long_long_long_l;*.extensin_50_2_long_long_long_long_long_long_long_l;*.extensin_50_3_long_long_long_long_long_long_long_l;*.extensin_50_4_long_long_long_long_long_long_long_l;*.extensin_50_5_long_long_long_long_long_long_long_l;*.extensin_50_6_long_long_long_long_long_long_long_l;*.extensin_50_7_long_long_long_long_long_long_long_l;*.extensin_50_8_long_long_long_long_long_long_long_l;*.extensin_50_9_long_long_long_long_long_long_long_l" + ); +} + +TEST(CFileExt, LongFilter) +{ + CFileExt cFileExt; + cFileExt.AppendExt( + L"ユーザ設定", + L"*.extensin_250_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_longX" + ); +} diff --git a/tests/unittests/tests1.vcxproj b/tests/unittests/tests1.vcxproj index 00fec312f2..5de9dfbcc1 100644 --- a/tests/unittests/tests1.vcxproj +++ b/tests/unittests/tests1.vcxproj @@ -111,8 +111,10 @@ + + diff --git a/tests/unittests/tests1.vcxproj.filters b/tests/unittests/tests1.vcxproj.filters index 4126fb8cea..6f2b2ee59e 100644 --- a/tests/unittests/tests1.vcxproj.filters +++ b/tests/unittests/tests1.vcxproj.filters @@ -122,6 +122,12 @@ Test Files + + Test Files + + + Test Files + From 4cbf16e424c98e963155aa83f9a16ef02b8eaa02 Mon Sep 17 00:00:00 2001 From: usagisita <40428610+usagisita@users.noreply.github.com> Date: Sun, 21 Mar 2021 17:05:50 +0900 Subject: [PATCH 08/14] =?UTF-8?q?=E6=8C=87=E6=91=98=E5=AF=BE=E5=BF=9C?= =?UTF-8?q?=E3=80=80ConvertTypesExtToDlgExt=E3=81=AE=E5=87=A6=E7=90=86?= =?UTF-8?q?=E7=B5=90=E6=9E=9C=E3=82=92=E6=88=BB=E3=82=8A=E5=80=A4=E3=81=AB?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sakura_core/CFileExt.cpp | 7 ++++--- sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp | 3 ++- sakura_core/doc/CDocFileOperation.cpp | 2 +- sakura_core/env/CDocTypeManager.cpp | 8 ++++---- sakura_core/env/CDocTypeManager.h | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/sakura_core/CFileExt.cpp b/sakura_core/CFileExt.cpp index 938cc5598f..49198112ce 100644 --- a/sakura_core/CFileExt.cpp +++ b/sakura_core/CFileExt.cpp @@ -47,9 +47,10 @@ CFileExt::CFileExt() bool CFileExt::AppendExt( const WCHAR *pszName, const WCHAR *pszExt ) { - std::wstring workExt; - - if( !CDocTypeManager::ConvertTypesExtToDlgExt( pszExt, nullptr, workExt ) ) return false; + std::wstring workExt = CDocTypeManager::ConvertTypesExtToDlgExt(pszExt, nullptr); + if (workExt.empty()) { + return false; + } return AppendExtRaw( pszName, workExt.c_str() ); } diff --git a/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp b/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp index 95c124646c..4a5a3e84e7 100644 --- a/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp +++ b/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp @@ -707,7 +707,8 @@ bool CDlgOpenFile_CommonItemDialog::DoModalOpenDlg( continue; } specs[2 + i].pszName = type->m_szTypeName; - if (CDocTypeManager::ConvertTypesExtToDlgExt(type->m_szTypeExts, NULL, worksString)) { + worksString = CDocTypeManager::ConvertTypesExtToDlgExt(type->m_szTypeExts, nullptr); + if (!worksString.empty()) { strs[2 + i] = worksString; specs[2 + i].pszSpec = strs[2 + i].c_str(); } diff --git a/sakura_core/doc/CDocFileOperation.cpp b/sakura_core/doc/CDocFileOperation.cpp index fb775ad704..3e69f56798 100644 --- a/sakura_core/doc/CDocFileOperation.cpp +++ b/sakura_core/doc/CDocFileOperation.cpp @@ -251,7 +251,7 @@ bool CDocFileOperation::SaveFileDialog( } } else { - CDocTypeManager::ConvertTypesExtToDlgExt(type.m_szTypeExts, szExt, strDefaultWildCard); + strDefaultWildCard = CDocTypeManager::ConvertTypesExtToDlgExt(type.m_szTypeExts, szExt); } if(!this->m_pcDocRef->m_cDocFile.GetFilePathClass().IsValidPath()){ diff --git a/sakura_core/env/CDocTypeManager.cpp b/sakura_core/env/CDocTypeManager.cpp index a4bf8d1990..1b40a429b7 100644 --- a/sakura_core/env/CDocTypeManager.cpp +++ b/sakura_core/env/CDocTypeManager.cpp @@ -221,11 +221,11 @@ void CDocTypeManager::GetFirstExt(const WCHAR* pszTypeExts, WCHAR szFirstExt[], @date 2014.12.06 syat CFileExtから移動 */ -bool CDocTypeManager::ConvertTypesExtToDlgExt(const WCHAR *pszSrcExt, const WCHAR* szExt, std::wstring& destExt) +std::wstring CDocTypeManager::ConvertTypesExtToDlgExt(const WCHAR *pszSrcExt, const WCHAR* szExt) { - destExt.resize(0); + std::wstring destExt; // 2003.08.14 MIK NULLじゃなくてfalse - if( NULL == pszSrcExt ) return false; + if( NULL == pszSrcExt ) return L""; if (szExt != NULL && szExt[0] != L'\0') { // ファイルパスがあり、拡張子ありの場合、トップに指定 @@ -255,5 +255,5 @@ bool CDocTypeManager::ConvertTypesExtToDlgExt(const WCHAR *pszSrcExt, const WCHA } token = wcstok_s(nullptr, m_typeExtSeps, &context); } - return true; + return destExt; } diff --git a/sakura_core/env/CDocTypeManager.h b/sakura_core/env/CDocTypeManager.h index a0027169c8..49a55e2340 100644 --- a/sakura_core/env/CDocTypeManager.h +++ b/sakura_core/env/CDocTypeManager.h @@ -51,7 +51,7 @@ class CDocTypeManager{ static bool IsFileNameMatch(const WCHAR* pszTypeExts, const WCHAR* pszFileName); // タイプ別拡張子にファイル名がマッチするか static void GetFirstExt(const WCHAR* pszTypeExts, WCHAR szFirstExt[], int nBuffSize); // タイプ別拡張子の先頭拡張子を取得する - static bool ConvertTypesExtToDlgExt(const WCHAR *pszSrcExt, const WCHAR* szExt, std::wstring& destExt); // タイプ別設定の拡張子リストをダイアログ用リストに変換する + static std::wstring ConvertTypesExtToDlgExt(const WCHAR *pszSrcExt, const WCHAR* szExt); // タイプ別設定の拡張子リストをダイアログ用リストに変換する static const WCHAR* m_typeExtSeps; // タイプ別拡張子の区切り文字 static const WCHAR* m_typeExtWildcards; // タイプ別拡張子のワイルドカード From 5a77929a6fc935ae9ee1937551d6e5f4e3ba1e11 Mon Sep 17 00:00:00 2001 From: usagisita <40428610+usagisita@users.noreply.github.com> Date: Sun, 21 Mar 2021 17:25:05 +0900 Subject: [PATCH 09/14] =?UTF-8?q?CFileExt=E3=81=AE=E3=82=B3=E3=83=B3?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=83=A9=E3=82=AF=E3=82=BF=E3=82=92default?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E3=81=AB=E3=81=97=E3=83=87=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=83=A9=E3=82=AF=E3=82=BF=E3=82=92=E6=9A=97=E9=BB=99=E7=94=9F?= =?UTF-8?q?=E6=88=90=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sakura_core/CFileExt.cpp | 10 ---------- sakura_core/CFileExt.h | 3 +-- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/sakura_core/CFileExt.cpp b/sakura_core/CFileExt.cpp index 49198112ce..7455e22aff 100644 --- a/sakura_core/CFileExt.cpp +++ b/sakura_core/CFileExt.cpp @@ -35,16 +35,6 @@ #include "CFileExt.h" #include "env/CDocTypeManager.h" -CFileExt::CFileExt() -{ - m_vstrFilter.resize( 1 ); - m_vstrFilter[0] = L'\0'; - -// //テキストエディタとして、既定でリストに載ってほしい拡張子 -// AppendExt( "すべてのファイル", "*" ); -// AppendExt( "テキストファイル", "txt" ); -} - bool CFileExt::AppendExt( const WCHAR *pszName, const WCHAR *pszExt ) { std::wstring workExt = CDocTypeManager::ConvertTypesExtToDlgExt(pszExt, nullptr); diff --git a/sakura_core/CFileExt.h b/sakura_core/CFileExt.h index 9236ebde39..2bd82a5aef 100644 --- a/sakura_core/CFileExt.h +++ b/sakura_core/CFileExt.h @@ -40,8 +40,7 @@ class CFileExt { public: - CFileExt(); - ~CFileExt() = default; + CFileExt() = default; bool AppendExt( const WCHAR *pszName, const WCHAR *pszExt ); bool AppendExtRaw( const WCHAR *pszName, const WCHAR *pszExt ); From 60008c8903083e042103d463ccfc7caf6059383a Mon Sep 17 00:00:00 2001 From: usagisita <40428610+usagisita@users.noreply.github.com> Date: Sun, 21 Mar 2021 18:09:02 +0900 Subject: [PATCH 10/14] =?UTF-8?q?ConvertTypesExtToDlgExt=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=B1=E3=83=BC=E3=82=B9=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/unittests/test-cdoctypemanager.cpp | 106 +++++++++++++++++++++++ tests/unittests/tests1.vcxproj | 1 + tests/unittests/tests1.vcxproj.filters | 3 + 3 files changed, 110 insertions(+) create mode 100644 tests/unittests/test-cdoctypemanager.cpp diff --git a/tests/unittests/test-cdoctypemanager.cpp b/tests/unittests/test-cdoctypemanager.cpp new file mode 100644 index 0000000000..57afc24850 --- /dev/null +++ b/tests/unittests/test-cdoctypemanager.cpp @@ -0,0 +1,106 @@ +/* + Copyright (C) 2021, Sakura Editor Organization + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; + you must not claim that you wrote the original software. + If you use this software in a product, an acknowledgment + in the product documentation would be appreciated but is + not required. + + 2. Altered source versions must be plainly marked as such, + and must not be misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ + +#include +#include +#include +#include "mem/CNativeW.h" +#include "env/CDocTypeManager.h" + +TEST(CDocTypeManager, ConvertTypesExtToDlgExtNullptr1) +{ + const std::wstring expected = { L"" }; + std::wstring actual = CDocTypeManager::ConvertTypesExtToDlgExt(nullptr, nullptr); + EXPECT_EQ(expected, actual); +} + +TEST(CDocTypeManager, ConvertTypesExtToDlgExtNullptr2) +{ + const std::wstring expected = { L"" }; + std::wstring actual = CDocTypeManager::ConvertTypesExtToDlgExt(nullptr, L".txt"); + EXPECT_EQ(expected, actual); +} + +TEST(CDocTypeManager, ConvertTypesExtToDlgExtOnce) +{ + const std::wstring expected = { L"*.txt;*.cpp" }; + std::wstring actual = CDocTypeManager::ConvertTypesExtToDlgExt(L"cpp", L".txt"); + EXPECT_EQ(expected, actual); +} + +TEST(CDocTypeManager, ConvertTypesExtToDlgExtTwo) +{ + const std::wstring expected = { L"*.txt;*.cpp;*.h" }; + std::wstring actual = CDocTypeManager::ConvertTypesExtToDlgExt(L"cpp;h", L".txt"); + EXPECT_EQ(expected, actual); +} + +TEST(CDocTypeManager, ConvertTypesExtToDlgExtThree) +{ + const std::wstring expected = { L"*.txt;*.cpp;*.h;*.hpp" }; + std::wstring actual = CDocTypeManager::ConvertTypesExtToDlgExt(L"cpp;h;hpp", L".txt"); + EXPECT_EQ(expected, actual); +} + +TEST(CDocTypeManager, ConvertTypesExtToDlgExtAppendPeriod) +{ + const std::wstring expected = { L"*.txt;*.cpp;*.h" }; + std::wstring actual = CDocTypeManager::ConvertTypesExtToDlgExt(L".cpp;.h", L".txt"); + EXPECT_EQ(expected, actual); +} + +TEST(CDocTypeManager, ConvertTypesExtToDlgExtSeparatorSpace) +{ + const std::wstring expected = { L"*.txt;*.cpp;*.h" }; + std::wstring actual = CDocTypeManager::ConvertTypesExtToDlgExt(L"cpp h", L".txt"); + EXPECT_EQ(expected, actual); +} + +TEST(CDocTypeManager, ConvertTypesExtToDlgExtSeparatorComma) +{ + const std::wstring expected = { L"*.txt;*.cpp;*.h" } ; + std::wstring actual = CDocTypeManager::ConvertTypesExtToDlgExt(L"cpp,h", L".txt"); + EXPECT_EQ(expected, actual); +} + +TEST(CDocTypeManager, ConvertTypesExtToDlgExtTopNullptr) +{ + const std::wstring expected = { L"*.cpp;*.h" }; + std::wstring actual = CDocTypeManager::ConvertTypesExtToDlgExt(L"cpp,h", nullptr); + EXPECT_EQ(expected, actual); +} + +TEST(CDocTypeManager, ConvertTypesExtToDlgExtExts64) +{ + const std::wstring expected = { L"*.txt;*.a;*.b;*.c;*.d;*.e;*.f;*.g;*.h;*.i;*.j;*.k;*.l;*.m;*.n;*.o;*.p;*.q;*.r;*.s;*.t;*.u;*.v;*.w;*.x;*.y;*.z;*.1;*.2;*.3;*.4;*.5;*.6" }; + std::wstring actual = CDocTypeManager::ConvertTypesExtToDlgExt(L"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,1,2,3,4,5,6", L".txt"); + EXPECT_EQ(expected, actual); +} + +TEST(CDocTypeManager, ConvertTypesExtToDlgExtExts64LongFileExt) +{ + const std::wstring expected = { L"*.extension_260_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long;*.a;*.b;*.c;*.d;*.e;*.f;*.g;*.h;*.i;*.j;*.k;*.l;*.m;*.n;*.o;*.p;*.q;*.r;*.s;*.t;*.u;*.v;*.w;*.x;*.y;*.z;*.1;*.2;*.3;*.4;*.5;*.6" }; + std::wstring actual = CDocTypeManager::ConvertTypesExtToDlgExt(L"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,1,2,3,4,5,6", L".extension_260_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long"); + EXPECT_EQ(expected, actual); +} diff --git a/tests/unittests/tests1.vcxproj b/tests/unittests/tests1.vcxproj index 5de9dfbcc1..3c3fc818d9 100644 --- a/tests/unittests/tests1.vcxproj +++ b/tests/unittests/tests1.vcxproj @@ -113,6 +113,7 @@ + diff --git a/tests/unittests/tests1.vcxproj.filters b/tests/unittests/tests1.vcxproj.filters index 6f2b2ee59e..931d2a1aa2 100644 --- a/tests/unittests/tests1.vcxproj.filters +++ b/tests/unittests/tests1.vcxproj.filters @@ -128,6 +128,9 @@ Test Files + + Test Files + From 40fb2a3875d9fe4d2a71e1cb5a355d960730acdf Mon Sep 17 00:00:00 2001 From: usagisita <40428610+usagisita@users.noreply.github.com> Date: Sun, 21 Mar 2021 22:40:25 +0900 Subject: [PATCH 11/14] =?UTF-8?q?m=5FstrDefaultWildCard=E3=81=AE=E6=AF=94?= =?UTF-8?q?=E8=BC=83=E3=82=92wcscmp=E3=81=8B=E3=82=89!=3D=E3=81=AB?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp | 2 +- sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp b/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp index 7e4b3d8c17..e5366d420d 100644 --- a/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp +++ b/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp @@ -739,7 +739,7 @@ bool CDlgOpenFile_CommonFileDialog::DoModal_GetOpenFileName( WCHAR* pszPath, EFi break; } - if( 0 != wcscmp(m_strDefaultWildCard.c_str(), L"*.*") ){ + if (m_strDefaultWildCard != L"*.*") { cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME3), L"*.*" ); } diff --git a/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp b/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp index 4a5a3e84e7..c4997f0285 100644 --- a/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp +++ b/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp @@ -484,7 +484,7 @@ bool CDlgOpenFile_CommonItemDialog::DoModal_GetOpenFileName( WCHAR* pszPath, EFi break; } - if( 0 != wcscmp(m_strDefaultWildCard.c_str(), L"*.*") ){ + if (m_strDefaultWildCard != L"*.*") { strs.push_back(LS(STR_DLGOPNFL_EXTNAME3)); specs.push_back(COMDLG_FILTERSPEC{strs.back().c_str(), L"*.*"}); } From b822a6486d822af10d16f4089d41058bb7c9c356 Mon Sep 17 00:00:00 2001 From: usagisita <40428610+usagisita@users.noreply.github.com> Date: Sun, 21 Mar 2021 22:47:27 +0900 Subject: [PATCH 12/14] =?UTF-8?q?CDlgOpenFile=E3=81=AE=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=81=A7GetDllShareData()=E3=81=8C=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E3=81=AA=E3=81=9F=E3=82=81DISABLED=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/unittests/test-cdlgopenfile.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unittests/test-cdlgopenfile.cpp b/tests/unittests/test-cdlgopenfile.cpp index cf09ee64cd..90bc235cb9 100644 --- a/tests/unittests/test-cdlgopenfile.cpp +++ b/tests/unittests/test-cdlgopenfile.cpp @@ -43,7 +43,7 @@ TEST(CDlgOpenFile, Construct) CDlgOpenFile cDlgOpenFile; } -TEST(CDlgOpenFile, CommonItemDialogCreate) +TEST(CDlgOpenFile, DISABLED_CommonItemDialogCreate) { std::shared_ptrimpl = New_CDlgOpenFile_CommonItemDialog(); impl->Create( @@ -56,7 +56,7 @@ TEST(CDlgOpenFile, CommonItemDialogCreate) ); } -TEST(CDlgOpenFile, CommonFileDialogCreate) +TEST(CDlgOpenFile, DISABLED_CommonFileDialogCreate) { std::shared_ptrimpl = New_CDlgOpenFile_CommonFileDialog(); impl->Create( @@ -69,7 +69,7 @@ TEST(CDlgOpenFile, CommonFileDialogCreate) ); } -TEST(CDlgOpenFile, CommonItemDialogDefaltFilterLong) +TEST(CDlgOpenFile, DISABLED_CommonItemDialogDefaltFilterLong) { std::shared_ptrimpl = New_CDlgOpenFile_CommonItemDialog(); // 落ちたり例外にならないこと @@ -83,7 +83,7 @@ TEST(CDlgOpenFile, CommonItemDialogDefaltFilterLong) ); } -TEST(CDlgOpenFile, CommonFileDialogDefaltFilterLong) +TEST(CDlgOpenFile, DISABLED_CommonFileDialogDefaltFilterLong) { std::shared_ptrimpl = New_CDlgOpenFile_CommonFileDialog(); // 落ちたり例外にならないこと @@ -97,7 +97,7 @@ TEST(CDlgOpenFile, CommonFileDialogDefaltFilterLong) ); } -TEST(CDlgOpenFile, CommonFileDialogDefaltFilterMany) +TEST(CDlgOpenFile, DISABLED_CommonFileDialogDefaltFilterMany) { std::shared_ptrimpl = New_CDlgOpenFile_CommonFileDialog(); // 落ちたり例外にならないこと @@ -111,7 +111,7 @@ TEST(CDlgOpenFile, CommonFileDialogDefaltFilterMany) ); } -TEST(CDlgOpenFile, CommonItemDialogDefaltFilterMany) +TEST(CDlgOpenFile, DISABLED_CommonItemDialogDefaltFilterMany) { std::shared_ptrimpl = New_CDlgOpenFile_CommonItemDialog(); // 落ちたり例外にならないこと From fb761e8d34fce57f806395f272747bc3fbd26bed Mon Sep 17 00:00:00 2001 From: usagisita <40428610+usagisita@users.noreply.github.com> Date: Sun, 21 Mar 2021 23:26:47 +0900 Subject: [PATCH 13/14] =?UTF-8?q?SonarCloud=E5=AF=BE=E7=AD=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp | 3 +-- sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp | 2 +- sakura_core/env/CDocTypeManager.cpp | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp b/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp index e5366d420d..b27e974592 100644 --- a/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp +++ b/sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp @@ -93,7 +93,7 @@ struct CDlgOpenFile_CommonFileDialog final : public IDlgOpenFile DLLSHAREDATA* m_pShareData; - std::wstring m_strDefaultWildCard; /* 「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */ + std::wstring m_strDefaultWildCard{ L"*.*" }; /* 「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */ SFilePath m_szInitialDir; /* 「開く」での初期ディレクトリ */ std::vector m_vMRU; @@ -649,7 +649,6 @@ int AddComboCodePages(HWND hdlg, HWND combo, int nSelCode, bool& bInit) @date 2008.05.05 novice GetModuleHandle(NULL)→NULLに変更 */ CDlgOpenFile_CommonFileDialog::CDlgOpenFile_CommonFileDialog() - :m_strDefaultWildCard(L"*.*") //「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) { m_hInstance = NULL; /* アプリケーションインスタンスのハンドル */ m_hwndParent = NULL; /* オーナーウィンドウのハンドル */ diff --git a/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp b/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp index c4997f0285..f01170e88c 100644 --- a/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp +++ b/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp @@ -77,7 +77,7 @@ struct CDlgOpenFile_CommonItemDialog final DLLSHAREDATA* m_pShareData; - std::wstring m_strDefaultWildCard; /* 「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */ + std::wstring m_strDefaultWildCard{ L"*.*" }; /* 「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */ SFilePath m_szInitialDir; /* 「開く」での初期ディレクトリ */ std::vector m_vMRU; diff --git a/sakura_core/env/CDocTypeManager.cpp b/sakura_core/env/CDocTypeManager.cpp index 1b40a429b7..244c1a7b09 100644 --- a/sakura_core/env/CDocTypeManager.cpp +++ b/sakura_core/env/CDocTypeManager.cpp @@ -223,10 +223,10 @@ void CDocTypeManager::GetFirstExt(const WCHAR* pszTypeExts, WCHAR szFirstExt[], */ std::wstring CDocTypeManager::ConvertTypesExtToDlgExt(const WCHAR *pszSrcExt, const WCHAR* szExt) { - std::wstring destExt; // 2003.08.14 MIK NULLじゃなくてfalse - if( NULL == pszSrcExt ) return L""; + if (pszSrcExt == nullptr) return L""; + std::wstring destExt; if (szExt != NULL && szExt[0] != L'\0') { // ファイルパスがあり、拡張子ありの場合、トップに指定 destExt.assign(L"*"); From d55fa1531c0af20f76f09a2745b8352260fe653d Mon Sep 17 00:00:00 2001 From: usagisita <40428610+usagisita@users.noreply.github.com> Date: Mon, 22 Mar 2021 02:55:58 +0900 Subject: [PATCH 14/14] =?UTF-8?q?PR=E3=83=9F=E3=82=B9=E3=81=AECDlgOpenFile?= =?UTF-8?q?=5FCommonItemDialog=E3=82=B3=E3=83=B3=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=83=A9=E3=82=AF=E3=82=BF=E3=81=AE=E5=88=9D=E6=9C=9F=E5=8C=96?= =?UTF-8?q?=E9=87=8D=E8=A4=87=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp b/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp index f01170e88c..2e809ee199 100644 --- a/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp +++ b/sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp @@ -398,7 +398,6 @@ enum CtrlId { }; CDlgOpenFile_CommonItemDialog::CDlgOpenFile_CommonItemDialog() - :m_strDefaultWildCard(L"*.*") //「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) { m_hInstance = NULL; /* アプリケーションインスタンスのハンドル */ m_hwndParent = NULL; /* オーナーウィンドウのハンドル */