Skip to content

Commit

Permalink
Merge pull request #1315 from JDimproved/root-suppress-error-message-…
Browse files Browse the repository at this point in the history
…for-saving-empty-bbsmenu-txt

Root: Suppress error message for saving empty bbsmenu.txt
  • Loading branch information
ma8ma authored Jan 6, 2024
2 parents 6916733 + c4dbbb0 commit c47155a
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/dbtree/root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1910,34 +1910,36 @@ bool Root::remove_bbsmenu( const std::string& url, const std::string& name )
*
* @details BBSMenuのオブジェクトから bbsmenu.txt を作成する。
* Root::save_etc() を参考にしているがNavi2chとは関係ない。
* m_list_bbsmenu が空でも保存する
* m_list_bbsmenu が空でもデータを更新するため保存する
*/
void Root::save_bbsmenu()
{
std::string bbsmenu_data;
std::string buf;

for( const DBTREE::BBSMenu& bbsmenu : m_list_bbsmenu ) {

bbsmenu_data.append( bbsmenu.get_name() );
bbsmenu_data.push_back( '\n' );
bbsmenu_data.append( bbsmenu.get_url() );
bbsmenu_data.push_back( '\n' );
bbsmenu_data.append( bbsmenu.path_bbsmenu_boards_xml() );
bbsmenu_data.push_back( '\n' );
buf.append( bbsmenu.get_name() );
buf.push_back( '\n' );
buf.append( bbsmenu.get_url() );
buf.push_back( '\n' );
buf.append( bbsmenu.path_bbsmenu_boards_xml() );
buf.push_back( '\n' );
}

const std::string bbsmenu_root = CACHE::path_bbsmenu_root();
if( ! CACHE::jdmkdir( bbsmenu_root ) ) {
MISC::ERRMSG( "Can't create " + bbsmenu_root );
if( const std::string path_root = CACHE::path_bbsmenu_root();
! CACHE::jdmkdir( path_root ) ) {
MISC::ERRMSG( "Can't create " + path_root );
return;
}

const std::string bbsmenu_txt = CACHE::path_bbsmenu();
if( ! CACHE::save_rawdata( bbsmenu_txt, bbsmenu_data ) && ! bbsmenu_txt.empty() ) {
MISC::ERRMSG( "Failed to save " + bbsmenu_txt );
// save_rawdata() は保存に失敗したとき、または空データを保存(空ファイルを作成)したときに 0 を返す
// buf の長さが 0 つまり空データときはエラーを表示しないようにする
if( const std::string path = CACHE::path_bbsmenu();
! CACHE::save_rawdata( path, buf ) && ! buf.empty() ) {
MISC::ERRMSG( "Failed to save " + path );
}

#ifdef _DEBUG
std::cout << "Root::save_bbsmenu : bbsmenu_data = " << bbsmenu_data << std::endl;
std::cout << "Root::save_bbsmenu : bbsmenu data = " << buf << std::endl;
#endif
}

0 comments on commit c47155a

Please sign in to comment.