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
38
XP
103
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
35
XP
4,275
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
38
XP
103
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
35
XP
4,275
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
38
XP
103
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,671
Trophies
3
Age
25
XP
21,191
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
38
XP
103
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
38
XP
103
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
  • Sicklyboy @ Sicklyboy:
    I'm late for the bbq sauce discussion and I have opinions
  • Sicklyboy @ Sicklyboy:
    Sweet Baby Rays is like baseline for a decent/good bbq sauce, but nothing outright incredible
    +1
  • Sicklyboy @ Sicklyboy:
    Stubbs is a pretty damn good sauce that I think you'll find on most grocery shelves as I don't think it's regional
  • Sicklyboy @ Sicklyboy:
    This shit though
  • Sicklyboy @ Sicklyboy:
    Best bbq sauce I've ever bought on a grocery store shelf
  • Sicklyboy @ Sicklyboy:
    smokey flavor that reminds me of beef jerkey on top of a really rich kind of bbq sauce. Heat level that is a nice zing, not overwhelming, but it tingles all the way down your throat
    +1
  • K3Nv2 @ K3Nv2:
    50% closer to getting my teeth fixed
    +4
  • K3Nv2 @ K3Nv2:
    I'm at the grace gods of my insurance fucking me over
  • K3Nv2 @ K3Nv2:
    I was like is this the way out, oh probably there's a giant exit sign
  • BigOnYa @ BigOnYa:
    We all should have free health, dental, vision care, and make the college kids pay for the schooling, f that college forgiveness plan our govt doing now, its really not fair for all others in the past that had to pay for they're schooling anyways (like me, with 2 kids I paid to send to college in the past)
  • mthrnite @ mthrnite:
    whynotboth.jpg
    +2
  • BigOnYa @ BigOnYa:
    True, very true
  • Sicklyboy @ Sicklyboy:
    I think we should outlaw healthcare entirely because the fact that people can get healthcare today is unfair to those in the past that couldn't
    +2
  • BigOnYa @ BigOnYa:
    Lol
  • mthrnite tempBOT: @ mthrnite
    smacks Sicklyboy around a bit with a large leech
  • Sicklyboy @ Sicklyboy:
    Howdy @mthrnite , great to see you :D
  • mthrnite @ mthrnite:
    hola mi hermano
  • cearp @ cearp:
    @Sicklyboy - the comparison would be forgiving all medical debt, not making healthcare illegal!
  • cearp @ cearp:
    Although I still don't agree, medical debt is rarely a choice, whereas enrolling in university is certainly a choice
  • mthrnite @ mthrnite:
    we need more smart cats tho for reals
  • Sicklyboy @ Sicklyboy:
    College costs, college loans, book prices, the entire thing is predatory, oft touted as essential to a successful life for my generation and the ones since, and completely unaffordable without putting you through an insane financial hardship for literal decades in many situations.
  • Sicklyboy @ Sicklyboy:
    Many of the same issues can be seen for the insanely predatory healthcare and health insurance system in the US
    Sicklyboy @ Sicklyboy: Many of the same issues can be seen for the insanely predatory healthcare and health insurance...