Homebrew [Discontinued] TWLoader - CTR-mode NDS app

  • Thread starter Thread starter RocketRobz
  • Start date Start date
  • Views Views 1,815,040
  • Replies Replies 9,252
  • Likes Likes 147
Status
Not open for further replies.
@Robz8 @GerbilSoft @umbjolt

Significantly improved workflow for the main selfcheck
This includes the ini creation, migration and twloader.cia update.
it creates these folders /_nds/twloader/cias/
Code:
  1: check if /_nds/twloader/twloader.ini file exists
     no go-to 2
     yes go-to 8
  2: check if /_nds/twloader/ path exists
     no go-to 3
     yes go-to 6
  3: check if /_nds/ path exists
     no go-to 5
     yes go-to 4
  4: mkdir /_nds/twloader/ (non-recursive)
  5: mkdir /_nds/twloader/ (recursive)
  6: check if there is enough space free for the file
     no go-to 27
     yes go-to 7
  7: create versioned ini file using defaults and go-to 1
  8: read ini file (don't use any of the values yet)
  9: check ini file version
     old/no-version go-to 10
     current go-to 14
 10: parse the ini file using legacy parser
 11: perform sanity check on old values
 12: fill new or broken values with defaults
 13: write updated ini to disk, go-back-to 1
 14: is auto updating of twloader allowed?
      yes go-to 15
      no go-to 29
 15: has there been an update check recently
      no/old value go-to 16
      yes go-to 29
 16: is there an internet connection?
      yes go-to 17
      no go-to 28
 17: download version number, size and hash from server and store in memory
     sucess go-to 18
     fail
     are there retries left in the loop? (don't loop forever)
       no go-to 28
        yes go-to 17
 18: compare remote and local version numbers and write timestap for next update check
      old go-to 19
      current go-to 29
 19: check if /_nds/twloader/cias/twloader.cia exists
     no go-to 20
     yes go-to 21
 20: check if /_nds/twloader/cias/ path exists
     no go-to 22
     yes go-to 23
 21: delete /_nds/twloader/cias/twloader.cia --> go-to 23
 22: mkdir /_nds/twloader/cias/ (non-recursive)
 23: check if there is enough space free for the file
     no go-to 28
     yes go-to 24
 24: download twloader.cia to /_nds/twloader/cias/
     sucess go-to 25
     fail
     are there retries left in the loop? (don't loop forever)
       no go-to 28
        yes go-to 23
 25: hash check on twloader.cia
     sucess go-to 26
     fail
     are there retries left in the loop? (don't loop forever)
       no go-to 28
        yes go-to 24
 26: update ini with new version, hash
 27: install cia and restart twloader --end
 28: print error message
 29: continue starting up

EDIT: i forgot to add timestamp writing and checking within steps 14-16, it should check for a timestamp if updating is allowed. Create it when it doesn't exist. And abort further checks if its not older than the set timewindow.

EDIT2: i added timestamp checking to the workflow, but it could be neater

EDIT3: looking at it after a while i realize there is a lot of missing error handling :blush:
 
Last edited by bakawun,
  • Like
Reactions: AtlasFontaine
The FS service doesn't seem to have a way to check file timestamps. That having been said, we could save the current time in an INI file when downloading a boxart and use that as a reference.

Also, recursive mkdir() can be done even if some of the directories exist. No need to manually check first.
 
The FS service doesn't seem to have a way to check file timestamps. That having been said, we could save the current time in an INI file when downloading a boxart and use that as a reference.

Also, recursive mkdir() can be done even if some of the directories exist. No need to manually check first.
Ok we could do recursive and save some time there.
When i talk about timestamps i do mean manually generated ones that we store in ini files.

Can we check for free space on the disk though?
 
Can we check for free space on the disk though?
FBI uses the following code:
Code:
char* currBuffer = ui_free_space_buffer;
FS_ArchiveResource resource = {0};

if(R_SUCCEEDED(FSUSER_GetArchiveResource(&resource, SYSTEM_MEDIATYPE_SD)) && currBuffer < ui_free_space_buffer + sizeof(ui_free_space_buffer)) {
    if(currBuffer != ui_free_space_buffer) {
	snprintf(currBuffer, sizeof(ui_free_space_buffer) - (currBuffer - ui_free_space_buffer), ", ");
	currBuffer += strlen(currBuffer);
    }

    u64 size = (u64) resource.freeClusters * (u64) resource.clusterSize;
    snprintf(currBuffer, sizeof(ui_free_space_buffer) - (currBuffer - ui_free_space_buffer), "SD: %.1f %s", util_get_display_size(size), util_get_display_size_units(size));
    currBuffer += strlen(currBuffer);
}
Valid values for mediaType here are:
  • SYSTEM_MEDIATYPE_SD: The SD card.
  • SYSTEM_MEDIATYPE_CTR_NAND: The CTR NAND partition.
  • SYSTEM_MEDIATYPE_TWL_NAND: The TWL NAND partition.
  • SYSTEM_MEDIATYPE_TWL_PHOTO: The TWL PHOTO partition.
 
  • Like
Reactions: bakawun
FBI uses the following code:
Code:
char* currBuffer = ui_free_space_buffer;
FS_ArchiveResource resource = {0};

if(R_SUCCEEDED(FSUSER_GetArchiveResource(&resource, SYSTEM_MEDIATYPE_SD)) && currBuffer < ui_free_space_buffer + sizeof(ui_free_space_buffer)) {
    if(currBuffer != ui_free_space_buffer) {
    snprintf(currBuffer, sizeof(ui_free_space_buffer) - (currBuffer - ui_free_space_buffer), ", ");
    currBuffer += strlen(currBuffer);
    }

    u64 size = (u64) resource.freeClusters * (u64) resource.clusterSize;
    snprintf(currBuffer, sizeof(ui_free_space_buffer) - (currBuffer - ui_free_space_buffer), "SD: %.1f %s", util_get_display_size(size), util_get_display_size_units(size));
    currBuffer += strlen(currBuffer);
}
Valid values for mediaType here are:
  • SYSTEM_MEDIATYPE_SD: The SD card.
  • SYSTEM_MEDIATYPE_CTR_NAND: The CTR NAND partition.
  • SYSTEM_MEDIATYPE_TWL_NAND: The TWL NAND partition.
  • SYSTEM_MEDIATYPE_TWL_PHOTO: The TWL PHOTO partition.
Great so we use that code to check for space before we create new files (either from code or download)
 
Is there a way to create the new banner .bin files from the command line on a PC? Looks like ndstool creates a different type of bin...
 
Is there a way to create the new banner .bin files from the command line on a PC? Looks like ndstool creates a different type of bin...
Why not use "Add Games"? It'll create the .bin files for your flashcard games.
 
Why not use "Add Games"? It'll create the .bin files for your flashcard games.

But only one game at a time, then it reboots and I have to start the home menu, twloader and add game again...
 
I dunno why it reboots.

I thought this was intentional. I can select a game and it creates the bin and ini files just fine but directly reboots (or crashes?) after that. The last thing I see is "ini. file created", then the "Software closed." screen appears. I have to press "home", wait for the home launcher to appear, start twl again and repeat...

--------------------- MERGED ---------------------------

reboot was fixed for me by clean install on 3ds sd and flashcard sd

I already did that when installing the latest twl
 
I thought this was intentional. I can select a game and it creates the bin and ini files just fine but directly reboots (or crashes?) after that. The last thing I see is "ini. file created", then the "Software closed." screen appears. I have to press "home", wait for the home launcher to appear, start twl again and repeat...

--------------------- MERGED ---------------------------



I already did that when installing the latest twl
try https://3ds.guide/troubleshooting edit @Robz8 can you confirm if those files are actually the latest or not?
 
Last edited by bakawun,
The CIA files in the guide should be the latest.
allright well you fixed it for me somehow with the last version of the galaxy eagle pack

(ps you can change the name and compatibility there.
i infact have a r4i, with r4i.ndsi.in on the sticker but this card is identical to the galaxy eagle and r4ultra from a kernel point of view
 
Status
Not open for further replies.

Site & Scene News

Popular threads in this forum