mirror of
https://github.com/DarkStore-3DS/Project_CTR.git
synced 2026-07-05 16:59:02 +00:00
[makerom] Fixed "self referencing problems" work around.
This commit is contained in:
+9
-13
@@ -2,7 +2,8 @@
|
|||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
#include "utf.h"
|
#include "utf.h"
|
||||||
|
|
||||||
/* This is mainly a FS interface for ROMFS generation */
|
/* This is the FS interface for ROMFS generation */
|
||||||
|
/* Tested working on Windows/Linux/OSX */
|
||||||
int fs_InitDir(u16 *path, u32 pathlen, fs_dir *dir);
|
int fs_InitDir(u16 *path, u32 pathlen, fs_dir *dir);
|
||||||
int fs_ManageDirSlot(fs_dir *dir);
|
int fs_ManageDirSlot(fs_dir *dir);
|
||||||
int fs_ManageFileSlot(fs_dir *dir);
|
int fs_ManageFileSlot(fs_dir *dir);
|
||||||
@@ -13,7 +14,7 @@ bool fs_EntryIsDirNav(fs_entry *entry);
|
|||||||
int fs_AddDir(fs_entry *entry, fs_dir *dir);
|
int fs_AddDir(fs_entry *entry, fs_dir *dir);
|
||||||
int fs_AddFile(fs_entry *entry, fs_dir *dir);
|
int fs_AddFile(fs_entry *entry, fs_dir *dir);
|
||||||
|
|
||||||
int fs_u16StrLen(fs_romfs_char *str)
|
int fs_RomFsStrLen(fs_romfs_char *str)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for( i = 0; str[i] != 0x0; i++ );
|
for( i = 0; str[i] != 0x0; i++ );
|
||||||
@@ -159,8 +160,7 @@ int fs_AddDir(fs_entry *entry, fs_dir *dir)
|
|||||||
fs_ManageDirSlot(dir);
|
fs_ManageDirSlot(dir);
|
||||||
u32 current_slot = dir->u_dir;
|
u32 current_slot = dir->u_dir;
|
||||||
dir->u_dir++;
|
dir->u_dir++;
|
||||||
fs_dir *tmp = (fs_dir*)dir->dir;
|
return fs_OpenDir(entry->fs_name,entry->name,entry->name_len,&dir->dir[current_slot]);
|
||||||
return fs_OpenDir(entry->fs_name,entry->name,entry->name_len,&tmp[current_slot]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int fs_AddFile(fs_entry *entry, fs_dir *dir)
|
int fs_AddFile(fs_entry *entry, fs_dir *dir)
|
||||||
@@ -288,9 +288,8 @@ void fs_PrintDir(fs_dir *dir, u32 depth) // This is just for simple debugging, p
|
|||||||
}
|
}
|
||||||
if(dir->u_dir)
|
if(dir->u_dir)
|
||||||
{
|
{
|
||||||
fs_dir *tmp = (fs_dir*)dir->dir;
|
|
||||||
for(u32 i = 0; i < dir->u_dir; i++)
|
for(u32 i = 0; i < dir->u_dir; i++)
|
||||||
fs_PrintDir(&tmp[i],depth+1);
|
fs_PrintDir(&dir->dir[i],depth+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,13 +304,11 @@ void fs_FreeDir(fs_dir *dir)
|
|||||||
free(dir->file);
|
free(dir->file);
|
||||||
|
|
||||||
|
|
||||||
fs_dir *tmp = (fs_dir*)dir->dir;
|
//printf("free dir names and\n");
|
||||||
//printf("free dir names\n");
|
|
||||||
for(u32 i = 0; i < dir->u_dir; i++)
|
for(u32 i = 0; i < dir->u_dir; i++)
|
||||||
{
|
{
|
||||||
//wprintf(L"freeing: %s\n",tmp[i].name);
|
free(dir->dir[i].name);
|
||||||
free(tmp[i].name);
|
fs_FreeDir(&dir->dir[i]);
|
||||||
fs_FreeDir(&tmp[i]);
|
|
||||||
}
|
}
|
||||||
//printf("free dir struct\n");
|
//printf("free dir struct\n");
|
||||||
free(dir->dir);
|
free(dir->dir);
|
||||||
@@ -326,7 +323,6 @@ void fs_FreeFiles(fs_dir *dir)
|
|||||||
fclose(dir->file[i].fp);
|
fclose(dir->file[i].fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
fs_dir *tmp = (fs_dir*)dir->dir;
|
|
||||||
for(u32 i = 0; i < dir->u_dir; i++)
|
for(u32 i = 0; i < dir->u_dir; i++)
|
||||||
fs_FreeFiles(&tmp[i]);
|
fs_FreeFiles(&dir->dir[i]);
|
||||||
}
|
}
|
||||||
+12
-12
@@ -21,7 +21,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
struct fs_entry
|
||||||
{
|
{
|
||||||
bool IsDir;
|
bool IsDir;
|
||||||
fs_char *fs_name;
|
fs_char *fs_name;
|
||||||
@@ -29,35 +29,35 @@ typedef struct
|
|||||||
u32 name_len;
|
u32 name_len;
|
||||||
u64 size;
|
u64 size;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
} fs_entry;
|
};
|
||||||
|
|
||||||
typedef struct
|
struct fs_file
|
||||||
{
|
{
|
||||||
fs_romfs_char *name;
|
fs_romfs_char *name;
|
||||||
u32 name_len;
|
u32 name_len;
|
||||||
u64 size;
|
u64 size;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
} fs_file;
|
};
|
||||||
|
|
||||||
typedef struct
|
struct fs_dir
|
||||||
{
|
{
|
||||||
fs_romfs_char *name;
|
fs_romfs_char *name;
|
||||||
u32 name_len;
|
u32 name_len;
|
||||||
|
|
||||||
void *dir; // treated as type 'fs_dir'. This officially type 'void' to prevent self referencing problems
|
struct fs_dir *dir;
|
||||||
u32 m_dir;
|
u32 m_dir;
|
||||||
u32 u_dir;
|
u32 u_dir;
|
||||||
|
|
||||||
fs_file *file;
|
struct fs_file *file;
|
||||||
u32 m_file;
|
u32 m_file;
|
||||||
u32 u_file;
|
u32 u_file;
|
||||||
} fs_dir;
|
};
|
||||||
|
|
||||||
|
typedef struct fs_entry fs_entry;
|
||||||
|
typedef struct fs_file fs_file;
|
||||||
|
typedef struct fs_dir fs_dir;
|
||||||
|
|
||||||
int fs_u8String_to_u16String(u16 **dst, u32 *dst_len, u8 *src, u32 src_len);
|
int fs_RomFsStrLen(fs_romfs_char *str);
|
||||||
int fs_u16String_to_u16String(u16 **dst, u32 *dst_len, u16 *src, u32 src_len);
|
|
||||||
int fs_u32String_to_u16String(u16 **dst, u32 *dst_len, u32 *src, u32 src_len);
|
|
||||||
int fs_u16StrLen(fs_romfs_char *str);
|
|
||||||
|
|
||||||
int fs_OpenDir(fs_char *fs_path, fs_romfs_char *path, u32 pathlen, fs_dir *dir);
|
int fs_OpenDir(fs_char *fs_path, fs_romfs_char *path, u32 pathlen, fs_dir *dir);
|
||||||
void fs_PrintDir(fs_dir *dir, u32 depth);
|
void fs_PrintDir(fs_dir *dir, u32 depth);
|
||||||
|
|||||||
+2
-2
@@ -308,13 +308,13 @@ void BuildRomfsHeader(romfs_buildctx *ctx)
|
|||||||
|
|
||||||
u32 GetFileHashTableIndex(romfs_buildctx *ctx, u32 parent, fs_romfs_char *path)
|
u32 GetFileHashTableIndex(romfs_buildctx *ctx, u32 parent, fs_romfs_char *path)
|
||||||
{
|
{
|
||||||
u32 hash = CalcPathHash(parent, path, 0, fs_u16StrLen(path));
|
u32 hash = CalcPathHash(parent, path, 0, fs_RomFsStrLen(path));
|
||||||
return hash % ctx->m_fileHashTable;
|
return hash % ctx->m_fileHashTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GetDirHashTableIndex(romfs_buildctx *ctx, u32 parent, fs_romfs_char* path)
|
u32 GetDirHashTableIndex(romfs_buildctx *ctx, u32 parent, fs_romfs_char* path)
|
||||||
{
|
{
|
||||||
u32 hash = CalcPathHash(parent, path, 0, fs_u16StrLen(path));
|
u32 hash = CalcPathHash(parent, path, 0, fs_RomFsStrLen(path));
|
||||||
return hash % ctx->m_dirHashTable;
|
return hash % ctx->m_dirHashTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user