Homebrew Homebrew Development

D

Deleted User

Guest
Hey, Voxel here with yet another question...

Is there a way to read specific parts of a text file? for example, reading and printing a word from the middle of a sentence. Thank you for any answers.
 

Slashcash

Well-Known Member
Member
Joined
Oct 15, 2015
Messages
338
Trophies
0
XP
611
Country
Italy
Hey, Voxel here with yet another question...

Is there a way to read specific parts of a text file? for example, reading and printing a word from the middle of a sentence. Thank you for any answers.

copy the file content into a buffer using standard file i/o and then search the word you need into that buffer. If the file is too big don't copy it entirely, it would be SO slow (you could divide the file into different chunks, for example)

Additional challenge: load the chunks and search into them with different threads and you will have the faster search function in the homebrew scene!
 
D

Deleted User

Guest
copy the file content into a buffer using standard file i/o and then search the word you need into that buffer. If the file is too big don't copy it entirely, it would be SO slow (you could divide the file into different chunks, for example)

Additional challenge: load the chunks and search into them with different threads and you will have the faster search function in the homebrew scene!
Still have no idea, but thanks anyway. (I'll take a look at some sources and see if that helps..)

EDIT: Ah, I seem to have found a good example in the romfs example.
 

Slashcash

Well-Known Member
Member
Joined
Oct 15, 2015
Messages
338
Trophies
0
XP
611
Country
Italy
Still have no idea, but thanks anyway. (I'll take a look at some sources and see if that helps..)

Would i be rude suggesting to change the approach here? Looking at source code from experienced programmers without understanding the bases will result in a working code (maybe) and in a confuse coder. I pointed you in the right direction, follow that direction all by yourself, it will take some time but it will make you skillful.

Start learning about standard file io in c/c++ and everything will come naturally, i assure ;)
there are a lot of tutiorals online on the matter
 
Last edited by Slashcash,
D

Deleted User

Guest
Would i be rude suggesting to change the approach here? Looking at source code from experienced programmers without understanding the bases will result in a working code (maybe) and in a confuse coder. I pointed you in the right direction, follow that direction all by yourself, it will take some time but it will make you skillful.

Start learning about standard file io in c/c++ and everything will come naturally, i assure ;)
Well, I guess it is very similar to your general i/o in C, since you have your strlen, fgets, sizeof functions etc. and I am confident with using all of those once I look at examples (like I did just now). :)
 

Slashcash

Well-Known Member
Member
Joined
Oct 15, 2015
Messages
338
Trophies
0
XP
611
Country
Italy
Is there a errorcodes database?
When trying to open a file in savedata archive i get this error: -931117979

I don't know if it is available anywhere else (never found it) but you should get a general error description by logging into #3dsdev on irc and writing !err 0xERRORNUMBER

(be sure to write the error number in hex)
 

Rinnegatamante

Well-Known Member
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,857
Country
Italy
I don't know if it is available anywhere else (never found it) but you should get a general error description by logging into #3dsdev on irc and writing !err 0xERRORNUMBER

(be sure to write the error number in hex)


MMmmmhhh could it be related to the fact i need two archives to be opened? It looks like with latest changes in ctrulib, handles are no more supported so maybe the problem could came from this.
 

Slashcash

Well-Known Member
Member
Joined
Oct 15, 2015
Messages
338
Trophies
0
XP
611
Country
Italy
Well, I guess it is very similar to your general i/o in C, since you have your strlen, fgets, sizeof functions etc. and I am confident with using all of those once I look at examples (like I did just now). :)

Yes, file i/o shares some concepts with regular i/o. But you are getting confused among totally different things. strlen is a c string function, sizeof is in the core of the language. They have nothing to do with file i/o

MMmmmhhh could it be related to the fact i need two archives to be opened? It looks like with latest changes in ctrulib, handles are no more supported so maybe the problem could came from this.

What are you trying to do here? Accessing a savedata archive? With ctrulib's great refactor having two different archives for sd and savefile access is not needed anymore. Use standard file access to access sd card and use ctrulib's function to access save data archive.

I'm opening the save file archive this way: https://github.com/Slashcash/PCHex-plusplus/blob/master/source/filesystem.cpp#L20#L31
 

Slashcash

Well-Known Member
Member
Joined
Oct 15, 2015
Messages
338
Trophies
0
XP
611
Country
Italy
What if i want to open both archives with fs instead of using normal I/O C functions?

Then do it. Opening an sd archive doesn't require any handle. First open the sd archive: https://github.com/Slashcash/pkm-save-manager/blob/master/source/filesystem.cpp#L10#L12 this way (just look at the sd archive opening)

and then open the save archive as i linked before.

Don't forget to close to close the FS session and both archives this way or you will likely get into troubles: https://github.com/Slashcash/PCHex-plusplus/blob/master/source/filesystem.cpp#L166#L169
 
Last edited by Slashcash,

Rinnegatamante

Well-Known Member
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,857
Country
Italy
Never tried but the remove(char* path) function from <stdio.h> should do the trick, Never tried using it but every other stdio.h function is working well on 3ds

Yep, it looks it's working good. Now i don't have any error but it looks like savegame is not touched:

Code:
Result ret = FSUSER_OpenFile(&output, saveArchive, filePath, FS_OPEN_READ, 0x00000000);
   if (ret == 0){
     FSFILE_Close(output);
     svcCloseHandle(output);
     FSUSER_DeleteFile(saveArchive, filePath);
   }
   ret = FSUSER_OpenFile( &output, saveArchive, filePath, FS_OPEN_WRITE | FS_OPEN_CREATE, 0x00000000);
   if (ret != 0){
     printf("ERROR (%i)\n\n", ret);
     printf("Press B to continue.");
     gfxFlushBuffers();
     while(!(hidKeysDown() & KEY_B)) hidScanInput();
     return;
   }else printf("Done!\nWriting savegame... ");
   gfxFlushBuffers();
   FSFILE_Write(output, NULL, 0, buffer, fileSize, 0x10001);
   FSFILE_Close(output);
   svcCloseHandle(output);
   printf("Done!\n");
   gfxFlushBuffers();
 

Slashcash

Well-Known Member
Member
Joined
Oct 15, 2015
Messages
338
Trophies
0
XP
611
Country
Italy

Rinnegatamante

Well-Known Member
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,857
Country
Italy

daxtsu

Well-Known Member
Member
Joined
Jun 9, 2007
Messages
5,627
Trophies
2
XP
5,194
Country
Antarctica
  • Like
Reactions: Rinnegatamante

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    SylverReZ @ SylverReZ: @salazarcosplay, Im alright.