Compare commits
1 Commits
agent/w092
...
agent/w092
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61123b6f01 |
@@ -53,9 +53,9 @@ Progress
|
||||
<!-- progress:start -->
|
||||
| Decompiled | Matched | Linked | Data |
|
||||
|:---:|:---:|:---:|:---:|
|
||||
| 84.89% | 75.24% | 56.76% | 86.70% |
|
||||
| 84.12% | 74.70% | 56.76% | 86.51% |
|
||||
|
||||
units 748/1027 complete, functions 10976/12563 matched.
|
||||
units 748/1027 complete, functions 10894/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
|
||||
<!-- progress:end -->
|
||||
|
||||
@@ -1682,11 +1682,11 @@ config.libs = [
|
||||
]
|
||||
),
|
||||
RVLSDKLib("fa", [
|
||||
Object(NonMatching, "fa/pf_clib.c"),
|
||||
Object(NonMatching, "fa/pf_code.c"),
|
||||
Object(Matching, "fa/pf_clib.c"),
|
||||
Object(Matching, "fa/pf_code.c"),
|
||||
Object(NonMatching, "fa/pf_service.c"),
|
||||
Object(NonMatching, "fa/pf_str.c"),
|
||||
Object(NonMatching, "fa/pf_driver.c"),
|
||||
Object(Matching, "fa/pf_str.c"),
|
||||
Object(Matching, "fa/pf_driver.c"),
|
||||
Object(NonMatching, "fa/pdm_api.c"),
|
||||
Object(NonMatching, "fa/pdm_bpb.c"),
|
||||
Object(NonMatching, "fa/pdm_disk.c"),
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace textinput {
|
||||
u32 GetModifierState() const;
|
||||
void SetModifierState(u32, u32);
|
||||
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
#ifdef TI_PC_KEYBOARD_IMPLEMENTATION
|
||||
class KeySet {
|
||||
public:
|
||||
u8 GetKey() const;
|
||||
|
||||
@@ -142,9 +142,6 @@ namespace textinput {
|
||||
MEMAllocator* mpAllocator; // 0x08
|
||||
};
|
||||
|
||||
#ifdef TISIGNWINDOW_IMPLEMENTATION
|
||||
bool isAtokActive() const;
|
||||
#endif
|
||||
virtual ~Base();
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
Base(Manager* manager);
|
||||
|
||||
@@ -12,32 +12,28 @@ namespace textinput {
|
||||
KeyboardBase() : meLanguage(JP) {}
|
||||
#endif
|
||||
virtual ~KeyboardBase() {}
|
||||
#if !defined(TI_PC_KEYBOARD_IMPLEMENTATION) && !defined(TIMANAGER_IMPLEMENTATION) && !defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
#if !defined(TI_PC_KEYBOARD_IMPLEMENTATION) && !defined(TIMANAGER_IMPLEMENTATION)
|
||||
virtual void create(MEMAllocator* alloc) override;
|
||||
virtual void init() override;
|
||||
virtual void setCommandReceiver(CommandReceiver* receiver) override;
|
||||
virtual void sendCommand(u32 command, void*) override;
|
||||
#endif
|
||||
#if !defined(TIMANAGER_IMPLEMENTATION) && !defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
#ifndef TIMANAGER_IMPLEMENTATION
|
||||
virtual void updateFromReceiver(u32, void*) override;
|
||||
#endif
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
virtual void onKey(u32, void*);
|
||||
#else
|
||||
virtual void onKey(u32);
|
||||
#endif
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
virtual int getType();
|
||||
#else
|
||||
virtual void getType();
|
||||
#endif
|
||||
virtual void setLanguage(Language language);
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
#ifdef TISIGNWINDOW_IMPLEMENTATION
|
||||
virtual Language getLanguage() const;
|
||||
#else
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
virtual Language getLanguage() const { return meLanguage; }
|
||||
#endif
|
||||
virtual void update() {}
|
||||
#else
|
||||
virtual Language getLanguage() const;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace textinput {
|
||||
class TiEventHandler : public gui::EventHandler {
|
||||
public:
|
||||
typedef struct Input {
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
u32 controller;
|
||||
f32 x;
|
||||
f32 y;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef TEXTINPUT_PC_KEYBOARD_H
|
||||
#define TEXTINPUT_PC_KEYBOARD_H
|
||||
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#include "tiPcKeyboardImpl.h"
|
||||
#else
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace textinput {
|
||||
}
|
||||
namespace keyboard {
|
||||
namespace signwindow {
|
||||
#ifndef TISIGNWINDOW_IMPLEMENTATION
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
struct LanguageDependencyData;
|
||||
class Base : public KeyboardBase {
|
||||
@@ -88,7 +87,6 @@ namespace textinput {
|
||||
virtual void open(KeyboardBase* keyboard, bool repeat);
|
||||
virtual bool isActive();
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
#ifndef TEXTINPUT_SIGN_WINDOW_H
|
||||
#define TEXTINPUT_SIGN_WINDOW_H
|
||||
|
||||
#include "tiKeyboard.h"
|
||||
#include "tiNw4rManager.h"
|
||||
#include "tiSwData.h"
|
||||
|
||||
namespace textinput {
|
||||
class Manager;
|
||||
namespace keyboard {
|
||||
|
||||
namespace signwindow {
|
||||
|
||||
struct LanguageDependency {
|
||||
u8 count;
|
||||
const PaneNameToCharCodeInSignMode* keys;
|
||||
};
|
||||
|
||||
class Base : public KeyboardBase {
|
||||
public:
|
||||
virtual ~Base();
|
||||
virtual void create(MEMAllocator*) override;
|
||||
virtual void init() override;
|
||||
virtual void onKey(u32, void*) override;
|
||||
virtual bool isLocked();
|
||||
virtual void setPage(u8);
|
||||
virtual u8 getPage();
|
||||
virtual void movePrevSignPage();
|
||||
virtual void moveNextSignPage();
|
||||
virtual void close();
|
||||
virtual int getType() override;
|
||||
virtual void setLanguage(Language) override;
|
||||
|
||||
protected:
|
||||
u8 mInputFlags;
|
||||
bool mbLocked;
|
||||
bool mbRepeat;
|
||||
u8 muPage;
|
||||
const LanguageDependency* mpLanguageDependency;
|
||||
MEMAllocator* mpAllocator;
|
||||
Manager* mpManager;
|
||||
};
|
||||
|
||||
class EventHandler;
|
||||
|
||||
class LayoutByNW4R : public Base, public nw4rmanager::Layout, public nw4rmanager::AnmObserver {
|
||||
public:
|
||||
virtual ~LayoutByNW4R();
|
||||
virtual void create(MEMAllocator*) override;
|
||||
virtual void init() override;
|
||||
virtual void onKey(u32, void*) override;
|
||||
virtual void movePrevSignPage() override;
|
||||
virtual void moveNextSignPage() override;
|
||||
virtual void close() override;
|
||||
virtual void draw() override;
|
||||
virtual void open(KeyboardBase*, bool);
|
||||
virtual bool isActive();
|
||||
virtual void onChangeAnmState(AnmEvent, nw4rmanager::AnmPane*, nw4rmanager::Anim*) override;
|
||||
virtual bool updateInput(int, f32, f32, u32, u32, u32, void*) override;
|
||||
virtual bool updateInput(input::HKBManager&) override;
|
||||
virtual void throwReleaseForAll();
|
||||
virtual void resetAnmSignWindow();
|
||||
virtual void setSignKeyTop(u16, u16);
|
||||
virtual void setPageNumber(u16);
|
||||
virtual void endToClose();
|
||||
virtual void startToInput();
|
||||
virtual void movePrevSignWindow();
|
||||
virtual void moveNextSignWindow();
|
||||
|
||||
bool mbActive;
|
||||
bool mbInput;
|
||||
EventHandler* mpEventHandler;
|
||||
KeyboardBase* mpKeyboard;
|
||||
};
|
||||
|
||||
class Sample : public LayoutByNW4R {
|
||||
public:
|
||||
virtual ~Sample();
|
||||
};
|
||||
|
||||
class EventHandler : public nw4rmanager::TiEventHandler {
|
||||
public:
|
||||
explicit EventHandler(LayoutByNW4R* layout) : mpLayoutByNW4R(layout) {}
|
||||
virtual ~EventHandler();
|
||||
virtual void onTiEvent(gui::PaneComponent*, u32, Input*) override;
|
||||
LayoutByNW4R* mpLayoutByNW4R;
|
||||
};
|
||||
|
||||
class AnmPane : public nw4rmanager::AnmPane {
|
||||
public:
|
||||
AnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer)
|
||||
: nw4rmanager::AnmPane(pane, observer), muAnimation(0) {}
|
||||
inline virtual ~AnmPane();
|
||||
virtual void init() override;
|
||||
virtual void changeAnimation(u32) override;
|
||||
virtual u32 getKeyType() const;
|
||||
|
||||
protected:
|
||||
s32 muAnimation;
|
||||
u32 muKeyType;
|
||||
};
|
||||
|
||||
class CellPhoneSignAllAnmPane : public AnmPane {
|
||||
public:
|
||||
CellPhoneSignAllAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer)
|
||||
: AnmPane(pane, observer) { muKeyType = 0; }
|
||||
virtual ~CellPhoneSignAllAnmPane();
|
||||
virtual void init() override;
|
||||
virtual void onAnmEvent(AnmPaneEvent) override;
|
||||
};
|
||||
|
||||
class CellPhoneSignScrollAnmPane : public AnmPane {
|
||||
public:
|
||||
CellPhoneSignScrollAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer)
|
||||
: AnmPane(pane, observer) { muKeyType = 1; }
|
||||
virtual ~CellPhoneSignScrollAnmPane();
|
||||
virtual void init() override;
|
||||
virtual void onAnmEvent(AnmPaneEvent) override;
|
||||
};
|
||||
|
||||
class CellPhoneSignButtonPane : public AnmPane {
|
||||
public:
|
||||
CellPhoneSignButtonPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer)
|
||||
: AnmPane(pane, observer) { muKeyType = 2; }
|
||||
virtual ~CellPhoneSignButtonPane();
|
||||
virtual void init() override;
|
||||
virtual void onAnmEvent(AnmPaneEvent) override;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -70,7 +70,7 @@ namespace textinput {
|
||||
INPUT_COMMAND_37 = 37,
|
||||
} INPUT_COMMAND;
|
||||
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
struct ChangePredictMode { u32 mode; bool enabled; };
|
||||
#endif
|
||||
virtual void clearSender();
|
||||
|
||||
177
libs/RVL_SDK/src/fa/pf_clib.c
Normal file
177
libs/RVL_SDK/src/fa/pf_clib.c
Normal file
@@ -0,0 +1,177 @@
|
||||
#include <private/vf/PrFILE2/pf_types.h>
|
||||
|
||||
pf_s32 pf_toupper(pf_s32 c) {
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
return c + ('A' - 'a');
|
||||
} else {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
void* pf_memcpy(void* dst, void* src, pf_u32 length) {
|
||||
pf_s8* d;
|
||||
const pf_s8* s;
|
||||
|
||||
pf_u32* ld = (pf_u32*)dst;
|
||||
const pf_u32* ls = (pf_u32*)src;
|
||||
|
||||
if (((pf_u32)ld & 3) == 0 && ((pf_u32)ls & 3) == 0) {
|
||||
for (; length > 3; length -= 4) {
|
||||
*ld++ = *ls++;
|
||||
}
|
||||
}
|
||||
|
||||
d = (pf_s8*)ld;
|
||||
s = (pf_s8*)ls;
|
||||
|
||||
while (length-- != 0) {
|
||||
*d++ = *s++;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
void* pf_memset(void* dst, pf_s32 c, pf_u32 length) {
|
||||
pf_s8* d = (pf_s8*)dst;
|
||||
pf_u32* ld;
|
||||
pf_u32 lc;
|
||||
|
||||
for (; ((pf_u32)d & 3) != 0; length--) {
|
||||
*d++ = c;
|
||||
}
|
||||
|
||||
ld = (pf_u32*)d;
|
||||
lc = (c << 24) | (c << 16) | (c << 8) | (c);
|
||||
|
||||
for (; length > 3; length -= 4) {
|
||||
*ld++ = lc;
|
||||
}
|
||||
|
||||
d = (pf_s8*)ld;
|
||||
while (length-- != 0) {
|
||||
*d++ = c;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
pf_s32 pf_memcmp(const void* s1, const void* s2, pf_u32 length) {
|
||||
const pf_u8* p1 = (const pf_u8*)s1;
|
||||
const pf_u8* p2 = (const pf_u8*)s2;
|
||||
|
||||
if (((pf_u32)p1 & 3) == 0 && ((pf_u32)p2 & 3) == 0) {
|
||||
const pf_u32* lp1 = (const pf_u32*)p1;
|
||||
const pf_u32* lp2 = (const pf_u32*)p2;
|
||||
|
||||
for (; length > 3; length -= 4, lp1++, lp2++) {
|
||||
if (*lp1 != *lp2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
p1 = (const pf_u8*)lp1;
|
||||
p2 = (const pf_u8*)lp2;
|
||||
}
|
||||
|
||||
while (length-- != 0) {
|
||||
if (*p1 != *p2) {
|
||||
return *p1 - *p2;
|
||||
}
|
||||
p1++;
|
||||
p2++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_u32 pf_strlen(const pf_s8* s) {
|
||||
const pf_s8* t = s;
|
||||
|
||||
while (*t != 0) {
|
||||
t++;
|
||||
}
|
||||
|
||||
return (pf_u32)(t - s);
|
||||
}
|
||||
|
||||
pf_s8* pf_strcpy(pf_s8* dst, const pf_s8* src) {
|
||||
pf_s8* d;
|
||||
|
||||
for (d = dst; (*d = *src) != 0; src++, d++) {
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
pf_s32 pf_strcmp(const pf_s8* s1, const pf_s8* s2) {
|
||||
const pf_u8* p1 = (pf_u8*)s1;
|
||||
const pf_u8* p2 = (pf_u8*)s2;
|
||||
|
||||
while (*p1 != 0 && *p2 != 0 && *p1 == *p2) {
|
||||
p1++;
|
||||
p2++;
|
||||
}
|
||||
|
||||
return *p1 - *p2;
|
||||
}
|
||||
|
||||
pf_s32 pf_strncmp(const pf_s8* s1, const pf_s8* s2, pf_u32 length) {
|
||||
const pf_u8* p1 = (pf_u8*)s1;
|
||||
const pf_u8* p2 = (pf_u8*)s2;
|
||||
|
||||
while (length-- != 0) {
|
||||
if (!(*p1 != 0 && *p2 != 0 && *p1 == *p2)) {
|
||||
return *p1 - *p2;
|
||||
}
|
||||
p1++;
|
||||
p2++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_u32 pf_w_strlen(const pf_u16* s) {
|
||||
const pf_u16* t = s;
|
||||
|
||||
while (*t != 0) {
|
||||
t++;
|
||||
}
|
||||
|
||||
return ((pf_s8*)t - (pf_s8*)s) >> 1;
|
||||
}
|
||||
|
||||
pf_u16* pf_w_strcpy(pf_u16* dst, const pf_u16* src) {
|
||||
pf_u16* d;
|
||||
|
||||
for (d = dst; (*d = *src) != 0; src++, d++) {
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
pf_s32 pf_w_strcmp(const pf_u16* s1, const pf_u16* s2) {
|
||||
const pf_u16* p1 = (pf_u16*)s1;
|
||||
const pf_u16* p2 = (pf_u16*)s2;
|
||||
|
||||
while (*p1 != 0 && *p2 != 0 && *p1 == *p2) {
|
||||
p1++;
|
||||
p2++;
|
||||
}
|
||||
|
||||
return *p1 - *p2;
|
||||
}
|
||||
|
||||
pf_s32 pf_w_strncmp(const pf_u16* s1, const pf_u16* s2, pf_u32 length) {
|
||||
const pf_u16* p1 = (pf_u16*)s1;
|
||||
const pf_u16* p2 = (pf_u16*)s2;
|
||||
|
||||
while (length-- != 0) {
|
||||
if (*p1 == 0 || *p2 == 0 || *p1 != *p2) {
|
||||
return *p1 - *p2;
|
||||
}
|
||||
p1++;
|
||||
p2++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
21
libs/RVL_SDK/src/fa/pf_code.c
Normal file
21
libs/RVL_SDK/src/fa/pf_code.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <private/vf/PrFILE2/pf_types.h>
|
||||
|
||||
// clang-format off
|
||||
const pf_u8 pf_valid_fn_char_8162E6B0[96] = {
|
||||
1, 3, 0, 3, 3, 3, 3, 3, 3, 3, 0, 1, 1, 3, 3, 0,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 1, 0, 1, 0, 0,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 0, 1, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 3, 0,
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
pf_s32 PFCODE_Combine_Width(pf_s16 oem_width, pf_s16 uni_width) {
|
||||
return (oem_width << 16) + uni_width;
|
||||
}
|
||||
|
||||
void PFCODE_Divide_Width(pf_s32 width, pf_s16* oem_width, pf_s16* uni_width) {
|
||||
*oem_width = (width & 0xFFFF0000) >> 16;
|
||||
*uni_width = (width & 0x0000FFFF);
|
||||
}
|
||||
442
libs/RVL_SDK/src/fa/pf_driver.c
Normal file
442
libs/RVL_SDK/src/fa/pf_driver.c
Normal file
@@ -0,0 +1,442 @@
|
||||
#include <private/vf/PrFILE2/pf_types.h>
|
||||
|
||||
typedef struct PFDRV_BPB {
|
||||
pf_u16 bytes_per_sector; // 0x00
|
||||
pf_u8 pad_02[0x12]; // 0x02
|
||||
pf_u16 fs_info_sector; // 0x14
|
||||
pf_u8 pad_16[0x6]; // 0x16
|
||||
pf_s32 fat_type; // 0x1C
|
||||
pf_u8 tail[0x38 - 0x20]; // 0x20
|
||||
} PFDRV_BPB;
|
||||
|
||||
typedef struct PFDRV_VOLUME {
|
||||
PFDRV_BPB bpb; // 0x00
|
||||
pf_u32 num_free_clusters; // 0x38
|
||||
pf_u32 last_free_cluster; // 0x3C
|
||||
pf_u8 file_and_dir_state[0x1648 - 0x40]; // 0x40
|
||||
pf_s8 label[12]; // 0x1648
|
||||
pf_u8 tail_1654[0x1F84 - 0x1654]; // 0x1654
|
||||
pf_s32 last_driver_error; // 0x1F84
|
||||
pf_u32 reserved_1f88; // 0x1F88
|
||||
pf_u16 flags; // 0x1F8C
|
||||
pf_u16 options; // 0x1F8E
|
||||
pf_u16 fsi_flag; // 0x1F90
|
||||
pf_u16 cluster_link_flags; // 0x1F92
|
||||
pf_u16 cluster_link_interval; // 0x1F94
|
||||
pf_u32* cluster_link_buffer; // 0x1F98
|
||||
pf_u32 cluster_link_capacity; // 0x1F9C
|
||||
void* driver_partition; // 0x1FA0
|
||||
pf_u8 gap_1fa4[4]; // 0x1FA4
|
||||
const pf_u8* format_options; // 0x1FA8
|
||||
} PFDRV_VOLUME;
|
||||
|
||||
typedef struct PFDRV_VOLUME_SET {
|
||||
pf_u8 state_prefix[0x40]; // 0x00
|
||||
pf_s32 last_error; // 0x40
|
||||
pf_s32 last_driver_error; // 0x44
|
||||
pf_u8 tail_48[0x88 - 0x48]; // 0x48
|
||||
PFDRV_VOLUME volumes[26]; // 0x88
|
||||
} PFDRV_VOLUME_SET;
|
||||
|
||||
extern PFDRV_VOLUME_SET pf_vol_set;
|
||||
|
||||
typedef struct PFDRV_CACHE_PAGE {
|
||||
pf_u16 stat;
|
||||
pf_u16 option;
|
||||
pf_u8* buffer;
|
||||
pf_u8* p_buf;
|
||||
pf_u8* p_mod_sbuf;
|
||||
pf_u8* p_mod_ebuf;
|
||||
pf_u32 size;
|
||||
pf_u32 sector;
|
||||
void* signature;
|
||||
struct PFDRV_CACHE_PAGE* p_next;
|
||||
struct PFDRV_CACHE_PAGE* p_prev;
|
||||
} PFDRV_CACHE_PAGE;
|
||||
|
||||
typedef struct PFDRV_PART_FUNC {
|
||||
void (*insert)(void* partition);
|
||||
void (*eject)(void* partition);
|
||||
} PFDRV_PART_FUNC;
|
||||
|
||||
typedef struct PFDRV_MEDIA_INFO {
|
||||
pf_u32 total_sectors; // 0x00
|
||||
pf_u16 cylinders; // 0x04
|
||||
pf_u8 heads; // 0x06
|
||||
pf_u8 sectors_per_track; // 0x07
|
||||
pf_u16 bytes_per_sector; // 0x08
|
||||
pf_u16 reserved_0a; // 0x0A
|
||||
pf_u32 media_attr; // 0x0C
|
||||
const pf_u8* format_param; // 0x10
|
||||
} PFDRV_MEDIA_INFO;
|
||||
|
||||
typedef struct PFDRV_VOLUME_INFO {
|
||||
pf_s8 label[12]; // 0x00
|
||||
pf_u8 tail[8]; // 0x0C
|
||||
} PFDRV_VOLUME_INFO;
|
||||
|
||||
enum {
|
||||
FAT_32 = 2
|
||||
};
|
||||
|
||||
extern void* pf_memcpy(void* dst, const void* src, pf_u32 length);
|
||||
|
||||
extern pf_s32 PFCACHE_AllocateDataPage(PFDRV_VOLUME* volume, pf_u32 sector, PFDRV_CACHE_PAGE** p_page, pf_u32* option);
|
||||
extern void PFCACHE_FreeDataPage(PFDRV_VOLUME* volume, PFDRV_CACHE_PAGE* p_page);
|
||||
|
||||
extern pf_s32 pdm_part_logical_read(void* partition, pf_u8* buffer, pf_u32 sector, pf_u32 num_sector, pf_u16 bps,
|
||||
pf_u32* p_num_success);
|
||||
extern pf_s32 pdm_part_logical_write(void* partition, const pf_u8* buffer, pf_u32 sector, pf_u32 num_sector, pf_u16 bps,
|
||||
pf_u32* p_num_success);
|
||||
extern pf_s32 pdm_part_register_callback(void* partition, const PFDRV_PART_FUNC* func);
|
||||
extern pf_s32 pdm_part_unregister_callback(void* partition);
|
||||
extern pf_s32 pdm_part_init(void* partition);
|
||||
extern pf_s32 pdm_part_finalize(void* partition);
|
||||
extern pf_s32 pdm_part_mount(void* partition);
|
||||
extern pf_s32 pdm_part_unmount(void* partition, pf_u32 mode);
|
||||
extern pf_s32 pdm_part_get_media_attribute(void* partition, PFDRV_MEDIA_INFO* info);
|
||||
extern pf_s32 pdm_part_get_driver_error_code(void* partition);
|
||||
extern pf_s32 pdm_part_format(void* partition, const pf_u8* format_param);
|
||||
extern pf_s32 pdm_bpb_InitVolumeWithBootSector(PFDRV_VOLUME* volume, const pf_u8* buf);
|
||||
extern pf_s32 pdm_bpb_InitVolumeWithFSINFOSector(PFDRV_VOLUME* volume, const pf_u8* buf, pf_u32* p_num_free_clusters,
|
||||
pf_u32* p_last_free_cluster);
|
||||
|
||||
void PFDRV_LoadVolumeLabelFromBuf(PFDRV_VOLUME* volume, const pf_u8* buf) {
|
||||
pf_memcpy(volume->label, buf, 0xB);
|
||||
volume->label[0xB] = 0;
|
||||
}
|
||||
|
||||
void PFDRV_StoreVolumeLabelToBuf(PFDRV_VOLUME_INFO* volume_info, PFDRV_VOLUME* volume) {
|
||||
pf_memcpy(volume_info->label, volume->label, 0xB);
|
||||
volume_info->label[0xB] = 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_StoreVolumeLabelToBPB(PFDRV_VOLUME* volume, const pf_s8* label) {
|
||||
PFDRV_CACHE_PAGE* p_page;
|
||||
pf_u32 option;
|
||||
pf_u32 num_sector;
|
||||
pf_s32 err;
|
||||
pf_s32 result;
|
||||
|
||||
err = PFCACHE_AllocateDataPage(volume, -1, &p_page, &option);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = pdm_part_logical_read(volume->driver_partition, p_page->p_buf, 0, 1, volume->bpb.bytes_per_sector, &num_sector);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
result = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = result;
|
||||
volume->last_driver_error = result;
|
||||
result = 0x1000;
|
||||
} else {
|
||||
result = -1;
|
||||
}
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
if (result != 0) {
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (num_sector != 1) {
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
return 0x11;
|
||||
}
|
||||
|
||||
if (volume->bpb.fat_type == FAT_32) {
|
||||
pf_memcpy(p_page->p_buf + 0x47, label, 0xB);
|
||||
} else {
|
||||
pf_memcpy(p_page->p_buf + 0x2B, label, 0xB);
|
||||
}
|
||||
|
||||
err = pdm_part_logical_write(volume->driver_partition, p_page->p_buf, 0, 1, volume->bpb.bytes_per_sector,
|
||||
&num_sector);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
result = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = result;
|
||||
volume->last_driver_error = result;
|
||||
result = 0x1000;
|
||||
} else {
|
||||
result = -1;
|
||||
}
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (num_sector != 1) {
|
||||
return 0x11;
|
||||
}
|
||||
|
||||
pf_memcpy(volume->label, label, 0xB);
|
||||
volume->label[0xB] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PFDRV_MediaEject(void* partition) {
|
||||
PFDRV_VOLUME* p_vol;
|
||||
pf_u32 i;
|
||||
|
||||
p_vol = pf_vol_set.volumes;
|
||||
for (i = 0; i < 26; p_vol++, i++) {
|
||||
if (p_vol->driver_partition == partition) {
|
||||
if ((p_vol->flags & 0x08) != 0) {
|
||||
p_vol->flags |= 0x20;
|
||||
}
|
||||
p_vol->flags &= ~0x0C;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PFDRV_MediaInsert(void* partition) {
|
||||
PFDRV_VOLUME* p_vol;
|
||||
pf_u32 i;
|
||||
|
||||
p_vol = pf_vol_set.volumes;
|
||||
for (i = 0; i < 26; p_vol++, i++) {
|
||||
if (p_vol->driver_partition == partition) {
|
||||
p_vol->flags |= 0x14;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_IsInserted(PFDRV_VOLUME* volume) {
|
||||
return (volume->flags >> 2) & 1;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_IsMountRequested(PFDRV_VOLUME* volume) {
|
||||
return (volume->flags >> 4) & 1;
|
||||
}
|
||||
|
||||
void PFDRV_ClearMountRequested(PFDRV_VOLUME* volume) {
|
||||
volume->flags &= ~0x10;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_IsUnmountRequested(PFDRV_VOLUME* volume) {
|
||||
return (volume->flags >> 5) & 1;
|
||||
}
|
||||
|
||||
void PFDRV_ClearUnmountRequested(PFDRV_VOLUME* volume) {
|
||||
volume->flags &= ~0x20;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_init(PFDRV_VOLUME* volume) {
|
||||
PFDRV_PART_FUNC func;
|
||||
pf_s32 err;
|
||||
|
||||
func.insert = PFDRV_MediaInsert;
|
||||
func.eject = PFDRV_MediaEject;
|
||||
|
||||
err = pdm_part_register_callback(volume->driver_partition, &func);
|
||||
if (err != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = pdm_part_init(volume->driver_partition);
|
||||
if (err != 0) {
|
||||
pdm_part_unregister_callback(volume->driver_partition);
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
return 0x1000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_finalize(PFDRV_VOLUME* volume) {
|
||||
pf_s32 err;
|
||||
|
||||
err = pdm_part_unregister_callback(volume->driver_partition);
|
||||
if (err != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = pdm_part_finalize(volume->driver_partition);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
return 0x1000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_mount(PFDRV_VOLUME* volume) {
|
||||
PFDRV_MEDIA_INFO info;
|
||||
pf_u32 option;
|
||||
PFDRV_CACHE_PAGE* p_page;
|
||||
pf_u32 num_sector;
|
||||
pf_s32 err;
|
||||
|
||||
err = pdm_part_mount(volume->driver_partition);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
return 0x1000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = pdm_part_get_media_attribute(volume->driver_partition, &info);
|
||||
if (err != 0) {
|
||||
pdm_part_unmount(volume->driver_partition, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((info.media_attr & 0x01) != 0) {
|
||||
volume->flags |= 0x02;
|
||||
} else {
|
||||
volume->flags &= ~0x02;
|
||||
}
|
||||
if ((info.media_attr & 0x02) != 0) {
|
||||
const pf_u8* format_param = info.format_param;
|
||||
volume->flags |= 0x40;
|
||||
volume->format_options = format_param;
|
||||
}
|
||||
if ((info.media_attr & 0x08) != 0) {
|
||||
volume->flags |= 0x80;
|
||||
}
|
||||
|
||||
PFCACHE_AllocateDataPage(volume, -1, &p_page, &option);
|
||||
|
||||
err = pdm_part_logical_read(volume->driver_partition, p_page->buffer, 0, 1, 0x200, &num_sector);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
err = 0x1000;
|
||||
} else {
|
||||
err = -1;
|
||||
}
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
pdm_part_unmount(volume->driver_partition, 0);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = pdm_bpb_InitVolumeWithBootSector(volume, p_page->buffer);
|
||||
if (err != 0) {
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
pdm_part_unmount(volume->driver_partition, 0);
|
||||
return 7;
|
||||
}
|
||||
|
||||
volume->num_free_clusters = -1;
|
||||
volume->last_free_cluster = -1;
|
||||
|
||||
if (volume->bpb.fat_type == FAT_32) {
|
||||
err = pdm_part_logical_read(volume->driver_partition, p_page->buffer, volume->bpb.fs_info_sector, 1, 0x200,
|
||||
&num_sector);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
err = 0x1000;
|
||||
} else {
|
||||
err = -1;
|
||||
}
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
pdm_part_unmount(volume->driver_partition, 0);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = pdm_bpb_InitVolumeWithFSINFOSector(volume, p_page->buffer, &volume->num_free_clusters,
|
||||
&volume->last_free_cluster);
|
||||
if (err != 0) {
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
pdm_part_unmount(volume->driver_partition, 0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_unmount(PFDRV_VOLUME* volume, pf_u32 mode) {
|
||||
pf_s32 err;
|
||||
|
||||
err = pdm_part_unmount(volume->driver_partition, mode == 1);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
return 0x1000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_format(PFDRV_VOLUME* volume, const pf_u8* format_options) {
|
||||
pf_s32 err;
|
||||
|
||||
err = pdm_part_format(volume->driver_partition, format_options);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
return 0x1000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_lread(PFDRV_VOLUME* volume, pf_u8* buffer, pf_u32 sector, pf_u32 num_sector, pf_u32* p_num_success) {
|
||||
pf_s32 err;
|
||||
|
||||
err = pdm_part_logical_read(volume->driver_partition, buffer, sector, num_sector, volume->bpb.bytes_per_sector,
|
||||
p_num_success);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
return 0x1000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_lwrite(PFDRV_VOLUME* volume, const pf_u8* buffer, pf_u32 sector, pf_u32 num_sector, pf_u32* p_num_success) {
|
||||
pf_s32 err;
|
||||
|
||||
err = pdm_part_logical_write(volume->driver_partition, buffer, sector, num_sector, volume->bpb.bytes_per_sector,
|
||||
p_num_success);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
return 0x1000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,747 +0,0 @@
|
||||
#include <private/vf/PrFILE2/fatfs/pf_entry.h>
|
||||
|
||||
typedef struct PFITER_FAT_HINT {
|
||||
pf_u32 chain_index;
|
||||
pf_u32 cluster;
|
||||
pf_u32 previous_cluster;
|
||||
} PFITER_FAT_HINT;
|
||||
|
||||
typedef struct PFITER_FFD {
|
||||
pf_u32 start_cluster;
|
||||
pf_u32 current_start_cluster;
|
||||
pf_u32* p_start_cluster;
|
||||
PF_LAST_CLUSTER last_cluster;
|
||||
PF_FAT_LAST_ACCESS last_access_cluster;
|
||||
PF_CLUSTER_LINK cluster_link;
|
||||
PFITER_FAT_HINT* p_hint;
|
||||
PF_VOLUME* p_vol;
|
||||
} PFITER_FFD;
|
||||
|
||||
typedef struct PFITER_ENT_ITER {
|
||||
pf_u32 index;
|
||||
PF_VOLUME* p_vol;
|
||||
PFITER_FFD ffd;
|
||||
pf_u32 file_sector_index;
|
||||
pf_u32 sector;
|
||||
pf_u16 offset;
|
||||
pf_u16 offset_mask;
|
||||
pf_u8 buf[32];
|
||||
pf_u8 log2_entries_per_sector;
|
||||
} PFITER_ENT_ITER;
|
||||
|
||||
typedef struct PFITER_BPB {
|
||||
pf_u16 bytes_per_sector;
|
||||
pf_u16 num_reserved_sectors;
|
||||
pf_u16 num_root_dir_entries;
|
||||
pf_u8 sectors_per_cluster;
|
||||
pf_u8 num_FATs;
|
||||
pf_u32 total_sectors;
|
||||
pf_u32 sectors_per_FAT;
|
||||
pf_u32 root_dir_cluster;
|
||||
pf_u16 fs_info_sector;
|
||||
pf_u16 backup_boot_sector;
|
||||
pf_u16 ext_flags;
|
||||
pf_u8 media;
|
||||
pf_s32 fat_type;
|
||||
pf_u8 log2_bytes_per_sector;
|
||||
pf_u8 log2_sectors_per_cluster;
|
||||
pf_u8 num_active_FATs;
|
||||
pf_u16 num_root_dir_sectors;
|
||||
pf_u32 active_FAT_sector;
|
||||
pf_u32 first_root_dir_sector;
|
||||
pf_u32 first_data_sector;
|
||||
pf_u32 num_clusters;
|
||||
} PFITER_BPB;
|
||||
|
||||
struct PF_VOLUME {
|
||||
PFITER_BPB bpb;
|
||||
};
|
||||
|
||||
typedef struct PFITER_CONTEXT_VOLUME {
|
||||
pf_u32 stat;
|
||||
pf_s32 context_id;
|
||||
PF_VOLUME* p_vol;
|
||||
} PFITER_CONTEXT_VOLUME;
|
||||
|
||||
typedef struct PFITER_VOLUME_SET {
|
||||
pf_u32 flags;
|
||||
pf_u32 reserved;
|
||||
PF_VOLUME* current_volume;
|
||||
PFITER_CONTEXT_VOLUME context_volumes[3];
|
||||
pf_s32 num_attached;
|
||||
pf_s32 num_mounted;
|
||||
pf_u32 config;
|
||||
void* user_data;
|
||||
pf_s32 last_error;
|
||||
pf_s32 last_driver_error;
|
||||
void (*code_callbacks[6])(void);
|
||||
pf_u32 setting;
|
||||
} PFITER_VOLUME_SET;
|
||||
|
||||
extern PFITER_VOLUME_SET pf_vol_set;
|
||||
pf_s8* PFSTR_GetStrPos(PF_STR*, pf_u32);
|
||||
pf_u32 PFSTR_GetCodeMode(PF_STR* p_str);
|
||||
void PFSTR_MoveStrPos(PF_STR* p_str, pf_s16 num_char);
|
||||
pf_u16 PFSTR_StrLen(PF_STR* p_str);
|
||||
pf_u16 PFSTR_StrNumChar(PF_STR* p_str, pf_u32 target);
|
||||
pf_s32 PFSTR_StrCmp(const PF_STR* p_str, const pf_s8* s);
|
||||
pf_s32 PFSTR_StrNCmp(PF_STR* p_str, const pf_s8* s, pf_u32 target, pf_s16 offset, pf_u16 num);
|
||||
void* pf_memcpy(void* dst, void* src, pf_u32 length);
|
||||
void* pf_memset(void* dst, pf_s32 c, pf_u32 length);
|
||||
pf_s32 pf_strncmp(const pf_s8* s1, const pf_s8* s2, pf_u32 length);
|
||||
pf_u8 PFENT_CalcCheckSum(PF_DIR_ENT* p_ent);
|
||||
void PFENT_LoadShortNameFromBuf(PF_DIR_ENT* p_ent, const pf_u8* buf);
|
||||
void PFENT_loadEntryNumericFieldsFromBuf(PF_DIR_ENT* p_ent, const pf_u8* buf);
|
||||
pf_s32 PFENT_LoadLFNEntryFieldsFromBuf(PF_DIR_ENT* p_ent, const pf_u8* buf);
|
||||
pf_s32 PFENT_GetRootDir(PF_VOLUME* p_vol, PF_DIR_ENT* p_ent);
|
||||
pf_s32 PFFAT_GetSectorSpecified(PFITER_FFD* p_ffd, pf_u32 file_sector_index, pf_u32 may_allocate, pf_u32* p_sector);
|
||||
pf_s32 PFFAT_getBeforeChain(PF_VOLUME* p_vol, pf_u32 start_cluster, pf_u32 lActive, pf_u32* p_cluster);
|
||||
pf_s32 PFFAT_ResetFFD(PFITER_FFD* p_ffd, pf_u32* p_start_cluster);
|
||||
pf_s32 PFFAT_InitFFD(PFITER_FFD* p_ffd, PFITER_FAT_HINT* p_hint, PF_VOLUME* p_vol, pf_u32* p_start_cluster);
|
||||
void PFPATH_InitTokenOfPath(PF_STR* p_str, pf_s8* path, pf_u32 code_mode);
|
||||
pf_s32 PFPATH_GetNextTokenOfPath(PF_STR* p_str, pf_bool wildcard);
|
||||
pf_bool PFPATH_MatchFileNameWithPattern(const pf_s8* file_name, PF_STR* p_pattern, pf_bool is_long_name);
|
||||
void PFPATH_getLongNameformShortName(pf_s8* short_name, pf_s8* long_name, pf_u8 flag);
|
||||
pf_u32 PFPATH_GetLengthFromShortname(const pf_s8* sSrc);
|
||||
pf_u32 PFPATH_GetLengthFromUnicode(const pf_u16* sSrc);
|
||||
pf_s32 PFPATH_transformInUnicode(pf_u16* sDestStr, const pf_s8* sSrcStr);
|
||||
pf_bool PFPATH_GetExtShortNameIndex(PF_STR* p_str, pf_u32* p_index);
|
||||
pf_s32 PFSEC_ReadData(PF_VOLUME* p_vol, pf_u8* p_buf, pf_u32 sector, pf_u16 offset, pf_u32 size, pf_u32* p_success_size, pf_bool set_sig);
|
||||
pf_s32 PFSEC_WriteData(PF_VOLUME* p_vol, const pf_u8* p_buf, pf_u32 sector, pf_u16 offset, pf_u32 size, pf_u32* p_success_size, pf_bool set_sig);
|
||||
pf_s32 PFVOL_GetCurrentDir(PF_VOLUME*, PF_DIR_ENT*);
|
||||
pf_s32 PFCACHE_AllocateDataPage(PF_VOLUME*, pf_u32, PF_CACHE_PAGE**, pf_bool*);
|
||||
pf_s32 PFCACHE_FreeDataPage(PF_VOLUME*, PF_CACHE_PAGE*);
|
||||
pf_s32 PFENT_RecalcEntryIterator(PFITER_ENT_ITER*, pf_u32);
|
||||
pf_s32 PFENT_ITER_IteratorInitialize(PFITER_ENT_ITER*, pf_u32);
|
||||
pf_bool PFENT_ITER_IsAtLogicalEnd(PFITER_ENT_ITER*);
|
||||
pf_s32 PFENT_ITER_MoveTo(PFITER_ENT_ITER*, pf_u32, pf_u32);
|
||||
pf_s32 PFENT_ITER_Advance(PFITER_ENT_ITER*, pf_u32);
|
||||
pf_s32 PFENT_ITER_Retreat(PFITER_ENT_ITER*, pf_u32);
|
||||
pf_s32 PFENT_ITER_FindDirEntryFromCluster(PFITER_ENT_ITER*, PF_DIR_ENT*, pf_u32, pf_bool*);
|
||||
|
||||
#pragma dont_inline on
|
||||
pf_s32 PFENT_RecalcEntryIterator(PFITER_ENT_ITER* p_iter, pf_u32 may_allocate) {
|
||||
pf_u32 file_sector_index;
|
||||
pf_u32 previous_fsindex;
|
||||
pf_u32 sector_count;
|
||||
pf_s32 err;
|
||||
PF_CACHE_PAGE* page;
|
||||
pf_u32 success_size;
|
||||
pf_bool hit;
|
||||
file_sector_index = p_iter->index >> p_iter->log2_entries_per_sector;
|
||||
previous_fsindex = p_iter->file_sector_index;
|
||||
if (file_sector_index != p_iter->file_sector_index) {
|
||||
p_iter->file_sector_index = file_sector_index;
|
||||
err = PFFAT_GetSectorSpecified(&p_iter->ffd, file_sector_index, 0, &p_iter->sector);
|
||||
if (err != 0) return err;
|
||||
if (p_iter->sector == -1U && may_allocate != 0) {
|
||||
err = PFFAT_GetSectorSpecified(&p_iter->ffd, file_sector_index, 1, &p_iter->sector);
|
||||
if (err != 0) return err;
|
||||
if (p_iter->sector != -1U && previous_fsindex != -1U) {
|
||||
err = PFCACHE_AllocateDataPage(p_iter->p_vol, -1U, &page, &hit);
|
||||
if (err != 0) return err;
|
||||
pf_memset(page->p_buf, 0, p_iter->p_vol->bpb.bytes_per_sector);
|
||||
for (sector_count = 0; sector_count < p_iter->p_vol->bpb.sectors_per_cluster; ++sector_count) {
|
||||
err = PFSEC_WriteData(p_iter->p_vol, page->p_buf, p_iter->sector + sector_count, 0,
|
||||
p_iter->p_vol->bpb.bytes_per_sector, &success_size, 0);
|
||||
if (err != 0) {
|
||||
PFCACHE_FreeDataPage(p_iter->p_vol, page);
|
||||
return err;
|
||||
}
|
||||
if (success_size != p_iter->p_vol->bpb.bytes_per_sector) {
|
||||
PFCACHE_FreeDataPage(p_iter->p_vol, page);
|
||||
return 17;
|
||||
}
|
||||
}
|
||||
PFCACHE_FreeDataPage(p_iter->p_vol, page);
|
||||
}
|
||||
}
|
||||
}
|
||||
p_iter->offset = (p_iter->index & p_iter->offset_mask) * 32;
|
||||
return 0;
|
||||
}
|
||||
#pragma dont_inline reset
|
||||
|
||||
static inline pf_s32 PFENT_ITER_LoadEntry(PFITER_ENT_ITER* p_iter) {
|
||||
pf_u32 success_size;
|
||||
pf_s32 err;
|
||||
|
||||
if (p_iter->sector == -1) {
|
||||
return 16;
|
||||
}
|
||||
err = PFSEC_ReadData(p_iter->p_vol, p_iter->buf, p_iter->sector, p_iter->offset, 0x20U, &success_size, 0U);
|
||||
if (success_size != 0x20) {
|
||||
return 17;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline pf_s32 PFENT_ITER_DoMoveTo(PFITER_ENT_ITER* p_iter, pf_u32 index, pf_u32 may_allocate) {
|
||||
pf_u32 prev_index = p_iter->index;
|
||||
pf_s32 err;
|
||||
|
||||
p_iter->index = index;
|
||||
err = PFENT_RecalcEntryIterator(p_iter, may_allocate);
|
||||
if (err != 0) {
|
||||
p_iter->index = prev_index;
|
||||
PFENT_RecalcEntryIterator(p_iter, 0U);
|
||||
return err;
|
||||
}
|
||||
err = PFENT_ITER_LoadEntry(p_iter);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void PFENT_ITER_MakeLongFileName(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent) {
|
||||
pf_s32 lengthName;
|
||||
signed char filename[13];
|
||||
|
||||
lengthName = 0;
|
||||
PFPATH_getLongNameformShortName(p_ent->short_name, filename, p_iter->buf[0xC]);
|
||||
lengthName = PFPATH_transformInUnicode(p_ent->long_name, filename);
|
||||
p_ent->num_entry_LFNs = ((lengthName % 13) ? 1 : 0) + (lengthName / 13);
|
||||
p_ent->check_sum = PFENT_CalcCheckSum(p_ent);
|
||||
p_ent->ordinal = 1;
|
||||
}
|
||||
|
||||
static inline pf_s32 InitializeIterator(PFITER_ENT_ITER* p_iter, pf_u32 index) {
|
||||
p_iter->p_vol = p_iter->ffd.p_vol;
|
||||
p_iter->log2_entries_per_sector = p_iter->p_vol->bpb.log2_bytes_per_sector - 5;
|
||||
p_iter->offset_mask = (1 << p_iter->log2_entries_per_sector) - 1;
|
||||
p_iter->file_sector_index = -1U;
|
||||
return PFENT_ITER_DoMoveTo(p_iter, index, 0);
|
||||
}
|
||||
|
||||
static inline pf_s32 AdvanceIterator(PFITER_ENT_ITER* p_iter, pf_u32 may_allocate) {
|
||||
pf_s32 err = PFENT_ITER_DoMoveTo(p_iter, p_iter->index + 1, may_allocate);
|
||||
if (err != 0) return err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void LoadNumericEntry(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent) {
|
||||
PFENT_loadEntryNumericFieldsFromBuf(p_ent, p_iter->buf);
|
||||
p_ent->entry_sector = p_iter->sector;
|
||||
p_ent->entry_offset = p_iter->offset;
|
||||
p_ent->p_vol = p_iter->ffd.p_vol;
|
||||
if ((p_ent->attr & 0x10) && p_ent->start_cluster == 0) p_ent->start_cluster = 1;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_DoFindEntry(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_STR* p_pattern,
|
||||
pf_u32 attr_required, pf_u32 attr_forbidden, pf_bool* p_is_found) {
|
||||
pf_s32 err = 0;
|
||||
pf_u32 index_search_from;
|
||||
pf_u32 is_extsfn = 0;
|
||||
*p_is_found = 0;
|
||||
if (PFSTR_StrCmp(p_pattern, (pf_s8*)"..") == 0 && (p_ent->attr & 0x10) && p_ent->start_cluster == 1) return 2;
|
||||
if (PFSTR_StrCmp(p_pattern, (pf_s8*)".") == 0) {
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->ordinal = 0;
|
||||
p_ent->check_sum = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
if ((pf_vol_set.setting & 2) == 2) is_extsfn = PFPATH_GetExtShortNameIndex(p_pattern, &index_search_from);
|
||||
if (is_extsfn == 1) {
|
||||
for (err = InitializeIterator(p_iter, index_search_from - 1);; err = PFENT_ITER_Retreat(p_iter, 0)) {
|
||||
pf_s32 attr;
|
||||
if (err != 0) return err;
|
||||
if ((p_iter->buf[11] & 15) == 15) {
|
||||
if (PFENT_LoadLFNEntryFieldsFromBuf(p_ent, p_iter->buf) != 0) return 3;
|
||||
if (!(p_iter->buf[0] & 0x40)) continue;
|
||||
} else return 0;
|
||||
err = InitializeIterator(p_iter, index_search_from);
|
||||
if (err != 0) return err;
|
||||
attr = p_iter->buf[11];
|
||||
if (attr == 0) attr = 0x40;
|
||||
if (attr_required & 0x80) {
|
||||
attr_required &= 0x7f;
|
||||
attr_forbidden &= 0x7f;
|
||||
if ((attr_required && (pf_s32)(attr_required & attr) != (pf_s32)attr_required) ||
|
||||
(attr_forbidden && (pf_s32)(attr_forbidden & attr) == (pf_s32)attr_forbidden)) err = -1;
|
||||
} else if (attr_required != 0x7f && attr != attr_required &&
|
||||
(!(attr & attr_required) || (attr & attr_forbidden))) err = -1;
|
||||
if (err == -1) return 0;
|
||||
if (attr & 8) return 3;
|
||||
PFENT_LoadShortNameFromBuf(p_ent, p_iter->buf);
|
||||
if (PFPATH_MatchFileNameWithPattern(p_ent->short_name, p_pattern, 0)) {
|
||||
LoadNumericEntry(p_iter, p_ent);
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
for (; PFENT_ITER_IsAtLogicalEnd(p_iter) == PF_FALSE; err = AdvanceIterator(p_iter, 0)) {
|
||||
pf_s32 attr;
|
||||
if (err != 0) return err;
|
||||
if (p_iter->buf[0] == 0) break;
|
||||
if (p_iter->buf[0] == 0xe5) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
continue;
|
||||
}
|
||||
attr = p_iter->buf[11];
|
||||
if ((attr & 15) == 15) {
|
||||
if (PFENT_LoadLFNEntryFieldsFromBuf(p_ent, p_iter->buf) != 0) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (attr == 0) attr = 0x40;
|
||||
if (attr_required & 0x80) {
|
||||
attr_required &= 0x7f;
|
||||
attr_forbidden &= 0x7f;
|
||||
if ((attr_required && (pf_s32)(attr_required & attr) != (pf_s32)attr_required) ||
|
||||
(attr_forbidden && (pf_s32)(attr_forbidden & attr) == (pf_s32)attr_forbidden)) err = -1;
|
||||
} else if ((pf_u8)attr_required != 0x7f && (pf_u32)attr != (pf_u8)attr_required &&
|
||||
(!(attr & (pf_u8)attr_required) || (attr & (pf_u8)attr_forbidden))) err = -1;
|
||||
if (err == -1) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
continue;
|
||||
}
|
||||
if (attr & 8) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
}
|
||||
PFENT_LoadShortNameFromBuf(p_ent, p_iter->buf);
|
||||
if (p_ent->num_entry_LFNs && p_ent->ordinal == 1 && p_ent->check_sum == PFENT_CalcCheckSum(p_ent) &&
|
||||
PFPATH_MatchFileNameWithPattern((pf_s8*)p_ent->long_name, p_pattern, 1)) {
|
||||
LoadNumericEntry(p_iter, p_ent);
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
if (PFPATH_MatchFileNameWithPattern(p_ent->short_name, p_pattern, 0)) {
|
||||
if (p_iter->buf[12] & 0x18) PFENT_ITER_MakeLongFileName(p_iter, p_ent);
|
||||
LoadNumericEntry(p_iter, p_ent);
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
}
|
||||
finish:
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_DoGetEntry(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_VOLUME* p_vol, PF_STR* p_path, pf_bool wildcard,
|
||||
pf_bool no_look_last_token) {
|
||||
pf_s8* p;
|
||||
PF_STR token;
|
||||
pf_bool is_found;
|
||||
PFITER_FAT_HINT hint;
|
||||
pf_u32 start_cluster;
|
||||
PF_DIR_ENT current_ent;
|
||||
pf_s32 err;
|
||||
pf_u32 code_mode;
|
||||
|
||||
if (PFSTR_StrNCmp(p_path, (pf_s8*)":", 1, 1, 1) == 0) {
|
||||
PFSTR_MoveStrPos(p_path, 2);
|
||||
}
|
||||
if ((PFSTR_StrNCmp(p_path, (pf_s8*)"\\", 1, 0, 1) == 0 || PFSTR_StrNCmp(p_path, (pf_s8*)"/", 1, 0, 1) == 0)) {
|
||||
err = PFENT_GetRootDir(p_vol, p_ent);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (PFSTR_StrNumChar(p_path, 1) == 1 && (PFSTR_StrNCmp(p_path, (pf_s8*)"\0", 2, 0, 1) == 0)) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
err = PFVOL_GetCurrentDir(p_vol, p_ent);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
p = PFSTR_GetStrPos(p_path, 1);
|
||||
PFFAT_InitFFD(&p_iter->ffd, &hint, p_vol, &p_iter->ffd.current_start_cluster);
|
||||
p_iter->ffd.current_start_cluster = p_ent->start_cluster;
|
||||
code_mode = PFSTR_GetCodeMode(p_path);
|
||||
PFPATH_InitTokenOfPath(&token, p, code_mode);
|
||||
|
||||
for (err = PFPATH_GetNextTokenOfPath(&token, wildcard); token.p_head != 0; err = PFPATH_GetNextTokenOfPath(&token, wildcard)) {
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (no_look_last_token != 0 && (PFSTR_StrNCmp(&token, (pf_s8*)"\0", 2, 0, 1) == 0)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ((p_ent->attr & 0x10) == 0) {
|
||||
return 2;
|
||||
}
|
||||
if (PFSTR_StrLen(&token) == 0) {
|
||||
return 2;
|
||||
}
|
||||
p_iter->ffd.current_start_cluster = p_ent->start_cluster;
|
||||
PFFAT_ResetFFD(&p_iter->ffd, &p_iter->ffd.current_start_cluster);
|
||||
err = InitializeIterator(p_iter, 0);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
start_cluster = *p_iter->ffd.p_start_cluster;
|
||||
err = PFENT_ITER_DoFindEntry(p_iter, p_ent, &token, 0x7F, 0, &is_found);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (!is_found) {
|
||||
err = PFPATH_GetNextTokenOfPath(&token, wildcard);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return (token.p_head == PF_NULL) + 2;
|
||||
}
|
||||
if (!wildcard) {
|
||||
if ((p_ent->attr & 0x10) != 0 && p_ent->start_cluster == 1) {
|
||||
p_ent->path_len = 3;
|
||||
continue;
|
||||
}
|
||||
if ((p_ent->attr & 0x10) != 0 && p_ent->short_name[0] == '.' && p_ent->short_name[1] == '.') {
|
||||
PFFAT_ResetFFD(&p_iter->ffd, &p_ent->start_cluster);
|
||||
err = InitializeIterator(p_iter, 0);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
current_ent.attr = p_ent->attr;
|
||||
current_ent.start_cluster = p_ent->start_cluster;
|
||||
err = PFENT_ITER_FindDirEntryFromCluster(p_iter, ¤t_ent, start_cluster, &is_found);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (is_found == 0) {
|
||||
return 2;
|
||||
}
|
||||
if (current_ent.num_entry_LFNs != 0) {
|
||||
p_ent->path_len -= PFPATH_GetLengthFromUnicode(current_ent.long_name);
|
||||
} else {
|
||||
p_ent->path_len -= PFPATH_GetLengthFromShortname(¤t_ent.short_name[0]);
|
||||
}
|
||||
p_ent->path_len--;
|
||||
continue;
|
||||
}
|
||||
if ((p_ent->attr & 0x10) == 0 || p_ent->short_name[0] != '.') {
|
||||
p_ent->path_len = (PFSTR_StrNumChar(&token, 1) + 1) + p_ent->path_len;
|
||||
if ((PFSTR_StrNCmp(&token, (pf_s8*)"\0", 2, 0, 1) != 0)) {
|
||||
p_ent->path_len -= PFSTR_StrNumChar(&token, 2);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_IteratorInitialize(PFITER_ENT_ITER* p_iter, pf_u32 index_start_from) {
|
||||
pf_s32 err;
|
||||
|
||||
p_iter->p_vol = p_iter->ffd.p_vol;
|
||||
p_iter->log2_entries_per_sector = p_iter->p_vol->bpb.log2_bytes_per_sector - 5;
|
||||
p_iter->offset_mask = (1 << p_iter->log2_entries_per_sector) - 1;
|
||||
p_iter->file_sector_index = -1;
|
||||
err = PFENT_ITER_DoMoveTo(p_iter, index_start_from, 0U);
|
||||
return err;
|
||||
}
|
||||
|
||||
pf_bool PFENT_ITER_IsAtLogicalEnd(PFITER_ENT_ITER* p_iter) {
|
||||
pf_s32 err;
|
||||
pf_u32 save_index;
|
||||
pf_u32 save_fsindex;
|
||||
|
||||
if (p_iter->sector == -1U || p_iter->buf[0] == 0 || p_iter->index >= (1000000 - 1)) {
|
||||
save_index = p_iter->index;
|
||||
save_fsindex = p_iter->file_sector_index;
|
||||
p_iter->index = (p_iter->file_sector_index + 1) << p_iter->log2_entries_per_sector;
|
||||
err = PFENT_RecalcEntryIterator(p_iter, PF_FALSE);
|
||||
if (err != 0) {
|
||||
p_iter->index = save_index;
|
||||
p_iter->file_sector_index = save_fsindex;
|
||||
return PF_TRUE;
|
||||
}
|
||||
if (p_iter->sector != -1) {
|
||||
err = PFENT_ITER_LoadEntry(p_iter);
|
||||
if (err != 0) {
|
||||
return PF_TRUE;
|
||||
}
|
||||
return PF_FALSE;
|
||||
}
|
||||
return PF_TRUE;
|
||||
}
|
||||
return PF_FALSE;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_MoveTo(PFITER_ENT_ITER* p_iter, pf_u32 index, pf_u32 may_allocate) {
|
||||
pf_s32 err;
|
||||
|
||||
if (p_iter->index != index || p_iter->sector != -1U || may_allocate == PF_FALSE) {
|
||||
err = PFENT_ITER_DoMoveTo(p_iter, index, may_allocate);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_Advance(PFITER_ENT_ITER* p_iter, pf_u32 may_allocate) {
|
||||
return PFENT_ITER_MoveTo(p_iter, p_iter->index + 1, may_allocate);
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_FindCluster(PF_DIR_ENT* p_ent, pf_u32 cluster, pf_bool* p_is_found) {
|
||||
PFITER_FAT_HINT hint;
|
||||
pf_u32 entries_per_sector;
|
||||
pf_u32 current_cluster;
|
||||
PFITER_ENT_ITER iter;
|
||||
pf_u32 sector_index;
|
||||
pf_s32 err;
|
||||
*p_is_found = 0;
|
||||
if (p_ent->entry_sector < p_ent->p_vol->bpb.first_data_sector) return 0;
|
||||
current_cluster = (p_ent->entry_sector - p_ent->p_vol->bpb.first_data_sector) >> p_ent->p_vol->bpb.log2_sectors_per_cluster;
|
||||
sector_index = (p_ent->p_vol->bpb.sectors_per_cluster - 1) & (p_ent->entry_sector - p_ent->p_vol->bpb.first_data_sector);
|
||||
if (current_cluster == cluster) {
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
iter.ffd.p_start_cluster = ¤t_cluster;
|
||||
iter.ffd.p_hint = &hint;
|
||||
iter.ffd.p_vol = p_ent->p_vol;
|
||||
iter.ffd.start_cluster = 1;
|
||||
iter.ffd.cluster_link.buffer = PF_NULL;
|
||||
iter.log2_entries_per_sector = p_ent->p_vol->bpb.log2_bytes_per_sector - 5;
|
||||
iter.file_sector_index = sector_index;
|
||||
entries_per_sector = 1 << iter.log2_entries_per_sector;
|
||||
iter.offset_mask = entries_per_sector - 1;
|
||||
iter.p_vol = p_ent->p_vol;
|
||||
iter.sector = p_ent->entry_sector;
|
||||
iter.offset = p_ent->entry_offset;
|
||||
iter.index = ((pf_u32)p_ent->entry_offset >> 5) + sector_index * entries_per_sector;
|
||||
hint.chain_index = 0;
|
||||
hint.cluster = current_cluster;
|
||||
hint.previous_cluster = 1;
|
||||
if (iter.index < 2) {
|
||||
hint.chain_index = 1;
|
||||
iter.file_sector_index += p_ent->p_vol->bpb.sectors_per_cluster;
|
||||
iter.index += entries_per_sector << p_ent->p_vol->bpb.log2_sectors_per_cluster;
|
||||
}
|
||||
while (iter.index != 0) {
|
||||
err = PFENT_ITER_LoadEntry(&iter);
|
||||
if (err != 0) return err;
|
||||
if (pf_strncmp((pf_s8*)iter.buf, (pf_s8*)"..", 2) == 0) break;
|
||||
err = PFENT_ITER_Retreat(&iter, 0);
|
||||
if (err != 0) return err;
|
||||
if (current_cluster == cluster) {
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
if (current_cluster <= 2) return 0;
|
||||
if (iter.index < 1) {
|
||||
++hint.chain_index;
|
||||
iter.file_sector_index += p_ent->p_vol->bpb.sectors_per_cluster;
|
||||
iter.index += (1 << iter.log2_entries_per_sector) << p_ent->p_vol->bpb.log2_sectors_per_cluster;
|
||||
}
|
||||
}
|
||||
current_cluster = (PF_SWAP_16(*(pf_u16*)&iter.buf[20]) << 16) | PF_SWAP_16(*(pf_u16*)&iter.buf[26]);
|
||||
hint.chain_index = 0;
|
||||
iter.file_sector_index = 0;
|
||||
hint.cluster = current_cluster;
|
||||
iter.sector = p_ent->p_vol->bpb.first_data_sector + ((current_cluster - 2) << p_ent->p_vol->bpb.log2_sectors_per_cluster);
|
||||
iter.offset = 32;
|
||||
iter.index = 1;
|
||||
while (current_cluster > 2) {
|
||||
err = PFENT_ITER_LoadEntry(&iter);
|
||||
if (err != 0) return err;
|
||||
if (pf_strncmp((pf_s8*)iter.buf, (pf_s8*)"..", 2) == 0) {
|
||||
if (current_cluster == cluster) {
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
current_cluster = (PF_SWAP_16(*(pf_u16*)&iter.buf[20]) << 16) | PF_SWAP_16(*(pf_u16*)&iter.buf[26]);
|
||||
hint.cluster = current_cluster;
|
||||
iter.sector = p_ent->p_vol->bpb.first_data_sector + ((current_cluster - 2) << p_ent->p_vol->bpb.log2_sectors_per_cluster);
|
||||
} else return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_Retreat(PFITER_ENT_ITER* p_iter, pf_u32 may_allocate) {
|
||||
pf_u32 before_cluster;
|
||||
pf_u32 cur_cluster;
|
||||
pf_s32 err;
|
||||
|
||||
if (p_iter->index == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (p_iter->file_sector_index != ((p_iter->index - 1) >> p_iter->log2_entries_per_sector)) {
|
||||
cur_cluster = ((p_iter->sector - p_iter->p_vol->bpb.first_data_sector) >> p_iter->p_vol->bpb.log2_sectors_per_cluster) + 2;
|
||||
if ((p_iter->file_sector_index % p_iter->p_vol->bpb.sectors_per_cluster) == 0 || p_iter->p_vol->bpb.sectors_per_cluster == 1) {
|
||||
if (p_iter->p_vol->bpb.fat_type == FAT_32 ||
|
||||
(*p_iter->ffd.p_start_cluster > 1 && p_iter->p_vol->bpb.first_data_sector <= p_iter->sector)) {
|
||||
err = PFFAT_getBeforeChain(p_iter->p_vol, cur_cluster, cur_cluster, &before_cluster);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (before_cluster == -1) {
|
||||
return 14;
|
||||
}
|
||||
} else {
|
||||
before_cluster = *p_iter->ffd.p_start_cluster;
|
||||
}
|
||||
} else {
|
||||
before_cluster = cur_cluster;
|
||||
}
|
||||
p_iter->index--;
|
||||
p_iter->file_sector_index--;
|
||||
if (p_iter->p_vol->bpb.fat_type == FAT_32 || *p_iter->ffd.p_start_cluster > 1 && p_iter->p_vol->bpb.first_data_sector <= p_iter->sector) {
|
||||
p_iter->sector = (p_iter->p_vol->bpb.first_data_sector + ((before_cluster - 2) << p_iter->p_vol->bpb.log2_sectors_per_cluster)) +
|
||||
(p_iter->file_sector_index & (p_iter->p_vol->bpb.sectors_per_cluster - 1));
|
||||
} else {
|
||||
p_iter->sector--;
|
||||
}
|
||||
p_iter->offset = (p_iter->index & p_iter->offset_mask) * 0x20;
|
||||
return 0;
|
||||
}
|
||||
return PFENT_ITER_MoveTo(p_iter, p_iter->index - 1, may_allocate);
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_FindDirEntryFromCluster(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, pf_u32 cluster, pf_bool* p_is_found) {
|
||||
pf_u8 attr;
|
||||
pf_s32 err = 0;
|
||||
|
||||
*p_is_found = PF_FALSE;
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->ordinal = 0;
|
||||
p_ent->check_sum = 0;
|
||||
if ((p_ent->attr & 0x10) && p_ent->start_cluster == 1) return 2;
|
||||
for (; PFENT_ITER_IsAtLogicalEnd(p_iter) == PF_FALSE; err = AdvanceIterator(p_iter, PF_FALSE)) {
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (p_iter->buf[0] == 0xE5) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
continue;
|
||||
}
|
||||
attr = p_iter->buf[0xB];
|
||||
if ((attr & (0x01 | 0x02 | 0x04 | 0x08)) == (0x01 | 0x02 | 0x04 | 0x08)) {
|
||||
err = PFENT_LoadLFNEntryFieldsFromBuf(p_ent, p_iter->buf);
|
||||
if (err != 0) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ((attr & 0x08) != 0) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
continue;
|
||||
}
|
||||
if ((attr & 0x10) == 0) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
continue;
|
||||
}
|
||||
PFENT_LoadShortNameFromBuf(p_ent, p_iter->buf);
|
||||
if (p_ent->num_entry_LFNs != 0 && p_ent->ordinal == 1 && p_ent->check_sum == PFENT_CalcCheckSum(p_ent)) {
|
||||
PFENT_loadEntryNumericFieldsFromBuf(p_ent, p_iter->buf);
|
||||
p_ent->entry_sector = p_iter->sector;
|
||||
p_ent->entry_offset = p_iter->offset;
|
||||
p_ent->p_vol = p_iter->ffd.p_vol;
|
||||
if ((p_ent->attr & 0x10) != 0 && p_ent->start_cluster != cluster) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
continue;
|
||||
}
|
||||
if ((p_ent->attr & 0x10) != 0 && p_ent->start_cluster == 0) {
|
||||
p_ent->start_cluster = 1;
|
||||
}
|
||||
*p_is_found = 1;
|
||||
}
|
||||
if ((p_iter->buf[0xC] & (0x10 | 0x08)) != 0) {
|
||||
PFENT_ITER_MakeLongFileName(p_iter, p_ent);
|
||||
}
|
||||
PFENT_loadEntryNumericFieldsFromBuf(p_ent, p_iter->buf);
|
||||
p_ent->entry_sector = p_iter->sector;
|
||||
p_ent->entry_offset = p_iter->offset;
|
||||
p_ent->p_vol = p_iter->ffd.p_vol;
|
||||
|
||||
if ((p_ent->attr & 0x10) && p_ent->start_cluster != cluster) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
*p_is_found = 0;
|
||||
continue;
|
||||
}
|
||||
if ((p_ent->attr & 0x10) && p_ent->start_cluster == 0) p_ent->start_cluster = 1;
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_FindEntry(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_STR* p_pattern,
|
||||
pf_u32 attr_required, pf_u32 attr_forbidden, pf_bool* p_is_found) {
|
||||
pf_s32 err;
|
||||
*p_is_found = 0;
|
||||
if (attr_required & attr_forbidden) return 10;
|
||||
if (PFSTR_StrNCmp(p_pattern, (pf_s8*)":", 1, 1, 1) == 0) PFSTR_MoveStrPos(p_pattern, 2);
|
||||
if (PFSTR_StrNCmp(p_pattern, (pf_s8*)"\\", 1, 0, 1) == 0 || PFSTR_StrNCmp(p_pattern, (pf_s8*)"/", 1, 0, 1) == 0) {
|
||||
err = PFENT_GetRootDir(p_iter->p_vol, p_ent);
|
||||
if (err != 0) return err;
|
||||
if (PFSTR_StrNumChar(p_pattern, 1) == 1 && PFSTR_StrNCmp(p_pattern, (pf_s8*)"\0", 2, 0, 1) == 0) return 0;
|
||||
} else {
|
||||
err = PFVOL_GetCurrentDir(p_iter->p_vol, p_ent);
|
||||
if (err != 0) return err;
|
||||
}
|
||||
err = PFENT_ITER_DoFindEntry(p_iter, p_ent, p_pattern, attr_required, attr_forbidden, p_is_found);
|
||||
if (err != 0) return err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_FindEntryNoPathCheck(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_STR* p_pattern,
|
||||
pf_u32 attr_required, pf_u32 attr_forbidden, pf_bool* p_is_found) {
|
||||
pf_s32 err;
|
||||
*p_is_found = 0;
|
||||
if (attr_required & attr_forbidden) return 10;
|
||||
err = PFENT_ITER_DoFindEntry(p_iter, p_ent, p_pattern, attr_required, attr_forbidden, p_is_found);
|
||||
if (err != 0) return err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_GetEntryOfPath(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_VOLUME* p_vol, PF_STR* p_path, pf_u32 no_look_last_token) {
|
||||
return PFENT_ITER_DoGetEntry(p_iter, p_ent, p_vol, p_path, 0, no_look_last_token);
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_GetEntryOfPattern(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_VOLUME* p_vol, PF_STR* p_path) {
|
||||
return PFENT_ITER_DoGetEntry(p_iter, p_ent, p_vol, p_path, 1, 1);
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_GetEntryOfIter(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent) {
|
||||
PFENT_LoadShortNameFromBuf(p_ent, p_iter->buf);
|
||||
PFENT_loadEntryNumericFieldsFromBuf(p_ent, p_iter->buf);
|
||||
p_ent->entry_sector = p_iter->sector;
|
||||
p_ent->entry_offset = p_iter->offset;
|
||||
p_ent->p_vol = p_iter->p_vol;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_GetLFNEntryName(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent) {
|
||||
pf_u32 i;
|
||||
pf_s32 err;
|
||||
if (p_ent->num_entry_LFNs != 0 && !(p_ent->small_letter_flag & 0x18)) {
|
||||
for (i = 0; i < p_ent->num_entry_LFNs; ++i) {
|
||||
pf_u16* destination;
|
||||
err = PFENT_ITER_Retreat(p_iter, 0);
|
||||
if (err != 0) return err;
|
||||
err = PFENT_ITER_LoadEntry(p_iter);
|
||||
if (err != 0) return err;
|
||||
destination = &p_ent->long_name[(i * 26U) / 2U];
|
||||
pf_memcpy(destination, &p_iter->buf[1], 10);
|
||||
pf_memcpy(destination + 5, &p_iter->buf[14], 12);
|
||||
pf_memcpy(destination + 11, &p_iter->buf[28], 4);
|
||||
}
|
||||
p_ent->long_name[(p_ent->num_entry_LFNs * 26U) / 2U] = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
22
libs/RVL_SDK/src/fa/pf_service.c
Normal file
22
libs/RVL_SDK/src/fa/pf_service.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <private/vf/PrFILE2/pf_types.h>
|
||||
|
||||
pf_u16 PF_GET_LE_U16(const pf_u8* buf) {
|
||||
return (pf_u16)((pf_u16)buf[1] << 8 | (pf_u16)buf[0]);
|
||||
}
|
||||
|
||||
void PF_LE16_TO_U16_STR(pf_u8* sSrc, pf_u32 num) {
|
||||
pf_u32 cnt;
|
||||
pf_s8 tmp_src;
|
||||
pf_u8* pSrc = sSrc;
|
||||
|
||||
for (cnt = 0; cnt < num; cnt += sizeof(pf_u16), pSrc += sizeof(pf_u16)) {
|
||||
tmp_src = *pSrc;
|
||||
#ifdef DEBUG
|
||||
*((pf_u8*)sSrc + cnt) = *((pf_u8*)sSrc + cnt + 1);
|
||||
*((pf_u8*)sSrc + cnt + 1) = tmp_src;
|
||||
#else
|
||||
sSrc[cnt] = sSrc[cnt + 1];
|
||||
sSrc[cnt + 1] = tmp_src;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
229
libs/RVL_SDK/src/fa/pf_str.c
Normal file
229
libs/RVL_SDK/src/fa/pf_str.c
Normal file
@@ -0,0 +1,229 @@
|
||||
#include <private/vf/PrFILE2/pf_types.h>
|
||||
|
||||
typedef struct PF_STR {
|
||||
const pf_s8* p_head;
|
||||
const pf_s8* p_tail;
|
||||
const pf_s8* p_current;
|
||||
pf_u32 code_mode;
|
||||
} PF_STR;
|
||||
|
||||
typedef struct PFSTR_CHARCODE {
|
||||
pf_s32 (*oem2unicode)(const pf_s8*, pf_u16*);
|
||||
pf_s32 (*unicode2oem)(const pf_u16*, pf_s8*);
|
||||
pf_s32 (*oem_char_width)(const pf_s8*);
|
||||
pf_bool (*is_oem_mb_char)(pf_s8, pf_bool);
|
||||
pf_s32 (*unicode_char_width)(const pf_u16*);
|
||||
pf_bool (*is_unicode_mb_char)(pf_u16, pf_bool);
|
||||
} PFSTR_CHARCODE;
|
||||
|
||||
typedef struct PFSTR_VOLUME_SET {
|
||||
pf_u8 state_prefix[0x48];
|
||||
PFSTR_CHARCODE codeset;
|
||||
} PFSTR_VOLUME_SET;
|
||||
|
||||
extern PFSTR_VOLUME_SET pf_vol_set;
|
||||
|
||||
extern pf_s32 pf_toupper(pf_s32 c);
|
||||
extern pf_u32 pf_strlen(const pf_s8* s);
|
||||
extern pf_u32 pf_w_strlen(const pf_u16* s);
|
||||
extern pf_s32 pf_strcmp(const pf_s8* s1, const pf_s8* s2);
|
||||
extern pf_s32 pf_strncmp(const pf_s8* s1, const pf_s8* s2, pf_u32 length);
|
||||
|
||||
void PFSTR_SetCodeMode(PF_STR* p_str, pf_u32 code_mode) {
|
||||
p_str->code_mode = code_mode;
|
||||
}
|
||||
|
||||
pf_u32 PFSTR_GetCodeMode(PF_STR* p_str) {
|
||||
return p_str->code_mode;
|
||||
}
|
||||
|
||||
void PFSTR_SetLocalStr(PF_STR* p_str, const pf_s8* local_str) {
|
||||
if (p_str->code_mode == 1 || local_str == PF_NULL) {
|
||||
p_str->p_current = p_str->p_head;
|
||||
} else {
|
||||
p_str->p_current = local_str;
|
||||
}
|
||||
}
|
||||
|
||||
pf_s8* PFSTR_GetStrPos(PF_STR* p_str, pf_u32 target) {
|
||||
pf_s8* p_pos;
|
||||
if (target == 1) {
|
||||
p_pos = (pf_s8*)p_str->p_head;
|
||||
} else if (target == 2) {
|
||||
p_pos = (pf_s8*)p_str->p_tail;
|
||||
} else {
|
||||
p_pos = (pf_s8*)p_str->p_current;
|
||||
}
|
||||
return p_pos;
|
||||
}
|
||||
|
||||
void PFSTR_MoveStrPos(PF_STR* p_str, pf_s16 num_char) {
|
||||
pf_s16 cnt;
|
||||
pf_s16 offset = 0;
|
||||
pf_s32 width;
|
||||
pf_s8* p;
|
||||
pf_u16* wp;
|
||||
|
||||
if (PFSTR_GetCodeMode(p_str) == 1) {
|
||||
p = (pf_s8*)p_str->p_head;
|
||||
while (num_char != 0) {
|
||||
if (pf_vol_set.codeset.is_oem_mb_char((pf_s8)*p, PF_TRUE)) {
|
||||
offset++;
|
||||
}
|
||||
offset++;
|
||||
num_char--;
|
||||
}
|
||||
} else {
|
||||
wp = (pf_u16*)p_str->p_head;
|
||||
|
||||
for (cnt = 0; cnt < num_char; cnt++) {
|
||||
width = pf_vol_set.codeset.unicode_char_width(wp);
|
||||
wp += width;
|
||||
offset += (pf_s16)width;
|
||||
}
|
||||
}
|
||||
|
||||
p_str->p_head = &p_str->p_head[offset];
|
||||
}
|
||||
|
||||
pf_s32 PFSTR_InitStr(PF_STR* p_str, const pf_s8* s, pf_u32 code_mode) {
|
||||
if (code_mode == 1) {
|
||||
p_str->p_head = s;
|
||||
p_str->p_tail = &s[pf_strlen(s)];
|
||||
} else if (code_mode == 2) {
|
||||
p_str->p_head = s;
|
||||
p_str->p_tail = s + (pf_w_strlen((pf_u16*)s) * sizeof(pf_u16));
|
||||
}
|
||||
|
||||
PFSTR_SetCodeMode(p_str, code_mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_u16 PFSTR_StrLen(PF_STR* p_str) {
|
||||
return (pf_u16)(p_str->p_tail - p_str->p_head);
|
||||
}
|
||||
|
||||
pf_u16 PFSTR_StrNumChar(PF_STR* p_str, pf_u32 target) {
|
||||
pf_s8* p;
|
||||
pf_u16 cnt;
|
||||
pf_s32 width;
|
||||
|
||||
if (target == 1) {
|
||||
p = (pf_s8*)p_str->p_head;
|
||||
} else {
|
||||
p = (pf_s8*)p_str->p_tail;
|
||||
}
|
||||
|
||||
if (p_str->code_mode == 1) {
|
||||
for (cnt = 0; (pf_s8)*p != 0; cnt++) {
|
||||
if (pf_vol_set.codeset.is_oem_mb_char((pf_s8)*p, PF_TRUE)) {
|
||||
p++;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
} else {
|
||||
for (cnt = 0; (pf_s8)p[0] != 0 || (pf_s8)p[1] != 0; cnt++) {
|
||||
width = pf_vol_set.codeset.unicode_char_width((pf_u16*)p);
|
||||
p += width;
|
||||
}
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
pf_s32 PFSTR_StrCmp(const PF_STR* p_str, const pf_s8* s) {
|
||||
pf_u16 wc;
|
||||
const pf_u16* wp;
|
||||
const pf_s8* p1;
|
||||
const pf_s8* p2;
|
||||
pf_s32 ret;
|
||||
|
||||
if (p_str->code_mode == 1) {
|
||||
p1 = p_str->p_head;
|
||||
p2 = s;
|
||||
ret = pf_strcmp(p1, p2);
|
||||
} else {
|
||||
wp = (pf_u16*)p_str->p_head;
|
||||
|
||||
do {
|
||||
pf_vol_set.codeset.oem2unicode((pf_s8*)s, &wc);
|
||||
s++;
|
||||
|
||||
if (*wp++ != wc) {
|
||||
break;
|
||||
}
|
||||
} while (*(wp - 1) != 0 && wc != 0);
|
||||
|
||||
wp--;
|
||||
ret = *wp - wc;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
pf_s32 PFSTR_StrNCmp(PF_STR* p_str, const pf_s8* s, pf_u32 target, pf_s16 offset, pf_u16 num) {
|
||||
pf_u16 wc;
|
||||
const pf_u16* wp;
|
||||
const pf_s8* p1;
|
||||
const pf_s8* p2;
|
||||
pf_s32 ret;
|
||||
|
||||
if (p_str->code_mode == 1 || target == 3) {
|
||||
if (target == 1) {
|
||||
p1 = &p_str->p_head[offset];
|
||||
} else if (target == 2) {
|
||||
p1 = &p_str->p_tail[offset];
|
||||
} else {
|
||||
p1 = &p_str->p_current[offset];
|
||||
}
|
||||
p2 = s;
|
||||
ret = pf_strncmp(p1, p2, num);
|
||||
} else {
|
||||
if (target == 1) {
|
||||
wp = (pf_u16*)p_str->p_head + offset;
|
||||
} else {
|
||||
wp = (pf_u16*)p_str->p_tail + offset;
|
||||
}
|
||||
|
||||
do {
|
||||
pf_vol_set.codeset.oem2unicode((pf_s8*)s, &wc);
|
||||
s++;
|
||||
num--;
|
||||
|
||||
if (*wp++ != wc || num == 0) {
|
||||
break;
|
||||
}
|
||||
} while (*(wp - 1) != 0 && wc != 0);
|
||||
|
||||
wp--;
|
||||
ret = *wp - wc;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void PFSTR_ToUpperNStr(PF_STR* p_str, pf_u16 num, pf_s8* dest) {
|
||||
pf_u16 wc;
|
||||
const pf_u16* wp;
|
||||
const pf_s8* p;
|
||||
|
||||
if (p_str->code_mode == 1) {
|
||||
p = (pf_s8*)p_str->p_head;
|
||||
|
||||
for (; num != 0 && *p != 0; p++, num--) {
|
||||
*dest++ = pf_toupper(*p);
|
||||
}
|
||||
} else {
|
||||
wp = (pf_u16*)p_str->p_head;
|
||||
|
||||
for (; num != 0 && *wp != 0; wp++, num--) {
|
||||
wc = (*wp >= 'a' && *wp <= 'z') ? *wp + ('A' - 'a') : *wp;
|
||||
*(dest) = (pf_u8)wc;
|
||||
*(dest + 1) = (pf_u8)(wc >> 8);
|
||||
dest += sizeof(pf_u16);
|
||||
}
|
||||
*dest = 0;
|
||||
}
|
||||
|
||||
*dest = 0;
|
||||
}
|
||||
@@ -21,22 +21,19 @@ typedef struct NWC24MsgObjPrivate {
|
||||
u32 type; // 0x04
|
||||
u32 length; // 0x08
|
||||
u32 appId; // 0x0C
|
||||
#if defined(NWC24_MBOX_CTRL) || defined(NWC24_MSG_COMMIT)
|
||||
#ifdef NWC24_MBOX_CTRL
|
||||
u32 unk_0x10;
|
||||
#else
|
||||
u8 unk_0x10[0x4];
|
||||
#endif
|
||||
u32 tag; // 0x14
|
||||
u32 ledPattern; // 0x18
|
||||
#if defined(NWC24_MBOX_CTRL) || defined(NWC24_MSG_COMMIT)
|
||||
#ifdef NWC24_MBOX_CTRL
|
||||
u32 unk_0x1C;
|
||||
#endif
|
||||
#if defined(NWC24_MBOX_CTRL) || defined(NWC24_MSG_COMMIT)
|
||||
#ifdef NWC24_MBOX_CTRL
|
||||
union {
|
||||
NWC24UserId fromId;
|
||||
#ifdef NWC24_MSG_COMMIT
|
||||
NWC24Data fromAddr;
|
||||
#endif
|
||||
struct { u32 fromIdHigh, fromIdLow; };
|
||||
};
|
||||
#else
|
||||
|
||||
@@ -1,906 +0,0 @@
|
||||
#define NWC24_MSG_COMMIT
|
||||
#include <private/nwc24.h>
|
||||
#include <revolution/net/NETMisc.h>
|
||||
#include <revolution/nwc24.h>
|
||||
|
||||
static char MultiPartDivider[64];
|
||||
BOOL LoopBackEnable = TRUE;
|
||||
static NWC24File* m_pFile;
|
||||
|
||||
static NWC24Err NWC24CommitMsgInternal(NWC24MsgObjPrivate* msg, NWC24MBoxType type);
|
||||
static NWC24Err CheckMsgObject(const NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err CheckMsgBoxSpace(const NWC24MsgObjPrivate* msg, NWC24MBoxType type);
|
||||
static NWC24Err SynthesizeAddrStr(const NWC24Data* address, u32 type, char* dest, s32 capacity, u32* length);
|
||||
static NWC24Err WriteSMTP_MAILFROM(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteSMTP_RCPTTO(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteFromField(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteToField(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteDateField(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteXWiiAppIdField(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteXWiiFaceField(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteXWiiAltNameField(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteMIMEAttachHeader(NWC24MsgObjPrivate* msg, u32 index);
|
||||
static NWC24Err WriteContentTypeField(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WritePlainText(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteBase64Data(const u8* data, s32 size, u32* length);
|
||||
static NWC24Err WriteQPData(const u8* data, s32 size, u32* length);
|
||||
NWC24Err NWC24iMBoxOpenNewMsg(NWC24MBoxType type, NWC24File* file, u32* id);
|
||||
NWC24Err NWC24iMBoxCloseMsg(NWC24File* file);
|
||||
NWC24Err NWC24iMBoxAddMsgObj(NWC24MBoxType type, NWC24MsgObjPrivate* msg);
|
||||
NWC24Err NWC24iMBoxCancelMsg(NWC24File* file, NWC24MBoxType type, u32 id);
|
||||
NWC24Err NWC24iMBoxFlushHeader(NWC24MBoxType type);
|
||||
NWC24Err NWC24iMBoxCheck(NWC24MBoxType type, u32 size);
|
||||
NWC24Err NWC24iDateToMinutes(u32* minutes, const NWC24Date* date);
|
||||
NWC24Err NWC24iMinutesToDate(NWC24Date* date, u32 minutes);
|
||||
|
||||
static inline NWC24Err WriteString(NWC24MsgObjPrivate* msg, char* buffer) {
|
||||
s32 length = Mail_strlen(buffer);
|
||||
NWC24Err err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
#define CHECK_WRITE(operation) \
|
||||
do { \
|
||||
err = (operation); \
|
||||
if (err != NWC24_OK) { \
|
||||
NWC24FClose(&file); \
|
||||
result = err; \
|
||||
goto finish; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static inline NWC24Err WriteSubjectField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
if (msg->subject.size == 0)
|
||||
return NWC24_ERR_NULL;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "Subject: ");
|
||||
Mail_strncat(buffer, msg->subject.ptr, 1021);
|
||||
Mail_strncat(buffer, "\r\n", 1024);
|
||||
length = STD_strnlen(buffer, 1024);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteSMTPData(NWC24MsgObjPrivate* msg, const char* text) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
Mail_strcpy(buffer, text);
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += 6;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteCmdField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
if (msg->ledPattern == 0)
|
||||
return NWC24_OK;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "X-Wii-Cmd: %08X\r\n", msg->ledPattern);
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteTagField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
if (msg->tag == 0)
|
||||
return NWC24_OK;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "X-Wii-Tag: %08X\r\n", msg->tag);
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteDWCIdField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
if (!(msg->type & 0x2000))
|
||||
return NWC24_OK;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "X-Wii-DWCId: %08X\r\n", msg->dwcId);
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteIconNewField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
if (msg->iconNew == 0 || msg->iconNew == 0x80000000)
|
||||
return NWC24_OK;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "X-Wii-IconNew: %08X\r\n", msg->iconNew);
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteMessageIdField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
const char* domain;
|
||||
NWC24UserId myId;
|
||||
char idText[32];
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
domain = NWC24GetAccountDomain();
|
||||
NWC24GetMyUserId(&myId);
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "Message-Id: <");
|
||||
Mail_memset(idText, 0, 32);
|
||||
Mail_sprintf(idText, "%05X%08X%08X%08X", msg->msgId, (u32)(myId >> 32), (u32)myId, msg->unk_0x28);
|
||||
Mail_strcat(buffer, idText);
|
||||
Mail_strcat(buffer, domain);
|
||||
Mail_strcat(buffer, ">\r\n");
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
NWC24Err NWC24CommitMsg(NWC24MsgObj* object) {
|
||||
BOOL loopback = FALSE;
|
||||
NWC24MsgObjPrivate* msg = (NWC24MsgObjPrivate*)object;
|
||||
NWC24UserId myId;
|
||||
if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool())
|
||||
return NWC24_ERR_LIB_NOT_OPENED;
|
||||
if (!(msg->type & 0x100) || (msg->type & 0x200))
|
||||
return NWC24_ERR_PROTECTED;
|
||||
if (LoopBackEnable && (msg->type & 1)) {
|
||||
NWC24GetMyUserId(&myId);
|
||||
if (msg->numTo == 1 && msg->toIds[0] == myId)
|
||||
loopback = TRUE;
|
||||
}
|
||||
return NWC24CommitMsgInternal(msg, loopback);
|
||||
}
|
||||
|
||||
static NWC24Err NWC24CommitMsgInternal(NWC24MsgObjPrivate* msg, NWC24MBoxType type) {
|
||||
NWC24File file;
|
||||
NWC24Data attached[2];
|
||||
NWC24Data subject;
|
||||
NWC24Data text;
|
||||
u32 id, encodedLength;
|
||||
s32 initIndex;
|
||||
u32 index;
|
||||
char* buffer;
|
||||
s32 length;
|
||||
NWC24Err result, err;
|
||||
NWC24Data_Init(&subject);
|
||||
NWC24Data_Init(&text);
|
||||
for (initIndex = 0; initIndex < 2; ++initIndex)
|
||||
NWC24Data_Init(&attached[initIndex]);
|
||||
NWC24iSetErrorCode(0);
|
||||
result = CheckMsgObject(msg);
|
||||
if (result != NWC24_OK)
|
||||
goto report;
|
||||
result = CheckMsgBoxSpace(msg, type);
|
||||
if (result != NWC24_OK)
|
||||
goto report;
|
||||
err = NWC24iMBoxOpenNewMsg(type, &file, &id);
|
||||
if (err != NWC24_OK) {
|
||||
result = err;
|
||||
goto finish;
|
||||
}
|
||||
{
|
||||
msg->msgId = id;
|
||||
msg->length = 0;
|
||||
m_pFile = &file;
|
||||
if (type == NWC24_MBOX_TYPE_SEND) {
|
||||
CHECK_WRITE(WriteSMTP_MAILFROM(msg));
|
||||
CHECK_WRITE(WriteSMTP_RCPTTO(msg));
|
||||
CHECK_WRITE(WriteSMTPData(msg, "DATA\r\n"));
|
||||
}
|
||||
CHECK_WRITE(WriteDateField(msg));
|
||||
CHECK_WRITE(WriteFromField(msg));
|
||||
CHECK_WRITE(WriteToField(msg));
|
||||
CHECK_WRITE(WriteMessageIdField(msg));
|
||||
subject.ptr = (const void*)(msg->length + 9);
|
||||
err = WriteSubjectField(msg);
|
||||
if (err == NWC24_OK)
|
||||
subject.size = msg->length - (u32)subject.ptr - 2;
|
||||
else if (err == NWC24_ERR_NULL) {
|
||||
err = NWC24_OK;
|
||||
subject.ptr = NULL;
|
||||
}
|
||||
if (err != NWC24_OK) {
|
||||
NWC24FClose(&file);
|
||||
result = err;
|
||||
goto finish;
|
||||
}
|
||||
if (msg->type & 1) {
|
||||
CHECK_WRITE(WriteXWiiAppIdField(msg));
|
||||
CHECK_WRITE(WriteCmdField(msg));
|
||||
CHECK_WRITE(WriteTagField(msg));
|
||||
CHECK_WRITE(WriteDWCIdField(msg));
|
||||
CHECK_WRITE(WriteXWiiAltNameField(msg));
|
||||
CHECK_WRITE(WriteXWiiFaceField(msg));
|
||||
CHECK_WRITE(WriteIconNewField(msg));
|
||||
if (msg->msgBoardFlags.raw != 0) {
|
||||
if (msg->msgBoardFlags.raw & 0x80000000) {
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "X-Wii-MB-NoReply: -\r\n");
|
||||
err = NWC24FWrite(buffer, 21, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += 21;
|
||||
if (err != NWC24_OK) {
|
||||
NWC24FClose(&file);
|
||||
result = err;
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
if (msg->msgBoardFlags.raw & 0xFFFF) {
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "X-Wii-MB-RegDate: %04X\r\n", msg->msgBoardFlags.raw & 0xFFFF);
|
||||
length = STD_strnlen(buffer, 1024);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
if (err != NWC24_OK) {
|
||||
NWC24FClose(&file);
|
||||
result = err;
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
if (msg->msgBoardFlags.raw & 0xFF0000) {
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "X-Wii-MB-Delay: %02X\r\n", (msg->msgBoardFlags.raw >> 16) & 0xFF);
|
||||
length = STD_strnlen(buffer, 1024);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
if (err != NWC24_OK) {
|
||||
NWC24FClose(&file);
|
||||
result = err;
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (msg->unk_0xD0.size != 0) {
|
||||
err = NWC24FWrite(msg->unk_0xD0.ptr, msg->unk_0xD0.size, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += msg->unk_0xD0.size;
|
||||
if (err != NWC24_OK) {
|
||||
NWC24FClose(&file);
|
||||
result = err;
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
Mail_memset(MultiPartDivider, 0, 40);
|
||||
Mail_sprintf(MultiPartDivider, "Boundary-NWC24-%08X%05X", msg->unk_0x28, msg->msgId);
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "MIME-Version: 1.0\r\n");
|
||||
if (msg->type & 0x10000) {
|
||||
Mail_strcat(buffer, "Content-Type: multipart/mixed;\r\n boundary=\"");
|
||||
Mail_strcat(buffer, MultiPartDivider);
|
||||
Mail_strcat(buffer, "\"\r\n");
|
||||
}
|
||||
CHECK_WRITE(WriteString(msg, buffer));
|
||||
if (msg->type & 0x10000) {
|
||||
msg->unk_0x10 = msg->length;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "\r\n--%s", MultiPartDivider);
|
||||
Mail_strcat(buffer, "\r\n");
|
||||
CHECK_WRITE(WriteString(msg, buffer));
|
||||
}
|
||||
CHECK_WRITE(WriteContentTypeField(msg));
|
||||
if (!(msg->type & 0x10000))
|
||||
msg->unk_0x10 = msg->length;
|
||||
text.ptr = (const void*)msg->length;
|
||||
err = WritePlainText(msg);
|
||||
if (err == NWC24_ERR_NULL)
|
||||
err = NWC24_OK;
|
||||
if (err != NWC24_OK) {
|
||||
NWC24FClose(&file);
|
||||
result = err;
|
||||
goto finish;
|
||||
}
|
||||
text.size = msg->length - (u32)text.ptr;
|
||||
for (index = 0; index < msg->numAttached; ++index) {
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "\r\n--%s", MultiPartDivider);
|
||||
Mail_strcat(buffer, "\r\n");
|
||||
CHECK_WRITE(WriteString(msg, buffer));
|
||||
CHECK_WRITE(WriteMIMEAttachHeader(msg, index));
|
||||
attached[index].ptr = (const void*)msg->length;
|
||||
err = WriteBase64Data(msg->attached[index].ptr, msg->attached[index].size, &encodedLength);
|
||||
msg->length += encodedLength;
|
||||
if (err != NWC24_OK) {
|
||||
NWC24FClose(&file);
|
||||
result = err;
|
||||
goto finish;
|
||||
}
|
||||
attached[index].size = msg->length - (u32)attached[index].ptr;
|
||||
if (index == msg->numAttached - 1) {
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "\r\n--%s", MultiPartDivider);
|
||||
Mail_strcat(buffer, "--\r\n");
|
||||
CHECK_WRITE(WriteString(msg, buffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
finish:
|
||||
if (result == NWC24_OK) {
|
||||
NWC24iMBoxCloseMsg(&file);
|
||||
} else {
|
||||
NWC24iMBoxCancelMsg(&file, type, id);
|
||||
NWC24iMBoxFlushHeader(type);
|
||||
goto report;
|
||||
}
|
||||
{
|
||||
msg->subject = subject;
|
||||
msg->text = text;
|
||||
msg->attached[0] = attached[0];
|
||||
msg->attached[1] = attached[1];
|
||||
msg->type |= 0x200;
|
||||
if (type == NWC24_MBOX_TYPE_RECV)
|
||||
msg->type |= 0x20;
|
||||
else if (type == NWC24_MBOX_TYPE_SEND)
|
||||
msg->type |= 0x10;
|
||||
err = NWC24iMBoxAddMsgObj(type, msg);
|
||||
if (result != NWC24_OK)
|
||||
err = result;
|
||||
result = err;
|
||||
if (type == NWC24_MBOX_TYPE_RECV) {
|
||||
u32 flags = 1;
|
||||
if (msg->type & 8)
|
||||
flags |= 2;
|
||||
NWC24iSetNewMsgArrived(flags);
|
||||
}
|
||||
}
|
||||
report:
|
||||
if (result == NWC24_ERR_FULL || (result <= -16 && result >= -21) || result == -38 || result == -41 || result == -43 || result == -46)
|
||||
NWC24iSetErrorCode(result - 109300);
|
||||
return result;
|
||||
}
|
||||
|
||||
static NWC24Err CheckMsgObject(const NWC24MsgObjPrivate* msg) {
|
||||
const char* subject;
|
||||
if (msg->numTo == 0)
|
||||
return NWC24_ERR_NULL;
|
||||
if (msg->numTo > 8)
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
subject = msg->subject.ptr;
|
||||
if (subject != NULL) {
|
||||
for (; *subject != '\0'; ++subject) {
|
||||
if (*subject == '\r' && subject[1] != '\n')
|
||||
return NWC24_ERR_FORMAT;
|
||||
if (*subject == '\n' && subject[1] != ' ')
|
||||
return NWC24_ERR_FORMAT;
|
||||
}
|
||||
}
|
||||
if (msg->numAttached > 2)
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
static NWC24Err CheckMsgBoxSpace(const NWC24MsgObjPrivate* msg, NWC24MBoxType type) {
|
||||
u32 total = 0;
|
||||
u32 textSize = 0;
|
||||
s32 index;
|
||||
NWC24Err err;
|
||||
for (index = 0; index < msg->numAttached; ++index) {
|
||||
u32 size = msg->attachedSize[index];
|
||||
total += (size * 4 + 2) / 3 + size / 57 * 2 + 4;
|
||||
}
|
||||
switch (msg->encoding) {
|
||||
case NWC24_ENC_7BIT:
|
||||
case NWC24_ENC_8BIT:
|
||||
textSize = msg->text.size;
|
||||
break;
|
||||
case NWC24_ENC_BASE64:
|
||||
textSize = (msg->text.size * 4 + 2) / 3 + msg->text.size / 57 * 2 + 4;
|
||||
break;
|
||||
case NWC24_ENC_QUOTED_PRINTABLE:
|
||||
textSize = msg->text.size * 4 / 3;
|
||||
break;
|
||||
default:
|
||||
textSize = 0;
|
||||
break;
|
||||
}
|
||||
total += textSize;
|
||||
if (total >= 0x31C00)
|
||||
return NWC24_ERR_OVERFLOW;
|
||||
err = NWC24iMBoxCheck(type, total + 1024);
|
||||
if (err != NWC24_OK)
|
||||
return err;
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
static NWC24Err SynthesizeAddrStr(const NWC24Data* address, u32 type, char* dest, s32 capacity, u32* length) {
|
||||
char id[32];
|
||||
NWC24Err err = NWC24_OK;
|
||||
const char* domain;
|
||||
s32 domainLength, written;
|
||||
if (type & 1) {
|
||||
domain = NWC24GetAccountDomain();
|
||||
domainLength = Mail_strlen(domain);
|
||||
if (domainLength <= 0)
|
||||
err = NWC24_ERR_CONFIG;
|
||||
else if (domainLength + 18 >= capacity)
|
||||
err = NWC24_ERR_NOMEM;
|
||||
else {
|
||||
NWC24iConvIdToStr(*(const NWC24UserId*)address, id);
|
||||
written = Mail_sprintf(dest, "%c%s%s", 'w', id, domain);
|
||||
if (written == 0)
|
||||
err = NWC24_ERR_FATAL;
|
||||
else
|
||||
*length = written;
|
||||
}
|
||||
} else if (type & 2) {
|
||||
if (address->size + 3 >= (u32)capacity)
|
||||
err = NWC24_ERR_NOMEM;
|
||||
else {
|
||||
written = Mail_sprintf(dest, "%s", address->ptr);
|
||||
if (written == 0)
|
||||
err = NWC24_ERR_FATAL;
|
||||
else
|
||||
*length = written;
|
||||
}
|
||||
} else
|
||||
err = NWC24_ERR_INVALID_VALUE;
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteSMTP_MAILFROM(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
char* address;
|
||||
u32 length;
|
||||
s32 total;
|
||||
u32 type;
|
||||
NWC24Err err;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strncat(buffer, "MAIL FROM: ", 1022);
|
||||
address = buffer + 11;
|
||||
type = 1;
|
||||
if (msg->type & 0x100000)
|
||||
type = 2;
|
||||
err = SynthesizeAddrStr(&msg->fromAddr, type, address, 1009, &length);
|
||||
if (err != NWC24_OK)
|
||||
return err;
|
||||
{
|
||||
address += length;
|
||||
address[0] = '\r';
|
||||
address[1] = '\n';
|
||||
total = length + 13;
|
||||
if ((s32)(1009 - length) <= 0)
|
||||
return NWC24_ERR_NOMEM;
|
||||
}
|
||||
if (err == NWC24_OK) {
|
||||
err = NWC24FWrite(NWC24WorkP->stringWork, total, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += total;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteSMTP_RCPTTO(NWC24MsgObjPrivate* msg) {
|
||||
char* cursor = NWC24WorkP->stringWork;
|
||||
u32 index;
|
||||
s32 total = 0, remaining;
|
||||
u32 length;
|
||||
NWC24Err err = NWC24_OK;
|
||||
Mail_memset(cursor, 0, 1024);
|
||||
remaining = 1022;
|
||||
for (index = 0; index < msg->numTo; ++index) {
|
||||
Mail_strncat(cursor, "RCPT TO: ", remaining);
|
||||
cursor += 9;
|
||||
remaining -= 11;
|
||||
err = SynthesizeAddrStr(&msg->toAddrs[index], msg->type, cursor, remaining, &length);
|
||||
if (err != NWC24_OK)
|
||||
break;
|
||||
cursor += length;
|
||||
cursor[0] = '\r';
|
||||
cursor[1] = '\n';
|
||||
cursor += 2;
|
||||
remaining -= length;
|
||||
total += length + 11;
|
||||
if (remaining <= 0) {
|
||||
err = NWC24_ERR_NOMEM;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (err == NWC24_OK) {
|
||||
err = NWC24FWrite(NWC24WorkP->stringWork, total, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += total;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteFromField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
char* address;
|
||||
u32 length;
|
||||
s32 total;
|
||||
u32 type;
|
||||
NWC24Err err;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strncat(buffer, "From: ", 1022);
|
||||
address = buffer + 6;
|
||||
msg->unk_0x30.ptr = (const void*)(msg->length + 6);
|
||||
type = 1;
|
||||
if (msg->type & 0x100000)
|
||||
type = 2;
|
||||
err = SynthesizeAddrStr(&msg->fromAddr, type, address, 1014, &length);
|
||||
if (err != NWC24_OK)
|
||||
return err;
|
||||
{
|
||||
address += length;
|
||||
address[0] = '\r';
|
||||
address[1] = '\n';
|
||||
total = length + 8;
|
||||
if ((s32)(1014 - length) <= 0)
|
||||
return NWC24_ERR_NOMEM;
|
||||
}
|
||||
if (err == NWC24_OK) {
|
||||
err = NWC24FWrite(NWC24WorkP->stringWork, total, m_pFile);
|
||||
if (err == NWC24_OK) {
|
||||
msg->length += total;
|
||||
msg->unk_0x30.size = msg->length - (u32)msg->unk_0x30.ptr - 2;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteToField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
char* cursor;
|
||||
s32 index, total, remaining;
|
||||
u32 length;
|
||||
NWC24Err err = NWC24_OK;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strncat(buffer, "To: ", 1022);
|
||||
cursor = buffer + 4;
|
||||
index = 0;
|
||||
total = 4;
|
||||
msg->unk_0x38.ptr = (const void*)(msg->length + 4);
|
||||
remaining = 1018;
|
||||
for (; index < msg->numTo; ++index) {
|
||||
err = SynthesizeAddrStr(&msg->toAddrs[index], msg->type, cursor, remaining, &length);
|
||||
if (err != NWC24_OK)
|
||||
break;
|
||||
remaining -= length;
|
||||
cursor += length;
|
||||
total += length;
|
||||
if (remaining <= 4) {
|
||||
err = NWC24_ERR_NOMEM;
|
||||
break;
|
||||
}
|
||||
if (index < msg->numTo - 1) {
|
||||
cursor[0] = ',';
|
||||
cursor[1] = '\r';
|
||||
cursor[2] = '\n';
|
||||
cursor[3] = ' ';
|
||||
total += 4;
|
||||
remaining -= 4;
|
||||
cursor += 4;
|
||||
}
|
||||
}
|
||||
cursor[0] = '\r';
|
||||
cursor[1] = '\n';
|
||||
if (err == NWC24_OK) {
|
||||
err = NWC24FWrite(NWC24WorkP->stringWork, total + 2, m_pFile);
|
||||
if (err == NWC24_OK) {
|
||||
msg->length += total + 2;
|
||||
msg->unk_0x38.size = msg->length - (u32)msg->unk_0x38.ptr - 2;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteDateField(NWC24MsgObjPrivate* msg) {
|
||||
static const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
NWC24Date date;
|
||||
OSCalendarTime calendar;
|
||||
char* buffer;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
NWC24Date_Init(&date);
|
||||
NETGetUniversalCalendar(&calendar);
|
||||
date.year = calendar.year;
|
||||
date.month = calendar.mon + 1;
|
||||
date.day = calendar.mday;
|
||||
date.hour = calendar.hour;
|
||||
date.min = calendar.min;
|
||||
date.sec = calendar.sec;
|
||||
if (date.month > 12)
|
||||
return NWC24_ERR_FORMAT;
|
||||
NWC24iDateToMinutes(&msg->unk_0x28, &date);
|
||||
if (msg->type & 0x1000000)
|
||||
NWC24iMinutesToDate(&date, msg->unk_0x2C);
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "Date: %02d %s %d %02d:%02d:%02d -0000\r\n", date.day, months[date.month - 1], date.year, date.hour, date.min, date.sec);
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteXWiiAppIdField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
char appIdText[16];
|
||||
u32 type = 0;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "X-Wii-AppId: ");
|
||||
if (!NWC24IsMsgLibOpenedByTool() && NWC24GetAppId() != 0x48414541 && msg->appId != 0x48414341)
|
||||
msg->appId = NWC24GetAppId();
|
||||
if (msg->type & 4)
|
||||
type |= 1;
|
||||
if (msg->type & 8)
|
||||
type |= 2;
|
||||
Mail_memset(appIdText, 0, 16);
|
||||
Mail_sprintf(appIdText, "%d-%08X-%04X\r\n", type, msg->appId, msg->groupId);
|
||||
Mail_strcat(buffer, appIdText);
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteXWiiFaceField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer;
|
||||
const u8* data;
|
||||
s32 offset, remaining, chunk;
|
||||
u32 length;
|
||||
NWC24Err err;
|
||||
if (msg->faceData.size == 0)
|
||||
return NWC24_OK;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "X-WiiFace:");
|
||||
data = msg->faceData.ptr;
|
||||
offset = 10;
|
||||
for (remaining = msg->faceData.size; remaining > 0; remaining -= chunk) {
|
||||
buffer[offset++] = ' ';
|
||||
chunk = remaining;
|
||||
if (remaining > 42)
|
||||
chunk = 42;
|
||||
NWC24Base64Encode((u8*)data, chunk, (u8*)(buffer + offset), 76, &length);
|
||||
data += chunk;
|
||||
offset += length;
|
||||
buffer[offset++] = '\r';
|
||||
buffer[offset++] = '\n';
|
||||
}
|
||||
err = NWC24FWrite(buffer, offset, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += offset;
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteXWiiAltNameField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer;
|
||||
const u8* data;
|
||||
s32 offset, remaining, chunk;
|
||||
u32 length;
|
||||
NWC24Err err;
|
||||
if (msg->altName.size == 0)
|
||||
return NWC24_OK;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "X-Wii-AltName:");
|
||||
data = msg->altName.ptr;
|
||||
offset = 14;
|
||||
for (remaining = msg->altName.size; remaining > 0; remaining -= chunk) {
|
||||
buffer[offset++] = ' ';
|
||||
chunk = remaining;
|
||||
if (remaining > 42)
|
||||
chunk = 42;
|
||||
NWC24Base64Encode((u8*)data, chunk, (u8*)(buffer + offset), 76, &length);
|
||||
data += chunk;
|
||||
offset += length;
|
||||
buffer[offset++] = '\r';
|
||||
buffer[offset++] = '\n';
|
||||
}
|
||||
err = NWC24FWrite(buffer, offset, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += offset;
|
||||
return err;
|
||||
}
|
||||
|
||||
const char* ContentTypeA = "Content-Type: %s;\r\n name=%c%07d.%s\r\n";
|
||||
const char* ContentTxEncA = "Content-Transfer-Encoding: base64\r\n";
|
||||
const char* ContentDispA = "Content-Disposition: attachment;\r\n filename=%c%07d.%s\r\n\r\n";
|
||||
|
||||
static NWC24Err WriteMIMEAttachHeader(NWC24MsgObjPrivate* msg, u32 index) {
|
||||
char* buffer;
|
||||
const char* mime;
|
||||
const char* suffix;
|
||||
s32 typeLength, encodingLength, dispositionLength, mimeLength;
|
||||
s32 first, second, third, total;
|
||||
NWC24Err err;
|
||||
Mail_memset(NWC24WorkP->stringWork, 0, 1024);
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
mime = NWC24GetMIMETypeStr(msg->attachedType[index]);
|
||||
suffix = NWC24iGetMIMETypeSuffix(msg->attachedType[index]);
|
||||
encodingLength = Mail_strlen(ContentTxEncA);
|
||||
typeLength = Mail_strlen(ContentTypeA);
|
||||
dispositionLength = Mail_strlen(ContentDispA);
|
||||
typeLength += encodingLength;
|
||||
mimeLength = Mail_strlen(mime);
|
||||
if (mimeLength + (dispositionLength + typeLength) + 4 >= 1024)
|
||||
return NWC24_ERR_NOMEM;
|
||||
first = Mail_sprintf(buffer, (char*)ContentTypeA, mime, (char)('a' + index), msg->msgId, suffix);
|
||||
if (first <= 0)
|
||||
return NWC24_ERR_FAILED;
|
||||
buffer += first;
|
||||
second = Mail_sprintf(buffer, (char*)ContentTxEncA);
|
||||
if (second <= 0)
|
||||
return NWC24_ERR_FAILED;
|
||||
buffer += second;
|
||||
total = first + second;
|
||||
third = Mail_sprintf(buffer, (char*)ContentDispA, (char)('a' + index), msg->msgId, suffix);
|
||||
if (third <= 0)
|
||||
return NWC24_ERR_FAILED;
|
||||
total += third;
|
||||
err = NWC24FWrite(NWC24WorkP->stringWork, total, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += total;
|
||||
return err;
|
||||
}
|
||||
|
||||
const char* ContentTypeTP = "Content-Type: text/plain; charset=%s\r\n";
|
||||
const char* ContentTxEncT = "Content-Transfer-Encoding: %s\r\n\r\n";
|
||||
|
||||
static NWC24Err WriteContentTypeField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
const char* name;
|
||||
const char* encoding;
|
||||
s32 total = 0;
|
||||
NWC24Err err;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
name = NWC24GetCharsetStr(msg->charset);
|
||||
if (name != NULL) {
|
||||
Mail_sprintf(buffer, (char*)ContentTypeTP, name);
|
||||
msg->unk_0x50.ptr = (const void*)(msg->length + 34);
|
||||
msg->unk_0x50.size = Mail_strlen(name) + 1;
|
||||
total = Mail_strlen(buffer);
|
||||
buffer += total;
|
||||
}
|
||||
encoding = NWC24GetEncodingStr(msg->encoding);
|
||||
if (encoding != NULL) {
|
||||
Mail_sprintf(buffer, (char*)ContentTxEncT, encoding);
|
||||
msg->unk_0x58.ptr = (const void*)(total + msg->length + 27);
|
||||
msg->unk_0x58.size = Mail_strlen(encoding) + 1;
|
||||
total += Mail_strlen(buffer);
|
||||
}
|
||||
if (total == 0)
|
||||
return NWC24_OK;
|
||||
err = NWC24FWrite(NWC24WorkP->stringWork, total, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += total;
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WritePlainText(NWC24MsgObjPrivate* msg) {
|
||||
u32 length;
|
||||
NWC24Err err;
|
||||
if (msg->text.size == 0)
|
||||
return NWC24_ERR_NULL;
|
||||
switch (msg->encoding) {
|
||||
case NWC24_ENC_7BIT:
|
||||
case NWC24_ENC_8BIT:
|
||||
err = NWC24FWrite(msg->text.ptr, msg->text.size, m_pFile);
|
||||
length = msg->text.size;
|
||||
break;
|
||||
case NWC24_ENC_BASE64:
|
||||
err = WriteBase64Data(msg->text.ptr, msg->text.size, &length);
|
||||
break;
|
||||
case NWC24_ENC_QUOTED_PRINTABLE:
|
||||
err = WriteQPData(msg->text.ptr, msg->text.size, &length);
|
||||
break;
|
||||
default:
|
||||
err = NWC24_ERR_INVALID_VALUE;
|
||||
break;
|
||||
}
|
||||
if (err == NWC24_OK) {
|
||||
msg->textSize = msg->text.size;
|
||||
msg->length += length;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteBase64Data(const u8* data, s32 size, u32* totalLength) {
|
||||
const u8* cursor = data;
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
u32 length;
|
||||
u32 total = 0;
|
||||
NWC24Err err = NWC24_OK;
|
||||
while (size >= 57) {
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
err = NWC24Base64Encode((u8*)cursor, 57, (u8*)buffer, 76, &length);
|
||||
if (err != NWC24_OK)
|
||||
break;
|
||||
buffer[length++] = '\r';
|
||||
buffer[length++] = '\n';
|
||||
buffer[length] = '\0';
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err != NWC24_OK)
|
||||
break;
|
||||
cursor += 57;
|
||||
size -= 57;
|
||||
total += length;
|
||||
}
|
||||
if (err == NWC24_OK) {
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
err = NWC24Base64Encode((u8*)cursor, size, (u8*)buffer, 76, &length);
|
||||
if (err == NWC24_OK) {
|
||||
buffer[length++] = '\r';
|
||||
buffer[length++] = '\n';
|
||||
buffer[length++] = '\r';
|
||||
buffer[length++] = '\n';
|
||||
buffer[length] = '\0';
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
total += length;
|
||||
}
|
||||
}
|
||||
*totalLength = total;
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteQPData(const u8* data, s32 size, u32* totalLength) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
const u8* cursor = data;
|
||||
s32 total = 0;
|
||||
s32 remaining = size;
|
||||
u32 consumed, length;
|
||||
NWC24Err err = NWC24_OK;
|
||||
for (; remaining > 0; remaining -= consumed) {
|
||||
if (total > 0) {
|
||||
Mail_memcpy(buffer, "=\r\n", 3);
|
||||
err = NWC24FWrite(buffer, 3, m_pFile);
|
||||
if (err != NWC24_OK)
|
||||
break;
|
||||
total += 3;
|
||||
}
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
err = NWC24EncodeQuotedPrintable(buffer, 1024, &length, (u8*)cursor, remaining, &consumed);
|
||||
if (err != NWC24_OK && err != NWC24_ERR_OVERFLOW)
|
||||
break;
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err != NWC24_OK)
|
||||
break;
|
||||
cursor += consumed;
|
||||
total += length;
|
||||
}
|
||||
*totalLength = total;
|
||||
return err;
|
||||
}
|
||||
@@ -1,678 +0,0 @@
|
||||
#define TISIGNWINDOW_IMPLEMENTATION
|
||||
#include "keyboard/tiSignWindow.h"
|
||||
#include "keyboard/tiManager.h"
|
||||
#include "keyboard/tiLanguageIndependentData.h"
|
||||
#include "keyboard/tiUtil.h"
|
||||
|
||||
#include <new>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
|
||||
|
||||
namespace textinput {
|
||||
namespace keyboard {
|
||||
|
||||
namespace signwindow {
|
||||
|
||||
struct AnimationFile {
|
||||
u32 id;
|
||||
char name[64];
|
||||
};
|
||||
|
||||
struct PaneAnimation {
|
||||
s32 type;
|
||||
char paneName[20];
|
||||
u32 animationCount;
|
||||
const char* forceName;
|
||||
const AnimationFile* animations[8];
|
||||
};
|
||||
|
||||
struct PaneControlKey {
|
||||
char paneName[20];
|
||||
u32 key;
|
||||
};
|
||||
|
||||
const char* csSgnKeys[20] = {
|
||||
"P_SGNkey_00", "P_SGNkey_01", "P_SGNkey_02", "P_SGNkey_03", "P_SGNkey_04",
|
||||
"P_SGNkey_05", "P_SGNkey_06", "P_SGNkey_07", "P_SGNkey_08", "P_SGNkey_09",
|
||||
"P_SGNkey_10", "P_SGNkey_11", "P_SGNkey_12", "P_SGNkey_13", "P_SGNkey_14",
|
||||
"P_SGNkey_15", "P_SGNkey_16", "P_SGNkey_17", "P_SGNkey_18", "P_SGNkey_19",
|
||||
};
|
||||
|
||||
static const char* csSgnKeyBase = "P_SGNkey_00";
|
||||
static const char* csSgnKeyClose = "P_SGNkey_close";
|
||||
|
||||
const AnimationFile csAninationFileForSign[9] = {
|
||||
{0, "fs_signWindow_a_SGN_normal.brlan"},
|
||||
{1, "fs_signWindow_a_SGN_FADE-IN.brlan"},
|
||||
{8, "fs_signWindow_a_Scroll_FADE-OUT.brlan"},
|
||||
{2, "fs_signWindow_a_SGN_Focus-IN.brlan"},
|
||||
{6, "fs_signWindow_a_SGN_Focus-OUT.brlan"},
|
||||
{3, "fs_signWindow_a_SGN_Roll_over.brlan"},
|
||||
{4, "fs_signWindow_a_SGN_Pushed.brlan"},
|
||||
{7, "fs_signWindow_a_SGN_scroll_next.brlan"},
|
||||
{5, "fs_signWindow_a_SGN_scroll_prev.brlan"},
|
||||
};
|
||||
|
||||
static const PaneControlKey csPaneNameToControlKey[3] = {
|
||||
{"B_SGNkey_close", 0x18},
|
||||
{"B_SGNkey_prev", 0x1A},
|
||||
{"B_SGNkey_next", 0x19},
|
||||
};
|
||||
|
||||
static const LanguageDependency csLanguageDependencyData[10] = {
|
||||
{4, csSignKeyJP}, {10, csSignKeyUS}, {10, csSignKeyUK}, {10, csSignKeyFR}, {10, csSignKeyDE},
|
||||
{10, csSignKeyIT}, {10, csSignKeySP}, {10, csSignKeyNL}, {4, csSignKeyCN}, {4, csSignKeyKR},
|
||||
};
|
||||
|
||||
struct InputCharacter {
|
||||
wchar_t character;
|
||||
u16 type;
|
||||
bool repeat;
|
||||
u32 value;
|
||||
};
|
||||
static const InputCharacter inputCharacterTemplate = {0, 3, false, 0};
|
||||
|
||||
static PaneAnimation csPaneToAnimationInSign[25] = {
|
||||
{0, "N_SGNkeytop_all", 3, 0, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2]}},
|
||||
{1, "N_SGNkeyall", 3, 0, {&csAninationFileForSign[0], &csAninationFileForSign[7], &csAninationFileForSign[8]}},
|
||||
{2, "P_SGNkey_00", 7, 0, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_01", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_02", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_03", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_04", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_05", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_06", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_07", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_08", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_09", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_10", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_11", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_12", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_13", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_14", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_15", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_16", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_17", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_18", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_19", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_prev", 7, csSgnKeyClose, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_next", 7, csSgnKeyClose, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_close", 7, 0, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
};
|
||||
|
||||
static inline s32 findControlKey(const char* paneName) {
|
||||
u32 index = 0;
|
||||
do {
|
||||
if (util::strcmp(csPaneNameToControlKey[index & 0xFFFF].paneName, paneName))
|
||||
return csPaneNameToControlKey[index & 0xFFFF].key;
|
||||
++index;
|
||||
} while (index < 3);
|
||||
return 0x1B;
|
||||
}
|
||||
|
||||
static inline wchar_t findSignCharacter(const PaneNameToCharCodeInSignMode* keys, u16 page, const char* paneName) {
|
||||
u32 index = 0;
|
||||
do {
|
||||
if (util::strcmp(keys[index & 0xFFFF].szPaneName, paneName))
|
||||
return keys[index & 0xFFFF].wc[page];
|
||||
++index;
|
||||
} while (index < 20);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Base::create(MEMAllocator*) {
|
||||
muPage = 0;
|
||||
mbLocked = 0;
|
||||
mbRepeat = 0;
|
||||
mpLanguageDependency = &csLanguageDependencyData[getLanguage()];
|
||||
}
|
||||
|
||||
void Base::init() {
|
||||
muPage = 0;
|
||||
mbLocked = 0;
|
||||
mbRepeat = 0;
|
||||
mpLanguageDependency = &csLanguageDependencyData[getLanguage()];
|
||||
}
|
||||
|
||||
void Base::onKey(u32 command, void* data) {
|
||||
s32 key;
|
||||
if (command != 4) {
|
||||
return;
|
||||
}
|
||||
|
||||
key = findControlKey(static_cast<const char*>(data));
|
||||
|
||||
if (key != 0x1B) {
|
||||
switch (key) {
|
||||
case 0x18:
|
||||
close();
|
||||
break;
|
||||
case 0x1A:
|
||||
movePrevSignPage();
|
||||
break;
|
||||
case 0x19:
|
||||
moveNextSignPage();
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
u16 code = findSignCharacter(mpLanguageDependency->keys, muPage, static_cast<const char*>(data));
|
||||
|
||||
if (code != 0) {
|
||||
InputCharacter input = inputCharacterTemplate;
|
||||
input.character = code;
|
||||
input.repeat = mbRepeat;
|
||||
if (mpManager->getInputForm()->isAtokActive()) {
|
||||
input.repeat = true;
|
||||
}
|
||||
if (meLanguage - 8U <= 1U) {
|
||||
input.repeat = 1;
|
||||
}
|
||||
sendCommand(5, &input);
|
||||
}
|
||||
}
|
||||
|
||||
void Base::close() {}
|
||||
|
||||
void Base::movePrevSignPage() {
|
||||
if (muPage == 0) {
|
||||
muPage = mpLanguageDependency->count - 1;
|
||||
return;
|
||||
}
|
||||
muPage = muPage - 1;
|
||||
return;
|
||||
}
|
||||
|
||||
void Base::moveNextSignPage() {
|
||||
u8 page = muPage + 1;
|
||||
muPage = page;
|
||||
if (page < mpLanguageDependency->count) {
|
||||
return;
|
||||
}
|
||||
muPage = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
LayoutByNW4R::~LayoutByNW4R() {
|
||||
mpEventHandler->~EventHandler();
|
||||
MEMFreeToAllocator(mpAllocator, mpEventHandler);
|
||||
AnmPane* pane = static_cast<AnmPane*>(nw4r::ut::List_GetNext(&mAnmPanes, NULL));
|
||||
while (pane != NULL) {
|
||||
nw4r::ut::List_Remove(&mAnmPanes, pane);
|
||||
pane->destroy(mpAllocator);
|
||||
pane = static_cast<AnmPane*>(nw4r::ut::List_GetNext(&mAnmPanes, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
Base::~Base() {}
|
||||
|
||||
EventHandler::~EventHandler() {}
|
||||
|
||||
void LayoutByNW4R::create(MEMAllocator* allocator) {
|
||||
mpAllocator = allocator;
|
||||
Base::create(allocator);
|
||||
void* eventBuffer = MEMAllocFromAllocator(allocator, sizeof(EventHandler));
|
||||
mpEventHandler = new (eventBuffer) EventHandler(this);
|
||||
Layout::createWithEventHandler(allocator, mpEventHandler);
|
||||
mpPaneManager->setAllComponentTriggerTarget(false);
|
||||
mpPaneManager->setAllBoundingBoxComponentTriggerTarget(true);
|
||||
|
||||
const char* forceName;
|
||||
u32 animationCount;
|
||||
u32 paneIndex = 0;
|
||||
do {
|
||||
AnmPane* pane = NULL;
|
||||
const PaneAnimation& paneInfo = csPaneToAnimationInSign[paneIndex & 0xFFFF];
|
||||
switch (paneInfo.type) {
|
||||
case 2: {
|
||||
void* paneBuffer = MEMAllocFromAllocator(allocator, sizeof(CellPhoneSignButtonPane));
|
||||
pane = new (paneBuffer) CellPhoneSignButtonPane(getPane(paneInfo.paneName), this);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
void* paneBuffer = MEMAllocFromAllocator(allocator, sizeof(CellPhoneSignScrollAnmPane));
|
||||
pane = new (paneBuffer) CellPhoneSignScrollAnmPane(getPane(paneInfo.paneName), this);
|
||||
break;
|
||||
}
|
||||
case 0: {
|
||||
void* paneBuffer = MEMAllocFromAllocator(allocator, sizeof(CellPhoneSignAllAnmPane));
|
||||
pane = new (paneBuffer) CellPhoneSignAllAnmPane(getPane(paneInfo.paneName), this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nw4r::ut::List_Append(&mAnmPanes, pane);
|
||||
forceName = paneInfo.forceName;
|
||||
animationCount = paneInfo.animationCount;
|
||||
u16 animationIndex = 0;
|
||||
while (animationIndex < animationCount) {
|
||||
void* resource = mpMultiArcResourceAccessor->GetResource(0, paneInfo.animations[animationIndex]->name);
|
||||
AnimTransformPane* transform = static_cast<AnimTransformPane*>(
|
||||
getLayout()->CreateAnimTransform(resource, mpMultiArcResourceAccessor));
|
||||
if (forceName != NULL) {
|
||||
pane->forceAddAnimation(allocator, paneInfo.animations[animationIndex]->id, transform, forceName, false, true);
|
||||
} else {
|
||||
pane->addAnimation(allocator, paneInfo.animations[animationIndex]->id, transform, false, true);
|
||||
}
|
||||
++animationIndex;
|
||||
}
|
||||
++paneIndex;
|
||||
} while (paneIndex < 25);
|
||||
init();
|
||||
}
|
||||
|
||||
AnmPane::~AnmPane() {}
|
||||
|
||||
void LayoutByNW4R::init() {
|
||||
Base::init();
|
||||
searchAnmPane("N_SGNkeytop_all")->changeAnimation(0);
|
||||
setVisible("N_SGNkeytop_all", true);
|
||||
searchAnmPane("P_SGNkey_prev")->changeAnimation(0);
|
||||
searchAnmPane("P_SGNkey_next")->changeAnimation(0);
|
||||
setSignKeyTop(muPage, muPage);
|
||||
setPageNumber(muPage);
|
||||
mpLayout->Animate(0);
|
||||
mpLayout->CalculateMtx(mDrawInfo);
|
||||
}
|
||||
|
||||
void LayoutByNW4R::onKey(u32 command, void* data) {
|
||||
Base::onKey(command, data);
|
||||
if (command == 4) {
|
||||
s32 key;
|
||||
const char* paneName = static_cast<const char*>(data);
|
||||
key = findControlKey(paneName);
|
||||
|
||||
if (key == 0x1B) {
|
||||
goto character;
|
||||
}
|
||||
switch (key) {
|
||||
case 0x18:
|
||||
mpEventObserver->onSE(sound::SE_CHAR_DECIDE);
|
||||
break;
|
||||
case 0x19:
|
||||
case 0x1A:
|
||||
break;
|
||||
}
|
||||
return;
|
||||
|
||||
character:
|
||||
u16 code = findSignCharacter(mpLanguageDependency->keys, muPage, paneName);
|
||||
|
||||
if ((code != 0) && (mpKeyboard->getType() == 0)) {
|
||||
sendCommand(0x27, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutByNW4R::open(KeyboardBase* keyboard, bool input) {
|
||||
resetAnmSignWindow();
|
||||
throwReleaseForAll();
|
||||
getPaneManager()->init();
|
||||
if (meLanguage - 8U <= 1U) {
|
||||
sendCommand(6, NULL);
|
||||
}
|
||||
mbActive = 1;
|
||||
mbInput = 0;
|
||||
mpKeyboard = keyboard;
|
||||
initPaneLastDrawReceived();
|
||||
mbRepeat = input;
|
||||
setSignKeyTop(muPage, muPage);
|
||||
setPageNumber(muPage);
|
||||
searchAnmPane("N_SGNkeytop_all")->onAnmEvent(nw4rmanager::AnmPane::PE_6);
|
||||
mpEventObserver->onSE(sound::SE_SYMBOL_PAGE_OPEN);
|
||||
}
|
||||
|
||||
void LayoutByNW4R::close() {
|
||||
if (mpKeyboard->getType() == 0) {
|
||||
keyboard::pctype::LayoutByNW4R* keyboard = static_cast<keyboard::pctype::LayoutByNW4R*>(mpKeyboard);
|
||||
static_cast<nw4rmanager::Layout&>(*keyboard).getLayout()->GetRootPane()->SetVisible(true);
|
||||
}
|
||||
searchAnmPane("N_SGNkeytop_all")->onAnmEvent(nw4rmanager::AnmPane::PE_7);
|
||||
mbInput = 0;
|
||||
}
|
||||
|
||||
void LayoutByNW4R::endToClose() {
|
||||
if (mpKeyboard != NULL) {
|
||||
mpKeyboard->update();
|
||||
}
|
||||
mbActive = 0;
|
||||
setVisible("N_SGNkeytop_all", false);
|
||||
}
|
||||
|
||||
void LayoutByNW4R::startToInput() {
|
||||
mbInput = 1;
|
||||
if (mpKeyboard->getType() == 0) {
|
||||
keyboard::pctype::LayoutByNW4R* keyboard = static_cast<keyboard::pctype::LayoutByNW4R*>(mpKeyboard);
|
||||
static_cast<nw4rmanager::Layout&>(*keyboard).getLayout()->GetRootPane()->SetVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutByNW4R::onChangeAnmState(AnmEvent event, nw4rmanager::AnmPane* pane, nw4rmanager::Anim* anim) {
|
||||
if (util::strcmp("N_SGNkeyall", pane->getPane()->GetName()) &&
|
||||
((anim->muID == 7 || anim->muID == 5) && event == nw4rmanager::AnmObserver::E_1)) {
|
||||
setSignKeyTop(muPage, muPage);
|
||||
}
|
||||
if (util::strcmp("N_SGNkeytop_all", pane->getPane()->GetName())) {
|
||||
if ((anim->muID == 8) && (event == nw4rmanager::AnmObserver::E_1)) {
|
||||
endToClose();
|
||||
}
|
||||
if ((anim->muID == 1) && (event == nw4rmanager::AnmObserver::E_1)) {
|
||||
startToInput();
|
||||
}
|
||||
}
|
||||
if (anim->muID == 7 || anim->muID == 5) {
|
||||
if (event == nw4rmanager::AnmObserver::E_0) {
|
||||
mbLocked = 1;
|
||||
}
|
||||
if (event == nw4rmanager::AnmObserver::E_1) {
|
||||
mbLocked = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutByNW4R::throwReleaseForAll() {
|
||||
nw4rmanager::AnmPane* pane = static_cast<nw4rmanager::AnmPane*>(nw4r::ut::List_GetNext(&mAnmPanes, NULL));
|
||||
while (pane != NULL) {
|
||||
s32 keyType = static_cast<AnmPane*>(pane)->getKeyType();
|
||||
if (keyType == 2) {
|
||||
pane->onAnmEvent(nw4rmanager::AnmPane::PE_2);
|
||||
}
|
||||
pane = static_cast<nw4rmanager::AnmPane*>(nw4r::ut::List_GetNext(&mAnmPanes, pane));
|
||||
}
|
||||
}
|
||||
|
||||
u32 AnmPane::getKeyType() const {
|
||||
return muKeyType;
|
||||
}
|
||||
|
||||
void LayoutByNW4R::resetAnmSignWindow() {
|
||||
for (u16 i = 0; i < 25; i++) {
|
||||
searchAnmPane(csPaneToAnimationInSign[i].paneName)->init();
|
||||
}
|
||||
}
|
||||
|
||||
void AnmPane::init() {
|
||||
muAnimation = 0;
|
||||
}
|
||||
|
||||
void LayoutByNW4R::setSignKeyTop(u16 oldPage, u16 newPage) {
|
||||
char paneName[17];
|
||||
wchar_t oldCharacter[2];
|
||||
wchar_t newCharacter[2];
|
||||
for (u16 i = 0; i < 20; i++) {
|
||||
const char* sourcePaneName = mpLanguageDependency->keys[i].szPaneName;
|
||||
memset(paneName, 0, 0x11);
|
||||
strncpy(paneName, sourcePaneName, strlen(sourcePaneName));
|
||||
paneName[0] = 'T';
|
||||
oldCharacter[0] = mpLanguageDependency->keys[i].wc[oldPage];
|
||||
oldCharacter[1] = 0;
|
||||
const char* nextPaneName = mpLanguageDependency->keys[i].szNextPaneName;
|
||||
newCharacter[0] = mpLanguageDependency->keys[i].wc[newPage];
|
||||
newCharacter[1] = 0;
|
||||
nw4r::lyt::TextBox* textBox = static_cast<nw4r::lyt::TextBox*>(getPane(paneName));
|
||||
textBox->SetString(oldCharacter, 0);
|
||||
textBox = static_cast<nw4r::lyt::TextBox*>(getPane(nextPaneName));
|
||||
textBox->SetString(newCharacter, 0);
|
||||
}
|
||||
setString("T_SGNkey_prev", langindependent::cLanguageIndependentString[langindependent::LANG_STRID_PREV][getLanguage()]);
|
||||
setString("T_SGNkey_next", langindependent::cLanguageIndependentString[langindependent::LANG_STRID_NEXT][getLanguage()]);
|
||||
setString("T_SGNkey_close", langindependent::cLanguageIndependentString[langindependent::LANG_STRID_CLOSE][getLanguage()]);
|
||||
}
|
||||
|
||||
void LayoutByNW4R::setPageNumber(u16 page) {
|
||||
wchar_t text[17];
|
||||
swprintf(text, 0x11, L"%d/%d", page + 1, mpLanguageDependency->count);
|
||||
nw4r::lyt::TextBox* textBox = static_cast<nw4r::lyt::TextBox*>(getPane("T_SGN_pageNumber"));
|
||||
textBox->SetString(text, 0);
|
||||
}
|
||||
|
||||
void LayoutByNW4R::movePrevSignPage() {
|
||||
u8 oldPage = muPage;
|
||||
if (oldPage == 0) {
|
||||
muPage = mpLanguageDependency->count - 1;
|
||||
} else {
|
||||
muPage = oldPage - 1;
|
||||
}
|
||||
u8 newPage = muPage;
|
||||
setSignKeyTop(oldPage, newPage);
|
||||
setPageNumber(newPage);
|
||||
movePrevSignWindow();
|
||||
mpEventObserver->onSE(sound::SE_15);
|
||||
}
|
||||
|
||||
void LayoutByNW4R::moveNextSignPage() {
|
||||
u8 oldPage = muPage;
|
||||
u8 page = oldPage + 1;
|
||||
muPage = page;
|
||||
if (page >= mpLanguageDependency->count) {
|
||||
muPage = 0;
|
||||
}
|
||||
u8 newPage = muPage;
|
||||
setSignKeyTop(oldPage, newPage);
|
||||
setPageNumber(newPage);
|
||||
moveNextSignWindow();
|
||||
mpEventObserver->onSE(sound::SE_15);
|
||||
}
|
||||
|
||||
void LayoutByNW4R::movePrevSignWindow() {
|
||||
searchAnmPane("N_SGNkeyall")->onAnmEvent(static_cast<nw4rmanager::AnmPane::AnmPaneEvent>(8));
|
||||
}
|
||||
|
||||
void LayoutByNW4R::moveNextSignWindow() {
|
||||
searchAnmPane("N_SGNkeyall")->onAnmEvent(static_cast<nw4rmanager::AnmPane::AnmPaneEvent>(9));
|
||||
}
|
||||
|
||||
bool LayoutByNW4R::updateInput(int point, f32 x, f32 y, u32 trig, u32 hold, u32 release, void* data) {
|
||||
if (mbInput != 0) {
|
||||
return nw4rmanager::Layout::updateInput(point, x, y, trig, hold, release, data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LayoutByNW4R::updateInput(input::HKBManager& manager) {
|
||||
if (mbInput == 0) {
|
||||
return false;
|
||||
}
|
||||
input::HKBManager::KeySet keySet = manager.GetTriggeredKeySet();
|
||||
if (keySet.IsValid()) {
|
||||
throwReleaseForAll();
|
||||
close();
|
||||
mpEventObserver->onSE(sound::SE_CHAR_DECIDE);
|
||||
return false;
|
||||
}
|
||||
return nw4rmanager::Layout::updateInput(manager);
|
||||
}
|
||||
|
||||
void EventHandler::onTiEvent(gui::PaneComponent* paneComponent, u32 event, Input* input) {
|
||||
s32 eventType = event;
|
||||
const char* name = paneComponent->getPane()->GetName();
|
||||
if (!mpLayoutByNW4R->isLocked() || event != 4) {
|
||||
if (event == 4 && (input->trigger & 0x800) != 0) {
|
||||
mpLayoutByNW4R->onKey(4, const_cast<char*>(name));
|
||||
}
|
||||
if (name[0] == 'B') {
|
||||
char paneName[24];
|
||||
memset(paneName, 0, 0x11);
|
||||
strncpy(paneName, name, strlen(name));
|
||||
paneName[0] = 'P';
|
||||
AnmPane* pane = static_cast<AnmPane*>(mpLayoutByNW4R->searchAnmPane(paneName));
|
||||
if (pane != NULL) {
|
||||
switch (eventType) {
|
||||
case 4:
|
||||
if ((input->trigger & 0x800) != 0) {
|
||||
pane->onAnmEvent(nw4rmanager::AnmPane::PE_0);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
pane->onAnmEvent(nw4rmanager::AnmPane::PE_2);
|
||||
break;
|
||||
case 0:
|
||||
mpEventObserver->onSE(sound::SE_SELECT);
|
||||
mpLayoutByNW4R->setPaneLastDrawReceived(pane->getPane());
|
||||
pane->onAnmEvent(nw4rmanager::AnmPane::PE_1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Base::isLocked() {
|
||||
return mbLocked;
|
||||
}
|
||||
|
||||
void CellPhoneSignAllAnmPane::onAnmEvent(AnmPaneEvent event) {
|
||||
if (event == 6) {
|
||||
getPane()->SetVisible(true);
|
||||
changeAnimation(1);
|
||||
return;
|
||||
}
|
||||
if (event == 7) {
|
||||
changeAnimation(8);
|
||||
return;
|
||||
}
|
||||
if (muAnimation != 8) {
|
||||
if (muAnimation >= 8) {
|
||||
return;
|
||||
}
|
||||
if (muAnimation != 1) {
|
||||
return;
|
||||
}
|
||||
if (event != 4) {
|
||||
return;
|
||||
}
|
||||
changeAnimation(0);
|
||||
return;
|
||||
}
|
||||
if (event == 4) {
|
||||
getPane()->SetVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
void AnmPane::changeAnimation(u32 animation) {
|
||||
muAnimation = animation;
|
||||
nw4rmanager::AnmPane::changeAnimation(animation);
|
||||
}
|
||||
|
||||
void CellPhoneSignScrollAnmPane::onAnmEvent(AnmPaneEvent event) {
|
||||
switch (muAnimation) {
|
||||
case 0:
|
||||
if (event == 9) {
|
||||
changeAnimation(5);
|
||||
}
|
||||
if (event != 8) {
|
||||
return;
|
||||
}
|
||||
changeAnimation(7);
|
||||
return;
|
||||
case 5:
|
||||
case 7:
|
||||
if (event != 4) {
|
||||
return;
|
||||
}
|
||||
changeAnimation(0);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void CellPhoneSignButtonPane::onAnmEvent(AnmPaneEvent event) {
|
||||
if (event == 0) {
|
||||
changeAnimation(4);
|
||||
}
|
||||
switch (muAnimation) {
|
||||
case 0:
|
||||
if (event == 1) {
|
||||
changeAnimation(2);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (event == 4) {
|
||||
changeAnimation(3);
|
||||
}
|
||||
if (event == 2) {
|
||||
changeAnimation(6);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (event == 2) {
|
||||
changeAnimation(6);
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if (event == 4) {
|
||||
changeAnimation(0);
|
||||
}
|
||||
if (event == 1) {
|
||||
changeAnimation(2);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (event == 4) {
|
||||
changeAnimation(3);
|
||||
}
|
||||
if (event == 2) {
|
||||
changeAnimation(6);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutByNW4R::draw() {
|
||||
nw4rmanager::Layout::draw();
|
||||
}
|
||||
|
||||
}
|
||||
void KeyboardBase::onActive() {}
|
||||
namespace signwindow {
|
||||
|
||||
u8 Base::getPage() {
|
||||
return muPage;
|
||||
}
|
||||
|
||||
void Base::setPage(u8 page) {
|
||||
muPage = page;
|
||||
if (muPage < mpLanguageDependency->count) {
|
||||
return;
|
||||
}
|
||||
muPage = 0;
|
||||
}
|
||||
|
||||
void Base::setLanguage(Language language) {
|
||||
meLanguage = language;
|
||||
init();
|
||||
}
|
||||
|
||||
int Base::getType() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
bool LayoutByNW4R::isActive() {
|
||||
return mbActive;
|
||||
}
|
||||
|
||||
CellPhoneSignButtonPane::~CellPhoneSignButtonPane() {}
|
||||
|
||||
void CellPhoneSignButtonPane::init() {
|
||||
muAnimation = 0;
|
||||
}
|
||||
|
||||
void CellPhoneSignScrollAnmPane::init() {
|
||||
muAnimation = 0;
|
||||
}
|
||||
|
||||
CellPhoneSignAllAnmPane::~CellPhoneSignAllAnmPane() {}
|
||||
|
||||
void CellPhoneSignAllAnmPane::init() {
|
||||
muAnimation = 0;
|
||||
}
|
||||
|
||||
CellPhoneSignScrollAnmPane::~CellPhoneSignScrollAnmPane() {}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
# NWC24MsgCommit matching attempts
|
||||
|
||||
Baseline: no source, 0/18 functions, 0/8532 code bytes, 0/904 data bytes.
|
||||
All 18 functions are implemented in target object order. The private header's
|
||||
additional mailbox/message views are guarded by NWC24_MSG_COMMIT, defined only
|
||||
in this source. NWC24_MBOX_CTRL retains its existing view.
|
||||
|
||||
## Remaining functions
|
||||
|
||||
- NWC24CommitMsgInternal: the initial implementation has 781/827 instructions,
|
||||
82.8549%. A signed initialization index, swapping subject/text declarations,
|
||||
and inclusive file-error bounds were tested separately. Separating the overall
|
||||
result from each write's status gives 812/827 instructions, 88.46554%. Generic
|
||||
optional field writers give 826/827, 90.1052%; individual command/tag/DWC/icon
|
||||
inline writers give 817/827, 92.53204%. Moving cancellation before object
|
||||
publication gives 818/827, 94.54534%. Combining unsigned attachment iteration,
|
||||
partial-write byte accounting, subject/text declaration order, and inclusive
|
||||
status bounds gives 94.71463%. A separate inline message-ID writer gives
|
||||
94.72672%, 818/827. Remaining differences involve write/error control flow,
|
||||
formatting temporaries, and register allocation.
|
||||
- CheckMsgBoxSpace: the initial estimate gives 223/223 instructions, 85.57399%.
|
||||
Splitting the base64 estimate into three accumulation statements gives
|
||||
78.098656%, 109 differences. Signed accumulation counters give 86.13453%,
|
||||
76 differences, but change the final unsigned capacity comparison. Moving
|
||||
the per-attachment size temporary outside the scan gives 85.57399%,
|
||||
75 differences. The final source keeps unsigned counters and the original
|
||||
unsigned overflow comparison. Remaining differences are chiefly scheduling
|
||||
and allocation in the compiler's eight-way unrolled attachment estimate.
|
||||
- WriteToField: deferring field-counter initialization gives 99.71111%,
|
||||
90/90 instructions, six differences. An inclusive capacity check reduces this
|
||||
to four differences, 99.77778%. Moving the cursor before the buffer, moving
|
||||
the buffer after the counters/length/error, and separating initialization
|
||||
from declaration retain those four differences. An explicit recipient
|
||||
pointer gives 98.977776%, 14 differences; moving the cursor declaration after
|
||||
the length gives 97.5%, 36 differences. The remaining four differences select
|
||||
r24 instead of r25 for the initial scratch buffer, before recipient iteration.
|
||||
- WriteMIMEAttachHeader: the initial form gives 92/92 instructions, 86.815216%,
|
||||
53 differences. Reloading the work buffer after clearing gives 92.41304%,
|
||||
25 differences. Nonpositive format-count checks give 87.01087%. Computing
|
||||
the first two formatted counts before the final format gives 91/92
|
||||
instructions. Advancing the cursor before that sum restores 92/92 and gives
|
||||
97.33696%, eight differences. Combining template lengths before reading the
|
||||
MIME-name length gives 99.45652%; grouping the final template sum gives
|
||||
99.51087%, seven differences. Reusing template-length temporaries for
|
||||
formatted lengths and reordering those declarations do not resolve them.
|
||||
Remaining differences are the template-sum schedule and register choices.
|
||||
- WriteQPData: the initial form gives 60/60 instructions, 98.333336%,
|
||||
19 differences. Signed total and reversed encoded/consumed-count declarations
|
||||
give 98.5%, 13 differences. An input cursor declared before the total gives
|
||||
98.833336%, ten differences. Separating the remaining-byte count gives 99%,
|
||||
nine differences. Moving the error/counters/output pointer and trying cursor
|
||||
declarations before/after those locals were also tested. The remaining nine
|
||||
differences are callee-saved register choices; instruction count matches.
|
||||
|
||||
## Exact objdiff results
|
||||
|
||||
13/18 functions, 3364/8532 code bytes. The exact functions are NWC24CommitMsg,
|
||||
CheckMsgObject, SynthesizeAddrStr, WriteSMTP_MAILFROM, WriteSMTP_RCPTTO,
|
||||
WriteFromField, WriteDateField, WriteXWiiAppIdField, WriteXWiiFaceField,
|
||||
WriteXWiiAltNameField, WriteContentTypeField, WritePlainText, and WriteBase64Data.
|
||||
|
||||
Declaration/lifetime changes resolve loopback, address synthesis, recipient
|
||||
iteration, application flags, folded base64 headers, and content headers.
|
||||
Advancing the synthesized-address cursor and caching the complete field length
|
||||
resolve the SMTP sender and From header. A while loop with explicit cursor and
|
||||
remaining-byte updates resolves the base64 writer. Inclusive validation bounds
|
||||
resolve message validation and the Date header.
|
||||
|
||||
The gate counts 11 instruction-exact functions. Its disassembler and ctxdiff
|
||||
misnormalize the two cr1 branches in each of WriteSMTP_MAILFROM and
|
||||
WriteFromField: odiff.dis reads operands[0].imm as the target even when the first
|
||||
operand is the condition-register field. These functions are at different unit
|
||||
positions while the preceding commit function remains short. Direct .text byte
|
||||
comparison confirms all 232/256 bytes respectively are identical to the target;
|
||||
objdiff reports both at 100%. No tool or target metadata was edited to bypass
|
||||
that count. All other eleven exact functions have zero ctxdiff differences.
|
||||
|
||||
## Data
|
||||
|
||||
pool_diff and the gate report identical pools. Every long string occupies its
|
||||
target .data offset, and the twelve-month table is at 0x140 in source order.
|
||||
The unrelocated .data bytes match the complete 678-byte source prefix of the
|
||||
680-byte target; the remaining target bytes are alignment zeros. The twelve
|
||||
month-pointer relocations are present in both objects. The target extraction
|
||||
combines the first thirteen strings into one 296-byte symbol, whereas MWCC
|
||||
emits individual literal symbols. The table's small-string destinations also
|
||||
retain the .sdata offset differences below. Objdiff does not score .data as
|
||||
matched despite the identical raw prefix; its relocations/symbol grouping
|
||||
remain open.
|
||||
|
||||
.bss MultiPartDivider is 64 bytes and matches 100%. .sbss m_pFile matches 100%.
|
||||
.sdata scores 18.765432%. Its first difference is byte four: the target's
|
||||
LoopBackEnable symbol includes a trailing zero word, whereas the source's
|
||||
ordinary BOOL definition is four bytes. The target also contains separate
|
||||
subject and multipart CRLF literals; MWCC pools the source literals together.
|
||||
The source .sdata is 140 bytes versus the target's 152 bytes, including trailing
|
||||
section alignment. No extra object, packed string blob, alignment directive,
|
||||
symbol-size change, or placement trick was introduced to cover these gaps.
|
||||
Total matched data is 72/904 bytes. These data-layout differences remain open.
|
||||
@@ -20,8 +20,9 @@ def main():
|
||||
off, size = target["st_value"], target["st_size"]
|
||||
relocs = {}
|
||||
rt = e.get_section_by_name(".rela.text")
|
||||
for r in rt.iter_relocations():
|
||||
relocs[r["r_offset"]] = names[r["r_info_sym"]]
|
||||
if rt is not None:
|
||||
for r in rt.iter_relocations():
|
||||
relocs[r["r_offset"]] = names[r["r_info_sym"]]
|
||||
data = e.get_section_by_name(".text").data()[off:off + size]
|
||||
md = Cs(CS_ARCH_PPC, CS_MODE_32 + CS_MODE_BIG_ENDIAN)
|
||||
md.detail = True
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
# fa/pf_entry_iterator attempts
|
||||
|
||||
The matching vf implementation supplied iterator movement, path traversal, and directory parsing. The fa object adds a word to FFD, extends the FAT hint, changes search attribute handling and entry-name matching, and replaces FindCluster with an ancestor search. All 16 target functions are implemented in object order; 14 are instruction-exact.
|
||||
|
||||
PFENT_ITER_FindCluster:
|
||||
- Initial ancestor traversal: 231/237 instructions; unused standalone chain counter disappeared.
|
||||
- Use hint.chain_index, correct cluster_link initialization, and unsigned entry-offset shift: 237/237; 48 differences, mostly register allocation.
|
||||
- Move hint before current_cluster and delay hint.chain_index initialization: 237/237; 11 register differences.
|
||||
- Swap sector-index/entries-per-sector declaration order: 237/237; 8 register differences. Retained.
|
||||
- Reverse sector-index bitwise operands: no change. Move entries declaration first: no change. Delay FFD start-cluster assignment: 16 differences; reverted.
|
||||
|
||||
PFENT_ITER_GetLFNEntryName:
|
||||
- Separate long_name expressions for each copy: 77/73 instructions; three independently advanced destination offsets.
|
||||
- Reuse one destination pointer: 78/73; fewer address calculations, but signed final division added correction instructions.
|
||||
- Unsigned final index and explicit byte-offset loop: 76/73; compiler advances destination pointer directly, unlike target's offset addition.
|
||||
- Signed loop counter: 76/73, adds signed comparison; reverted.
|
||||
- Destination index (i * 26U) / 2U: 74/73; one extra alignment-mask instruction and loop/destination register allocation. Retained.
|
||||
- Byte-pointer arithmetic, integer-address arithmetic, or three byte-pointer copy expressions: 76/73; same pointer induction. Reverted.
|
||||
|
||||
Data: ordinary literals occur in target order. Candidate .sdata is 22 bytes; target is 24 bytes. The common 22 bytes are identical; two trailing zero bytes remain unresolved. No padding or extra literals added. pool_diff.py requires .data and raises KeyError for this unit; the gate reports identical empty .data pools, so the explicit ELF .sdata comparison is the meaningful data check.
|
||||
@@ -1,45 +0,0 @@
|
||||
# tiSignWindow matching attempts
|
||||
|
||||
Baseline: absent source, 0/56 functions and 0/7184 code bytes. The source reconstructs the actual animation, pane, language, and key-name tables using ordinary literals and typed objects. Previous scratch C++ and the original-object Ghidra export were references. Their explicit padding, mangled free-function calls, manual vtable dispatch, and raw pointer offsets were removed before the first build.
|
||||
|
||||
## Data
|
||||
|
||||
The first build already had all 30 strings in the original pool order. The nine animation records occupy 612 bytes; the compiler supplies the following alignment naturally, without a padding record. InputCharacter is a real 12-byte command payload with ordinary aggregate initialization.
|
||||
|
||||
The first .data score was 83.582375%. Declaring the three concrete animation-pane classes in reverse vtable emission order restored their table order. Inheriting CommandSender::setCommandReceiver and sendCommand for this unit corrected the two Base/Layout vtables. All data sections subsequently reached 100% in objdiff: .data, .rodata, .sdata, and .ctors. A trial making the key-name table static caused the compiler to remove it and broke the pool; the table retains ordinary external linkage so the real target table is present.
|
||||
|
||||
## Matched functions
|
||||
|
||||
Most functions matched on the first readable implementation, including destruction, initialization, modal-window operations, character/page rendering, input handling, and animation callbacks.
|
||||
|
||||
- The input payload's repeat flag initially read an unsigned-byte member into bool and emitted three normalization instructions. Declaring the actual boolean repeat/locked/input/active fields restored the target loads and stores.
|
||||
- CellPhoneSignAllAnmPane::onAnmEvent had 39/39 instructions with two unsigned comparisons. Making the stored animation state signed restored both comparisons and gave zero diffs.
|
||||
- Base::onKey initially had 115/115 instructions with 13 differences. Moving counters into their respective scopes produced 19 differences; reversing the two counter declarations also produced 19; using an unsigned control-key result increased the count to 116. These variants were reverted.
|
||||
- A real inline control-key lookup reduced Base::onKey to ten differences and LayoutByNW4R::onKey to eight. A character lookup accepting LanguageDependency reduced the layout function to five differences. Swapping the helper's parameter order left five differences. Passing the actual key array to the character helper restored the target register allocation for both functions.
|
||||
- Base::onKey then showed two false ctxdiff differences on CR1 branches. Inspection found identical instruction bytes for both branches; the helper normalizes the CR operand as if it were a branch address when function offsets differ. Declaring the already-existing KeyboardBase::getLanguage externally in this unit avoided a duplicate weak inline body, restored the original function offset, and ctxdiff reported zero differences without any instruction changes to onKey.
|
||||
|
||||
## Remaining function: LayoutByNW4R::create
|
||||
|
||||
All variants use typed placement construction, real class sizes, and the same 221 instructions as the target. The remaining differences are callee-saved register allocation, including hoisted vtable addresses, animation count, and animation-record temporaries.
|
||||
|
||||
1. Initial scoped const forceName/animationCount variables: 61 differences.
|
||||
2. Declared forceName and animationCount outside the pane loop and assigned them after appending the pane: 34 differences.
|
||||
3. Declared the pane pointer before the pane-table reference: still 34 differences.
|
||||
4. Reversed the forceName/count declarations: 37 differences, reverted.
|
||||
5. Changed the outer for loop to a do/while loop with an explicit paneIndex: still 34 differences, retained.
|
||||
6. Kept forceName outside but made animationCount local and const: 59 differences, reverted.
|
||||
|
||||
The retained version has 221/221 instructions and 34 register differences. No artificial code or data placement was used.
|
||||
|
||||
## Changed files
|
||||
|
||||
- src/keyboard/tiSignWindow.cpp
|
||||
- include/keyboard/tiSignWindow.h
|
||||
- include/keyboard/tiHKBManager.h
|
||||
- include/keyboard/tiInputForm.h
|
||||
- include/keyboard/tiKeyboard.h
|
||||
- include/keyboard/tiNw4rManager.h
|
||||
- include/keyboard/tiPcKeyboard.h
|
||||
- include/keyboard/tiPcKeyboardImpl.h
|
||||
- include/keyboard/tiTextInputBase.h
|
||||
- tools/decomp-assist/tiSignWindow.attempts.md
|
||||
Reference in New Issue
Block a user