Homebrew [Discontinued] TWLoader - CTR-mode NDS app

Status
Not open for further replies.

bakawun

Well-Known Member
Member
Joined
Jan 10, 2017
Messages
227
Trophies
0
Age
37
XP
93
Country
Luxembourg
@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

GerbilSoft

Well-Known Member
Member
Joined
Mar 8, 2012
Messages
2,395
Trophies
2
Age
34
XP
4,253
Country
United States
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.
 

bakawun

Well-Known Member
Member
Joined
Jan 10, 2017
Messages
227
Trophies
0
Age
37
XP
93
Country
Luxembourg
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?
 

GerbilSoft

Well-Known Member
Member
Joined
Mar 8, 2012
Messages
2,395
Trophies
2
Age
34
XP
4,253
Country
United States
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

bakawun

Well-Known Member
Member
Joined
Jan 10, 2017
Messages
227
Trophies
0
Age
37
XP
93
Country
Luxembourg
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)
 

mcmn

Active Member
Newcomer
Joined
Nov 20, 2016
Messages
33
Trophies
0
Age
41
XP
54
Country
Swaziland
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...
 

RocketRobz

Stylish TWiLight Hero
OP
Developer
Joined
Oct 1, 2010
Messages
16,617
Trophies
3
Age
24
XP
21,034
Country
United States
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.
 

mcmn

Active Member
Newcomer
Joined
Nov 20, 2016
Messages
33
Trophies
0
Age
41
XP
54
Country
Swaziland
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
 

bakawun

Well-Known Member
Member
Joined
Jan 10, 2017
Messages
227
Trophies
0
Age
37
XP
93
Country
Luxembourg
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,

bakawun

Well-Known Member
Member
Joined
Jan 10, 2017
Messages
227
Trophies
0
Age
37
XP
93
Country
Luxembourg
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

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: Wheat flour has a lower chance at survival