diff --git a/README.md b/README.md index f283bb37..b82b4878 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,9 @@ Progress | Decompiled | Matched | Linked | Data | |:---:|:---:|:---:|:---:| -| 96.72% | 83.24% | 58.20% | 89.93% | +| 97.04% | 83.51% | 58.20% | 89.93% | -units 778/1027 complete, functions 12006/12563 matched. +units 778/1027 complete, functions 12020/12563 matched. decompiled = code with a C/C++ implementation (objdiff fuzzy), matched = byte-exact code, linked = code actually linked into the DOL, data = byte-exact data diff --git a/include/keyboard/tiCellPhone.h b/include/keyboard/tiCellPhone.h index b93479b4..d48baa8e 100644 --- a/include/keyboard/tiCellPhone.h +++ b/include/keyboard/tiCellPhone.h @@ -325,7 +325,14 @@ namespace textinput { class CellPhoneAnmPane : public nw4rmanager::AnmPane { public: CellPhoneAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer) +#ifdef TI_CELLPHONE_MATCH_LAYOUT + : nw4rmanager::AnmPane(pane, observer), meState(ANM_Normal), meKeyType(KT_NormalButton) { + init(); + changeAnimation(meState); + } +#else : nw4rmanager::AnmPane(pane, observer), meState(ANM_Normal), meKeyType(KT_NormalButton) {} +#endif virtual void init() override; virtual void onAnmEvent(AnmPaneEvent event) override; diff --git a/include/keyboard/tiCpData.h b/include/keyboard/tiCpData.h index 057a5e4b..c861aba0 100644 --- a/include/keyboard/tiCpData.h +++ b/include/keyboard/tiCpData.h @@ -93,8 +93,13 @@ namespace textinput { extern const KeySet csKeySetCNPinyin; extern const KeySet csKeySetHangul; +#ifdef TI_CELLPHONE_MATCH_LAYOUT + extern const wchar_t* csSpaceZero; + extern const wchar_t* csSpace; +#else extern const wchar_t csSpaceZero[3]; extern const wchar_t csSpace[3]; +#endif } } } diff --git a/include/keyboard/tiHKBManager.h b/include/keyboard/tiHKBManager.h index 036384ad..462ca054 100644 --- a/include/keyboard/tiHKBManager.h +++ b/include/keyboard/tiHKBManager.h @@ -151,6 +151,26 @@ namespace textinput { u32 GetModifierState() const; void SetModifierState(u32, u32); +#if defined(TI_CELLPHONE_HKB_KEYSET) + class KeySet { + public: + u8 GetKey() const; + u32 GetWChar() const; + bool IsValid() const; + KeySet GetNext() const; + KeySet(const KeySet& other) + : mpManager(other.mpManager), mKind(other.mKind), mIndex(other.mIndex), + mDevice(other.mDevice), mCharacter(other.mCharacter) {} + private: + const HKBManager* mpManager; + u8 mKind; + s8 mIndex; + u8 mDevice; + u16 mCharacter; + }; + KeySet GetTriggeredKeySet() const; + KeySet GetRepeatedKeySet() const; +#else #if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION) || defined(TIHWKEYBOARD_IMPLEMENTATION) class KeySet { public: @@ -202,6 +222,7 @@ namespace textinput { KeySet GetRepeatedKeySet() const; #endif +#endif #endif private: u8 unk_0x00[0xFC]; diff --git a/libs/RVL_SDK/src/fa/pf_dir.c b/libs/RVL_SDK/src/fa/pf_dir.c index 64b4a6ec..13aaf4e4 100644 --- a/libs/RVL_SDK/src/fa/pf_dir.c +++ b/libs/RVL_SDK/src/fa/pf_dir.c @@ -93,14 +93,18 @@ typedef struct PFDIR_VOLUME_DIRS { PFDIR_DIR udds[3]; pf_s32 num_opened_files; pf_s32 num_opened_directories; - pf_u8 cache_state[0x20]; - void* cache_signature; - pf_u8 volume_tail[0x1F80 - 0x1648]; + PF_SECTOR_CACHE cache; + pf_s8 label[12]; + PF_CUR_DIR current_dirs[4]; + PF_DIR_TAIL tail_entry; pf_s32 last_error; } PFDIR_VOLUME_DIRS; typedef struct PFDIR_GLOBAL_STATE { - pf_u8 state_prefix[0x40]; + union { + pf_u8 state_prefix[0x40]; + PF_CUR_VOLUME volumes[4]; + } volume_state; pf_s32 last_error; pf_u8 driver_and_code_state[0x1C]; pf_u32 setting; @@ -136,6 +140,21 @@ extern pf_s32 PFVOL_CheckCurrentDir(PF_VOLUME* volume, pf_u32 start_cluster); extern pf_s32 PFENT_RemoveEntry(PF_DIR_ENT* entry, PF_ENT_ITER* iter); extern pf_s32 PFFAT_FreeChain(PFDIR_FFD* ffd, pf_u32 start_cluster, pf_u32 chain_index, pf_u32 size); +static inline pf_u32 current_directory_is_open(PF_VOLUME* volume, pf_u32 cluster) { + pf_u32 index; + for (index = 0; index < 4; index++) { + if (pf_vol_set.volume_state.volumes[index].p_vol == volume) { + PFDIR_VOLUME_DIRS* state = (PFDIR_VOLUME_DIRS*)volume; + PF_CUR_DIR* directory = state->current_dirs; + pf_u32 slot; + for (slot = 0; slot < 4; slot++, directory++) { + if ((directory->stat & 1) != 0 && directory->directory.start_cluster == cluster) { return 1; } + } + } + } + return 0; +} + static inline pf_u32 directory_is_open(PF_DIR_ENT* entry) { PFDIR_VOLUME_DIRS* volume = (PFDIR_VOLUME_DIRS*)entry->p_vol; pf_s32 index; @@ -209,8 +228,8 @@ PFDIR_SDD* PFDIR_GetSDD(PF_VOLUME* volume, PF_DIR_ENT* entry) { entry->entry_offset == volume_dirs->sdds[i].dir_entry.entry_offset) { return &volume_dirs->sdds[i]; } - i++; free_candidate++; + i++; } if (first_free_sdd == 0) { return 0; @@ -370,127 +389,268 @@ extern pf_s32 PFPATH_transformInUnicode(pf_u16*, const pf_s8*); extern void PFPATH_SetSearchPattern(pf_s8*, pf_u16*, PFDIR_STR*); extern pf_u16* pf_w_strcpy(pf_u16*, const pf_u16*); -pf_s32 PFDIR_p_mkdir(PF_VOLUME* p_vol, PF_STR* p_path, pf_u32 option, PF_DTA* p_dta) { - pf_s32 err; - PFDIR_STR full_path; - PFDIR_STR dirname; - pf_u16 dirname_len; - PF_ENT_ITER parent_iter; - PF_DIR_ENT entry; +extern pf_s32 PFPATH_parseShortName(pf_s8* name, PFDIR_STR* path); +extern pf_s32 PFENT_AdjustSFN(PF_DIR_ENT* parent, pf_s8* name); +extern pf_s32 PFENT_ITER_FindDirEntryFromCluster(PF_ENT_ITER* iter, PF_DIR_ENT* entry, pf_u32 cluster, pf_u32* found); +extern pf_s32 PFENT_ITER_FindEntryNoPathCheck(PF_ENT_ITER* iter, PF_DIR_ENT* entry, PFDIR_STR* pattern, pf_u8 attributes, pf_u32 start, pf_u32* found); +extern pf_s32 PFENT_ITER_GetEntryOfIter(PF_ENT_ITER* iter, PF_DIR_ENT* entry); +extern pf_s32 pf_strncmp(const pf_s8* left, const pf_s8* right, pf_u32 count); +extern pf_s32 PFENT_ITER_FindCluster(PF_DIR_ENT* entry, pf_u32 cluster, pf_u32* found); +extern pf_s32 PFENT_ITER_Retreat(PF_ENT_ITER* iter, pf_u32 may_allocate); +extern pf_s32 PFENT_allocateEntryPos(PF_DIR_ENT* entry, pf_u8 count, PFDIR_FFD* ffd, pf_u32* chain, PFDIR_STR* filename, pf_u32* position); +extern pf_u8 PFENT_CalcCheckSum(PF_DIR_ENT* entry); +extern void PFENT_storeLFNEntryFieldsToBuf(pf_u8* buffer, PF_DIR_ENT* entry, pf_u8 ordinal, pf_u8 checksum, pf_u32 last); +extern pf_s32 PFSEC_WriteData(PF_VOLUME* volume, const pf_u8* buffer, pf_u32 sector, pf_u16 offset, pf_u32 size, pf_u32* written, pf_u32 direct); +extern pf_s32 PFCACHE_FlushDataCache(PF_VOLUME* volume); +extern pf_u32 PFSTR_GetCodeMode(PFDIR_STR* path); +extern const pf_s8* PFSTR_GetStrPos(PFDIR_STR* path, pf_u32 target); +extern pf_s32 PFFAT_GetSectorSpecified(PFDIR_FFD* ffd, pf_u32 index, pf_u32 allocate, pf_u32* sector); +extern void PFPATH_AdjustExtShortName(pf_s8* name, pf_u32 position); + +extern pf_s32 PFCACHE_AllocateDataPage(PF_VOLUME* volume, pf_u32 sector, PF_CACHE_PAGE** page, pf_u32* size); +extern void PFCACHE_FreeDataPage(PF_VOLUME* volume, PF_CACHE_PAGE* page); +static inline void set_dot_entry(pf_u8* buffer) { + buffer[0] = '.'; + buffer[1] = ' '; + buffer[2] = ' '; + buffer[3] = ' '; + buffer[4] = ' '; + buffer[5] = ' '; + buffer[6] = ' '; + buffer[7] = ' '; + buffer[8] = ' '; + buffer[9] = ' '; + buffer[10] = ' '; +} + +static inline void set_dot_dot_entry(pf_u8* buffer) { + buffer[0] = '.'; + buffer[1] = '.'; + buffer[2] = ' '; + buffer[3] = ' '; + buffer[4] = ' '; + buffer[5] = ' '; + buffer[6] = ' '; + buffer[7] = ' '; + buffer[8] = ' '; + buffer[9] = ' '; + buffer[10] = ' '; +} + +extern void PFENT_StoreEntryNumericFieldsToBuf(pf_u8* buffer, PF_DIR_ENT* entry); +extern PF_VOLUME* PFPATH_GetVolumeFromPath(PF_STR* path); +extern pf_s32 PFCACHE_FlushDataCacheSpecific(PF_VOLUME* volume, void* entry); +extern pf_s32 PFCACHE_FlushFATCache(PF_VOLUME* volume); +extern pf_s32 PFDIR_p_fsfirst(PF_VOLUME* volume, PF_STR* path, pf_u8 attributes, PF_DTA* data); +extern pf_s32 PFDIR_p_fsnext(PF_DTA* data); +extern pf_s32 PFDIR_p_fsexec(PF_DTA* data, pf_u32 flags, pf_u32 mode); +extern pf_s32 PFDIR_p_fsexec_chmod(PF_DTA* data, PF_DIR_ENT* entry, pf_u32 attributes, pf_u32 mode); +extern pf_s32 PFDIR_p_fsexec_remove(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter); +extern pf_s32 PFDIR_p_fsexec_fopen(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter, pf_u32 flags, + pf_u32 mode); +extern pf_s32 PFDIR_p_fsexec_opendir(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter, pf_u32 flags); +extern void PFFAT_FinalizeFFD(PF_FFD* ffd); +extern pf_s32 PFENT_ITER_GetEntryOfPattern(PF_ENT_ITER* iter, PF_DIR_ENT* entry, PF_VOLUME* volume, + PFDIR_STR* directory); +extern pf_s32 PFENT_ITER_FindEntry(PF_ENT_ITER* iter, PF_DIR_ENT* entry, PFDIR_STR* pattern, + pf_u8 attributes, pf_u32 start, pf_u32* found); +extern pf_s32 PFENT_findEntry(PFDIR_FFD* ffd, PF_DIR_ENT* entry, pf_u32 start, PFDIR_STR* pattern, + pf_u8 attributes, pf_u32* logical_position, pf_u32* entry_position); +extern pf_u32 PFSTR_GetCodeMode(PFDIR_STR* path); +extern const pf_s8* PFSTR_GetStrPos(PFDIR_STR* path, pf_u32 target); +extern pf_s32 PFPATH_SplitPathPattern(PF_STR* path, PFDIR_STR* directory, PFDIR_STR* pattern); +extern void PFPATH_SetSearchPattern(pf_s8* ansi_pattern, pf_u16* unicode_pattern, PFDIR_STR* pattern); +extern pf_u16* pf_w_strcpy(pf_u16* destination, const pf_u16* source); +extern pf_s32 PFPATH_transformInUnicode(pf_u16* destination, const pf_s8* source); + +extern pf_s32 PFENT_ITER_GetLFNEntryName(PF_ENT_ITER* iter); +extern void PFPATH_getLongNameformShortName(pf_s8* short_name, pf_s8* long_name, pf_u8 small_letter_flag); +extern pf_s32 PFFILE_FsexecOpenFile(PF_DIR_ENT* entry, PF_ENT_ITER* iter, pf_u32 mode, PF_DTA* data); +extern pf_s32 PFPATH_cmpName(const pf_s8* short_name, PFDIR_STR* pattern, pf_u32 short_search); +extern pf_s32 PFPATH_cmpNameUni(const pf_u16* name, PFDIR_STR* pattern); +pf_s32 PFDIR_p_mkdir(PF_VOLUME* volume, PF_STR* path, pf_u32 option, PF_DTA* data) { PF_DIR_ENT parent_entry; + PF_DIR_ENT entry; + pf_s8 normalized_name[512]; + PF_ENT_ITER iter; PFDIR_FFD ffd; - PFDIR_FAT_HINT fat_hint; - pf_u32 pos; - pf_u32 prev_chain[2]; - pf_u32 new_sector; + pf_u8 entry_buffer[32]; + PFDIR_STR directory; + PFDIR_STR filename; + PFDIR_FAT_HINT hint; + pf_u32 previous_chain[2]; + pf_u32 found; + pf_u32 position; + pf_u32 sector = 0; + pf_u32 written; + PF_CACHE_PAGE* page; + pf_u32 page_size; + pf_u16 filename_length; + pf_u16 original_offset; + pf_u8 lfn_count = 0; + pf_u8 checksum; + pf_u32 cluster; + pf_u32 index; + pf_u32* next_sector; + pf_s32 error; - (void)option; - - err = 0; - new_sector = 0; - - err = PFPATH_SplitPath((PFDIR_STR*)p_path, &full_path, &dirname); - if (err != 0) { - return err; + error = PFPATH_SplitPath((PFDIR_STR*)path, &directory, &filename); + if (error != 0) { return error; } + error = PFENT_ITER_GetEntryOfPath(&iter, &parent_entry, volume, &directory, 1); + if (error != 0) { return error; } + if ((parent_entry.attr & 0x10) == 0) { return 0x14; } + filename_length = PFSTR_StrNumChar(&filename, 1); + if (filename_length + parent_entry.path_len > 0x103) { return 2; } + if (filename_length > 255) { return 1; } + if (PFSTR_GetCodeMode(&filename) == 2) { + PFPATH_transformFromUnicodeToNormal(normalized_name, + (const pf_u16*)PFSTR_GetStrPos(&filename, 1)); } - err = PFENT_ITER_GetEntryOfPath(&parent_iter, &parent_entry, p_vol, - (PFDIR_STR*)&full_path, 1); - if (err != 0) { - return err; - } - if ((parent_entry.attr & 0x10) == 0) { - return 0x14; - } - if (p_dta != PF_NULL) { - p_dta->parent_start_cluster = parent_entry.start_cluster; - } - PFFAT_InitFFD(&ffd, &fat_hint, p_vol, &parent_entry.start_cluster); - err = PFENT_findEntry(&ffd, &entry, 0U, &dirname, 0x77U, PF_NULL, PF_NULL); - if (err == 0) { - return 8; - } - if (err != 3) { - return err; - } - dirname_len = PFSTR_StrNumChar(&dirname, 1U); - if (dirname_len + parent_entry.path_len > 0x103U) { return 2; } - if (dirname_len > 0xFFU) { return 1; } - err = VFiPFENT_InitENT(&entry, (PF_STR*)&dirname, 0x10U, 1U, &parent_entry, p_vol); - if (err == 0) { - PFFAT_InitFFD(&ffd, &fat_hint, p_vol, &parent_entry.start_cluster); - err = VFiPFENT_allocateEntry(&entry, (entry.num_entry_LFNs + 1), (PF_FFD*)&ffd, prev_chain, PF_NULL, 0x77U, &pos); - if (err == 0) { - entry.start_cluster = 0; - PFFAT_InitFFD(&ffd, &fat_hint, p_vol, &entry.start_cluster); - err = PFFAT_GetSectorSpecified(&ffd, 0U, 1U, &new_sector); - if (new_sector == -1U) { - err = 6; - } - if (err == 0) { - err = VFiPFENT_FillVoidEntryToSectors(p_vol, new_sector, p_vol->bpb.sectors_per_cluster, 1U, &entry, &parent_entry); - if (err == 0) { - if ((entry.long_name[0] != 0) && ((pf_vol_set.setting & 2) == 2)) { - VFiPFPATH_AdjustExtShortName(&entry.short_name[0], pos); - entry.check_sum = VFiPFENT_CalcCheckSum(&entry); - } - err = VFiPFENT_UpdateEntry(&entry, prev_chain, 0U); - } - if (err != 0) { - PFFAT_FreeChain(&ffd, entry.start_cluster, -1U, -1U); - } else if (p_dta != PF_NULL) { - p_dta->p_file = PF_NULL; - p_dta->p_dir = PF_NULL; - p_dta->p_vol = p_vol; - p_dta->parent_pos = pos + 1; - p_dta->num_entry_LFNs = entry.num_entry_LFNs; - p_dta->attr = entry.attr; - p_dta->Time = entry.modify_time; - p_dta->Date = entry.modify_date; - p_dta->FileSize = entry.file_size; - p_dta->Attribute = entry.attr; - if (VFiPFSTR_GetCodeMode((PF_STR*)&dirname) == 1) { - PFPATH_SetSearchPattern(p_dta->reg_exp, PF_NULL, &dirname); - p_dta->status |= 1; - } else { - PFPATH_SetSearchPattern(p_dta->reg_exp, ((PF_DTAW*)p_dta)->reg_expW, &dirname); - p_dta->status |= 2; - } - pf_strcpy(p_dta->FileName, &entry.short_name[0]); - if ((p_dta->status & 2) == 2) { - PFPATH_transformInUnicode(((PF_DTAW*)p_dta)->FileNameW, p_dta->FileName); - } - if (entry.long_name[0] == 0) { - p_dta->ordinal = 0; - p_dta->check_sum = 0; - p_dta->LongName[0] = 0; - if ((p_dta->status & 2) == 2) { - ((PF_DTAW*)p_dta)->LongNameW[0] = 0; - } - } else { - p_dta->ordinal = 1; - p_dta->check_sum = entry.check_sum; - if ((pf_vol_set.setting & 2) == 2) { - pf_vol_set.setting &= 0xFFFFFFFC; - pf_vol_set.setting |= 1; - PFPATH_transformFromUnicodeToNormal(p_dta->LongName, entry.long_name); - pf_vol_set.setting &= 0xFFFFFFFC; - pf_vol_set.setting |= 2; - } else { - PFPATH_transformFromUnicodeToNormal(p_dta->LongName, entry.long_name); - } - if ((p_dta->status & 2) == 2) { - pf_w_strcpy(((PF_DTAW*)p_dta)->LongNameW, entry.long_name); - } - } - } - } + PFSTR_SetLocalStr(&filename, (pf_u32)normalized_name); + if (data != 0) { + data->p_file = 0; + data->p_dir = 0; + data->parent_start_cluster = parent_entry.start_cluster; + data->p_vol = parent_entry.p_vol; + data->attr = 0x10; + if (PFSTR_GetCodeMode(&filename) == 1) { + PFPATH_SetSearchPattern(data->reg_exp, 0, &filename); + data->status |= 1; + } else { + PFPATH_SetSearchPattern(data->reg_exp, ((PF_DTAW*)data)->reg_expW, &filename); + data->status |= 2; } } - -exit: - return err; + PFFAT_InitFFD(&ffd, &hint, volume, &parent_entry.start_cluster); + iter.ffd = ffd; + PFFAT_ResetFFD(&iter.ffd, &parent_entry.start_cluster); + error = PFENT_ITER_IteratorInitialize(&iter, 0); + if (error != 0) { return error; } + error = PFENT_ITER_FindEntry(&iter, &entry, &filename, 0x10, 0, &found); + if (error != 0) { return error; } + if (found != 0) { return 8; } + error = PFPATH_parseShortName(entry.short_name, &filename); + if (error != 0 && entry.short_name[0] == 0) { return 1; } + if (error != 0) { + error = PFENT_AdjustSFN(&parent_entry, entry.short_name); + if (error != 0) { return error; } + if (PFSTR_GetCodeMode(&filename) == 1) { + filename_length = PFPATH_transformInUnicode(entry.long_name, PFSTR_GetStrPos(&filename, 1)); + } else { + pf_w_strcpy(entry.long_name, (const pf_u16*)PFSTR_GetStrPos(&filename, 1)); + } + } else { + entry.long_name[0] = 0; + } + entry.start_cluster = 0; + entry.file_size = 0; + entry.p_vol = volume; + entry.small_letter_flag = 0; + entry.attr = 0x10; + entry.create_time_ms = PFENT_getcurrentDateTimeForEnt(&entry.create_date, &entry.create_time); + entry.access_date = entry.create_date; + entry.modify_time = entry.create_time; + entry.modify_date = entry.create_date; + original_offset = entry.entry_offset; + if (entry.long_name[0] != 0 && (entry.small_letter_flag & 0x18) == 0) { + lfn_count = filename_length / 13 + (filename_length % 13 != 0); + error = PFENT_allocateEntryPos(&entry, lfn_count + 1, &ffd, previous_chain, &filename, &position); + if (error != 0) { return error; } + if ((pf_vol_set.setting & 2) == 2) { PFPATH_AdjustExtShortName(entry.short_name, position); } + } else { + error = PFENT_allocateEntryPos(&entry, 1, &ffd, previous_chain, &filename, &position); + if (error != 0) { return error; } + } + PFFAT_ResetFFD(&ffd, &entry.start_cluster); + error = PFFAT_GetSectorSpecified(&ffd, 0, 1, §or); + if (error != 0) { return error; } + if (sector == -1U) { return 6; } + cluster = ffd.p_hint->cluster; + if (volume->bpb.fat_type == FAT_32 && *iter.ffd.p_start_cluster == volume->bpb.root_dir_cluster && + original_offset == 0 && cluster == volume->bpb.root_dir_cluster) { + iter.ffd = ffd; + error = PFENT_ITER_IteratorInitialize(&iter, lfn_count); + if (error != 0) { return error; } + if (iter.buf[0] == 0) { + PFFAT_ResetFFD(&ffd, &entry.start_cluster); + *ffd.p_start_cluster = 0; + ffd.p_hint->cluster = 0; + cluster = volume->bpb.root_dir_cluster + 1; + error = PFFAT_GetSectorSpecified(&ffd, 0, 1, §or); + if (error != 0) { return error; } + } + } + error = PFCACHE_AllocateDataPage(volume, -1U, &page, &page_size); + if (error != 0) { return error; } + pf_memset(page->p_buf, 0, volume->bpb.bytes_per_sector); + index = volume->bpb.sectors_per_cluster; + while (index != 0) { + if (index == 1) { + set_dot_entry(page->p_buf); + PFENT_StoreEntryNumericFieldsToBuf(page->p_buf, &entry); + set_dot_dot_entry(page->p_buf + 32); + if (parent_entry.entry_sector == -1U) { entry.start_cluster = 0; } + else { entry.start_cluster = parent_entry.start_cluster; } + PFENT_StoreEntryNumericFieldsToBuf(page->p_buf + 32, &entry); + } + error = PFSEC_WriteData(volume, page->p_buf, sector + index - 1, 0, + volume->bpb.bytes_per_sector, &written, 0); + if (error != 0) { break; } + if (written != volume->bpb.bytes_per_sector) { error = 0x11; break; } + index--; + } + PFCACHE_FreeDataPage(volume, page); + if (error != 0) { return error; } + entry.num_entry_LFNs = lfn_count; + sector = entry.entry_sector; + checksum = PFENT_CalcCheckSum(&entry); + if ((parent_entry.small_letter_flag & 0x18) == 0) { + next_sector = previous_chain; + for (index = lfn_count; index >= 1; index--) { + PFENT_storeLFNEntryFieldsToBuf(entry_buffer, &entry, index, checksum, index == lfn_count); + error = PFSEC_WriteData(volume, entry_buffer, sector, entry.entry_offset, 32, &written, 0); + if (error != 0) { return error; } + if (written != 32) { return 0x11; } + entry.entry_offset += 32; + if (entry.entry_offset >= volume->bpb.bytes_per_sector) { + entry.entry_offset = 0; + sector = *next_sector++; + } + } + entry.entry_sector = sector; + } + entry.start_cluster = cluster; + error = PFENT_updateEntry(&entry, 0); + if (error != 0) { return error; } + if (data != 0) { + data->parent_pos = position + 1; + pf_strcpy(data->FileName, entry.short_name); + if ((data->status & 2) == 2) { PFPATH_transformInUnicode(((PF_DTAW*)data)->FileNameW, data->FileName); } + if (entry.long_name[0] != 0) { + if ((pf_vol_set.setting & 2) == 2) { + pf_vol_set.setting = (pf_vol_set.setting & ~3) | 1; + PFPATH_transformFromUnicodeToNormal(data->LongName, entry.long_name); + pf_vol_set.setting = (pf_vol_set.setting & ~3) | 2; + } else { PFPATH_transformFromUnicodeToNormal(data->LongName, entry.long_name); } + if ((data->status & 2) == 2) { pf_w_strcpy(((PF_DTAW*)data)->LongNameW, entry.long_name); } + data->check_sum = checksum; + data->ordinal = 1; + } else { + data->LongName[0] = 0; + if ((data->status & 2) == 2) { ((PF_DTAW*)data)->LongNameW[0] = 0; } + data->ordinal = 0; + data->check_sum = 0; + } + data->FileSize = entry.file_size; + data->Time = entry.modify_time; + data->Date = entry.modify_date; + data->Attribute = entry.attr; + data->num_entry_LFNs = entry.num_entry_LFNs; + } + return 0; } + pf_s32 PFDIR_p_chdir(PF_VOLUME* p_vol, PFDIR_STR* p_path_str) { pf_s32 err; PF_ENT_ITER iter; @@ -596,13 +756,14 @@ pf_s32 PFDIR_p_chmod(PF_VOLUME* volume, PFDIR_STR* path, pf_u32 attributes) { pf_s32 PFDIR_p_rmdir(PF_VOLUME* volume, PFDIR_STR* path) { PFDIR_STR directory_path; PFDIR_STR filename; - PFDIR_FAT_HINT saved_hint; PFDIR_FAT_HINT hint; + PFDIR_FAT_HINT saved_hint; PFDIR_FFD ffd; PF_ENT_ITER iter; PF_ENT_ITER directory_iter; PF_DIR_ENT entry; - pf_u32 is_empty = 0; + pf_u32 is_empty; + pf_u32 start_cluster; pf_u32 i; pf_s32 error; @@ -612,36 +773,39 @@ pf_s32 PFDIR_p_rmdir(PF_VOLUME* volume, PFDIR_STR* path) { if (error != 0) { return error; } + directory_iter = iter; + saved_hint = *iter.ffd.p_hint; if ((entry.attr & 0x10) == 0 || (entry.attr & 1) != 0) { return 0x14; } - directory_iter = iter; - saved_hint = *iter.ffd.p_hint; if (directory_is_open(&entry) != 0) { return 0x13; } error = PFVOL_CheckCurrentDir(volume, entry.start_cluster); if (error != 0 || entry.start_cluster == 1 || (volume->bpb.fat_type == FAT_32 && entry.start_cluster == volume->bpb.root_dir_cluster)) { return 0x1C; } PFFAT_InitFFD(&ffd, &hint, volume, &entry.start_cluster); - directory_iter.ffd = ffd; - error = PFENT_ITER_IteratorInitialize(&directory_iter, 0); + iter.ffd = ffd; + error = PFENT_ITER_IteratorInitialize(&iter, 0); if (error != 0) { return error; } - error = PFDIR_CheckDirIsEmpty(&directory_iter, &is_empty); + error = PFDIR_CheckDirIsEmpty(&iter, &is_empty); if (error != 0) { return error; } if (is_empty == 0) { return 0x1D; } + start_cluster = entry.start_cluster; iter = directory_iter; iter.ffd.p_hint = &saved_hint; error = PFENT_RemoveEntry(&entry, &iter); if (error != 0) { return error; } - return release_directory_chain(&iter.ffd, entry.start_cluster, -1U); + error = PFFAT_FreeChain(&iter.ffd, start_cluster, -1U, -1U); + if (error != 0) { return error; } + return 0; } pf_s32 PFDIR_p_fstat(PF_VOLUME* volume, PFDIR_STR* path, PFDIR_FILE_STAT* file_stat) { @@ -687,237 +851,388 @@ pf_s32 PFDIR_p_fstat(PF_VOLUME* volume, PFDIR_STR* path, PFDIR_FILE_STAT* file_s return 0; } -extern PF_VOLUME* PFPATH_GetVolumeFromPath(PF_STR* path); -extern pf_s32 PFCACHE_FlushDataCacheSpecific(PF_VOLUME* volume, void* entry); -extern pf_s32 PFCACHE_FlushFATCache(PF_VOLUME* volume); -extern pf_s32 PFDIR_p_fsfirst(PF_VOLUME* volume, PF_STR* path, pf_u8 attributes, PF_DTA* data); -extern pf_s32 PFDIR_p_fsnext(PF_DTA* data); -extern pf_s32 PFDIR_p_fsexec(PF_DTA* data, pf_u32 flags, pf_u32 mode); -extern pf_s32 PFDIR_p_fsexec_chmod(PF_DTA* data, PF_DIR_ENT* entry, pf_u32 attributes, pf_u32 mode); -extern pf_s32 PFDIR_p_fsexec_remove(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter); -extern pf_s32 PFDIR_p_fsexec_fopen(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter, pf_u32 flags, - pf_u32 mode); -extern pf_s32 PFDIR_p_fsexec_opendir(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter, pf_u32 flags); -extern void PFFAT_FinalizeFFD(PF_FFD* ffd); -extern pf_s32 PFENT_ITER_GetEntryOfPattern(PF_ENT_ITER* iter, PF_DIR_ENT* entry, PF_VOLUME* volume, - PFDIR_STR* directory); -extern pf_s32 PFENT_ITER_FindEntry(PF_ENT_ITER* iter, PF_DIR_ENT* entry, PFDIR_STR* pattern, - pf_u8 attributes, pf_u32 start, pf_u32* found); -extern pf_s32 PFENT_findEntry(PFDIR_FFD* ffd, PF_DIR_ENT* entry, pf_u32 start, PFDIR_STR* pattern, - pf_u8 attributes, pf_u32* logical_position, pf_u32* entry_position); -extern pf_u32 PFSTR_GetCodeMode(PFDIR_STR* path); -extern const pf_s8* PFSTR_GetStrPos(PFDIR_STR* path, pf_u32 target); -extern pf_s32 PFPATH_SplitPathPattern(PF_STR* path, PFDIR_STR* directory, PFDIR_STR* pattern); -extern void PFPATH_SetSearchPattern(pf_s8* ansi_pattern, pf_u16* unicode_pattern, PFDIR_STR* pattern); -extern pf_u16* pf_w_strcpy(pf_u16* destination, const pf_u16* source); -extern pf_s32 PFPATH_transformInUnicode(pf_u16* destination, const pf_s8* source); -extern pf_s32 PFPATH_parseShortName(PF_DIR_ENT* entry, const pf_s8* name); -extern pf_s32 PFENT_ITER_GetLFNEntryName(PF_ENT_ITER* iter); -extern void PFPATH_getLongNameformShortName(pf_s8* short_name, pf_s8* long_name, pf_u8 small_letter_flag); -extern pf_s32 PFFILE_FsexecOpenFile(PF_DIR_ENT* entry, PF_ENT_ITER* iter, pf_u32 mode, PF_DTA* data); -extern pf_s32 PFPATH_cmpName(const pf_s8* short_name, PFDIR_STR* pattern, pf_u32 short_search); -extern pf_s32 PFPATH_cmpNameUni(const pf_u16* name, PFDIR_STR* pattern); - pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) { - PF_ENT_ITER source_iter; - PF_ENT_ITER destination_iter; - PF_DIR_ENT source_entry; - PF_DIR_ENT source_parent; - PF_DIR_ENT destination_parent; - PF_DIR_ENT existing_entry; - PFDIR_STR source_directory; - PFDIR_STR source_name; - PFDIR_STR destination_directory; - PFDIR_STR destination_name; - pf_s8 normalized_name[512]; - pf_u32 code_mode; - const pf_s8* name; - pf_u32 entry_position; - pf_u16 filename_length; - pf_s32 error; - - error = PFPATH_SplitPath((PFDIR_STR*)old_path, &source_directory, &source_name); - if (error != 0) { - return error; - } - filename_length = PFSTR_StrNumChar(&source_name, 1); - if (filename_length > 0xFF) { return 1; } - if (PFSTR_GetCodeMode(&source_name) == 2) { - if (PFSTR_StrNumChar(&source_name, 1) > 0xFF) { - return 1; - } - error = PFPATH_transformFromUnicodeToNormal( - normalized_name, (const pf_u16*)PFSTR_GetStrPos(&source_name, 1)); - if (error != 0) { - return error; - } - PFSTR_SetLocalStr(&source_name, (pf_u32)normalized_name); - } - error = PFENT_ITER_GetEntryOfPath(&source_iter, &source_parent, volume, - &source_directory, 1); - if (error != 0) { - return error; - } - PFFAT_InitFFD(&source_iter.ffd, 0, volume, &source_parent.start_cluster); - error = PFENT_ITER_IteratorInitialize(&source_iter, 0); - if (error != 0) { - return error; - } - error = PFENT_ITER_FindEntry(&source_iter, &source_entry, &source_name, 0x7F, 0, - &entry_position); - if (error != 0) { - return error; - } - if (entry_position == 999999) { - return 3; - } - if ((source_entry.attr & 0x10) != 0) { - return 3; - } - if ((source_entry.attr & 1) != 0) { - return 0x18; - } - if (PFSTR_StrNCmp((PFDIR_STR*)new_path, (const pf_s8*)":", 1, 1, 1) == 0 && - PFPATH_GetVolumeFromPath(new_path) != volume) { - return 0x1F; - } - error = PFPATH_SplitPath((PFDIR_STR*)new_path, &destination_directory, - &destination_name); - if (error != 0) { - return error; - } - error = PFENT_ITER_GetEntryOfPath(&destination_iter, &destination_parent, volume, - &destination_directory, 1); - if (error != 0) { - return error; - } - if ((destination_parent.attr & 0x10) == 0) { - return 0x14; - } - if (source_iter.ffd.start_cluster != destination_parent.start_cluster) { - return 0x1F; - } - if ((code_mode = PFSTR_GetCodeMode(&destination_name)) == 2) { - if (PFSTR_StrNumChar(&destination_name, 1) > 0xFF) { - return 1; - } - error = PFPATH_transformFromUnicodeToNormal( - normalized_name, (const pf_u16*)PFSTR_GetStrPos(&destination_name, 1)); - if (error != 0) { - return error; - } - PFSTR_SetLocalStr(&destination_name, (pf_u32)normalized_name); - } - name = PFSTR_GetStrPos(&destination_name, 1); - error = PFENT_ITER_FindEntry(&destination_iter, &existing_entry, &destination_name, - 0x7F, 0, &entry_position); - if (error == 0) { - return 8; - } - if (error != 3) { - return error; - } - error = PFPATH_parseShortName(&source_entry, name); - if (error != 0) { - return error; - } - source_entry.long_name[0] = 0; - return PFENT_updateEntry(&source_entry, 1); -} - -pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) { - PF_ENT_ITER source_iter; - PF_ENT_ITER destination_iter; PF_DIR_ENT source_entry; PF_DIR_ENT destination_entry; - PF_DIR_ENT existing_entry; - PFDIR_STR destination_directory; - PFDIR_STR destination_name; - PFDIR_VOLUME_DIRS* volume_dirs; + PF_DIR_ENT source_parent; pf_s8 normalized_name[512]; - pf_u32 code_mode; - pf_u32 entry_position; - pf_u16 filename_length; - pf_s32 index = 0; + PF_ENT_ITER source_iter; + PF_ENT_ITER destination_iter; + pf_u8 entry_buffer[32]; + PFDIR_STR directory; + PFDIR_STR source_name; + PFDIR_STR destination_name; + PFDIR_FAT_HINT source_hint; + PFDIR_FAT_HINT destination_hint; + pf_u32 previous_chain[2]; + pf_u32 written; + pf_u32 position; + pf_u32 found; + pf_u16 time; + pf_u8 deleted_marker[1] = {0xE5}; + pf_u16 saved_initial_char = 0; + pf_u32 sector; + pf_u32* next_sector; + pf_s32 filename_length; + pf_s32 parse_error; + pf_s32 allocation_error = 0; pf_s32 error; + pf_u32 index; + PF_DIR_ENT* update_entry; - error = PFENT_ITER_GetEntryOfPath(&source_iter, &source_entry, volume, - (PFDIR_STR*)old_path, 0); - if (error != 0) { - return error; + error = PFPATH_SplitPath((PFDIR_STR*)old_path, &directory, &source_name); + if (error != 0) { return error; } + if (PFSTR_GetCodeMode(&source_name) == 2) { + if ((pf_s32)PFSTR_StrNumChar(&source_name, 1) > 255) { return 1; } + PFPATH_transformFromUnicodeToNormal(normalized_name, + (const pf_u16*)PFSTR_GetStrPos(&source_name, 1)); } - if (PFPATH_GetVolumeFromPath(new_path) != volume) { - return 0x1F; + PFSTR_SetLocalStr(&source_name, (pf_u32)normalized_name); + error = PFENT_ITER_GetEntryOfPath(&source_iter, &source_parent, volume, + (PFDIR_STR*)old_path, 1); + if (error != 0) { return error; } + PFFAT_InitFFD(&source_iter.ffd, &source_hint, volume, &source_iter.ffd.flags); + source_iter.ffd.flags = source_parent.start_cluster; + error = PFENT_ITER_IteratorInitialize(&source_iter, 0); + if (error != 0) { return error; } + error = PFENT_ITER_FindEntry(&source_iter, &source_entry, &source_name, 0x7F, 0, &found); + if (error != 0) { return error; } + if (found == 0 || (source_entry.attr & 8) != 0) { return 3; } + if ((source_entry.attr & 1) != 0) { return 0x18; } + if (PFSTR_StrNCmp((PFDIR_STR*)new_path, (const pf_s8*)":", 1, 1, 1) == 0 && + PFPATH_GetVolumeFromPath(new_path) != volume) { return 0x1F; } + error = PFPATH_SplitPath((PFDIR_STR*)new_path, &directory, &destination_name); + if (error != 0) { return error; } + if (PFSTR_GetCodeMode(&destination_name) == 2) { + if ((pf_s32)PFSTR_StrNumChar(&destination_name, 1) > 255) { return 1; } + PFPATH_transformFromUnicodeToNormal(normalized_name, + (const pf_u16*)PFSTR_GetStrPos(&destination_name, 1)); + } + PFSTR_SetLocalStr(&destination_name, (pf_u32)normalized_name); + if (PFSTR_GetCodeMode(&destination_name) == 1) { + const pf_s8* filename = PFSTR_GetStrPos(&destination_name, 1); + error = pf_strcmp(PFSTR_GetStrPos(&directory, 1), filename); + } else { + const pf_u16* filename = (const pf_u16*)PFSTR_GetStrPos(&destination_name, 1); + error = pf_w_strcmp((const pf_u16*)PFSTR_GetStrPos(&directory, 1), filename); } - error = PFPATH_SplitPath((PFDIR_STR*)new_path, &destination_directory, - &destination_name); if (error != 0) { - return error; + error = PFENT_ITER_GetEntryOfPath(&destination_iter, &destination_entry, + volume, (PFDIR_STR*)new_path, 1); + if (error != 0) { return error; } + if (destination_entry.start_cluster != source_parent.start_cluster) { return 0x20; } + } + destination_entry.start_cluster = source_parent.start_cluster; + PFFAT_InitFFD(&destination_iter.ffd, &destination_hint, volume, &destination_entry.start_cluster); + error = PFENT_findEntry(&destination_iter.ffd, &destination_entry, 0, &destination_name, 0x7F, 0, 0); + if (error == 0) { return 8; } + if (error != 0 && error != 3) { return error; } + if ((source_entry.attr & 0x10) == 0) { + if (PFFILE_IsOpened(&source_entry) != 0) { return 0x13; } + } else { + if (directory_is_open(&source_entry) != 0) { return 0x13; } + if (current_directory_is_open(source_entry.p_vol, source_entry.start_cluster) != 0) { return 0x1C; } + if (PFSTR_StrNCmp(&source_name, (const pf_s8*)"..", 1, 0, 2) == 0) { return 0x1C; } + if (PFSTR_StrNCmp(&source_name, (const pf_s8*)".", 1, 0, 1) == 0) { return 0x1C; } + { + PFDIR_SFD* file = ((PFDIR_VOLUME_DIRS*)volume)->sfds; + pf_u32 directory_sector = volume->bpb.first_data_sector + + ((source_entry.start_cluster - 2) << volume->bpb.log2_sectors_per_cluster); + for (index = 0; index < 5; index++, file++) { + if ((file->stat & 1) != 0 && (file->stat & 2) != 0) { + if (file->dir_entry.p_vol == volume && file->dir_entry.entry_sector == directory_sector) { return 0x13; } + found = 0; + error = PFENT_ITER_FindCluster(&file->dir_entry, source_entry.start_cluster, &found); + if (error != 0) { return error; } + if (found != 0) { return 0x13; } + } + } + } } filename_length = PFSTR_StrNumChar(&destination_name, 1); - if (filename_length > 0xFF) { return 1; } - if ((code_mode = PFSTR_GetCodeMode(&destination_name)) == 2) { - if (PFSTR_StrNumChar(&destination_name, 1) > 0xFF) { - return 1; + if (filename_length + source_parent.path_len > 0x103) { return 1; } + if ((source_entry.attr & 0x10) == 0 && filename_length > 255) { return 1; } + pf_memcpy(&destination_entry, &source_entry, sizeof(PF_DIR_ENT)); + parse_error = PFPATH_parseShortName(destination_entry.short_name, &destination_name); + if (destination_entry.short_name[0] == 0) { return 2; } + if (parse_error == 0 && source_entry.num_entry_LFNs == 0) { + destination_entry.long_name[0] = 0; + destination_entry.num_entry_LFNs = 0; + PFENT_getcurrentDateTimeForEnt(&destination_entry.access_date, &time); + error = PFENT_updateEntry(&destination_entry, 1); + if (error != 0) { return error; } + return allocation_error; + } + if (source_entry.num_entry_LFNs != 0 && (source_entry.small_letter_flag & 0x18) == 0) { + saved_initial_char = source_entry.long_name[0]; + source_entry.long_name[0] = 0; + for (index = 1; index <= source_entry.num_entry_LFNs; index++) { + error = PFENT_ITER_Retreat(&source_iter, 0); + if (error != 0) { return error; } + error = PFSEC_WriteData(volume, deleted_marker, source_iter.sector, + source_iter.offset, 1, &written, 0); + if (error != 0) { return error; } + if (written != 1) { return 0x11; } } - error = PFPATH_transformFromUnicodeToNormal( - normalized_name, (const pf_u16*)PFSTR_GetStrPos(&destination_name, 1)); - if (error != 0) { - return error; + } + error = PFSEC_WriteData(volume, deleted_marker, source_entry.entry_sector, + source_entry.entry_offset, 1, &written, 0); + if (error != 0) { return error; } + if (written != 1) { return 0x11; } + if ((((PFDIR_VOLUME_DIRS*)volume)->cache.mode & 4) != 0) { + error = PFCACHE_FlushDataCache(volume); + if (error != 0) { return error; } + } + if (parse_error != 0) { + error = PFENT_AdjustSFN(&source_parent, destination_entry.short_name); + if (error != 0) { return error; } + if (PFSTR_GetCodeMode(&destination_name) == 1) { + filename_length = PFPATH_transformInUnicode(destination_entry.long_name, + PFSTR_GetStrPos(&destination_name, 1)); + } else { + pf_w_strcpy(destination_entry.long_name, + (const pf_u16*)PFSTR_GetStrPos(&destination_name, 1)); } - PFSTR_SetLocalStr(&destination_name, (pf_u32)normalized_name); + destination_entry.num_entry_LFNs = filename_length / 13 + (filename_length % 13 != 0); + } else { + destination_entry.num_entry_LFNs = 0; } - error = PFENT_ITER_GetEntryOfPath(&destination_iter, &destination_entry, volume, - &destination_directory, 1); - if (error != 0) { - return error; - } - if ((destination_entry.attr & 0x10) == 0) { - return 0x14; - } - if ((source_entry.attr & 1) != 0) { - return 0x18; - } - volume_dirs = (PFDIR_VOLUME_DIRS*)volume; - if ((source_entry.attr & 0x10) != 0) { - if (PFVOL_CheckCurrentDir(volume, source_entry.start_cluster) != 0 || - source_entry.start_cluster == 1 || - (volume->bpb.fat_type == FAT_32 && - source_entry.start_cluster == volume->bpb.root_dir_cluster)) { - return 0x1C; + destination_entry.small_letter_flag = 0; + PFFAT_InitFFD(&source_iter.ffd, &destination_hint, volume, &source_parent.start_cluster); + allocation_error = PFENT_allocateEntryPos(&destination_entry, destination_entry.num_entry_LFNs + 1, + &source_iter.ffd, previous_chain, &destination_name, &position); + if (allocation_error != 0) { + if (source_entry.num_entry_LFNs != 0 && (source_entry.small_letter_flag & 0x18) == 0) { + source_entry.long_name[0] = saved_initial_char; + source_entry.entry_offset -= source_entry.num_entry_LFNs * 32; } - if (directory_is_open(&source_entry) != 0) { return 0x13; } - } else if (PFFILE_IsOpened(&source_entry) != 0) { - return 0x13; + update_entry = &source_entry; + } else { + if ((pf_vol_set.setting & 2) == 2) { PFPATH_AdjustExtShortName(destination_entry.short_name, position); } + destination_entry.check_sum = PFENT_CalcCheckSum(&destination_entry); + PFENT_getcurrentDateTimeForEnt(&destination_entry.access_date, &time); + update_entry = &destination_entry; } - PFFAT_InitFFD(&destination_iter.ffd, 0, volume, &destination_entry.start_cluster); - error = PFENT_ITER_IteratorInitialize(&destination_iter, 0); - if (error != 0) { - return error; + index = update_entry->num_entry_LFNs; + if (index != 0 && (update_entry->small_letter_flag & 0x18) == 0) { + sector = update_entry->entry_sector; + next_sector = previous_chain; + while (index >= 1) { + PFENT_storeLFNEntryFieldsToBuf(entry_buffer, update_entry, index, + update_entry->check_sum, index == update_entry->num_entry_LFNs); + error = PFSEC_WriteData(volume, entry_buffer, sector, update_entry->entry_offset, 32, &written, 0); + if (error != 0) { return error; } + if (written != 32) { return 0x11; } + update_entry->entry_offset += 32; + if (update_entry->entry_offset >= volume->bpb.bytes_per_sector) { + update_entry->entry_offset = 0; + sector = *next_sector++; + } + index--; + } + update_entry->entry_sector = sector; } - error = PFENT_ITER_FindEntry(&destination_iter, &existing_entry, &destination_name, - 0x7F, 0, &entry_position); + error = PFENT_updateEntry(update_entry, 1); + if (error != 0) { return error; } + return allocation_error; +} +pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) { + PF_DIR_ENT source_entry; + PF_DIR_ENT destination_entry; + PF_DIR_ENT destination_parent; + pf_s8 normalized_name[512]; + PF_ENT_ITER source_iter; + PF_ENT_ITER destination_iter; + pf_u8 entry_buffer[32]; + PFDIR_STR directory; + PFDIR_STR source_name; + PFDIR_STR destination_name; + PFDIR_STR parent_name; + PFDIR_FAT_HINT source_hint; + PFDIR_FAT_HINT destination_hint; + pf_u32 previous_chain[2]; + pf_u32 written; + pf_u32 position; + pf_u32 found; + pf_u16 time; + pf_u8 deleted_marker[1] = {0xE5}; + pf_u16 saved_initial_char = 0; + pf_u32 sector; + pf_u32* next_sector; + pf_s32 filename_length; + pf_s32 parse_error; + pf_s32 allocation_error; + pf_s32 error; + pf_u32 index; + pf_u32 lfn_index; + PF_DIR_ENT* update_entry; + + error = PFENT_ITER_GetEntryOfPath(&source_iter, &source_entry, volume, (PFDIR_STR*)old_path, 0); + if (error != 0) { return error; } + if (PFPATH_GetVolumeFromPath(new_path) != volume) { return 0x1F; } + error = PFPATH_SplitPath((PFDIR_STR*)new_path, &directory, &destination_name); + if (error != 0) { return error; } + if (PFSTR_GetCodeMode(&destination_name) == 2) { + if ((pf_s32)PFSTR_StrNumChar(&destination_name, 1) > 255) { return 1; } + PFPATH_transformFromUnicodeToNormal(normalized_name, + (const pf_u16*)PFSTR_GetStrPos(&destination_name, 1)); + } + PFSTR_SetLocalStr(&destination_name, (pf_u32)normalized_name); + error = PFENT_ITER_GetEntryOfPath(&destination_iter, &destination_parent, volume, (PFDIR_STR*)new_path, 1); + if (error != 0) { return error; } + destination_entry.start_cluster = destination_parent.start_cluster; + PFFAT_InitFFD(&destination_iter.ffd, &destination_hint, volume, &destination_entry.start_cluster); + error = PFENT_findEntry(&destination_iter.ffd, &destination_entry, 0, &destination_name, 0x7F, 0, 0); if (error == 0) { - if (source_entry.entry_sector == existing_entry.entry_sector && - source_entry.entry_offset == existing_entry.entry_offset) { - return 0; - } + if (destination_entry.entry_sector == source_entry.entry_sector && + destination_entry.entry_offset == source_entry.entry_offset) { return 0; } return 8; } - if (error != 3) { - return error; + if (error != 0 && error != 3) { return error; } + if ((source_entry.attr & 0x10) == 0) { + if (PFFILE_IsOpened(&source_entry) != 0) { return 0x13; } + } else { + if (directory_is_open(&source_entry) != 0) { return 0x13; } + if (current_directory_is_open(source_entry.p_vol, source_entry.start_cluster) != 0) { return 0x1C; } + error = PFPATH_SplitPath((PFDIR_STR*)old_path, &directory, &source_name); + if (error != 0) { return error; } + if (PFSTR_StrNCmp(&source_name, (const pf_s8*)"..", 1, 0, 2) == 0) { return 10; } + if (PFSTR_StrNCmp(&source_name, (const pf_s8*)".", 1, 0, 1) == 0) { return 10; } + { + PFDIR_SFD* file = ((PFDIR_VOLUME_DIRS*)volume)->sfds; + pf_u32 directory_sector = volume->bpb.first_data_sector + + ((source_entry.start_cluster - 2) << volume->bpb.log2_sectors_per_cluster); + for (index = 0; index < 5; index++, file++) { + if ((file->stat & 1) != 0 && (file->stat & 2) != 0) { + if (file->dir_entry.p_vol == volume && file->dir_entry.entry_sector == directory_sector) { return 0x13; } + found = 0; + error = PFENT_ITER_FindCluster(&file->dir_entry, source_entry.start_cluster, &found); + if (error != 0) { return error; } + if (found != 0) { return 0x13; } + } + } + } + destination_entry.start_cluster = destination_parent.start_cluster; + while (destination_entry.start_cluster != 1 && destination_entry.start_cluster != 0) { + pf_u32 parent_cluster; + PFFAT_InitFFD(&destination_iter.ffd, &destination_hint, volume, &destination_entry.start_cluster); + PFSTR_InitStr(&parent_name, (const pf_s8*)"..", 1); + PFSTR_SetLocalStr(&parent_name, 0); + error = PFENT_findEntry(&destination_iter.ffd, &destination_entry, 0, &parent_name, 0x7F, 0, 0); + if (error != 0) { return error; } + parent_cluster = destination_entry.start_cluster; + if (parent_cluster == 1 || parent_cluster == 0) { break; } + PFFAT_ResetFFD(&destination_iter.ffd, &destination_entry.start_cluster); + error = PFENT_ITER_IteratorInitialize(&destination_iter, 0); + if (error != 0) { return error; } + error = PFENT_ITER_FindDirEntryFromCluster(&destination_iter, &destination_entry, parent_cluster, &found); + if (error == 0) { + if (destination_entry.start_cluster == source_entry.start_cluster) { return 10; } + } else if (error != 0) { return error; } + } } - if (source_iter.ffd.start_cluster != destination_entry.start_cluster) { - return 0x1F; + filename_length = PFSTR_StrNumChar(&destination_name, 1); + if (filename_length + destination_parent.path_len > 0x103) { return 1; } + if ((source_entry.attr & 0x10) == 0 && filename_length > 255) { return 1; } + pf_memcpy(&destination_entry, &source_entry, sizeof(PF_DIR_ENT)); + parse_error = PFPATH_parseShortName(destination_entry.short_name, &destination_name); + if (destination_entry.short_name[0] == 0) { return 2; } + if (source_entry.num_entry_LFNs != 0 && (source_entry.small_letter_flag & 0x18) == 0) { + saved_initial_char = source_entry.long_name[0]; + source_entry.long_name[0] = 0; + for (index = 1; index <= source_entry.num_entry_LFNs; index++) { + error = PFENT_ITER_Retreat(&source_iter, 0); + if (error != 0) { return error; } + error = PFSEC_WriteData(volume, deleted_marker, source_iter.sector, + source_iter.offset, 1, &written, 0); + if (error != 0) { return error; } + if (written != 1) { return 0x11; } + } } - return PFDIR_p_rename(volume, old_path, new_path); + error = PFSEC_WriteData(volume, deleted_marker, source_entry.entry_sector, + source_entry.entry_offset, 1, &written, 0); + if (error != 0) { return error; } + if (written != 1) { return 0x11; } + if ((((PFDIR_VOLUME_DIRS*)volume)->cache.mode & 4) != 0) { + error = PFCACHE_FlushDataCache(volume); + if (error != 0) { return error; } + } + if (parse_error != 0) { + error = PFENT_AdjustSFN(&destination_parent, destination_entry.short_name); + if (error != 0) { return error; } + if (PFSTR_GetCodeMode(&destination_name) == 1) { + filename_length = PFPATH_transformInUnicode(destination_entry.long_name, + PFSTR_GetStrPos(&destination_name, 1)); + } else { + pf_w_strcpy(destination_entry.long_name, + (const pf_u16*)PFSTR_GetStrPos(&destination_name, 1)); + } + destination_entry.num_entry_LFNs = filename_length / 13 + (filename_length % 13 != 0); + } else { + destination_entry.num_entry_LFNs = 0; + } + destination_entry.small_letter_flag = 0; + PFFAT_InitFFD(&destination_iter.ffd, &source_hint, volume, &destination_parent.start_cluster); + allocation_error = PFENT_allocateEntryPos(&destination_entry, destination_entry.num_entry_LFNs + 1, + &destination_iter.ffd, previous_chain, &destination_name, &position); + if (allocation_error != 0) { + if (source_entry.num_entry_LFNs != 0 && (source_entry.small_letter_flag & 0x18) == 0) { + source_entry.long_name[0] = saved_initial_char; + source_entry.entry_offset -= source_entry.num_entry_LFNs * 32; + } + update_entry = &source_entry; + } else { + if ((pf_vol_set.setting & 2) == 2) { PFPATH_AdjustExtShortName(destination_entry.short_name, position); } + destination_entry.check_sum = PFENT_CalcCheckSum(&destination_entry); + PFENT_getcurrentDateTimeForEnt(&destination_entry.access_date, &time); + update_entry = &destination_entry; + if ((source_entry.attr & 0x10) != 0) { + PFFAT_InitFFD(&source_iter.ffd, &source_hint, volume, &source_entry.start_cluster); + PFSTR_InitStr(&parent_name, (const pf_s8*)"..", 1); + PFSTR_SetLocalStr(&parent_name, 0); + error = PFENT_findEntry(&source_iter.ffd, &source_entry, 0, &parent_name, 0x7F, 0, 0); + if (error != 0) { return error; } + if (destination_parent.start_cluster == 1 || destination_parent.start_cluster == 0 || + (destination_parent.start_cluster == 2 && volume->bpb.fat_type == FAT_32)) { + source_entry.start_cluster = 0; + } else { source_entry.start_cluster = destination_parent.start_cluster; } + error = PFENT_updateEntry(&source_entry, 1); + if (error != 0) { return error; } + if ((((PFDIR_VOLUME_DIRS*)volume)->cache.mode & 4) != 0) { + error = PFCACHE_FlushDataCache(volume); + if (error != 0) { return error; } + } + } + } + lfn_index = update_entry->num_entry_LFNs; + if (lfn_index != 0 && (update_entry->small_letter_flag & 0x18) == 0) { + sector = update_entry->entry_sector; + next_sector = previous_chain; + while (lfn_index >= 1) { + PFENT_storeLFNEntryFieldsToBuf(entry_buffer, update_entry, lfn_index, + update_entry->check_sum, lfn_index == update_entry->num_entry_LFNs); + error = PFSEC_WriteData(volume, entry_buffer, sector, update_entry->entry_offset, 32, &written, 0); + if (error != 0) { return error; } + if (written != 32) { return 0x11; } + update_entry->entry_offset += 32; + if (update_entry->entry_offset >= volume->bpb.bytes_per_sector) { + update_entry->entry_offset = 0; + sector = *next_sector++; + } + lfn_index--; + } + update_entry->entry_sector = sector; + } + error = PFENT_updateEntry(update_entry, 1); + if (error != 0) { allocation_error = error; } + return allocation_error; } pf_s32 PFDIR_p_fsexec_remove(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter) { PFDIR_VOLUME_DIRS* volume_dirs = (PFDIR_VOLUME_DIRS*)entry->p_vol; PFDIR_FAT_HINT hint; PF_ENT_ITER directory_iter; - pf_u32 is_empty = 0; + pf_u32 is_empty; pf_s32 index = 0; pf_u32 start_cluster; pf_u32 chain_size; @@ -1061,99 +1376,83 @@ pf_s32 PFDIR_p_fsexec_opendir(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter ((PFDIR_VOLUME_DIRS*)data->p_vol)->num_opened_directories++; return error; } - pf_s32 PFDIR_p_fsexec(PF_DTA* data, pf_u32 flags, pf_u32 mode) { + PF_DIR_ENT entry; PF_ENT_ITER iter; PFDIR_FFD ffd; PFDIR_FAT_HINT hint; - PF_DIR_ENT entry; + pf_s8 dot_name[11]; PFDIR_STR pattern; - pf_u32 logical_position; - pf_u32 entry_position; + PFDIR_STR long_pattern; + pf_u32 found; pf_u32 start_position; - pf_u32 code_mode; - const pf_s8* name; + pf_u32 attr_flags = flags & 6; + pf_u32 direct; pf_s32 error; - if ((flags & 6) == 0 && (flags & 1) == 0 && (flags & 0x10) == 0 && (flags & 0x20) == 0) { - return 10; - } - if ((flags & 6) != 0 || (flags & 1) != 0 || ((flags & 0x10) != 0 && mode != 2)) { - error = PFVOL_CheckForWrite(data->p_vol); - if (error != 0) { - return error; + if (attr_flags != 0 || (flags & 1) != 0 || (flags & 0x10) != 0 || (flags & 0x20) != 0) { + if (attr_flags != 0 || (flags & 1) != 0 || ((flags & 0x10) != 0 && mode != 2)) { + error = PFVOL_CheckForWrite(data->p_vol); + if (error != 0) { return error; } } - } - entry.start_cluster = data->parent_start_cluster; - entry.check_sum = 0; - PFFAT_InitFFD(&ffd, &hint, data->p_vol, &entry.start_cluster); - iter.p_vol = data->p_vol; - iter.ffd = ffd; - start_position = data->parent_pos - 1; - if ((flags & 0x80000000) == 0) { - start_position -= data->num_entry_LFNs; - } - error = PFENT_ITER_IteratorInitialize(&iter, start_position); - if (error != 0) { - return error; - } - if ((data->status & 1) == 1) { - code_mode = 1; - name = data->FileName; - } else { - code_mode = 2; - if ((pf_vol_set.setting & 2) != 0) { - name = (const pf_s8*)((PF_DTAW*)data)->LongNameW; - } else { - name = (const pf_s8*)((PF_DTAW*)data)->FileNameW; - } - } - error = PFSTR_InitStr(&pattern, name, code_mode); - if (error != 0) { - return error; - } - if ((pf_vol_set.setting & 2) != 0) { - PFSTR_SetLocalStr(&pattern, (pf_u32)data->LongName); - } else { - PFSTR_SetLocalStr(&pattern, (pf_u32)data->FileName); - } - error = PFENT_findEntryPos(&ffd, &entry, start_position, &pattern, 0x7F, 0, - &logical_position, &entry_position); - if (error != 0) { - return error; - } - if ((flags & 0x80000000) == 0) { - if ((data->status & 2) != 0) { - if (PFPATH_cmpNameUni(entry.long_name, &pattern) != 0) { - return 3; + entry.short_name[0] = 0; + entry.start_cluster = data->parent_start_cluster; + PFFAT_InitFFD(&ffd, &hint, data->p_vol, &entry.start_cluster); + iter.ffd = ffd; + direct = flags & 0x80000000; + start_position = data->parent_pos - 1; + if (direct == 0) { start_position -= data->num_entry_LFNs; } + error = PFENT_ITER_IteratorInitialize(&iter, start_position); + if (error != 0) { return error; } + if (direct == 0) { + if ((data->status & 1) == 1) { + error = PFSTR_InitStr(&pattern, data->FileName, 1); + } else if ((pf_vol_set.setting & 2) == 2) { + error = PFSTR_InitStr(&pattern, (const pf_s8*)((PF_DTAW*)data)->LongNameW, 2); + } else { + error = PFSTR_InitStr(&pattern, (const pf_s8*)((PF_DTAW*)data)->FileNameW, 2); } - } else if (PFPATH_cmpName(entry.short_name, &pattern, 1) != 0) { - return 3; + if (error != 0) { return error; } + if ((pf_vol_set.setting & 2) == 2) { + PFSTR_SetLocalStr(&pattern, (pf_u32)data->LongName); + } else { PFSTR_SetLocalStr(&pattern, (pf_u32)data->FileName); } + error = PFENT_ITER_FindEntryNoPathCheck(&iter, &entry, &pattern, 0x7F, 0, &found); + if (error != 0) { return error; } + if ((data->status & 2) != 2 || (pf_vol_set.setting & 2) != 2) { + if (PFPATH_cmpName(entry.short_name, &pattern, 1) != 0) { return 3; } + } + error = PFSTR_InitStr(&long_pattern, data->LongName, 1); + if (error != 0) { return error; } + PFSTR_SetLocalStr(&long_pattern, (pf_u32)data->LongName); + if (PFPATH_cmpNameUni(entry.long_name, &long_pattern) != 0) { return 3; } + } else { + if (iter.buf[0] == 0 || iter.buf[0] == 0xE5) { return 3; } + if ((flags & 0x20) == 0 && (iter.buf[11] & 0x18) != 0) { return 3; } + if ((flags & 0x20) != 0 && ((iter.buf[11] & 0x10) == 0 || (iter.buf[11] & 8) != 0)) { return 0x14; } + error = PFENT_ITER_GetEntryOfIter(&iter, &entry); + if (error != 0) { return error; } } - } - if (entry.short_name[0] == '.' && - ((entry.short_name[1] == ' ' && entry.short_name[2] == ' ') || entry.short_name[1] == '.')) { - return 0x1C; - } - error = PFENT_ITER_MoveTo(&iter, entry_position, 0); - if (error != 0) { - return error; - } - if ((flags & 6) != 0) { - return PFDIR_p_fsexec_chmod(data, &entry, mode, flags); - } - if ((flags & 1) != 0) { - return PFDIR_p_fsexec_remove(data, &entry, &iter); - } - if ((flags & 0x10) != 0) { - return PFDIR_p_fsexec_fopen(data, &entry, &iter, flags, mode); - } - if ((flags & 0x20) != 0) { - return PFDIR_p_fsexec_opendir(data, &entry, &iter, flags); + set_dot_entry((pf_u8*)dot_name); + if (pf_strncmp(entry.short_name, dot_name, 1) == 0) { return 0x1C; } + set_dot_dot_entry((pf_u8*)dot_name); + if (pf_strncmp(entry.short_name, dot_name, 2) == 0) { return 0x1C; } + if (attr_flags != 0) { + error = PFDIR_p_fsexec_chmod(data, &entry, flags, mode); + } else if ((flags & 1) != 0) { + error = PFDIR_p_fsexec_remove(data, &entry, &iter); + } else if ((flags & 0x10) != 0) { + error = PFDIR_p_fsexec_fopen(data, &entry, &iter, flags, mode); + } else { + if ((flags & 0x20) != 0) { error = PFDIR_p_fsexec_opendir(data, &entry, &iter, flags); } + } + goto done; } return 10; +done: + return error; } + void PFDIR_FinalizeAllDirs(PF_VOLUME* volume) { PFDIR_VOLUME_DIRS* volume_dirs = (PFDIR_VOLUME_DIRS*)volume; pf_u16 index; @@ -1211,7 +1510,7 @@ void PFDIR_fsexec(PF_DTA* data, pf_u32 flags, pf_u32 mode) { ((PFDIR_VOLUME_DIRS*)volume)->last_error = error; return; } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; error = PFDIR_p_fsexec(data, flags, mode); if (error != 0) { pf_vol_set.last_error = error; @@ -1223,7 +1522,7 @@ void PFDIR_fsexec(PF_DTA* data, pf_u32 flags, pf_u32 mode) { ((PFDIR_VOLUME_DIRS*)volume)->last_error = error; } } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; } void PFDIR_fstat(PF_STR* path, PFDIR_FILE_STAT* file_stat) { @@ -1252,7 +1551,7 @@ void PFDIR_rename(PF_STR* old_path, PF_STR* new_path) { ((PFDIR_VOLUME_DIRS*)volume)->last_error = error; return; } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; error = PFDIR_p_rename(volume, old_path, new_path); if (error != 0) { pf_vol_set.last_error = error; @@ -1270,7 +1569,7 @@ void PFDIR_rename(PF_STR* old_path, PF_STR* new_path) { } } } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; } void PFDIR_move(PF_STR* old_path, PF_STR* new_path) { @@ -1283,7 +1582,7 @@ void PFDIR_move(PF_STR* old_path, PF_STR* new_path) { ((PFDIR_VOLUME_DIRS*)volume)->last_error = error; return; } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; error = PFDIR_p_move(volume, old_path, new_path); if (error != 0) { pf_vol_set.last_error = error; @@ -1301,7 +1600,7 @@ void PFDIR_move(PF_STR* old_path, PF_STR* new_path) { } } } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; } pf_s32 PFDIR_opendir(PF_STR* path, PFDIR_DIR** dir) { @@ -1421,7 +1720,7 @@ void PFDIR_rmdir(PF_STR* path) { ((PFDIR_VOLUME_DIRS*)volume)->last_error = error; return; } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; error = PFDIR_p_rmdir(volume, (PFDIR_STR*)path); if (error != 0) { pf_vol_set.last_error = error; @@ -1433,7 +1732,7 @@ void PFDIR_rmdir(PF_STR* path) { ((PFDIR_VOLUME_DIRS*)volume)->last_error = error; } } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; } void PFDIR_mkdir(PF_STR* path) { @@ -1446,7 +1745,7 @@ void PFDIR_mkdir(PF_STR* path) { ((PFDIR_VOLUME_DIRS*)volume)->last_error = error; return; } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; error = PFDIR_p_mkdir(volume, path, 0, 0); if (error != 0) { pf_vol_set.last_error = error; @@ -1464,7 +1763,7 @@ void PFDIR_mkdir(PF_STR* path) { } } } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; } void PFDIR_createdir(PF_STR* path, pf_u32 option, PF_DTA* data) { @@ -1477,7 +1776,7 @@ void PFDIR_createdir(PF_STR* path, pf_u32 option, PF_DTA* data) { ((PFDIR_VOLUME_DIRS*)volume)->last_error = error; return; } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; error = PFDIR_p_mkdir(volume, path, option, data); if (error != 0) { pf_vol_set.last_error = error; @@ -1495,7 +1794,7 @@ void PFDIR_createdir(PF_STR* path, pf_u32 option, PF_DTA* data) { } } } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; } pf_s32 PFDIR_chdir(PF_STR* path) { @@ -1558,7 +1857,7 @@ void PFDIR_chmod(PF_STR* path, pf_u8 attributes) { ((PFDIR_VOLUME_DIRS*)volume)->last_error = error; return; } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; error = PFDIR_p_chmod(volume, (PFDIR_STR*)path, attributes); if (error != 0) { pf_vol_set.last_error = error; @@ -1576,7 +1875,7 @@ void PFDIR_chmod(PF_STR* path, pf_u8 attributes) { } } } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; } void PFDIR_chdmod(PF_STR* path, pf_u8 attributes) { @@ -1589,7 +1888,7 @@ void PFDIR_chdmod(PF_STR* path, pf_u8 attributes) { ((PFDIR_VOLUME_DIRS*)volume)->last_error = error; return; } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; error = PFDIR_p_chmod(volume, (PFDIR_STR*)path, (pf_u8)(attributes | 0x10)); if (error != 0) { pf_vol_set.last_error = error; @@ -1607,7 +1906,7 @@ void PFDIR_chdmod(PF_STR* path, pf_u8 attributes) { } } } - volume_dirs->cache_signature = 0; + volume_dirs->cache.signature = 0; } pf_s32 PFDIR_p_fsnext(PF_DTA* data) { @@ -1641,6 +1940,7 @@ pf_s32 PFDIR_p_fsnext(PF_DTA* data) { if (error != 0) { return error; } data->parent_pos = entry_position + 1; if (entry_position == 999999) { return 3; } + else { break; } } pf_strcpy(data->FileName, entry.short_name); if ((data->status & 2) == 2) { diff --git a/libs/RevoEX/src/nwc24/NWC24Download.c b/libs/RevoEX/src/nwc24/NWC24Download.c index e06f710e..a415c41c 100644 --- a/libs/RevoEX/src/nwc24/NWC24Download.c +++ b/libs/RevoEX/src/nwc24/NWC24Download.c @@ -167,6 +167,92 @@ static inline NWC24Err ClearDlTaskEntry(u16 taskId, NWC24File* file) { return WriteDlTaskEntry(task, file); } + + +static inline NWC24Err ReadDlTaskInline(NWC24DlTask* dlTask, NWC24DlId dlId) { + DlTaskListHeader* header; + NWC24File file; + NWC24Err result; + NWC24Err operationResult; + + if (NWC24WorkP != NULL) { + header = (DlTaskListHeader*)NWC24WorkP->dlHead; + } else { + header = NULL; + } + if (header == NULL) { + return NWC24_ERR_LIB_NOT_OPENED; + } + if (NWC24WorkP != NULL) { + header = (DlTaskListHeader*)NWC24WorkP->dlHead; + } else { + header = NULL; + } + if (dlId >= header->maxTaskCount || dlId == 0xffff) { + result = NWC24_ERR_INVALID_VALUE; + } else { + if (NWC24WorkP != NULL) { + header = (DlTaskListHeader*)NWC24WorkP->dlHead; + } else { + header = NULL; + } + if (header->entries[dlId].appId == 0) { + result = NWC24_ERR_NOT_FOUND; + } else { + result = NWC24_OK; + } + } + if (result < NWC24_OK) { + return result; + } + + result = NWC24FOpen(&file, DLFilePath, 0x0a); + if (result < NWC24_OK) { + return result; + } + + if (NWC24WorkP != NULL) { + header = (DlTaskListHeader*)NWC24WorkP->dlHead; + } else { + header = NULL; + } + if (header->maxTaskCount > NWC24_DL_TASK_MAX || dlId >= header->maxTaskCount) { + operationResult = NWC24_ERR_INVALID_VALUE; + } else { + operationResult = NWC24FSeek(&file, 0x800 + dlId * 0x200, NWC24_SEEK_BEG); + } + if (operationResult < NWC24_OK) { + result = operationResult; + } else { + operationResult = NWC24FRead(dlTask, 0x200, &file); + result = NWC24_OK; + if (operationResult < NWC24_OK) { + result = operationResult; + } + } + operationResult = NWC24FClose(&file); + if (result != NWC24_OK) { + return result; + } + return operationResult; +} + +static inline NWC24Err RemoveDlTask(NWC24DlTask* dlTask) { + NWC24Err result = ValidateDlTask(dlTask, FALSE); + if (result != NWC24_OK) { return result; } + result = DeleteDlTask(dlTask); + if (result < NWC24_OK) { return result; } + ((DlTaskData*)dlTask)->id = 0xffff; + return result; +} + +static inline NWC24Err GetMaxDlTaskCount(u16* count) { + DlTaskListHeader* header = GetCachedDlHeader(); + if (header == NULL) { return NWC24_ERR_LIB_NOT_OPENED; } + *count = header->maxTaskCount; + return NWC24_OK; +} + NWC24Err NWC24InitDlTask(NWC24DlTask* dlTask, NWC24DLType dlType) { char homePath[64] = {0}; u32 nwc24IdHigh; @@ -212,49 +298,12 @@ NWC24Err NWC24InitDlTask(NWC24DlTask* dlTask, NWC24DLType dlType) { task->interval = 0x0b40; task->intervalWait = 0x05a0; - useContentFile = FALSE; - if (dlType == NWC24_DLTYPE_OCTETSTREAM_V1 || dlType == NWC24_DLTYPE_OCTETSTREAM_V2) { - useContentFile = TRUE; - } + useContentFile = dlType == NWC24_DLTYPE_OCTETSTREAM_V1 || dlType == NWC24_DLTYPE_OCTETSTREAM_V2; if (useContentFile) { strcpy(task->fileName, "content.bin"); } - if (NWC24WorkP != NULL) { - header = (DlTaskListHeader*)NWC24WorkP->dlHead; - } else { - header = NULL; - } - if (dlTask == NULL) { - return NWC24_ERR_INVALID_VALUE; - } - if (header == NULL) { - return NWC24_ERR_LIB_NOT_OPENED; - } - - result = NWC24_OK; - allowed = NWC24IsMsgLibOpenedByTool(); - if (!allowed) { - u32 taskAppId = task->appId; - u32 appId = NWC24GetAppId(); - allowed = (taskAppId & 0xffffff00) == (appId & 0xffffff00); - if (!allowed) { - allowed = FALSE; - if (task->flags & 0x40) { - if (task->groupId == NWC24GetGroupId()) { - allowed = TRUE; - } - } - if (!allowed) { - result = NWC24_ERR_PROTECTED; - } - } - } - - if (result == NWC24_OK && task->id != 0xffff && task->id >= header->maxTaskCount) { - result = NWC24_ERR_INVALID_VALUE; - } - + result = ValidateDlTask(dlTask, TRUE); return result >> 31; } @@ -295,6 +344,27 @@ NWC24Err NWC24SetDlPriority(NWC24DlTask* dlTask, u8 dlPriority) { return NWC24_OK; } + + +static inline NWC24Err SetDlTaskNextTime(NWC24DlTask* dlTask, OSTime time) { + NWC24Work* work = NWC24WorkP; + DlTaskListHeader* header = work != NULL ? (DlTaskListHeader*)work->dlHead : NULL; + DlTaskData* task = (DlTaskData*)dlTask; + NWC24Err result; + u16 taskId; + if (task == NULL) { result = NWC24_ERR_INVALID_VALUE; } + else if (header == NULL) { result = NWC24_ERR_LIB_NOT_OPENED; } + else if (task->id != 0xffff && task->id >= header->maxTaskCount) { result = NWC24_ERR_INVALID_VALUE; } + else { result = NWC24_OK; } + if (result != NWC24_OK) { return result; } + taskId = task->id; + if (taskId == 0xffff) { return NWC24_ERR_FAILED; } + time /= 60; + header = work != NULL ? (DlTaskListHeader*)work->dlHead : NULL; + header->entries[taskId].nextTime = time; + return NWC24_OK; +} + NWC24Err NWC24SetDlInterval(NWC24DlTask* dlTask, u16 dlInterval) { DlTaskListHeader* header; DlTaskData* task; @@ -367,6 +437,13 @@ NWC24Err NWC24SetDlInterval(NWC24DlTask* dlTask, u16 dlInterval) { return NWC24_OK; } +static inline NWC24Err CheckDlUrlString(const char* url) { + NWC24Err result = NWC24iCheckStringLength(url, 7, 0x100); + if (result < NWC24_OK) { return result; } + if (strncmp(url, "http://", 7) != 0 && strncmp(url, "https://", 8) != 0) { return NWC24_ERR_FORMAT; } + return NWC24_OK; +} + NWC24Err NWC24SetDlUrl(NWC24DlTask* dlTask, const char* dlUrl) { DlTaskData* task; NWC24Err result; @@ -376,18 +453,8 @@ NWC24Err NWC24SetDlUrl(NWC24DlTask* dlTask, const char* dlUrl) { return result; } task = (DlTaskData*)dlTask; - result = NWC24iCheckStringLength(dlUrl, 7, 0x100); - if (result < NWC24_OK) { - return result; - } - if (strncmp(dlUrl, "http://", 7) != 0 && strncmp(dlUrl, "https://", 8) != 0) { - result = NWC24_ERR_FORMAT; - } else { - result = NWC24_OK; - } - if (result < NWC24_OK) { - return result; - } + result = CheckDlUrlString(dlUrl); + if (result < NWC24_OK) { return result; } task = (DlTaskData*)dlTask; if (!NWC24iLaxParameterCheck && (task->flags & 0x4) && strncmp(dlUrl, "http://", 7) == 0) { @@ -418,6 +485,9 @@ NWC24Err NWC24SetDlFlags(NWC24DlTask* dlTask, u32 dlFlags) { } break; } + case NWC24_DLTYPE_MULTIPART_V2: + case NWC24_DLTYPE_OCTETSTREAM_V2: + break; default: break; } @@ -507,7 +577,7 @@ NWC24Err NWC24IterateDlTask(NWC24DlId* dlIterateId, BOOL begin) { return NWC24_ERR_DONE; } - do { + for (; taskId < maxTaskCount; taskId++) { if (work != NULL) { header = (DlTaskListHeader*)work->dlHead; } else { @@ -525,15 +595,14 @@ NWC24Err NWC24IterateDlTask(NWC24DlId* dlIterateId, BOOL begin) { header = NULL; } result = NWC24_ERR_NOT_FOUND; - if (header->entries[taskId].appId == 0) { + if (header->entries[taskId].appId != 0) { result = NWC24_OK; } if (result >= NWC24_OK) { *dlIterateId = taskId; return result; } - taskId++; - } while (taskId < header->maxTaskCount); + } return NWC24_ERR_DONE; } @@ -571,7 +640,7 @@ NWC24Err NWC24IterateDlTaskEx(NWC24DlIterateWork* dlIterateWork, NWC24DlId* dlIt result = NWC24IterateDlTask(&taskId, TRUE); while (result >= NWC24_OK) { value = getValue(taskId); - if (value == state->comparisonValue && taskId > state->comparisonId) { + if (value == state->comparisonValue && (s32)taskId > (s32)state->comparisonId) { *dlIterateId = taskId; state->comparisonValue = value; state->selectedValue = value; @@ -584,22 +653,22 @@ NWC24Err NWC24IterateDlTaskEx(NWC24DlIterateWork* dlIterateWork, NWC24DlId* dlIt state->initialized = 0; } - state->comparisonValue = descending ? 0x80000001 : 0x7fffffff; + state->comparisonValue = (state->sortMode & 0x80000000) ? 0x80000001 : 0x7fffffff; result = NWC24IterateDlTask(&taskId, TRUE); while (result >= NWC24_OK) { value = getValue(taskId); if (descending) { - passesSelected = value <= state->selectedValue; + passesSelected = value < state->selectedValue; } else { - passesSelected = value >= state->selectedValue; + passesSelected = value > state->selectedValue; } - if (!passesSelected) { + if (passesSelected) { if (descending) { bestCandidate = value > state->comparisonValue; } else { bestCandidate = value < state->comparisonValue; } - if (!bestCandidate) { + if (bestCandidate) { *dlIterateId = taskId; state->comparisonValue = value; state->comparisonId = taskId; @@ -617,288 +686,116 @@ NWC24Err NWC24IterateDlTaskEx(NWC24DlIterateWork* dlIterateWork, NWC24DlId* dlIt return NWC24_ERR_DONE; } +static inline NWC24Err SetDlTaskAccessTime(NWC24DlTask* dlTask, OSTime time) { + NWC24Work* work = NWC24WorkP; + DlTaskListHeader* header = work != NULL ? (DlTaskListHeader*)work->dlHead : NULL; + DlTaskData* task = (DlTaskData*)dlTask; + NWC24Err result; + u16 taskId; + if (task == NULL) { result = NWC24_ERR_INVALID_VALUE; } + else if (header == NULL) { result = NWC24_ERR_LIB_NOT_OPENED; } + else if (task->id != 0xffff && task->id >= header->maxTaskCount) { result = NWC24_ERR_INVALID_VALUE; } + else { result = NWC24_OK; } + if (result != NWC24_OK) { return result; } + taskId = task->id; + if (taskId == 0xffff) { return NWC24_ERR_FAILED; } + time /= 60; + header = work != NULL ? (DlTaskListHeader*)work->dlHead : NULL; + header->entries[taskId].lastAccess = time; + return NWC24_OK; +} + +static inline NWC24Err CheckDlTaskRetry(NWC24DlTask* dlTask, u8 retryCount) { + DlTaskData* task = (DlTaskData*)dlTask; + NWC24Err result = ValidateDlTask(dlTask, FALSE); + u32 retryMask; + if (result != NWC24_OK) { return result; } + if (task->retryEnabled == 0) { return NWC24_ERR_INVALID_OPERATION; } + retryMask = task->retryMask; + if (retryMask == 0) { return NWC24_ERR_FATAL; } + if (retryCount > 31) { return NWC24_ERR_INVALID_VALUE; } + if ((retryMask & (1 << retryCount)) == 0) { return NWC24_ERR_DISABLED; } + return NWC24_OK; +} NWC24Err NWC24UpdateDlTask(NWC24DlTask* dlTask) { DlTaskData* task = (DlTaskData*)dlTask; - NWC24DlId taskId; - NWC24Err result; - OSTime universalTime; DlTaskListHeader* header; + u16 taskId; + OSTime universalTime; + NWC24Err result; result = ValidateDlTask(dlTask, TRUE); - if (result != NWC24_OK) { - return result; - } - task = (DlTaskData*)dlTask; + if (result != NWC24_OK) { return result; } taskId = task->id; - if (taskId != 0xffff) { - if (NWC24WorkP != NULL) { - header = (DlTaskListHeader*)NWC24WorkP->dlHead; - } else { - header = NULL; - } - if (header == NULL) { - return NWC24_ERR_LIB_NOT_OPENED; - } - if (taskId >= header->maxTaskCount) { - return NWC24_ERR_INVALID_VALUE; - } - - result = NWC24iGetUniversalTime(&universalTime); - if (result >= NWC24_OK) { - if (NWC24WorkP != NULL) { - header = (DlTaskListHeader*)NWC24WorkP->dlHead; - } else { - header = NULL; - } - result = NWC24_OK; - if (dlTask == NULL) { - result = NWC24_ERR_INVALID_VALUE; - } else if (header == NULL) { - result = NWC24_ERR_LIB_NOT_OPENED; - } else { - taskId = task->id; - if (taskId == 0xffff) { - result = NWC24_ERR_FAILED; - } else if (taskId >= header->maxTaskCount) { - result = NWC24_ERR_INVALID_VALUE; - } - } - if (result >= NWC24_OK) { - header->entries[taskId].lastAccess = universalTime / 60; - } - } - if (result < NWC24_OK) { - return result; - } + if (taskId == 0xffff || taskId >= GetCachedDlHeader()->maxTaskCount) { return NWC24_ERR_INVALID_VALUE; } + result = NWC24iGetUniversalTime(&universalTime); + if (result >= NWC24_OK) { + result = SetDlTaskAccessTime(dlTask, universalTime); + if (result < NWC24_OK) { return result; } } - - if (NWC24WorkP != NULL) { - header = (DlTaskListHeader*)NWC24WorkP->dlHead; - } else { - header = NULL; - } - result = NWC24_OK; - if (dlTask == NULL) { - result = NWC24_ERR_INVALID_VALUE; - } else if (header == NULL) { - result = NWC24_ERR_LIB_NOT_OPENED; - } else { - if (!NWC24IsMsgLibOpenedByTool()) { - u32 taskAppId = task->appId; - u32 appId = NWC24GetAppId(); - BOOL allowed = (taskAppId & 0xffffff00) == (appId & 0xffffff00); - if (!allowed && (task->flags & 0x40)) { - allowed = task->groupId == NWC24GetGroupId(); - } - if (!allowed) { - result = NWC24_ERR_PROTECTED; - } - } - taskId = task->id; - if (result == NWC24_OK && taskId != 0xffff && taskId >= header->maxTaskCount) { - result = NWC24_ERR_INVALID_VALUE; - } - } - - if (result == NWC24_OK && task->id != 0xffff) { + if (result < NWC24_OK) { return result; } + result = ValidateDlTask(dlTask, TRUE); + if (result == NWC24_OK) { task->unknown_0x20 = 0; task->unknown_0x1a = 0; } - if (task->retryEnabled == 1) { - do { - u8 retryCount; - u32 retryMask; - + for (;;) { + result = CheckDlTaskRetry(dlTask, task->retryCount); + if (result != NWC24_ERR_DISABLED) { break; } task->retryCount = (task->retryCount + 1) & 0x1f; - if (NWC24WorkP != NULL) { - header = (DlTaskListHeader*)NWC24WorkP->dlHead; - } else { - header = NULL; - } - if (dlTask == NULL) { - return NWC24_ERR_INVALID_VALUE; - } - if (header == NULL) { - return NWC24_ERR_LIB_NOT_OPENED; - } - if (!NWC24IsMsgLibOpenedByTool()) { - u32 taskAppId = task->appId; - u32 appId = NWC24GetAppId(); - BOOL allowed = (taskAppId & 0xffffff00) == (appId & 0xffffff00); - if (!allowed && (task->flags & 0x40)) { - allowed = task->groupId == NWC24GetGroupId(); - } - if (!allowed) { - return NWC24_ERR_PROTECTED; - } - } - taskId = task->id; - if (taskId != 0xffff && taskId >= header->maxTaskCount) { - return NWC24_ERR_INVALID_VALUE; - } - if (task->retryEnabled == 0) { - return NWC24_ERR_INVALID_OPERATION; - } - retryCount = task->retryCount; - retryMask = task->retryMask; - if (retryMask == 0) { - return NWC24_ERR_FATAL; - } - if (retryCount > 0x1f) { - return NWC24_ERR_INVALID_VALUE; - } - result = NWC24_OK; - if ((retryMask & (1 << retryCount)) == 0) { - result = NWC24_ERR_DISABLED; - } - } while (result == NWC24_ERR_DISABLED); - if (result < NWC24_OK) { - return result; } + if (result < NWC24_OK) { return result; } } - return StoreDlTask(dlTask); } - NWC24Err NWC24DeleteDlTask(NWC24DlTask* dlTask) { - DlTaskData* task; - DlTaskListHeader* header; NWC24Err result; - - if (NWC24GetAppId() == 0x48414541) { - result = NWC24_OK; - } else { - header = GetCachedDlHeader(); - - if (dlTask == NULL) { - return NWC24_ERR_INVALID_VALUE; - } - if (header == NULL) { - return NWC24_ERR_LIB_NOT_OPENED; - } - - task = (DlTaskData*)dlTask; - if (!NWC24IsMsgLibOpenedByTool()) { - u32 taskAppId = task->appId; - u32 appId = NWC24GetAppId(); - BOOL allowed = (taskAppId & 0xffffff00) == (appId & 0xffffff00); - if (!allowed && (task->flags & 0x40)) { - allowed = task->groupId == NWC24GetGroupId(); - } - if (!allowed) { - return NWC24_ERR_PROTECTED; - } - } - - if (task->id != 0xffff && task->id >= header->maxTaskCount) { - return NWC24_ERR_INVALID_VALUE; - } - result = NWC24_OK; - } - - if (result != NWC24_OK) { - return result; - } - - header = GetCachedDlHeader(); - if (dlTask == NULL) { - return NWC24_ERR_INVALID_VALUE; - } - if (header == NULL) { - return NWC24_ERR_LIB_NOT_OPENED; - } - - task = (DlTaskData*)dlTask; - if (task->id != 0xffff && task->id >= header->maxTaskCount) { - return NWC24_ERR_INVALID_VALUE; - } - - result = DeleteDlTask(dlTask); - if (result >= NWC24_OK) { - task->id = 0xffff; - } - return result; + if (NWC24GetAppId() != 0x48414541) { result = ValidateDlTask(dlTask, TRUE); } + else { result = NWC24_OK; } + if (result != NWC24_OK) { return result; } + return RemoveDlTask(dlTask); } + +static inline NWC24Err CheckDlTaskListHeader(DlTaskListHeader* header) { + if (header->maxTaskCount < 1 || header->taskCount < 1 || header->maxTaskCount < header->taskCount) { return NWC24_ERR_BROKEN; } + return NWC24_OK; +} NWC24Err NWC24AddDlTask(NWC24DlTask* dlTask) { - DlTaskListHeader* header; + DlTaskListHeader* header = GetCachedDlHeader(); NWC24File file; NWC24Err result; OSTime universalTime; - s64 nextTime; - s32 intervalSeconds; - u16 taskCount; - u16 maxTaskCount; - u16 taskId; - if (NWC24WorkP != NULL) { - header = (DlTaskListHeader*)NWC24WorkP->dlHead; - } else { - header = NULL; - } if (header->maxTaskCount == 0 && header->legacyTaskCount != 0) { header->maxTaskCount = header->legacyTaskCount; - if (header->legacyTaskCount > 0x20) { - header->legacyTaskCount = 0x20; - } + if (header->legacyTaskCount > 32) { header->legacyTaskCount = 32; } result = NWC24FOpen(&file, DLFilePath, 4); if (result >= NWC24_OK) { result = NWC24FSeek(&file, 0, NWC24_SEEK_BEG); - if (result >= NWC24_OK) { - result = NWC24FWrite(header, 0x800, &file); - } + if (result >= NWC24_OK) { NWC24FWrite(GetCachedDlHeader(), 0x800, &file); } NWC24FClose(&file); } } - - if (header->maxTaskCount < 1 || header->taskCount < 1 || header->maxTaskCount < header->taskCount) { - return NWC24_ERR_BROKEN; - } - - taskCount = header->taskCount; - maxTaskCount = header->maxTaskCount; - result = AddTaskInternal(dlTask, taskCount, maxTaskCount); - if (result < NWC24_OK) { - return result; - } - + result = CheckDlTaskListHeader(header); + if (result < NWC24_OK) { return result; } + result = AddTaskInternal(dlTask, GetCachedDlHeader()->taskCount, GetCachedDlHeader()->maxTaskCount); + if (result < NWC24_OK) { return result; } universalTime = 0; result = NWC24iGetUniversalTime(&universalTime); - if (result < NWC24_OK) { - return result; - } - + if (result < NWC24_OK) { return result; } + { + s32 intervalSeconds; + s64 nextTime; intervalSeconds = ((DlTaskData*)dlTask)->interval * 60; nextTime = universalTime + intervalSeconds; - if (NWC24WorkP != NULL) { - header = (DlTaskListHeader*)NWC24WorkP->dlHead; - } else { - header = NULL; + return SetDlTaskNextTime(dlTask, nextTime); } - - result = NWC24_OK; - if (dlTask == NULL) { - result = NWC24_ERR_INVALID_VALUE; - } else if (header == NULL) { - result = NWC24_ERR_LIB_NOT_OPENED; - } else { - taskId = ((DlTaskData*)dlTask)->id; - if (taskId == 0xffff) { - result = NWC24_ERR_FAILED; - } else if (taskId >= header->maxTaskCount) { - result = NWC24_ERR_INVALID_VALUE; - } - } - - if (result >= NWC24_OK) { - nextTime /= 60; - header->entries[taskId].nextTime = nextTime; - } - return result; } + NWC24Err NWC24GetDlTask(NWC24DlTask* dlTask, NWC24DlId dlId) { DlTaskListHeader* header; NWC24File file; @@ -985,9 +882,6 @@ NWC24Err NWC24PurgeOldestDlTask() { state.comparisonId = 0xffffffff; state.initialized = 1; state.valid = 1; - taskId = 0; - - header = GetCachedDlHeader(); result = NWC24_OK; do { @@ -1007,152 +901,22 @@ NWC24Err NWC24PurgeOldestDlTask() { taskPointer = &task; selectedId = taskId; - header = GetCachedDlHeader(); - if (header == NULL) { - return NWC24_ERR_LIB_NOT_OPENED; - } - if (selectedId >= header->maxTaskCount || selectedId == 0xffff) { - return NWC24_ERR_INVALID_VALUE; - } - header = GetCachedDlHeader(); - if (header->entries[selectedId].appId == 0) { - return NWC24_ERR_NOT_FOUND; - } - - result = NWC24FOpen(&file, DLFilePath, 0x0a); - if (result < NWC24_OK) { - return result; - } - - header = GetCachedDlHeader(); - if (header->maxTaskCount > NWC24_DL_TASK_MAX || selectedId >= header->maxTaskCount) { - result = NWC24_ERR_INVALID_VALUE; - } else { - result = NWC24FSeek(&file, 0x800 + selectedId * 0x200, NWC24_SEEK_BEG); - } - if (result >= NWC24_OK) { - result = NWC24FRead(taskPointer, sizeof(task), &file); - } - closeResult = NWC24FClose(&file); - if (result < NWC24_OK) { - return result; - } - result = closeResult; - if (result < NWC24_OK) { - return result; - } - - header = GetCachedDlHeader(); - if (header == NULL) { - result = NWC24_ERR_LIB_NOT_OPENED; - } else if (((DlTaskData*)taskPointer)->id == 0xffff || ((DlTaskData*)taskPointer)->id >= header->maxTaskCount) { - result = NWC24_ERR_INVALID_VALUE; - } else { - result = NWC24_OK; - } - if (result == NWC24_OK) { - result = DeleteDlTask(taskPointer); - } - if (result >= NWC24_OK) { - ((DlTaskData*)taskPointer)->id = 0xffff; - } - return result; + result = ReadDlTaskInline(taskPointer, selectedId); + if (result < NWC24_OK) { return result; } + return RemoveDlTask(taskPointer); } - NWC24Err NWC24ManageDlTaskListForMenu() { - DlTaskListHeader* header; - NWC24File file; NWC24DlTask task; - NWC24Err result; - NWC24Err closeResult; - - if (NWC24WorkP != NULL) { - header = (DlTaskListHeader*)NWC24WorkP->dlHead; - } else { - header = NULL; - } - result = NWC24_OK; - if (header == NULL) { - result = NWC24_ERR_LIB_NOT_OPENED; - } - if (result < NWC24_OK) { - return result; - } - if (header->maxTaskCount >= NWC24_DL_TASK_MAX) { - return result; - } - + u16 maxTaskCount; + NWC24Err result = GetMaxDlTaskCount(&maxTaskCount); + if (result < NWC24_OK) { return result; } + if (maxTaskCount >= NWC24_DL_TASK_MAX) { return NWC24_OK; } result = NWC24ExtendDlTaskList(NWC24_DL_TASK_MAX); - if (result < NWC24_OK) { - return result; - } - if (NWC24WorkP != NULL) { - header = (DlTaskListHeader*)NWC24WorkP->dlHead; - } else { - header = NULL; - } - result = NWC24_OK; - if (header == NULL) { - result = NWC24_ERR_LIB_NOT_OPENED; - } else if (header->maxTaskCount <= 2) { - result = NWC24_ERR_INVALID_VALUE; - } else if (header->entries[2].appId == 0) { - result = NWC24_ERR_NOT_FOUND; - } - if (result < NWC24_OK) { - return result; - } - - result = NWC24FOpen(&file, DLFilePath, 0x0a); - if (result < NWC24_OK) { - return result; - } - - if (NWC24WorkP != NULL) { - header = (DlTaskListHeader*)NWC24WorkP->dlHead; - } else { - header = NULL; - } - if (header == NULL) { - result = NWC24_ERR_LIB_NOT_OPENED; - } else if (header->maxTaskCount > NWC24_DL_TASK_MAX || header->maxTaskCount <= 2) { - result = NWC24_ERR_INVALID_VALUE; - } else { - result = NWC24FSeek(&file, 0xc00, NWC24_SEEK_BEG); - } - if (result >= NWC24_OK) { - result = NWC24FRead(&task, sizeof(task), &file); - } - closeResult = NWC24FClose(&file); - if (result >= NWC24_OK) { - result = closeResult; - } - if (result == NWC24_ERR_NOT_FOUND) { - return NWC24_OK; - } - if (result < NWC24_OK) { - return result; - } - - if (NWC24WorkP != NULL) { - header = (DlTaskListHeader*)NWC24WorkP->dlHead; - } else { - header = NULL; - } - if (header == NULL) { - result = NWC24_ERR_LIB_NOT_OPENED; - } else if (((DlTaskData*)&task)->id == 0xffff || ((DlTaskData*)&task)->id >= header->maxTaskCount) { - result = NWC24_ERR_INVALID_VALUE; - } else { - result = NWC24_OK; - } - if (result == NWC24_OK) { - result = DeleteDlTask(&task); - } - if (result >= NWC24_OK) { - ((DlTaskData*)&task)->id = 0xffff; - } - return result; + if (result < NWC24_OK) { return result; } + result = ReadDlTaskInline(&task, 2); + if (result == NWC24_ERR_NOT_FOUND) { return NWC24_OK; } + if (result < NWC24_OK) { return result; } + return RemoveDlTask(&task); } NWC24Err NWC24GetDlOptOutFlags(NWC24DlTask* dlTask, u8* dlOptOutFlags) { @@ -1265,84 +1029,44 @@ closeList: } NWC24Err NWC24iCheckDlHeaderConsistency(DlTaskListHeader* header, BOOL repair) { - NWC24DlId taskId; NWC24DlTask task; - NWC24File file; - DlTaskListHeader* currentHeader; + NWC24DlTask* taskPointer = &task; + NWC24DlId taskId; NWC24Err result; - NWC24Err closeResult; + DlTaskListHeader* currentHeader; + DlTaskListHeader* listHeader = header; + BOOL shouldRepair = repair; - for (taskId = 0; taskId < header->maxTaskCount; taskId++) { + for (taskId = 0; taskId < listHeader->maxTaskCount; taskId++) { currentHeader = GetCachedDlHeader(); - result = NWC24_OK; - if (currentHeader == NULL) { - result = NWC24_ERR_LIB_NOT_OPENED; - } else if (taskId >= currentHeader->maxTaskCount || taskId == 0xffff) { + if (taskId >= currentHeader->maxTaskCount || taskId == 0xffff) { result = NWC24_ERR_INVALID_VALUE; - } else if (currentHeader->entries[taskId].appId == 0) { - result = NWC24_ERR_NOT_FOUND; - } - if (result < NWC24_OK) { - continue; - } - - if (repair) { + } else { currentHeader = GetCachedDlHeader(); result = NWC24_OK; - if (currentHeader == NULL) { - result = NWC24_ERR_LIB_NOT_OPENED; - } else if (taskId >= currentHeader->maxTaskCount || taskId == 0xffff) { - result = NWC24_ERR_INVALID_VALUE; - } else if (currentHeader->entries[taskId].appId == 0) { - result = NWC24_ERR_NOT_FOUND; - } - if (result < NWC24_OK) { - continue; - } - - result = NWC24FOpen(&file, DLFilePath, 0x0a); - if (result < NWC24_OK) { - return result; + if (currentHeader->entries[taskId].appId == 0) { result = NWC24_ERR_NOT_FOUND; } + } + if (result != NWC24_OK || !shouldRepair) { continue; } + result = ReadDlTaskInline(taskPointer, taskId); + if (result < NWC24_OK) { + if (ValidateDlTask(taskPointer, FALSE) == NWC24_OK) { + result = DeleteDlTask(taskPointer); + if (result >= NWC24_OK) { ((DlTaskData*)taskPointer)->id = 0xffff; } } + } else { currentHeader = GetCachedDlHeader(); - if (currentHeader == NULL) { - result = NWC24_ERR_LIB_NOT_OPENED; - } else if (currentHeader->maxTaskCount > NWC24_DL_TASK_MAX || taskId >= currentHeader->maxTaskCount) { - result = NWC24_ERR_INVALID_VALUE; - } else { - result = NWC24FSeek(&file, 0x800 + taskId * 0x200, NWC24_SEEK_BEG); - } - if (result >= NWC24_OK) { - result = NWC24FRead(&task, sizeof(task), &file); - } - closeResult = NWC24FClose(&file); - if (result >= NWC24_OK) { - result = closeResult; - } - if (result == NWC24_ERR_NOT_FOUND) { - continue; - } - if (result < NWC24_OK) { - return result; - } - currentHeader = GetCachedDlHeader(); - if (currentHeader != NULL && taskId >= currentHeader->taskCount && ((DlTaskData*)&task)->subTaskCount == 0) { - if (((DlTaskData*)&task)->id == 0xffff || ((DlTaskData*)&task)->id >= currentHeader->maxTaskCount) { - result = NWC24_ERR_INVALID_VALUE; - } else { - result = DeleteDlTask(&task); + if (taskId >= currentHeader->taskCount && (s16)((DlTaskData*)taskPointer)->subTaskCount == 0) { + if (ValidateDlTask(taskPointer, FALSE) == NWC24_OK) { + result = DeleteDlTask(taskPointer); + if (result >= NWC24_OK) { ((DlTaskData*)taskPointer)->id = 0xffff; } } - if (result < NWC24_OK) { - return result; - } - ((DlTaskData*)&task)->id = 0xffff; } } } - return NWC24_OK; } + NWC24Err NWC24iCreateDlTaskList() { u16 taskId; DlTaskListHeader* header; @@ -1426,14 +1150,12 @@ NWC24Err NWC24iLoadDlHeader() { closeResult = NWC24FSeek(&file, 0, NWC24_SEEK_BEG); if (closeResult < NWC24_OK) { - return closeResult; - } - - closeResult = NWC24FRead(NWC24WorkP->dlHead, 0x800, &file); - result = closeResult < NWC24_OK ? closeResult : NWC24_OK; - if (result < NWC24_OK) { - return result; + result = closeResult; + } else { + closeResult = NWC24FRead(NWC24WorkP->dlHead, 0x800, &file); + result = closeResult < NWC24_OK ? closeResult : NWC24_OK; } + if (result < NWC24_OK) { return result; } result = NWC24FGetLength(&file, &fileLength); if (result >= NWC24_OK) { @@ -1497,196 +1219,86 @@ NWC24Err StoreDlTask(NWC24DlTask* dlTask) { return closeResult; } -NWC24Err AddTaskInternal(NWC24DlTask* dlTask, u16 taskCount, u16 maxTaskCount) { - DlTaskData* task; - DlTaskListHeader* header; +static inline NWC24Err ValidateDlTaskUrl(NWC24DlTask* dlTask) { + DlTaskData* task = (DlTaskData*)dlTask; + DlTaskListHeader* header = GetCachedDlHeader(); NWC24Err result; + if (task->id >= header->maxTaskCount && task->id != 0xffff) { return NWC24_ERR_INVALID_VALUE; } + result = NWC24iCheckStringLength(task->url, 7, 0x100); + if (result >= NWC24_OK) { + if (strncmp(task->url, "http://", 7) != 0 && strncmp(task->url, "https://", 8) != 0) { result = NWC24_ERR_FORMAT; } + else { result = NWC24_OK; } + } + if (result < NWC24_OK) { return result; } + return NWC24_OK; +} + +static inline NWC24Err FindFreeDlTask(NWC24DlTask* dlTask, u16 taskCount, u16 maxTaskCount) { + DlTaskListHeader* header = GetCachedDlHeader(); + NWC24DlId taskId; + if (dlTask == NULL || taskCount > maxTaskCount || taskCount >= header->maxTaskCount || maxTaskCount > header->maxTaskCount) { + return NWC24_ERR_INVALID_VALUE; + } + for (taskId = taskCount; taskId < maxTaskCount; taskId++) { + header = GetCachedDlHeader(); + if (header->entries[taskId].appId == 0) { + ((DlTaskData*)dlTask)->id = taskId; + return NWC24_OK; + } + } + return NWC24_ERR_FULL; +} + +static inline NWC24Err UpdateDlTaskInline(NWC24DlTask* dlTask) { + DlTaskData* task = (DlTaskData*)dlTask; + DlTaskListHeader* header; u16 taskId; - char* url; OSTime universalTime; + NWC24Err result; result = ValidateDlTask(dlTask, TRUE); - if (result != NWC24_OK) { - return result; - } - task = (DlTaskData*)dlTask; + if (result != NWC24_OK) { return result; } taskId = task->id; - url = task->url; - result = NWC24iCheckStringLength(url, 7, 0x100); - if (result >= NWC24_OK && strncmp(url, "http://", 7) != 0 && strncmp(url, "https://", 8) != 0) { - result = NWC24_ERR_FORMAT; + if (taskId == 0xffff || taskId >= GetCachedDlHeader()->maxTaskCount) { return NWC24_ERR_INVALID_VALUE; } + result = NWC24iGetUniversalTime(&universalTime); + if (result >= NWC24_OK) { + result = SetDlTaskAccessTime(dlTask, universalTime); + if (result < NWC24_OK) { return result; } } - if (result < NWC24_OK) { - return result; + if (result < NWC24_OK) { return result; } + result = ValidateDlTask(dlTask, TRUE); + if (result == NWC24_OK) { + task->unknown_0x20 = 0; + task->unknown_0x1a = 0; } - -retryExistingTask: - taskId = task->id; - if (taskId != 0xffff) { - header = GetCachedDlHeader(); - - result = NWC24_OK; - if (dlTask == NULL) { - result = NWC24_ERR_INVALID_VALUE; - } else if (header == NULL) { - result = NWC24_ERR_LIB_NOT_OPENED; - } else { - if (!NWC24IsMsgLibOpenedByTool()) { - u32 taskAppId = task->appId; - u32 appId = NWC24GetAppId(); - BOOL allowed = (taskAppId & 0xffffff00) == (appId & 0xffffff00); - if (!allowed && (task->flags & 0x40)) { - allowed = task->groupId == NWC24GetGroupId(); - } - if (!allowed) { - result = NWC24_ERR_PROTECTED; - } - } - taskId = task->id; - if (result == NWC24_OK && taskId != 0xffff && taskId >= header->maxTaskCount) { - result = NWC24_ERR_INVALID_VALUE; - } + if (task->retryEnabled == 1) { + for (;;) { + result = CheckDlTaskRetry(dlTask, task->retryCount); + if (result != NWC24_ERR_DISABLED) { break; } + task->retryCount = (task->retryCount + 1) & 0x1f; } - if (result < NWC24_OK) { - return result; - } - - header = GetCachedDlHeader(); - if (taskId >= header->maxTaskCount) { - return NWC24_ERR_INVALID_VALUE; - } - - result = NWC24iGetUniversalTime(&universalTime); - if (result >= NWC24_OK) { - header = GetCachedDlHeader(); - result = NWC24_OK; - if (dlTask == NULL) { - result = NWC24_ERR_INVALID_VALUE; - } else if (header == NULL) { - result = NWC24_ERR_LIB_NOT_OPENED; - } else { - taskId = task->id; - if (taskId == 0xffff) { - result = NWC24_ERR_FAILED; - } else if (taskId >= header->maxTaskCount) { - result = NWC24_ERR_INVALID_VALUE; - } - } - if (result >= NWC24_OK) { - header->entries[taskId].nextTime = universalTime / 60; - } - } - if (result < NWC24_OK) { - return result; - } - - header = GetCachedDlHeader(); - result = NWC24_OK; - if (dlTask == NULL) { - result = NWC24_ERR_INVALID_VALUE; - } else if (header == NULL) { - result = NWC24_ERR_LIB_NOT_OPENED; - } else { - if (!NWC24IsMsgLibOpenedByTool()) { - u32 taskAppId = task->appId; - u32 appId = NWC24GetAppId(); - BOOL allowed = (taskAppId & 0xffffff00) == (appId & 0xffffff00); - if (!allowed && (task->flags & 0x40)) { - allowed = task->groupId == NWC24GetGroupId(); - } - if (!allowed) { - result = NWC24_ERR_PROTECTED; - } - } - taskId = task->id; - if (result == NWC24_OK && taskId != 0xffff && taskId >= header->maxTaskCount) { - result = NWC24_ERR_INVALID_VALUE; - } - } - - if (result == NWC24_OK && task->id != 0xffff) { - task->unknown_0x20 = 0; - task->unknown_0x1a = 0; - } - - if (task->retryEnabled == 1) { - do { - u8 retryCount; - u32 retryMask; - - task->retryCount = (task->retryCount + 1) & 0x1f; - header = GetCachedDlHeader(); - if (dlTask == NULL) { - return NWC24_ERR_INVALID_VALUE; - } - if (header == NULL) { - return NWC24_ERR_LIB_NOT_OPENED; - } - if (!NWC24IsMsgLibOpenedByTool()) { - u32 taskAppId = task->appId; - u32 appId = NWC24GetAppId(); - BOOL allowed = (taskAppId & 0xffffff00) == (appId & 0xffffff00); - if (!allowed && (task->flags & 0x40)) { - allowed = task->groupId == NWC24GetGroupId(); - } - if (!allowed) { - return NWC24_ERR_PROTECTED; - } - } - taskId = task->id; - if (taskId != 0xffff && taskId >= header->maxTaskCount) { - return NWC24_ERR_INVALID_VALUE; - } - if (task->retryEnabled == 0) { - return NWC24_ERR_INVALID_OPERATION; - } - retryCount = task->retryCount; - retryMask = task->retryMask; - if (retryMask == 0) { - return NWC24_ERR_FATAL; - } - if (retryCount > 0x1f) { - return NWC24_ERR_INVALID_VALUE; - } - result = NWC24_OK; - if ((retryMask & (1 << retryCount)) == 0) { - result = NWC24_ERR_DISABLED; - } - } while (result == NWC24_ERR_DISABLED); - if (result < NWC24_OK) { - return result; - } - } - return StoreDlTask(dlTask); + if (result < NWC24_OK) { return result; } } - + return StoreDlTask(dlTask); +} +NWC24Err AddTaskInternal(NWC24DlTask* dlTask, u16 taskCount, u16 maxTaskCount) { + DlTaskData* task = (DlTaskData*)dlTask; + NWC24Err result; + result = ValidateDlTask(dlTask, TRUE); + if (result != NWC24_OK) { return result; } + result = ValidateDlTaskUrl(dlTask); + if (result < NWC24_OK) { return result; } for (;;) { - u16 currentTaskId; - - header = GetCachedDlHeader(); - if (dlTask == NULL || header == NULL || taskCount > maxTaskCount || taskCount >= header->maxTaskCount || - maxTaskCount > header->maxTaskCount) { - return NWC24_ERR_INVALID_VALUE; - } - - currentTaskId = taskCount; - while (currentTaskId < maxTaskCount) { - header = GetCachedDlHeader(); - if (header->entries[currentTaskId].appId == 0) { - task->id = currentTaskId; - goto retryExistingTask; - } - currentTaskId++; - } - - result = NWC24PurgeOldestDlTask(); - if (result < NWC24_OK) { - return result; - } - goto retryExistingTask; + if (task->id != 0xffff) { return UpdateDlTaskInline(dlTask); } + result = FindFreeDlTask(dlTask, taskCount, maxTaskCount); + if (result == NWC24_ERR_FULL) { + result = NWC24PurgeOldestDlTask(); + if (result < NWC24_OK) { return result; } + } else if (result < NWC24_OK) { return result; } } } + NWC24Err DeleteDlTask(NWC24DlTask* dlTask) { NWC24File file; NWC24Err result; diff --git a/src/keyboard/tiCellPhone.cpp b/src/keyboard/tiCellPhone.cpp index 4fb592d9..38cbd730 100644 --- a/src/keyboard/tiCellPhone.cpp +++ b/src/keyboard/tiCellPhone.cpp @@ -1,3 +1,5 @@ +#define TI_CELLPHONE_MATCH_LAYOUT +#define TI_CELLPHONE_HKB_KEYSET #define TI_CELLPHONE_IMPLEMENTATION #define TI_CELLPHONE_SAMPLE_CLASS #define MYTIMANAGER_IMPLEMENTATION @@ -231,164 +233,136 @@ namespace textinput { void Base::calc() {} + static inline const PaneNameToCharCode* findKeyForPane(const PaneNameToCharCode* keys, const char* paneName) { + for (u16 index = 0; index < 12; index++) { + if (util::strcmp(keys[index].szPaneName, paneName)) { return &keys[index]; } + } + return NULL; + } + void Base::onKey(u32 event, void* data) { - struct KeyEvent { - const char* paneName; - u8 state; + struct KeyEvent { const char* paneName; u8 state; }; + struct ConfirmInput { + wchar_t character; + u16 letterMode; + bool direct; + bool held; + bool confirmOnly; + bool silent; + const PaneNameToCharCode* holdingKey; }; - - struct KeyInputData { - u16 character; - u16 inputMode; - u32 state; - const PaneNameToCharCode* pane; - }; - - const KeyEvent& keyEvent = *static_cast(data); - - if (!mbInputModeLocked && event == gui::EventHandler::ON_TRIG) { - u32 controlKey; - u16 i; - for (i = 0; i < 12; ++i) { - if (util::strcmp(csPaneNameToControlKey[i].name, keyEvent.paneName)) { - controlKey = csPaneNameToControlKey[i].controlKey; - goto controlKeyFound; + if (mbInputModeLocked) { return; } + const char* paneName = static_cast(data)->paneName; + if (event == gui::EventHandler::ON_TRIG) { + u8 state = static_cast(data)->state; + s32 controlKey = 0x1B; + for (u16 index = 0; index < 12; index++) { + if (util::strcmp(csPaneNameToControlKey[index].name, paneName)) { + controlKey = csPaneNameToControlKey[index].controlKey; + break; } } - controlKey = 0x1B; - - controlKeyFound: if (controlKey != 0x1B) { onCtrlKey_(static_cast(controlKey)); - } else { - bool useKeySetInput = isZiActive(); - if (!useKeySetInput) { - Language language = getLanguage(); - if (language == CN) { - useKeySetInput = true; - } else if (getLanguage() == KR && mHoldingButton != 0) { - useKeySetInput = true; - } else if (getInputType() == 1) { - useKeySetInput = true; + } else if (!isZiActive() || getLanguage() == CN || + (getLanguage() == KR && mCurrentInputMode != 0) || getInputType() == 1) { + LanguageDependencyData* inputModeTable = static_cast(mpInputModeTable); + if (mHoldingButton == NULL) { + u32 inputMode = mCurrentInputMode; + if (getLanguage() == JP && inputMode == IM_02) { + if (!mbUpperCaseMode) { inputMode = IM_04; } + } else if (inputModeTable->keySets[inputMode]->uType == KEY_TYPE_ABC_UPPER && !mbUpperCaseMode) { + inputMode = IM_01; + } + const PaneNameToCharCode* keys = inputModeTable->keySets[inputMode]->pPaneNameToCharCode; + mHoldingButton = findKeyForPane(keys, paneName); + if (state) { + mPreviousInputMode = 15; + while (mHoldingButton->wc[mPreviousInputMode] == 0) { mPreviousInputMode--; } + } else { mPreviousInputMode = 0; } + } else { + if (state) { mPreviousInputMode--; } + else { mPreviousInputMode++; } + if (mPreviousInputMode == 16) { mPreviousInputMode = 0; } + else if (static_cast(mPreviousInputMode) < 0) { + mPreviousInputMode = 15; + while (mHoldingButton->wc[mPreviousInputMode] == 0) { mPreviousInputMode--; } + } + if (mHoldingButton->wc[mPreviousInputMode] == 0) { mPreviousInputMode = 0; } + } + if (mHoldingButton) { + ConfirmInput commandData = {0}; + commandData.character = mHoldingButton->wc[mPreviousInputMode]; + commandData.holdingKey = mHoldingButton; + if (getInputType() == 1 && mHoldingButton->wc[1] != L'0' && mHoldingButton->wc[0] != L' ') { + commandData.direct = true; + } + if (getLanguage() == KR && mCurrentInputMode != 0) { commandData.direct = true; } + if (getLanguage() == CN && mCurrentInputMode != 0) { commandData.direct = true; } + if (mHoldingButton->wc[1] == 0) { + if (mbNumericWithDotMode && commandData.character == L'*') { commandData.character = L'.'; } + sendCommand(5, &commandData); + mPreviousInputMode = 0; + mHoldingButton = NULL; + } else { + if (getLanguage() == JP && commandData.character == L' ' && + getInputMode() != IM_04 && getInputMode() != IM_02) { commandData.character = 0x3000; } + sendCommand(3, &commandData); } } - - if (useKeySetInput) { - LanguageDependencyData* inputModeTable = static_cast(mpInputModeTable); - const KeySet* keySet = inputModeTable->keySets[mCurrentInputMode]; - - if (mHoldingButton == 0) { - if (getLanguage() == JP && mCurrentInputMode == IM_02 && !mbUpperCaseMode) { - mCurrentInputMode = IM_04; - } else if (keySet->uType == KEY_TYPE_ABC_UPPER && !mbUpperCaseMode) { - mCurrentInputMode = IM_01; - } - - keySet = inputModeTable->keySets[mCurrentInputMode]; - for (u16 i = 0; i < 12; ++i) { - if (util::strcmp(keySet->pPaneNameToCharCode[i].szPaneName, keyEvent.paneName)) { - mHoldingButton = &keySet->pPaneNameToCharCode[i]; - break; - } - } - - const PaneNameToCharCode* pane = mHoldingButton; - if (keyEvent.state) { - mPreviousInputMode = 15; - while (pane && pane->wc[mPreviousInputMode] == 0) { - --mPreviousInputMode; - } + } else { + const PaneNameToCharCode* keys = csKeySetNumber.pPaneNameToCharCode; + for (u16 index = 0; index < 12; index++) { + const PaneNameToCharCode* pane = &keys[index]; + if (util::strcmp(pane->szPaneName, paneName)) { + wchar_t character = pane->wc[0]; + ConfirmInput commandData = {0}; + commandData.character = character; + commandData.letterMode = mCurrentInputMode; + commandData.holdingKey = mHoldingButton; + bool convertSpace = false; + sendCommand(0x20, &convertSpace); + if (character == L'0' && getLanguage() != KR) { + if (convertSpace) { sendCommand(6, NULL); } + ConfirmInput spaceInput = {L' ', 0, true, false, true, false, NULL}; + spaceInput.letterMode = mCurrentInputMode; + spaceInput.holdingKey = mHoldingButton; + sendCommand(5, &spaceInput); + mPreviousInputMode = 0; + mHoldingButton = NULL; } else { - mPreviousInputMode = 0; - } - } else if (keyEvent.state) { - --mPreviousInputMode; - if (static_cast(mPreviousInputMode) < 0) { - mPreviousInputMode = 15; - const PaneNameToCharCode* pane = mHoldingButton; - while (pane->wc[mPreviousInputMode] == 0) { - --mPreviousInputMode; - } - } - } else { - ++mPreviousInputMode; - if (mPreviousInputMode == 16) { - mPreviousInputMode = 0; - } - } - - const PaneNameToCharCode* pane = mHoldingButton; - if (pane && pane->wc[mPreviousInputMode] == 0) { - mPreviousInputMode = 0; - } - - if (pane) { - KeyInputData commandData = {0, 0, 0, NULL}; - commandData.character = pane->wc[mPreviousInputMode]; - commandData.inputMode = mCurrentInputMode; - commandData.pane = pane; - - keySet = inputModeTable->keySets[mCurrentInputMode]; - if (getInputType() == 1 && pane->wc[1] != 0x30 && pane->wc[0] != 0x20) { - commandData.state = 1; - } - if (getLanguage() == KR && mCurrentInputMode != 0) { - commandData.state = 1; - } - if (getLanguage() == CN && mCurrentInputMode != 0) { - commandData.state = 1; - } - - if (keySet->uNum == 0) { - if (mbNumericWithDotMode && commandData.character == 0x2A) { - commandData.character = 0x2E; + const LanguageDependencyData* table = static_cast(mpInputModeTable); + const PaneNameToCharCode* currentKeys = table->keySets[mCurrentInputMode]->pPaneNameToCharCode; + commandData.holdingKey = findKeyForPane(currentKeys, paneName); + if (table->keySets[mCurrentInputMode]->uType == KEY_TYPE_ABC_UPPER && !mbAbcMode) { + commandData.letterMode = IM_01; + currentKeys = table->keySets[IM_01]->pPaneNameToCharCode; + commandData.holdingKey = findKeyForPane(currentKeys, paneName); } + commandData.character = convertToZiCellphoneInput_(commandData.character); sendCommand(5, &commandData); - mPreviousInputMode = 0; - mHoldingButton = 0; - } else { - if (!isZiActive() && commandData.character == 0x20 && - getInputMode() != IM_04 && getInputMode() != IM_02) { - commandData.character = 0x3000; - } - sendCommand(3, &commandData); - } - } - } else { - const KeySet& numberKeySet = csKeySetNumber; - for (u16 i = 0; i < 12; ++i) { - const PaneNameToCharCode& pane = numberKeySet.pPaneNameToCharCode[i]; - if (util::strcmp(pane.szPaneName, keyEvent.paneName)) { - KeyInputData commandData = {pane.wc[0], static_cast(mCurrentInputMode), 0, NULL}; - sendCommand(0x20, &commandData); - - if (getLanguage() == KR && pane.wc[0] == 0x30) { - break; - } - - if (mbNumericWithDotMode && commandData.character == 0x2A) { - commandData.character = 0x2E; - } else { - commandData.character = convertToZiCellphoneInput_(commandData.character); - } - sendCommand(5, &commandData); - break; } } } } } - - if (event == gui::EventHandler::ON_LEFT && mHoldingButton != 0) { - const PaneNameToCharCode* pane = mHoldingButton; - if (util::strcmp(keyEvent.paneName, pane->szPaneName)) { - u16 character = pane->wc[mPreviousInputMode]; + if (event == gui::EventHandler::ON_LEFT && mHoldingButton != NULL) { + if (util::strcmp(paneName, mHoldingButton->szPaneName)) { + wchar_t character = mHoldingButton->wc[mPreviousInputMode]; if (character != 0x309B && character != 0x309C) { - KeyInputData commandData = {character, static_cast(mCurrentInputMode), 0, pane}; + if (getLanguage() == JP && character == L' ' && getInputMode() != IM_04 && getInputMode() != IM_02) { + character = 0x3000; + } + ConfirmInput commandData = {0, 0, false, false, true, false, NULL}; + commandData.character = character; + commandData.holdingKey = mHoldingButton; + if (getInputType() == 1) { commandData.direct = true; } + if (getLanguage() == KR && mCurrentInputMode != 0) { commandData.direct = true; } + if (getLanguage() == CN && mCurrentInputMode != 0) { commandData.direct = true; } sendCommand(5, &commandData); } mPreviousInputMode = 0; - mHoldingButton = 0; + mHoldingButton = NULL; } } } @@ -456,8 +430,6 @@ namespace textinput { bool Base::onClose() {} void Base::changeInputMode(InputMode mode) { - u8 activeData[4]; - u8 inactiveData[4]; mCurrentInputMode = mode; if (getLanguage()) { mbUpperCaseMode = true; @@ -469,12 +441,12 @@ namespace textinput { } if (mode == IM_00) { - activeData[0] = 1; - sendCommand(0x13, activeData); + struct ActiveMode { bool enabled; } activeData = {true}; + sendCommand(0x13, &activeData); } if (mode == IM_01) { - inactiveData[0] = 0; - sendCommand(0x13, inactiveData); + struct InactiveMode { bool enabled; } inactiveData = {false}; + sendCommand(0x13, &inactiveData); } updateFixMode(); @@ -550,18 +522,16 @@ namespace textinput { void Base::onActive() { u32 commandData = 0; - u8 activeData[4]; - u8 inactiveData[4]; sendCommand(0x12, &commandData); if (mCurrentInputMode == IM_00) { - activeData[0] = 1; - sendCommand(0x13, activeData); + struct ActiveMode { bool enabled; } activeData = {true}; + sendCommand(0x13, &activeData); } if (static_cast(mCurrentInputMode) == IM_01) { - inactiveData[0] = 0; - sendCommand(0x13, inactiveData); + struct InactiveMode { bool enabled; } inactiveData = {false}; + sendCommand(0x13, &inactiveData); } if (mCurrentInputMode == IM_00) { @@ -690,24 +660,21 @@ namespace textinput { mpPaneManager->setAllBoundingBoxComponentTriggerTarget(true); for (u16 i = 0; i < sizeof(csPaneNameNormalAnimationKey) / sizeof(csPaneNameNormalAnimationKey[0]); ++i) { - const PaneNameToAnimationKey& paneName = csPaneNameNormalAnimationKey[i]; void* paneMemory = MEMAllocFromAllocator(allocator, sizeof(CellPhoneAnmPane)); - CellPhoneAnmPane* pane; + CellPhoneAnmPane* pane = static_cast(paneMemory); if (paneMemory) { - pane = new (paneMemory) CellPhoneAnmPane(getPane(paneName.name), NULL); - pane->init(); - pane->changeAnimation(pane->getAnimationState()); - } else { - pane = NULL; + pane = new (paneMemory) CellPhoneAnmPane(getPane(csPaneNameNormalAnimationKey[i].name), NULL); } nw4r::ut::List_Append(&mAnmPanes, pane); + const PaneNameToAnimationKey& paneName = csPaneNameNormalAnimationKey[i]; + const char* animationKey = paneName.animationKey; for (u16 j = 0; j < 5; ++j) { const AnimationFileForControlKey& animation = csAninationFileForControlKey[j]; void* resource = mpMultiArcResourceAccessor->GetResource(0, animation.filename); AnimTransformPane* transform = static_cast( getLayout()->CreateAnimTransform(resource, mpMultiArcResourceAccessor)); - if (paneName.animationKey) { + if (animationKey) { pane->forceAddAnimation(allocator, animation.animation, transform, paneName.animationKey, false, true); } else { @@ -717,24 +684,21 @@ namespace textinput { } for (u16 i = 0; i < sizeof(csPaneNameToggleAnimationKey) / sizeof(csPaneNameToggleAnimationKey[0]); ++i) { - const PaneNameToAnimationKey& paneName = csPaneNameToggleAnimationKey[i]; void* paneMemory = MEMAllocFromAllocator(allocator, sizeof(CellPhoneControlAnmPane)); - CellPhoneControlAnmPane* pane; + CellPhoneControlAnmPane* pane = static_cast(paneMemory); if (paneMemory) { - pane = new (paneMemory) CellPhoneControlAnmPane(getPane(paneName.name), NULL); - pane->init(); - pane->changeAnimation(pane->getAnimationState()); - } else { - pane = NULL; + pane = new (paneMemory) CellPhoneControlAnmPane(getPane(csPaneNameToggleAnimationKey[i].name), NULL); } nw4r::ut::List_Append(&mAnmPanes, pane); + const PaneNameToAnimationKey& paneName = csPaneNameToggleAnimationKey[i]; + const char* animationKey = paneName.animationKey; for (u16 j = 0; j < 6; ++j) { const AnimationFileForControlKey& animation = csAninationFileForControlKey[j]; void* resource = mpMultiArcResourceAccessor->GetResource(0, animation.filename); AnimTransformPane* transform = static_cast( getLayout()->CreateAnimTransform(resource, mpMultiArcResourceAccessor)); - if (paneName.animationKey) { + if (animationKey) { pane->forceAddAnimation(allocator, animation.animation, transform, paneName.animationKey, false, true); } else { @@ -743,14 +707,12 @@ namespace textinput { } } - for (u32 i = 0; i < 3; ++i) { - nw4r::lyt::Material* material = mpLayout->GetRootPane()->FindPaneByName(csTexturePaneNames.names[i], true)->GetMaterial(); - material->GetTexture(&mTextures[i], 0); - } - + nw4r::lyt::Pane* rootPane = mpLayout->GetRootPane(); + rootPane->FindPaneByName(csTexturePaneNames.names[0], true)->GetMaterial()->GetTexture(&mTextures[0], 0); + rootPane->FindPaneByName(csTexturePaneNames.names[1], true)->GetMaterial()->GetTexture(&mTextures[1], 0); + rootPane->FindPaneByName(csTexturePaneNames.names[2], true)->GetMaterial()->GetTexture(&mTextures[2], 0); init(); - onActive(); - changeInputMode(static_cast(mCurrentInputMode)); + setLanguage(getLanguage()); } void LayoutByNW4R::init() { @@ -778,14 +740,14 @@ namespace textinput { strncpy(textPaneName, paneName, strlen(paneName)); textPaneName[0] = 'T'; - nw4r::lyt::Pane* textPane = getPane(textPaneName); + nw4r::lyt::TextBox* textPane = static_cast(getPane(textPaneName)); nw4r::lyt::Pane* buttonPane = getPane(paneName); const KeySet* keySet = static_cast(mpInputModeTable)->keySets[i]; if (keySet == NULL) { buttonPane->SetVisible(false); } else { buttonPane->SetVisible(true); - static_cast(textPane)->SetString(keySet->szKeySetName, 0); + textPane->SetString(static_cast(mpInputModeTable)->keySets[i]->szKeySetName, 0); } } @@ -807,7 +769,7 @@ namespace textinput { setVisible(csNumericModePaneNames.spaceJapanese, true); setVisible(csNumericModePaneNames.key09, true); setVisible(csNumericModePaneNames.key11, false); - setLineFeedButton(false); + setPredictLanguageButton(false); } else if (getLanguage() == KR) { setVisible(csNumericModePaneNames.predictionEuropeanMode, true); setVisible(csNumericModePaneNames.othersEuropean, true); @@ -817,7 +779,7 @@ namespace textinput { setVisible(csNumericModePaneNames.spaceJapanese, true); setVisible(csNumericModePaneNames.key09, false); setVisible(csNumericModePaneNames.key11, false); - setLineFeedButton(false); + setPredictLanguageButton(false); } else { setVisible(csNumericModePaneNames.predictionEuropeanMode, true); setVisible(csNumericModePaneNames.othersEuropean, true); @@ -836,7 +798,7 @@ namespace textinput { sendCommand(0x1F, &predictMode); updatePredictLanguage(&predictMode); - nw4rmanager::Layout::initPaneLastDrawReceived(); + static_cast(this)->initPaneLastDrawReceived(); mpLayout->Animate(0); mpLayout->CalculateMtx(mDrawInfo); @@ -860,26 +822,24 @@ namespace textinput { void LayoutByNW4R::update() {} + static inline s32 findCellPhoneControlKey(const char* paneName) { + for (u16 index = 0; index < 12; ++index) { + if (util::strcmp(csPaneNameToControlKey[index].name, paneName)) { + return csPaneNameToControlKey[index].controlKey; + } + } + return 0x1B; + } + void LayoutByNW4R::onKey(u32 event, void* data) { Base::onKey(event, data); if (!mbInputModeLocked) { s32 controlKey; bool isTrigger = event == gui::EventHandler::ON_TRIG; - u16 i; const char* paneName = *static_cast(data); if (isTrigger) { - i = 0; - while (i < 12) { - if (util::strcmp(csPaneNameToControlKey[i].name, paneName)) { - controlKey = csPaneNameToControlKey[i].controlKey; - goto controlKeyFound; - } - ++i; - } - controlKey = 0x1B; - - controlKeyFound: + controlKey = findCellPhoneControlKey(paneName); if (controlKey != 0x1B) { switch (controlKey) { case 9: @@ -915,12 +875,11 @@ namespace textinput { void LayoutByNW4R::onActive() { u32 commandData = 0; u8 inactiveData[4]; - u8 activeData[4]; sendCommand(0x12, &commandData); if (static_cast(mCurrentInputMode) == IM_00) { - activeData[0] = 1; - sendCommand(0x13, activeData); + struct ActiveMode { bool enabled; } activeData = {true}; + sendCommand(0x13, &activeData); } if (static_cast(mCurrentInputMode) == IM_01) { inactiveData[0] = 0; @@ -967,10 +926,12 @@ namespace textinput { } } - if (enabled) { + if (!enabled) { return; } + { setVisible(csNumericModePaneNames.smallCandidateChange, !enabled); setVisible(csNumericModePaneNames.key09, !enabled); setVisible("P_CPkey_dakuten", !enabled); + setVisible(csNumericModePaneNames.smallCandidateChange, !enabled); setVisible(csNumericModePaneNames.predictionEuropeanMode, !enabled); setVisible(csNumericModePaneNames.othersEuropean, !enabled); setVisible(csNumericModePaneNames.spaceJapanese, !enabled); @@ -1012,7 +973,8 @@ namespace textinput { void LayoutByNW4R::doNumericWithDotMode(bool enabled) { doNumericMode(enabled); setString("T_CPkey_11", L"."); - setVisible(csNumericModePaneNames.key11, enabled); + const NumericModePaneNames& paneNames = csNumericModePaneNames; + setVisible(paneNames.key11, enabled); mbNumericWithDotMode = true; } @@ -1020,63 +982,59 @@ namespace textinput { mbLineFeedButton = enabled; setVisible("W_CPkey_LF", mbLineFeedButton); } - bool LayoutByNW4R::updateInput(input::HKBManager& hkbManager) { if (mpManager->getToolBar()->isEnableKeytopChange()) { - const input::HKBManager::KeySet& keySet = hkbManager.GetTriggeredKeySet(); - if (keySet.IsValid()) { + const input::HKBManager::KeySet& triggeredKey = hkbManager.GetTriggeredKeySet(); + if (triggeredKey.IsValid()) { if (mHoldingButton) { - u32 keyData[2] = {reinterpret_cast(mHoldingButton), 0}; - onKey(1, keyData); + struct KeyEvent { const char* paneName; u32 state; } keyEvent = {NULL, 0}; + keyEvent.paneName = mHoldingButton->szPaneName; + onKey(gui::EventHandler::ON_LEFT, &keyEvent); } - changeAnimationAllToNormal(); mpManager->getToolBar()->setQwertyWithSE(true); - if (mpManager->getPCKeyboard()->isABC()) { - return false; - } - mpManager->getPCKeyboard()->setABC(true); - return false; + if (!mpManager->getPCKeyboard()->isABC()) { mpManager->getPCKeyboard()->setABC(true); } } - return false; - } - - { - input::HKBManager::KeySet triggeredKey(hkbManager.GetTriggeredKeySet()); - while (triggeredKey.IsValid()) { - u32 key = triggeredKey.GetKey(); + } else { + input::HKBManager::KeySet keySet(hkbManager.GetTriggeredKeySet()); + while (keySet.IsValid()) { nw4rmanager::AnmPane* pane = NULL; - if (key == 0x58 || key == 0x28) { - if (!(hkbManager.GetModifierState() & 4)) { - pane = searchAnmPane("W_CPkey_LF"); - } - } else { - pane = searchAnmPane(triggeredKey.GetWChar()); + u8 key = keySet.GetKey(); + u32 character = keySet.GetWChar(); + switch (key) { + case 0x58: + case 0x28: + if (!(hkbManager.GetModifierState() & 4)) { pane = searchAnmPane("W_CPkey_LF"); } + break; + default: + pane = searchAnmPane(static_cast(character)); + break; } - if (pane) { - pane->onAnmEvent(nw4rmanager::AnmPane::PE_0); - } - triggeredKey = triggeredKey.GetNext(); + if (pane) { pane->onAnmEvent(nw4rmanager::AnmPane::PE_0); } + keySet = keySet.GetNext(); } - } - - { - input::HKBManager::KeySet repeatedKey(hkbManager.GetRepeatedKeySet()); - while (repeatedKey.IsValid()) { - u32 key = repeatedKey.GetKey(); + keySet = hkbManager.GetRepeatedKeySet(); + while (keySet.IsValid()) { nw4rmanager::AnmPane* pane = NULL; - if (key == 0x4C || (key == 0x2A && !(hkbManager.GetModifierState() & 4))) { + u8 key = keySet.GetKey(); + keySet.GetWChar(); + switch (key) { + case 0x2A: + if (hkbManager.GetModifierState() & 4) { break; } + case 0x4C: pane = searchAnmPane("W_CPkey_DELETE"); + break; + default: + break; } - if (pane) { - pane->onAnmEvent(nw4rmanager::AnmPane::PE_0); - } - repeatedKey = repeatedKey.GetNext(); + if (pane) { pane->onAnmEvent(nw4rmanager::AnmPane::PE_0); } + keySet = keySet.GetNext(); } } return false; } + void LayoutByNW4R::setPredictLanguageButton(bool enabled) { setVisible(csNumericModePaneNames.predictionEuropeanMode, enabled); } @@ -1085,7 +1043,9 @@ namespace textinput { if (!enabled) { setVisible(csNumericModePaneNames.othersEuropean, enabled); setVisible(csNumericModePaneNames.othersJapanese, enabled); - } else { + return; + } + { setVisible(csNumericModePaneNames.othersEuropean, false); setVisible(csNumericModePaneNames.othersJapanese, false); if (getLanguage() == JP) { @@ -1176,7 +1136,6 @@ namespace textinput { } void LayoutByNW4R::changeInputMode(InputMode mode) { - u8 activeData[4]; u8 inactiveData[4]; mCurrentInputMode = mode; if (getLanguage()) { @@ -1189,8 +1148,8 @@ namespace textinput { } if (mode == IM_00) { - activeData[0] = 1; - sendCommand(0x13, activeData); + struct ActiveMode { bool enabled; } activeData = {true}; + sendCommand(0x13, &activeData); } if (mode == IM_01) { inactiveData[0] = 0; @@ -1200,14 +1159,14 @@ namespace textinput { updateFixMode(); sendCommand(0x29, NULL); - u32 keySetIndex = mode; - if (getLanguage() == JP) { - if (static_cast(keySetIndex) == IM_02 && !mbUpperCaseMode) { - keySetIndex = IM_04; + if (getLanguage() == JP) { + if (!mbUpperCaseMode && mode == IM_02) { + mode = IM_04; } - switch (keySetIndex) { + switch (mode) { case IM_00: + case IM_01: setVisible(csNumericModePaneNames.smallCandidateChange, false); setVisible(csNumericModePaneNames.key09, true); setVisible(csNumericModePaneNames.spaceJapanese, true); @@ -1234,8 +1193,9 @@ namespace textinput { } changeKeyTop(static_cast(mpInputModeTable) - ->keySets[keySetIndex]->pPaneNameToCharCode); - nw4rmanager::Layout::initPaneLastDrawReceived(); + ->keySets[mode]->pPaneNameToCharCode); + nw4rmanager::Layout* layout = this; + layout->initPaneLastDrawReceived(); } void LayoutByNW4R::changeKeyTop(const PaneNameToCharCode* keys) { @@ -1252,7 +1212,8 @@ namespace textinput { } void LayoutByNW4R::changeSpaceKeyTop(const PaneNameToCharCode* keys) { - if (getLanguage() != JP) { + if (getLanguage() == JP) { return; } + { char textPaneName[17]; util::replaceChar(textPaneName, sizeof(textPaneName), keys[10].szPaneName, 0, 'T'); nw4r::lyt::Pane* pane = mpLayout->GetRootPane()->FindPaneByName(textPaneName, true); @@ -1349,44 +1310,36 @@ namespace textinput { mpSignWindow->open(static_cast(this), isNumericMode); throwReleaseForAll(); } - + static inline bool isNormalCellPhoneKey(const char* paneName) { + for (int index = 0; index < 12; ++index) { + if (util::strcmp(paneName, csPaneNameNormalKey[index])) { return true; } + } + return false; + } void EventHandler::onTiEvent(gui::PaneComponent* paneComponent, u32 event, Input* input) { const char* paneName = paneComponent->getPane()->GetName(); if (paneName[0] == 'B') { char animationName[17]; util::replaceChar(animationName, sizeof(animationName), paneName, 0, 'W'); CellPhoneAnmPane* animation = static_cast(mpLayoutByNW4R->searchAnmPane(animationName)); - if (animation != NULL) { - switch (event) { - case gui::EventHandler::ON_TRIG: { - bool pressed = (input->field_0x0C & 0x1000) != 0; - bool normalKey = false; - if (!pressed && (input->field_0x0C & 0x800)) { - for (u32 i = 0; i < 12; ++i) { - if (util::strcmp(paneName, csPaneNameNormalKey[i])) { - normalKey = true; - break; - } - } - pressed = normalKey; - } - - if (pressed) { + if (animation) { + switch (static_cast(event)) { + case gui::EventHandler::ON_TRIG: + if ((input->field_0x0C & 0x800) || + ((input->field_0x0C & 0x400) && isNormalCellPhoneKey(paneName))) { if (animation->getKeyType() == KT_ControlButton) { nw4r::ut::List& panes = mpLayoutByNW4R->getAnmPaneList(); CellPhoneAnmPane* other = static_cast(nw4r::ut::List_GetNext(&panes, NULL)); while (other) { if (other != animation && other->getKeyType() == KT_ControlButton) { - other->changeAnimation(ANM_05); + other->onAnmEvent(nw4rmanager::AnmPane::PE_5); } other = static_cast(nw4r::ut::List_GetNext(&panes, other)); } - animation->changeAnimation(ANM_Normal); } animation->onAnmEvent(nw4rmanager::AnmPane::PE_0); } break; - } case gui::EventHandler::ON_LEFT: animation->onAnmEvent(nw4rmanager::AnmPane::PE_2); break; @@ -1400,54 +1353,47 @@ namespace textinput { } } } - struct KeyEvent { const char* paneName; u8 state; u8 repeat; } keyEvent = {paneName, 0, 0}; - if (event == gui::EventHandler::ON_TRIG) { - if (input->field_0x0C & 0x1000) { - mpLayoutByNW4R->onKey(event, &keyEvent); - } else if (input->field_0x0C & 0x800) { - for (u32 i = 0; i < 12; ++i) { - if (util::strcmp(paneName, csPaneNameNormalKey[i])) { - keyEvent.state = 1; - mpLayoutByNW4R->onKey(event, &keyEvent); - paneComponent->setFlightDuration(input->field_0x00, 0); - break; - } - } + if (input->field_0x0C & 0x800) { + keyEvent.state = 0; + mpLayoutByNW4R->onKey(gui::EventHandler::ON_TRIG, &keyEvent); + } else if ((input->field_0x0C & 0x400) && isNormalCellPhoneKey(paneName)) { + keyEvent.state = 1; + mpLayoutByNW4R->onKey(gui::EventHandler::ON_TRIG, &keyEvent); + paneComponent->setFlightDuration(input->field_0x00, 0); } - } else if (event == gui::EventHandler::ON_LEFT) { - mpLayoutByNW4R->onKey(event, &keyEvent); } - - if (event == gui::EventHandler::ON_MOVE && (input->field_0x10 & 0x1000) && - !(input->field_0x0C & 0x1000) && - (util::strcmp(paneName, csPaneNameNormalKey[13]) || - util::strcmp(paneName, csPaneNameNormalKey[16]))) { - if (paneComponent->isDragging(input->field_0x00)) { - u32 duration = mpLayoutByNW4R->getFlightDuration(input->field_0x00, paneName); - if (duration >= 30 && duration % 9 == 0) { - char animationName[17]; - util::replaceChar(animationName, sizeof(animationName), paneName, 0, 'W'); - CellPhoneAnmPane* animation = static_cast(mpLayoutByNW4R->searchAnmPane(animationName)); - if (animation) { - animation->changeAnimation(ANM_Normal); - } - keyEvent.state = 1; - mpLayoutByNW4R->onKey(gui::EventHandler::ON_TRIG, &keyEvent); - } - } - if (mpLayoutByNW4R->getFlightDuration(input->field_0x00, paneName) == 90) { - keyEvent.repeat = 1; - mpLayoutByNW4R->onKey(gui::EventHandler::ON_LEFT, &keyEvent); + if (event == gui::EventHandler::ON_LEFT) { + mpLayoutByNW4R->onKey(gui::EventHandler::ON_LEFT, &keyEvent); + } + if (event == gui::EventHandler::ON_MOVE && (input->field_0x10 & 0x800) && + !(input->field_0x0C & 0x800) && + (util::strcmp(csPaneNameNormalKey[13], paneName) || util::strcmp(csPaneNameNormalKey[16], paneName)) && + paneComponent->isDragging(input->field_0x00)) { + u32 duration = mpLayoutByNW4R->getFlightDuration(input->field_0x00, paneName); + if (duration >= 30 && duration % 9 == 0) { + char animationName[17]; + util::replaceChar(animationName, sizeof(animationName), paneName, 0, 'W'); + CellPhoneAnmPane* animation = static_cast(mpLayoutByNW4R->searchAnmPane(animationName)); + animation->onAnmEvent(nw4rmanager::AnmPane::PE_0); + mpLayoutByNW4R->onKey(gui::EventHandler::ON_TRIG, &keyEvent); } } + if (event == gui::EventHandler::ON_MOVE && mpLayoutByNW4R->getFlightDuration(input->field_0x00, paneName) == 90) { + keyEvent.repeat = 1; + mpLayoutByNW4R->onKey(gui::EventHandler::ON_LEFT, &keyEvent); + } } + + + + void CellPhoneAnmPane::init() { meState = ANM_Normal; } diff --git a/tools/decomp-assist/sol-high-attempts.md b/tools/decomp-assist/sol-high-attempts.md new file mode 100644 index 00000000..6d84d0f7 --- /dev/null +++ b/tools/decomp-assist/sol-high-attempts.md @@ -0,0 +1,165 @@ +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_rename | 1 reconstruct rename allocation rollback and LFN writes from all assembly blocks | BUILD FAILED: dir.d build/43U/src/libs/RVL_SDK/src/fa/pf_dir.d +### mwcceppc.exe Compiler: +# File: libs\RVL_SDK\src\fa\pf_dir.c +# ------------------------------------- +# 782: if (PFSTR_StrNCmp((PFDIR_STR*)new_path, ":", 1, 1, 1) == 0 && +# Error: ^ +# (10209) illegal implicit conversion from 'char[2]' to +# 'const signed char *' +# Too many errors printed, aborting program + +User break, cancelled... +ninja: build stopped: subcommand failed. + +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_rename | 1 completed control flow typed cache and literal argument fixes | objdiff 90.192000% | insns 584/625 | positional diffs 614 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_rename | 2 inline current directory traversal with typed volume state | objdiff 96.568000% | insns 626/625 | positional diffs 619 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_rename | 3 reorder real locals to match target stack lifetimes | objdiff 96.568000% | insns 626/625 | positional diffs 619 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_mkdir | 1 reconstruct all allocation root cluster dot entries and LFN assembly blocks | BUILD FAILED: ------------------------------------- +# 803: pf_u8 attributes, pf_u32 start, pf_u32* found); +# Error: ^ +# (10563) identifier 'PFENT_ITER_FindEntry(...)' redeclared as 'long (struct +# PF_ENT_ITER *, struct PF_DIR_ENT *, struct PFDIR_STR *, unsigned char, +# unsigned long, unsigned long *)' +# Too many errors printed, aborting program + +User break, cancelled... +ninja: build stopped: subcommand failed. + +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_mkdir | 1 complete body with original SDK function declarations | objdiff 92.156586% | insns 550/562 | positional diffs 551 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_mkdir | 2 inline dot directory name stores instead of out of line calls | objdiff 96.887900% | insns 571/562 | positional diffs 559 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_mkdir | 3 explicit sector countdown and separate LFN loop lifetimes | objdiff 96.887900% | insns 571/562 | positional diffs 559 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_move | 1 reconstruct move ancestry checks rollback LFN and dot dot relocation from assembly | objdiff 96.228210% | insns 636/631 | positional diffs 590 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_rename | 4 deletion buffer initializer and signed length checks | objdiff 97.376000% | insns 626/625 | positional diffs 614 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_move | 2 use semantic deletion byte buffer and signed unicode length checks | objdiff 96.980980% | insns 636/631 | positional diffs 563 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_move | 3 split open file index from LFN countdown temporary | objdiff 96.973060% | insns 636/631 | positional diffs 563 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_rmdir | 1 restore original iterator after empty check and preserve cluster before removal | objdiff 99.975250% | insns 202/202 | positional diffs 5 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_rmdir | 2 express free chain error normalization as ternary | objdiff 99.975250% | insns 202/202 | positional diffs 5 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_rmdir | 3 explicit free chain success return | objdiff 99.975250% | insns 202/202 | positional diffs 5 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_fsexec | 1 rebuild direct and searched entry branches from original control flow | objdiff 98.178570% | insns 279/280 | positional diffs 267 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_rmdir | 4 order live hint before saved hint to reproduce stack offsets | objdiff 100.000000% | insns 202/202 | positional diffs 0 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_fsexec | 2 order string locals and express accepted flag branch positively | objdiff 98.142860% | insns 279/280 | positional diffs 267 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_fsexec | 3 preserve result temporary through final dispatch branch | objdiff 98.142860% | insns 279/280 | positional diffs 267 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_GetSDD | 1 increment free candidate before index | objdiff 99.710144% | insns 69/69 | positional diffs 2 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_GetSDD | 2 update candidate in for increment | objdiff 99.681160% | insns 69/69 | positional diffs 2 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_GetSDD | 3 advance candidate by indexed next SDD | objdiff 99.536230% | insns 69/69 | positional diffs 3 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_fsexec_remove | 1 let empty-check output initialize is_empty | objdiff 100.000000% | insns 176/176 | positional diffs 0 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_fsexec_remove | 2 reuse entry attribute temporary for both tests | objdiff 100.000000% | insns 176/176 | positional diffs 0 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_fsexec_remove | 3 narrow empty flag lifetime to directory branch | objdiff 100.000000% | insns 176/176 | positional diffs 0 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_fsnext | 1 exit scan after a real entry is found | objdiff 100.000000% | insns 193/193 | positional diffs 0 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_fsnext | 2 express single lookup as guarded search | objdiff 94.948190% | insns 192/193 | positional diffs 164 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_fsnext | 3 use positive entry result branch | objdiff 100.000000% | insns 193/193 | positional diffs 0 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_GetSDD | 4 move index increment to loop update | objdiff 99.710144% | insns 69/69 | positional diffs 2 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_GetSDD | 5 candidate uses next indexed descriptor | objdiff 95.057970% | insns 72/69 | positional diffs 66 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_GetSDD | 6 scalar descriptor offset drives lookup | objdiff 88.753624% | insns 62/69 | positional diffs 67 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_fsexec | 4 put accepted flag paths inside branch and share invalid return at tail | objdiff 98.803570% | insns 279/280 | positional diffs 38 | regressions 0 +libs/RVL_SDK/src/fa/pf_dir | PFDIR_p_fsexec | 5 put dispatch result after invalid flag return and restore pattern order | objdiff 100.000000% | insns 280/280 | positional diffs 0 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24iCheckDlHeaderConsistency | 1 reconstruct header validation read failure and repair deletion assembly branches | objdiff 98.490560% | insns 212/212 | positional diffs 4 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24UpdateDlTask | 1 reconstruct id rejection access-time validation reset and preincrement retry check from asm | objdiff 90.992096% | insns 247/253 | positional diffs 250 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24iCheckDlHeaderConsistency | 2 signed subtask count and separate task pointer assignment | objdiff 98.773580% | insns 212/212 | positional diffs 3 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24iCheckDlHeaderConsistency | 3 separate list header and repair locals to test prologue scheduling | objdiff 98.773580% | insns 212/212 | positional diffs 3 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | AddTaskInternal | 1 rederive URL validation before retry and full-list allocation loop with existing-task update | objdiff 93.578550% | insns 397/401 | positional diffs 328 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | AddTaskInternal | 2 separate existing task result from free slot branch | objdiff 93.578550% | insns 397/401 | positional diffs 328 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | AddTaskInternal | 3 positive free-slot branch with explicit retry label | objdiff 93.578550% | insns 397/401 | positional diffs 328 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24UpdateDlTask | 2 distinct retry-count local retained across disabled branch | objdiff 90.992096% | insns 247/253 | positional diffs 250 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24UpdateDlTask | 3 explicit nested result normalization after access time update | objdiff 90.557310% | insns 246/253 | positional diffs 250 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24AddDlTask | 1 restore independent cached header reads and next-time validator from assembly | objdiff 97.552444% | insns 146/143 | positional diffs 140 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24AddDlTask | 2 scope interval and next time at scheduling call | objdiff 97.552444% | insns 146/143 | positional diffs 140 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24AddDlTask | 3 preserve scheduling helper result in caller | objdiff 97.552444% | insns 146/143 | positional diffs 140 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24IterateDlTaskEx | 1 restore strict selected and best candidate comparisons from assembly | objdiff 90.103450% | insns 143/145 | positional diffs 92 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24IterateDlTaskEx | 2 materialize selected comparison with ternary | objdiff 90.103450% | insns 143/145 | positional diffs 92 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24IterateDlTaskEx | 3 compare updated sort flag for sentinel each pass | objdiff 90.689650% | insns 144/145 | positional diffs 92 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24IterateDlTask | 1 return occupied task slots instead of empty entries | objdiff 81.113920% | insns 74/79 | positional diffs 36 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24IterateDlTask | 2 move slot advance into for loop increment | objdiff 83.962030% | insns 74/79 | positional diffs 52 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24IterateDlTask | 3 inline combined slot validity condition | objdiff 83.772150% | insns 72/79 | positional diffs 48 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24PurgeOldestDlTask | 1 inline original read and ordinary delete validator allowing unassigned ids | objdiff 84.312500% | insns 167/176 | positional diffs 86 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24PurgeOldestDlTask | 2 delay done-to-failed translation until iteration exit | objdiff 83.744316% | insns 168/176 | positional diffs 147 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24PurgeOldestDlTask | 3 scope selected task id at read boundary | objdiff 84.312500% | insns 167/176 | positional diffs 86 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24ManageDlTaskListForMenu | 1 use max-count accessor and original inline read and remove control flow | objdiff 94.335526% | insns 149/152 | positional diffs 124 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24ManageDlTaskListForMenu | 2 hold task pointer across read and deletion | objdiff 93.453950% | insns 151/152 | positional diffs 137 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24ManageDlTaskListForMenu | 3 store removal result before return | objdiff 94.335526% | insns 149/152 | positional diffs 124 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24SetDlUrl | 1 factor URL parsing result before setter validation | objdiff 100.000000% | insns 109/109 | positional diffs 0 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24SetDlUrl | 2 retain separate parse result local | objdiff 100.000000% | insns 109/109 | positional diffs 0 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24SetDlUrl | 3 separate lax check from secure-download URL check | objdiff 100.000000% | insns 109/109 | positional diffs 0 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24GetDlTask | 1 reuse inline reader at public entry point | objdiff 99.728264% | insns 92/92 | positional diffs 5 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24GetDlTask | 2 preserve destination pointer in read phase | objdiff 99.728264% | insns 92/92 | positional diffs 5 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24GetDlTask | 3 load task id only after file open | objdiff 99.728264% | insns 92/92 | positional diffs 5 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24SetDlFlags | 1 keep explicit nonlegacy task type cases | objdiff 100.000000% | insns 91/91 | positional diffs 0 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24SetDlFlags | 2 use enum temporary for legacy flag switch | objdiff 98.901100% | insns 90/91 | positional diffs 19 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24SetDlFlags | 3 separate legacy task flag result from setter | objdiff 98.901100% | insns 90/91 | positional diffs 19 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24InitDlTask | 1 materialize content type boolean and reuse original write validator | objdiff 96.541664% | insns 143/144 | positional diffs 103 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24InitDlTask | 2 order default task stores around content type comparison | objdiff 96.187500% | insns 143/144 | positional diffs 103 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24InitDlTask | 3 express final validation result as sign test | objdiff 96.541664% | insns 143/144 | positional diffs 103 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24DeleteDlTask | 1 rebuild admin exemption and nested remove validation | objdiff 98.047620% | insns 107/105 | positional diffs 52 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24DeleteDlTask | 2 branch admin exemption positively | objdiff 98.000000% | insns 107/105 | positional diffs 96 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24DeleteDlTask | 3 retain ordinary remove result in caller | objdiff 98.047620% | insns 107/105 | positional diffs 52 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24SetDlInterval | 1 shorten scheduled id lifetime after validation | objdiff 99.897960% | insns 147/147 | positional diffs 3 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24SetDlInterval | 2 retain local task pointer only until timestamp division | objdiff 99.897960% | insns 147/147 | positional diffs 3 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24SetDlInterval | 3 move time division into scheduler helper | objdiff 80.680275% | insns 175/147 | positional diffs 58 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24ExtendDlTaskList | 1 give reload result a separate lifetime after extension | objdiff 99.854010% | insns 137/137 | positional diffs 4 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24ExtendDlTaskList | 2 express close-error preference in ternary | objdiff 99.854010% | insns 137/137 | positional diffs 4 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24ExtendDlTaskList | 3 return close failure before reloaded success | objdiff 99.854010% | insns 137/137 | positional diffs 4 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24iCreateDlTaskList | 1 separate initialized header pointer from cached accessor | objdiff 99.624060% | insns 133/133 | positional diffs 10 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24iCreateDlTaskList | 2 narrow initialized header to setup scope | objdiff 99.624060% | insns 133/133 | positional diffs 10 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24iCreateDlTaskList | 3 retain task count as loop bound temporary | objdiff 99.624060% | insns 133/133 | positional diffs 10 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24iLoadDlHeader | 1 finish seek and read operation before status check | objdiff 100.000000% | insns 100/100 | positional diffs 0 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24iLoadDlHeader | 2 use explicit read-result normalization | objdiff 94.250000% | insns 101/100 | positional diffs 81 | regressions 0 +libs/RevoEX/src/nwc24/NWC24Download | NWC24iLoadDlHeader | 3 scoped header read with separate status local | objdiff 100.000000% | insns 100/100 | positional diffs 0 | regressions 0 +src/keyboard/tiCellPhone | updateInput__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFRQ39textinput5input10HKBManager | 1 isolate the real 12-byte hardware KeySet ABI while preserving all existing header guard sides | objdiff 76.839620% | insns 201/212 | positional diffs 201 | regressions 0 +src/keyboard/tiCellPhone | updateInput__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFRQ39textinput5input10HKBManager | 2 reconstruct both switch loops with a shared iterator and pane-name release event | BUILD FAILED: ^ +# (10184) return value expected +### mwcceppc.exe Compiler: +# 1073: bool LayoutByNW4R::updateInput(input::HKBManager& hkbManager) { +# Error: ^ +# (10333) object +# 'textinput::keyboard::cellphonetype::LayoutByNW4R::updateInput(textinput::i +# nput::HKBManager &)' redefined +# Too many errors printed, aborting program + +User break, cancelled... +ninja: build stopped: subcommand failed. + +src/keyboard/tiCellPhone | updateInput__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFRQ39textinput5input10HKBManager | 2 reconstruct both switch loops with a shared iterator and pane-name release event | objdiff 99.245285% | insns 211/212 | positional diffs 108 | regressions 0 +src/keyboard/tiCellPhone | updateInput__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFRQ39textinput5input10HKBManager | 3 retain wide character return until selected character-pane search | objdiff 100.000000% | insns 212/212 | positional diffs 0 | regressions 0 +src/keyboard/tiCellPhone | onKey__Q49textinput8keyboard13cellphonetype4BaseFUlPv | 1 reconstruct all key cycling prediction numeric-space and confirmation blocks with typed ConfirmInput | objdiff 94.837240% | insns 682/682 | positional diffs 539 | regressions 0 +src/keyboard/tiCellPhone | onKey__Q49textinput8keyboard13cellphonetype4BaseFUlPv | 2 use inline pane lookup and preserve Japanese mode branch before uppercase fallback | objdiff 96.895900% | insns 681/682 | positional diffs 494 | regressions 0 +src/keyboard/tiCellPhone | onKey__Q49textinput8keyboard13cellphonetype4BaseFUlPv | 3 give numeric-pane lookup a reference lifetime instead of retaining pointer | objdiff 96.895900% | insns 681/682 | positional diffs 494 | regressions 0 +src/keyboard/tiCellPhone | create__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFP12MEMAllocator | 1 unroll texture acquisition and restore target final setLanguage dispatch | objdiff 81.465460% | insns 331/333 | positional diffs 303 | regressions 0 +src/keyboard/tiCellPhone | create__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFP12MEMAllocator | 2 perform initialization inside the base pane constructor and delay descriptor lifetime | objdiff 90.981980% | insns 341/333 | positional diffs 320 | regressions 0 +src/keyboard/tiCellPhone | create__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFP12MEMAllocator | 3 retain the allocator result directly through the null path | objdiff 92.228226% | insns 337/333 | positional diffs 315 | regressions 0 +src/keyboard/tiCellPhone | onTiEvent__Q49textinput8keyboard13cellphonetype12EventHandlerFPQ39textinput3gui13PaneComponentUlPQ49textinput11nw4rmanager14TiEventHandler5Input | 1 derive event masks, animation dispatch, normal-key search and independent repeat timeout from target blocks | objdiff 100.000000% | insns 284/284 | positional diffs 0 | regressions 0 +src/keyboard/tiCellPhone | onTiEvent__Q49textinput8keyboard13cellphonetype12EventHandlerFPQ39textinput3gui13PaneComponentUlPQ49textinput11nw4rmanager14TiEventHandler5Input | 2 use signed event switch to retain the target comparison tree | objdiff 100.000000% | insns 284/284 | positional diffs 0 | regressions 0 +src/keyboard/tiCellPhone | onTiEvent__Q49textinput8keyboard13cellphonetype12EventHandlerFPQ39textinput3gui13PaneComponentUlPQ49textinput11nw4rmanager14TiEventHandler5Input | 3 leave event structure alignment to its natural padding | objdiff 100.000000% | insns 284/284 | positional diffs 0 | regressions 0 +src/keyboard/tiCellPhone | onActive__Q49textinput8keyboard13cellphonetype4BaseFv | 1 initialize a boolean command value in its owning branch | objdiff 95.825390% | insns 63/63 | positional diffs 6 | regressions 0 +src/keyboard/tiCellPhone | onActive__Q49textinput8keyboard13cellphonetype4BaseFv | 2 initialize a one-element boolean array using normal aggregate initialization | objdiff 99.936510% | insns 63/63 | positional diffs 4 | regressions 0 +src/keyboard/tiCellPhone | onActive__Q49textinput8keyboard13cellphonetype4BaseFv | 3 initialize a typed active-mode command structure | objdiff 99.936510% | insns 63/63 | positional diffs 4 | regressions 0 +src/keyboard/tiCellPhone | changeInputMode__Q49textinput8keyboard13cellphonetype4BaseFQ59textinput8keyboard13cellphonetype4Base9InputMode | 1 initialize a boolean command value in its owning branch | objdiff 96.242860% | insns 70/70 | positional diffs 6 | regressions 0 +src/keyboard/tiCellPhone | changeInputMode__Q49textinput8keyboard13cellphonetype4BaseFQ59textinput8keyboard13cellphonetype4Base9InputMode | 2 initialize a one-element boolean array using normal aggregate initialization | objdiff 99.942856% | insns 70/70 | positional diffs 4 | regressions 0 +src/keyboard/tiCellPhone | changeInputMode__Q49textinput8keyboard13cellphonetype4BaseFQ59textinput8keyboard13cellphonetype4Base9InputMode | 3 initialize a typed active-mode command structure | objdiff 99.942856% | insns 70/70 | positional diffs 4 | regressions 0 +src/keyboard/tiCellPhone | onActive__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFv | 1 initialize a boolean command value in its owning branch | objdiff 96.000000% | insns 65/65 | positional diffs 4 | regressions 0 +src/keyboard/tiCellPhone | onActive__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFv | 2 initialize a one-element boolean array using normal aggregate initialization | objdiff 100.000000% | insns 65/65 | positional diffs 0 | regressions 0 +src/keyboard/tiCellPhone | onActive__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFv | 3 initialize a typed active-mode command structure | objdiff 100.000000% | insns 65/65 | positional diffs 0 | regressions 0 +src/keyboard/tiCellPhone | onActive__Q49textinput8keyboard13cellphonetype4BaseFv | 4 scope the inactive command alongside the active command to restore stack lifetimes | objdiff 99.936510% | insns 63/63 | positional diffs 4 | regressions 0 +src/keyboard/tiCellPhone | changeInputMode__Q49textinput8keyboard13cellphonetype4BaseFQ59textinput8keyboard13cellphonetype4Base9InputMode | 4 scope the inactive command alongside the active command to restore stack lifetimes | objdiff 99.942856% | insns 70/70 | positional diffs 4 | regressions 0 +src/keyboard/tiCellPhone | changeInputMode__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFQ59textinput8keyboard13cellphonetype4Base9InputMode | 1 derive signed mode cases and condition order, aggregate active flag and restore virtual pane initialization | objdiff 90.062805% | insns 216/207 | positional diffs 189 | regressions 0 +src/keyboard/tiCellPhone | changeInputMode__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFQ59textinput8keyboard13cellphonetype4Base9InputMode | 2 use the passed mode as the remapped key-set index | objdiff 90.062805% | insns 216/207 | positional diffs 189 | regressions 0 +src/keyboard/tiCellPhone | changeInputMode__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFQ59textinput8keyboard13cellphonetype4Base9InputMode | 3 scope and type the inactive command value | objdiff 90.043480% | insns 216/207 | positional diffs 189 | regressions 0 +src/keyboard/tiCellPhone | changeSpaceKeyTop__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFPCQ49textinput8keyboard13cellphonetype18PaneNameToCharCode | 1 correct the cell-phone-only space-data declarations to the pointer loads shown by target asm | objdiff 100.000000% | insns 52/52 | positional diffs 0 | regressions 0 +src/keyboard/tiCellPhone | changeSpaceKeyTop__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFPCQ49textinput8keyboard13cellphonetype18PaneNameToCharCode | 2 select the space key label before issuing one SetString call | objdiff 82.884610% | insns 47/52 | positional diffs 21 | regressions 0 +src/keyboard/tiCellPhone | changeSpaceKeyTop__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFPCQ49textinput8keyboard13cellphonetype18PaneNameToCharCode | 3 return early for Japanese input before acquiring text pane | objdiff 100.000000% | insns 52/52 | positional diffs 0 | regressions 0 +src/keyboard/tiCellPhone | init__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFv | 1 re-derive Chinese and Korean prediction-button dispatch, key-set reload after visibility call and virtual FIFO initialization | objdiff 96.468285% | insns 544/536 | positional diffs 449 | regressions 0 +src/keyboard/tiCellPhone | init__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFv | 2 use a narrow index for the four toggle panes | objdiff 94.992540% | insns 545/536 | positional diffs 443 | regressions 0 +src/keyboard/tiCellPhone | init__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFv | 3 retain a typed text box and signed loop index | objdiff 96.468285% | insns 544/536 | positional diffs 449 | regressions 0 +src/keyboard/tiCellPhone | onKey__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFUlPv | 1 give the current control-key descriptor a scoped reference | objdiff 97.850464% | insns 107/107 | positional diffs 9 | regressions 0 +src/keyboard/tiCellPhone | onKey__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFUlPv | 2 use a conventional for loop and break for control-key search | objdiff 96.766360% | insns 107/107 | positional diffs 33 | regressions 0 +src/keyboard/tiCellPhone | onKey__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFUlPv | 3 inline a value-returning control-key lookup | objdiff 100.000000% | insns 107/107 | positional diffs 0 | regressions 0 +src/keyboard/tiCellPhone | doNumericMode__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFb | 1 restore the fourth pane-visibility call missing from the target control flow | objdiff 93.923080% | insns 173/169 | positional diffs 168 | regressions 0 +src/keyboard/tiCellPhone | doNumericMode__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFb | 2 compute the shared hidden-state value once before updating panes | objdiff 93.923080% | insns 173/169 | positional diffs 168 | regressions 0 +src/keyboard/tiCellPhone | doNumericMode__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFb | 3 return for disabled numeric mode before updating pane visibility | objdiff 93.923080% | insns 173/169 | positional diffs 168 | regressions 0 +src/keyboard/tiCellPhone | setSignWindowButton__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFb | 1 retain typed pane-name pointers for the two sign-window controls | objdiff 71.100000% | insns 72/70 | positional diffs 70 | regressions 0 +src/keyboard/tiCellPhone | setSignWindowButton__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFb | 2 finish the disabled sign-window branch with an early return | objdiff 87.071430% | insns 70/70 | positional diffs 21 | regressions 0 +src/keyboard/tiCellPhone | setSignWindowButton__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFb | 3 select the active regional sign pane before dispatching visibility | objdiff 73.842860% | insns 63/70 | positional diffs 43 | regressions 0 +src/keyboard/tiCellPhone | doNumericWithDotMode__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFb | 1 retain the dot key pane name across numeric-mode dispatch | objdiff 95.000000% | insns 36/35 | positional diffs 14 | regressions 0 +src/keyboard/tiCellPhone | doNumericWithDotMode__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFb | 2 dispatch dot-pane visibility through the layout base pointer | objdiff 87.971430% | insns 39/35 | positional diffs 20 | regressions 0 +src/keyboard/tiCellPhone | doNumericWithDotMode__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFb | 3 bind the numeric-pane descriptor at the point of use | objdiff 95.000000% | insns 36/35 | positional diffs 14 | regressions 0 +src/keyboard/tiCellPhone | onActive__Q49textinput8keyboard13cellphonetype4BaseFv | 5 type both activation command payloads as boolean structures to preserve stack order | objdiff 100.000000% | insns 63/63 | positional diffs 0 | regressions 0 +src/keyboard/tiCellPhone | changeInputMode__Q49textinput8keyboard13cellphonetype4BaseFQ59textinput8keyboard13cellphonetype4Base9InputMode | 5 type both activation command payloads as boolean structures to preserve stack order | objdiff 100.000000% | insns 70/70 | positional diffs 0 | regressions 0 diff --git a/tools/decomp-assist/sol-high-result.md b/tools/decomp-assist/sol-high-result.md new file mode 100644 index 00000000..2ac326ba --- /dev/null +++ b/tools/decomp-assist/sol-high-result.md @@ -0,0 +1,123 @@ +# Matching result + +Final full gate: all three units, fresh 43U rebuild; pools identical; zero regressions, forbidden additions and readability warnings. DOL SHA1: `26116613f624061ba99c8d1a299aaa6efa85670d`. + +| Unit | Instruction-exact functions | Fuzzy | Exact code bytes | Exact data bytes | +| --- | --- | --- | --- | --- | +| libs/RVL_SDK/src/fa/pf_dir | 30/38 -> 34/38 | 67.96859% -> 98.87879% | 8024 -> 11428 / 18976 | 0 -> 8 / 40 | +| libs/RevoEX/src/nwc24/NWC24Download | 13/30 -> 16/30 | 83.35883% -> 95.99360% | 2020 -> 3220 / 12496 | 80 -> 80 / 80 | +| src/keyboard/tiCellPhone | 72/86 -> 79/86 | 86.62876% -> 97.73765% | 7488 -> 10900 / 19028 | 4 -> 4 / 3860 | + +## Remaining functions + +Instruction counts below are source/target. Every initially nonexact function has at least three distinct logged source attempts; failed compilations are additional evidence, not counted toward the minimum. Explanations identify the surviving diff area; they do not establish a compiler tie-break. + +### libs/RVL_SDK/src/fa/pf_dir + +- `PFDIR_GetSDD`: 99.710144%; 69/69 instructions; load scheduling. +- `PFDIR_p_mkdir`: 96.887900%; 571/562 instructions; allocation and directory-write block scheduling. +- `PFDIR_p_rename`: 97.376000%; 626/625 instructions; retained path and directory temporaries. +- `PFDIR_p_move`: 96.973060%; 636/631 instructions; directory traversal and write block scheduling. + +### libs/RevoEX/src/nwc24/NWC24Download + +- `NWC24InitDlTask`: 96.541664%; 143/144 instructions; validation and default-field store scheduling. +- `NWC24SetDlInterval`: 99.897960%; 147/147 instructions; temporary register allocation. +- `NWC24IterateDlTask`: 83.962030%; 74/79 instructions; loop termination and callback-result scheduling. +- `NWC24IterateDlTaskEx`: 90.689650%; 144/145 instructions; inlined read-loop and callback-result scheduling. +- `NWC24UpdateDlTask`: 90.992096%; 247/253 instructions; retry-validation and timestamp block scheduling. +- `NWC24DeleteDlTask`: 98.047620%; 107/105 instructions; validation and deletion block scheduling. +- `NWC24AddDlTask`: 97.552444%; 146/143 instructions; validation and slot-search block scheduling. +- `NWC24GetDlTask`: 99.728264%; 92/92 instructions; parameter register allocation. +- `NWC24PurgeOldestDlTask`: 84.312500%; 167/176 instructions; slot-scan and inlined deletion blocks. +- `NWC24ManageDlTaskListForMenu`: 94.335526%; 149/152 instructions; menu-limit and task-deletion blocks. +- `NWC24ExtendDlTaskList`: 99.854010%; 137/137 instructions; reload-result register allocation. +- `NWC24iCheckDlHeaderConsistency`: 98.773580%; 212/212 instructions; prologue move scheduling. +- `NWC24iCreateDlTaskList`: 99.624060%; 133/133 instructions; header-pointer register allocation. +- `AddTaskInternal`: 93.578550%; 397/401 instructions; slot search and timestamp-update blocks. + +### src/keyboard/tiCellPhone + +- `onKey__Q49textinput8keyboard13cellphonetype4BaseFUlPv`: 96.895900%; 681/682 instructions; key lookup, command-payload and register scheduling. +- `create__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFP12MEMAllocator`: 92.228226%; 337/333 instructions; descriptor address setup and constructor scheduling. +- `init__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFv`: 96.468285%; 544/536 instructions; pane address setup, key-set reload and virtual-call scheduling. +- `changeInputMode__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFQ59textinput8keyboard13cellphonetype4Base9InputMode`: 90.062805%; 216/207 instructions; mode-branch and pane-address scheduling. +- `doNumericMode__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFb`: 93.923080%; 173/169 instructions; pane-address and shared visibility-value scheduling. +- `doNumericWithDotMode__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFb`: 95.000000%; 36/35 instructions; extra pane-address calculation. +- `setSignWindowButton__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFb`: 87.071430%; 70/70 instructions; regional pane-address setup and scheduling. + +## Validation + +```text +full build: ok +main.dol sha1: 26116613f624061ba99c8d1a299aaa6efa85670d +[libs/RVL_SDK/src/fa/pf_dir] pool: IDENTICAL +[libs/RVL_SDK/src/fa/pf_dir] objdiff: code 11428/18976 data 8/40 functions 34/38 fuzzy 98.8788 linked code 0 +[libs/RVL_SDK/src/fa/pf_dir] instruction-exact functions: 34/38 +[libs/RVL_SDK/src/fa/pf_dir] section .sdata size 32 match 92.85714 +[libs/RVL_SDK/src/fa/pf_dir] section .sdata2 size 8 match 100.0 +[libs/RVL_SDK/src/fa/pf_dir] section .text size 18976 match 98.87879 +[libs/RVL_SDK/src/fa/pf_dir] below 100: PFDIR_GetSDD 99.710144 +[libs/RVL_SDK/src/fa/pf_dir] below 100: PFDIR_p_mkdir 96.8879 +[libs/RVL_SDK/src/fa/pf_dir] below 100: PFDIR_p_rename 97.376 +[libs/RVL_SDK/src/fa/pf_dir] below 100: PFDIR_p_move 96.97306 +[libs/RVL_SDK/src/fa/pf_dir] baseline: code 8024/18976 data None functions 30 fuzzy 67.9686 +[libs/RevoEX/src/nwc24/NWC24Download] pool: IDENTICAL +[libs/RevoEX/src/nwc24/NWC24Download] objdiff: code 3220/12496 data 80/80 functions 16/30 fuzzy 95.9936 linked code 0 +[libs/RevoEX/src/nwc24/NWC24Download] instruction-exact functions: 16/30 +[libs/RevoEX/src/nwc24/NWC24Download] section .data size 56 match 100.0 +[libs/RevoEX/src/nwc24/NWC24Download] section .sbss size 8 match 100.0 +[libs/RevoEX/src/nwc24/NWC24Download] section .sdata size 16 match 100.0 +[libs/RevoEX/src/nwc24/NWC24Download] section .text size 12496 match 95.9936 +[libs/RevoEX/src/nwc24/NWC24Download] below 100: NWC24InitDlTask 96.541664 +[libs/RevoEX/src/nwc24/NWC24Download] below 100: NWC24SetDlInterval 99.89796 +[libs/RevoEX/src/nwc24/NWC24Download] below 100: NWC24IterateDlTask 83.96203 +[libs/RevoEX/src/nwc24/NWC24Download] below 100: NWC24IterateDlTaskEx 90.68965 +[libs/RevoEX/src/nwc24/NWC24Download] below 100: NWC24UpdateDlTask 90.992096 +[libs/RevoEX/src/nwc24/NWC24Download] below 100: NWC24DeleteDlTask 98.04762 +[libs/RevoEX/src/nwc24/NWC24Download] below 100: NWC24AddDlTask 97.552444 +[libs/RevoEX/src/nwc24/NWC24Download] below 100: NWC24GetDlTask 99.728264 +[libs/RevoEX/src/nwc24/NWC24Download] below 100: NWC24PurgeOldestDlTask 84.3125 +[libs/RevoEX/src/nwc24/NWC24Download] below 100: NWC24ManageDlTaskListForMenu 94.335526 +[libs/RevoEX/src/nwc24/NWC24Download] below 100: NWC24ExtendDlTaskList 99.85401 +[libs/RevoEX/src/nwc24/NWC24Download] below 100: NWC24iCheckDlHeaderConsistency 98.77358 +[libs/RevoEX/src/nwc24/NWC24Download] below 100: NWC24iCreateDlTaskList 99.62406 +[libs/RevoEX/src/nwc24/NWC24Download] below 100: AddTaskInternal 93.57855 +[libs/RevoEX/src/nwc24/NWC24Download] baseline: code 2020/12496 data 80 functions 13 fuzzy 83.3588 +[src/keyboard/tiCellPhone] pool: IDENTICAL +[src/keyboard/tiCellPhone] objdiff: code 10900/19028 data 4/3860 functions 79/86 fuzzy 97.7377 linked code 0 +[src/keyboard/tiCellPhone] instruction-exact functions: 79/86 +[src/keyboard/tiCellPhone] section .ctors size 4 match 100.0 +[src/keyboard/tiCellPhone] section .data size 2416 match 56.210873 +[src/keyboard/tiCellPhone] section .rodata size 1320 match 99.69697 +[src/keyboard/tiCellPhone] section .sdata size 112 match None +[src/keyboard/tiCellPhone] section .sdata2 size 8 match 55.555557 +[src/keyboard/tiCellPhone] section .text size 19028 match 97.73765 +[src/keyboard/tiCellPhone] below 100: onKey__Q49textinput8keyboard13cellphonetype4BaseFUlPv 96.8959 +[src/keyboard/tiCellPhone] below 100: create__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFP12MEMAllocator 92.228226 +[src/keyboard/tiCellPhone] below 100: init__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFv 96.468285 +[src/keyboard/tiCellPhone] below 100: changeInputMode__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFQ59textinput8keyboard13cellphonetype4Base9InputMode 90.062805 +[src/keyboard/tiCellPhone] below 100: doNumericMode__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFb 93.92308 +[src/keyboard/tiCellPhone] below 100: doNumericWithDotMode__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFb 95.0 +[src/keyboard/tiCellPhone] below 100: setSignWindowButton__Q49textinput8keyboard13cellphonetype12LayoutByNW4RFb 87.07143 +[src/keyboard/tiCellPhone] baseline: code 7488/19028 data 4 functions 72 fuzzy 86.6288 +regressions vs baseline: 0 +global matched_code_percent: 83.03911 -> 83.30673 +global fuzzy_match_percent: 96.63766 -> 96.95678 +global complete_code_percent: 58.19218 -> 58.19218 +global matched_data_percent: 89.88587 -> 89.88631 +forbidden patterns added (net, per file): 0 +readability warnings (net, per file; must be 0 in the final result): 0 +GATE PASS +``` + +## Files and commits + +- `libs/RVL_SDK/src/fa/pf_dir.c`: `26c329e5`, `f7cce6f6`. +- `libs/RevoEX/src/nwc24/NWC24Download.c`: `59a7118e`. +- `src/keyboard/tiCellPhone.cpp`, `include/keyboard/tiCellPhone.h`, `include/keyboard/tiCpData.h`, `include/keyboard/tiHKBManager.h`: `965687ab`. +- `tools/decomp-assist/sol-high-attempts.md`: source attempts and their measurements. + +## Limits + +25 functions and partial pf_dir/tiCellPhone data remain unmatched. No unit was switched to Matching. Linking was left for the later phase. The residual data differences were not proven to be only linker-deduplicated weak data; the matching-only result does not claim complete units.