Skip to content

Commit

Permalink
fix utf-8 names in file browser
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAaronLopezGarcia committed Dec 17, 2024
1 parent c77fa15 commit 471253f
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 111 deletions.
4 changes: 4 additions & 0 deletions extras/menus/arkMenu/imports.S
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ STUB_START "scePower", 0x40010000, 0x00030005
STUB_FUNC 0x2B7C7CF4, scePowerRequestStandby
STUB_FUNC 0x0442D852, scePowerRequestColdReset
STUB_FUNC 0xAC32C9CC, scePowerRequestSuspend
STUB_END

STUB_START "SysMemUserForUser", 0x40000011, 0x00030005
STUB_FUNC 0x7591C7DB, sceKernelSetCompiledSdkVersion
STUB_END
6 changes: 0 additions & 6 deletions extras/menus/arkMenu/include/browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ enum{
UMD_DIR,
};

typedef struct _pspMsPrivateDirent {
SceSize size;
char s_name[16];
char l_name[1024];
} pspMsPrivateDirent;

class BrowserDriver{
public:
virtual bool connect() = 0;
Expand Down
11 changes: 4 additions & 7 deletions extras/menus/arkMenu/include/browser_entries.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@ class BrowserFile : public Entry{
bool selected;
string fileSize;
int filetype;
string shortname;
string parent;

virtual unsigned getFileSize();

void setShortName(string shortname);

public:

BrowserFile();

BrowserFile(string path, string shortname);
BrowserFile(string parent, string name, string shortname);
BrowserFile(string path);
BrowserFile(string parent, string name);

~BrowserFile();

Expand Down Expand Up @@ -58,8 +55,8 @@ class BrowserFile : public Entry{

class BrowserFolder : public BrowserFile{
public:
BrowserFolder(string path, string shortname);
BrowserFolder(string parent, string name, string shortname);
BrowserFolder(string path);
BrowserFolder(string parent, string name);

~BrowserFolder();

Expand Down
7 changes: 3 additions & 4 deletions extras/menus/arkMenu/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@ using namespace std;
static SystemEntry* entries[MAX_ENTRIES];

extern "C" void my_malloc_init();
extern "C" int sceKernelSetCompiledSdkVersion(int version);

int main(int argc, char** argv){

sceKernelSetCompiledSdkVersion(FW_660);

// make malloc/free threadsafe
my_malloc_init();

srand(time(NULL));

int encoding = 5;
sceIoDevctl("fatms0:", 0x02425856, &encoding, 4, NULL, 0);
//sceIoDevctl("fatef0:", 0x02425856, &encoding, 4, NULL, 0);

intraFontInit();
ya2d_init();

Expand Down
69 changes: 8 additions & 61 deletions extras/menus/arkMenu/src/browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,32 +523,25 @@ void Browser::refreshDirs(const char* retry){
vector<Entry*> files;

// scan directory
pspMsPrivateDirent *pri_dirent = (pspMsPrivateDirent*)malloc(sizeof(pspMsPrivateDirent));
memset(pri_dirent, 0, sizeof(pspMsPrivateDirent));
pri_dirent->size = sizeof(pspMsPrivateDirent);
dit.d_private = (void*)pri_dirent;

while ((sceIoDread(dir, &dit)) > 0){
printf("got entry: %s -> %s\n", dit.d_name, pri_dirent);
printf("got entry: %s\n", dit.d_name);

if (dit.d_name[0] == '.' && strcmp(dit.d_name, ".") != 0 && strcmp(dit.d_name, "..") != 0 && !common::getConf()->show_hidden){
continue;
}

if (common::isFolder(&dit)){
printf("is dir\n");
folders.push_back(new Folder(cwd, dit.d_name, string((const char*)pri_dirent)));
folders.push_back(new Folder(cwd, dit.d_name));
}
else{
printf("is file\n");
files.push_back(new File(cwd, dit.d_name, string((const char*)pri_dirent)));
files.push_back(new File(cwd, dit.d_name));
}
}
printf("closing and cleaning\n");
sceIoDclose(dir);

free(pri_dirent);

// handle special folders
Entry* dot = NULL;
Entry* dotdot = NULL;
Expand All @@ -565,7 +558,7 @@ void Browser::refreshDirs(const char* retry){
}

if (cwd == GO_ROOT){
eh0 = new Folder(cwd, "<Go To eh0>", "");
eh0 = new Folder(cwd, "<Go To eh0>");
}

// sort entries if needed
Expand All @@ -577,9 +570,9 @@ void Browser::refreshDirs(const char* retry){

// insert special folders
if (eh0) folders.insert(folders.begin(), eh0);
if (!dotdot && !isRootDir(this->cwd)) dotdot = new Folder(cwd, "..", "");
if (!dotdot && !isRootDir(this->cwd)) dotdot = new Folder(cwd, "..");
if (dotdot) folders.insert(folders.begin(), dotdot);
if (!dot && !isRootDir(this->cwd)) dot = new Folder(cwd, ".", "");
if (!dot && !isRootDir(this->cwd)) dot = new Folder(cwd, ".");
if (dot) folders.insert(folders.begin(), dot);

// folders first, files last
Expand All @@ -590,7 +583,7 @@ void Browser::refreshDirs(const char* retry){
for (int i=0; i<files.size(); i++)
entries->push_back(files.at(i));
if (this->entries->size() == 0)
this->entries->push_back(new Folder(cwd, ".", ""));
this->entries->push_back(new Folder(cwd, "."));
SystemMgr::resumeDraw();

printf("done\n");
Expand Down Expand Up @@ -908,11 +901,6 @@ void Browser::recursiveFolderDelete(string path){
{
SceIoDirent entry;
memset(&entry, 0, sizeof(SceIoDirent));

pspMsPrivateDirent *pri_dirent = (pspMsPrivateDirent*)malloc(sizeof(pspMsPrivateDirent));
memset(pri_dirent, 0, sizeof(pspMsPrivateDirent));
pri_dirent->size = sizeof(pspMsPrivateDirent);
entry.d_private = (void*)pri_dirent;

//allocate memory to store the full file paths
string new_path;
Expand All @@ -932,25 +920,16 @@ void Browser::recursiveFolderDelete(string path){

if (common::isFolder(&entry)){
new_path = new_path + "/";
if (!common::folderExists(new_path)){
new_path = path + string((const char*)pri_dirent);
printf("%d: %s\n", (int)common::folderExists(new_path), new_path.c_str());
}
recursiveFolderDelete(new_path);
}
else{
if (!common::fileExists(new_path)){
new_path = path + string((const char*)pri_dirent);
printf("%d: %s\n", (int)common::fileExists(new_path), new_path.c_str());
}
self->deleteFile(new_path);
}

};

sceIoDclose(d); //close directory
sceIoRmdir(path.substr(0, path.length()-1).c_str()); //delete empty folder
free(pri_dirent);
};
}

Expand All @@ -963,11 +942,6 @@ long Browser::recursiveSize(string path){
{
SceIoDirent entry;
memset(&entry, 0, sizeof(SceIoDirent));

pspMsPrivateDirent *pri_dirent = (pspMsPrivateDirent*)malloc(sizeof(pspMsPrivateDirent));
memset(pri_dirent, 0, sizeof(pspMsPrivateDirent));
pri_dirent->size = sizeof(pspMsPrivateDirent);
entry.d_private = (void*)pri_dirent;

//allocate memory to store the full file paths
string new_path;
Expand All @@ -987,25 +961,16 @@ long Browser::recursiveSize(string path){

if (common::isFolder(&entry)){
new_path = new_path + "/";
if (!common::folderExists(new_path)){
new_path = path + string((const char*)pri_dirent);
printf("%d: %s\n", (int)common::folderExists(new_path), new_path.c_str());
}
total_size += recursiveSize(new_path);
}
else{
if (!common::fileExists(new_path)){
new_path = path + string((const char*)pri_dirent);
printf("%d: %s\n", (int)common::fileExists(new_path), new_path.c_str());
}
total_size += common::fileSize(new_path);
}

};

sceIoDclose(d); //close directory
sceIoRmdir(path.substr(0, path.length()-1).c_str()); //delete empty folder
free(pri_dirent);
}
else if ((d=sceIoOpen(path.c_str(), PSP_O_RDONLY, 0777)) >= 0){
total_size = sceIoLseek(d, 0, SEEK_END);
Expand Down Expand Up @@ -1155,10 +1120,6 @@ int Browser::copy_folder_recursive(const char * source, const char * destination
{
SceIoDirent entry;
memset(&entry, 0, sizeof(SceIoDirent));

pspMsPrivateDirent* pri_dirent = (pspMsPrivateDirent*)malloc(sizeof(pspMsPrivateDirent));
pri_dirent->size = sizeof(pspMsPrivateDirent);
entry.d_private = (void*)pri_dirent;

//start reading directory entries
while(sceIoDread(dir, &entry) > 0)
Expand All @@ -1172,31 +1133,17 @@ int Browser::copy_folder_recursive(const char * source, const char * destination
string src = new_source + entry.d_name;

if (common::isFolder(&entry)){
string dst;
if (!common::folderExists(src)){
string sname = string((const char*)pri_dirent);
src = new_source + sname;
dst = new_destination + sname;
printf("%d: %s\n", (int)common::folderExists(src), src.c_str());
}
else{
dst = new_destination + entry.d_name;
}
string dst = new_destination + entry.d_name;
copy_folder_recursive(src.c_str(), dst.c_str());
}
else{
if (!common::fileExists(src)){
src = new_source + string((const char*)pri_dirent);
printf("%d: %s\n", (int)common::fileExists(src), src.c_str());
}
if (pasteMode == COPY || (pasteMode == CUT && pspIoMove(src, new_destination) < 0))
copyFile(src, new_destination); //copy file
}

};
//close folder
sceIoDclose(dir);
free(pri_dirent);
};
}

Expand Down
27 changes: 4 additions & 23 deletions extras/menus/arkMenu/src/browser_entries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,46 +34,31 @@ int fileTypeByExtension(string path){
BrowserFile::BrowserFile(){
}

BrowserFile::BrowserFile(string path, string shortname){
BrowserFile::BrowserFile(string path){
size_t lastSlash = path.rfind('/', string::npos);
this->path = path;
this->name = path.substr(lastSlash+1, string::npos);
this->parent = path.substr(0, lastSlash);
this->icon0 = NULL;
this->selected = false;
this->filetype = FOLDER;
this->setShortName(shortname);
this->calcSize();
this->filetype = fileTypeByExtension(getPath());
}

BrowserFile::BrowserFile(string parent, string name, string shortname){
BrowserFile::BrowserFile(string parent, string name){
this->icon0 = NULL;
this->path = parent + name;
this->parent = parent;
this->name = name;
this->selected = false;
this->setShortName(shortname);
this->calcSize();
this->filetype = fileTypeByExtension(getPath());
}

BrowserFile::~BrowserFile(){
}

void BrowserFile::setShortName(string shortname){
this->shortname = "";
if (shortname.size() > 0 && shortname[0] != 0x14){
if (this->name.size() < shortname.size()){
this->path = this->parent + shortname;
this->name = shortname;
}
else {
this->shortname = shortname;
}
}
}

unsigned BrowserFile::getFileSize(){
return common::fileSize(getPath());
}
Expand Down Expand Up @@ -150,7 +135,7 @@ void BrowserFile::loadAVMedia(){
void BrowserFile::doExecute(){
}

BrowserFolder::BrowserFolder(string path, string shortname){
BrowserFolder::BrowserFolder(string path){
size_t lastSlash = path.rfind('/', path.length()-2);
this->path = path;
this->name = path.substr(lastSlash+1, string::npos);
Expand All @@ -159,20 +144,16 @@ BrowserFolder::BrowserFolder(string path, string shortname){
this->selected = false;
this->fileSize = "Folder";
this->filetype = FOLDER;
if (shortname.size() > 0) shortname;
this->setShortName(shortname);
}

BrowserFolder::BrowserFolder(string parent, string name, string shortname){
BrowserFolder::BrowserFolder(string parent, string name){
this->icon0 = NULL;
this->path = parent + name + '/';
this->name = name;
this->parent = parent;
this->selected = false;
this->fileSize = "Folder";
this->filetype = FOLDER;
if (shortname.size() > 0) shortname;
this->setShortName(shortname);
}

BrowserFolder::~BrowserFolder(){
Expand Down
6 changes: 3 additions & 3 deletions extras/menus/arkMenu/src/ftp/ftp_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ vector<Entry*> FTPDriver::listDirectory(string path){
string file_name(dir->files[i].d_name);
file_name = file_name.substr(file_name.find(' ')+1);
if (FIO_SO_ISDIR(dir->files[i].st_attr)) {
BrowserFolder* folder = new BrowserFolder(path, file_name, "");
BrowserFolder* folder = new BrowserFolder(path, file_name);
printf("adding folder: %s -> %s\n", file_name.c_str(), folder->getName().c_str());
folders.push_back(folder);
} else if (FIO_SO_ISREG(dir->files[i].st_attr)) {
Expand Down Expand Up @@ -195,8 +195,8 @@ vector<Entry*> FTPDriver::listDirectory(string path){
if (dot) folders.insert(folders.begin(), dot);
}

ret.push_back(new BrowserFolder("ftp:/", "<refresh>", ""));
ret.push_back(new BrowserFolder("ftp:/", "<disconnect>", ""));
ret.push_back(new BrowserFolder("ftp:/", "<refresh>"));
ret.push_back(new BrowserFolder("ftp:/", "<disconnect>"));

printf("FTP::Folders -> %d\n", folders.size());
for (int i=0; i<folders.size(); i++){
Expand Down
7 changes: 0 additions & 7 deletions extras/menus/arkMenu/src/gamemgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,6 @@ void GameManager::findISOs(const char* path){
SceIoDirent* dit = &entry;
memset(&entry, 0, sizeof(SceIoDirent));

pspMsPrivateDirent* pri_dirent = (pspMsPrivateDirent*)malloc(sizeof(pspMsPrivateDirent));
pri_dirent->size = sizeof(pspMsPrivateDirent);
entry.d_private = (void*)pri_dirent;

if (dir < 0)
return;

Expand All @@ -247,7 +243,6 @@ void GameManager::findISOs(const char* path){
if (dit->d_name[0] == '.' && !common::getConf()->show_hidden) continue;

string fullpath = string(path)+string(dit->d_name);
string shortpath = string(path) + string((const char*)pri_dirent);

if (FIO_SO_ISDIR(dit->d_stat.st_attr)){
if (common::getConf()->scan_cat && string(dit->d_name) != string("VIDEO")){
Expand All @@ -256,10 +251,8 @@ void GameManager::findISOs(const char* path){
continue;
}
if (Iso::isISO(fullpath.c_str())) this->categories[GAME]->addEntry(new Iso(fullpath));
else if (Iso::isISO(shortpath.c_str())) this->categories[GAME]->addEntry(new Iso(shortpath));
}
sceIoDclose(dir);
free(pri_dirent);
}

void GameManager::findSaveEntries(const char* path){
Expand Down

0 comments on commit 471253f

Please sign in to comment.