diff --git a/include/kabufuda/Card.hpp b/include/kabufuda/Card.hpp index ad9ef59..aac6ae9 100644 --- a/include/kabufuda/Card.hpp +++ b/include/kabufuda/Card.hpp @@ -336,108 +336,6 @@ public: */ ECardResult setStatus(uint32_t fileNo, const CardStat& stat); - /** - * @brief gameId - * @param fh - * @return - */ - const char* gameId(const FileHandle& fh) const; - - /** - * @brief maker - * @param fh - * @return - */ - const char* maker(const FileHandle& fh) const; - - /** - * @brief setBannerFormat - * @param fh - * @param fmt - */ - void setBannerFormat(const FileHandle& fh, EImageFormat fmt); - - /** - * @brief bannerFormat - * @param fh - * @return - */ - EImageFormat bannerFormat(const FileHandle& fh) const; - - /** - * @brief setIconAnimationType - * @param fh - * @param type - */ - void setIconAnimationType(const FileHandle& fh, EAnimationType type); - - /** - * @brief iconAnimationType - * @param fh - * @return - */ - EAnimationType iconAnimationType(const FileHandle& fh) const; - - /** - * @brief setIconFormat - * @param fh - * @param idx - * @param fmt - */ - void setIconFormat(const FileHandle& fh, uint32_t idx, EImageFormat fmt); - - /** - * @brief iconFormat - * @param fh - * @param idx - * @return - */ - EImageFormat iconFormat(const FileHandle& fh, uint32_t idx) const; - - /** - * @brief setIconSpeed - * @param fh - * @param idx - * @param speed - */ - void setIconSpeed(const FileHandle& fh, uint32_t idx, EAnimationSpeed speed); - - /** - * @brief iconSpeed - * @param fh - * @param idx - * @return - */ - EAnimationSpeed iconSpeed(const FileHandle& fh, uint32_t idx) const; - - /** - * @brief setImageAddress - * @param fh - * @param addr - */ - void setImageAddress(const FileHandle& fh, uint32_t addr); - - /** - * @brief imageAddress - * @param fh - * @return - */ - int32_t imageAddress(const FileHandle& fh) const; - - /** - * @brief setCommentAddress - * @param fh - * @param addr - */ - void setCommentAddress(const FileHandle& fh, uint32_t addr); - - /** - * @brief commentAddress - * @param fh - * @return - */ - int32_t commentAddress(const FileHandle& fh) const; - /** * @brief Copies a file from the current Card instance to a specified Card instance * @param fh The file to copy diff --git a/lib/kabufuda/Card.cpp b/lib/kabufuda/Card.cpp index a151f91..abe0e94 100644 --- a/lib/kabufuda/Card.cpp +++ b/lib/kabufuda/Card.cpp @@ -317,8 +317,18 @@ ECardResult Card::renameFile(const char* oldName, const char* newName) if (!f) return ECardResult::NOFILE; - strncpy(f->m_filename, newName, 32); - _updateDirAndBat(dir, m_bats[m_currentBat]); + if (File* replF = dir.getFile(m_game, m_maker, newName)) + { + BlockAllocationTable bat = m_bats[m_currentBat]; + _deleteFile(*replF, bat); + strncpy(f->m_filename, newName, 32); + _updateDirAndBat(dir, bat); + } + else + { + strncpy(f->m_filename, newName, 32); + _updateDirAndBat(dir, m_bats[m_currentBat]); + } return ECardResult::READY; } @@ -573,7 +583,7 @@ ECardResult Card::getStatus(const FileHandle& fh, CardStat& statOut) const ECardResult Card::getStatus(uint32_t fileNo, CardStat& statOut) const { - File* file = const_cast(m_dirs[m_currentDir]).getFile(fileNo); + const File* file = const_cast(m_dirs[m_currentDir]).getFile(fileNo); if (!file || file->m_game[0] == 0xFF) return ECardResult::NOFILE; @@ -639,7 +649,8 @@ ECardResult Card::setStatus(const FileHandle& fh, const CardStat& stat) ECardResult Card::setStatus(uint32_t fileNo, const CardStat& stat) { - File* file = m_dirs[m_currentDir].getFile(fileNo); + Directory dir = m_dirs[m_currentDir]; + File* file = dir.getFile(fileNo); if (!file || file->m_game[0] == 0xFF) return ECardResult::NOFILE; @@ -649,126 +660,10 @@ ECardResult Card::setStatus(uint32_t fileNo, const CardStat& stat) file->m_animSpeed = stat.x36_iconSpeed; file->m_commentAddr = stat.x38_commentAddr; + _updateDirAndBat(dir, m_bats[m_currentBat]); return ECardResult::READY; } -const char* Card::gameId(const FileHandle& fh) const -{ - File* file = _fileFromHandle(fh); - if (!file) - return nullptr; - return reinterpret_cast(file->m_game); -} - -const char* Card::maker(const FileHandle& fh) const -{ - File* file = _fileFromHandle(fh); - if (!file) - return nullptr; - return reinterpret_cast(file->m_maker); -} - -void Card::setBannerFormat(const FileHandle& fh, EImageFormat fmt) -{ - File* file = _fileFromHandle(fh); - if (!file) - return; - file->m_bannerFlags = (file->m_bannerFlags & ~3) | (uint8_t(fmt)); -} - -EImageFormat Card::bannerFormat(const FileHandle& fh) const -{ - File* file = _fileFromHandle(fh); - if (!file) - return EImageFormat::None; - return EImageFormat(file->m_bannerFlags & 3); -} - -void Card::setIconAnimationType(const FileHandle& fh, EAnimationType type) -{ - File* file = _fileFromHandle(fh); - if (!file) - return; - file->m_bannerFlags = (file->m_bannerFlags & ~4) | uint8_t(type); -} - -EAnimationType Card::iconAnimationType(const FileHandle& fh) const -{ - File* file = _fileFromHandle(fh); - if (!file) - return EAnimationType::Loop; - - return EAnimationType(file->m_bannerFlags & 4); -} - -void Card::setIconFormat(const FileHandle& fh, uint32_t idx, EImageFormat fmt) -{ - File* file = _fileFromHandle(fh); - if (!file) - return; - - file->m_iconFmt = (file->m_iconFmt & ~(3 << (2 * idx))) | (uint16_t(fmt) << (2 * idx)); -} - -EImageFormat Card::iconFormat(const FileHandle& fh, uint32_t idx) const -{ - File* file = _fileFromHandle(fh); - if (!file) - return EImageFormat::None; - - return EImageFormat(file->m_iconFmt >> (2 * (idx)) & 3); -} - -void Card::setIconSpeed(const FileHandle& fh, uint32_t idx, EAnimationSpeed speed) -{ - File* file = _fileFromHandle(fh); - if (!file) - return; - - file->m_animSpeed = (file->m_animSpeed & ~(3 << (2 * idx))) | (uint16_t(speed) << (2 * idx)); -} - -EAnimationSpeed Card::iconSpeed(const FileHandle& fh, uint32_t idx) const -{ - File* file = _fileFromHandle(fh); - if (!file) - return EAnimationSpeed::End; - - return EAnimationSpeed((file->m_animSpeed >> (2 * (idx))) & 3); -} - -void Card::setImageAddress(const FileHandle& fh, uint32_t addr) -{ - File* file = _fileFromHandle(fh); - if (!file) - return; - file->m_iconAddress = addr; -} - -int32_t Card::imageAddress(const FileHandle& fh) const -{ - File* file = _fileFromHandle(fh); - if (!file) - return -1; - return file->m_iconAddress; -} - -void Card::setCommentAddress(const FileHandle& fh, uint32_t addr) -{ - File* file = _fileFromHandle(fh); - if (!file) - return; - file->m_commentAddr = addr; -} - -int32_t Card::commentAddress(const FileHandle& fh) const -{ - File* file = _fileFromHandle(fh); - if (!file) - return -1; - return file->m_commentAddr; -} - bool Card::copyFileTo(FileHandle& fh, Card& dest) { if (!canCopy(fh)) diff --git a/test/main.cpp b/test/main.cpp index 72e38a5..6c255ca 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -21,7 +21,8 @@ int main() mc.setPublic(f, true); mc.setCanCopy(f, true); mc.setCanMove(f, true); - mc.setCommentAddress(f, 0); + kabufuda::CardStat stat = {}; + mc.setStatus(f, stat); mc.write(f, "Test\0", strlen("Test") + 1); mc.seek(f, 32, kabufuda::SeekOrigin::Begin); mc.write(f, "Test\0", strlen("Test") + 1);