Homebrew Requesting some guidance coding a Icon-Cache Refresher for the 3DS in LPP

tiduscrying

that butt...
OP
Member
Joined
Jun 12, 2012
Messages
509
Trophies
1
Location
HELL
Website
tiduscrying.wordpress.com
XP
2,312
Country
United States
Hi everyone. Last night I posted this idea on Reddit to gauge some opinions and get some information on whether or not my idea was possible. Turns out it is and it seems to be a relatively simple one. But let me go over it here, too.

My idea is to code a simple icon-cache refresher for the 3DS. This serves multiple purposes and could be helpful to a lot of people (mainly romhackers like myself). A lot of people think that the icon cache can only be cleared for a specific application if you uninstall it completely and then re-install it. While this is partially true, there is another, quicker and more efficient way to clear the icon cache that doesn't require uninstalling anything at all.

According to this thread, the icon cache is stored in the extdata as a file named "CacheD.dat" and can be easily deleted with no harm done to the system other than refreshing the icon cache and clearing the currently installed theme(s). Alternatively, the icon cache can also be cleared by deleting the file here: "SD:/Nintendo 3DS/<ID0>/<ID1>/extdata/00000000/0000008f/00000000/00000005". I have tested this multiple times using multiple methods. First method I used was booting into CTRX Explorer, navigating to the appropriate directory and deleting the 00000005 file. I then exited the program and rebooted my 3DS and the icon cache was cleared and the home menu data was refreshed. FBI has the ability to delete the icon cache as well by selecting the "Ext Save Data" option, selecting the 000000000000008f directory, selecting "Browse User Save Data" and then deleting the CacheD.dat file. I tried this, too and it seems to have worked. My home menu refreshed accordingly upon reboot.

Some comments on the reddit post suggested that the icon cache cannot be touched while in userland, but I believe with my results I have proven this as false, since I successfully cleared it twice while in userland. I don't know if this is the same for everyone else, and I would be interested to hear if anyone else can delete the files manually while the system is booted like I can.

This now brings me to what I want to do with all of this information and why I need help. I currently don't know a lot of things about programming, let alone programming for the 3DS, but I have seen a lot of simple tools created using @Rinnegatamante's Lua Player Plus port. What I would like to do is to code a simple application that can delete the icon-cache and reboot the system. Nothing more, nothing less (except for maybe warning the user that their theme is going to be removed upon rebooting). The only thing is that I don't quite know where to start, and I don't know if this is possible with LPP.

Here is how I was thinking the code would work:
  • First, the program would identify the region that the system is; this is because the extdata folder has a different name based on the region (8F for US, 98 for EUR and 82 for JP).
    • This would probably be an if/then statement, I think.
  • Once the program identifies the system, it scans for the folder. Once the folder is found, the program would be able to go deeper into the extdata and delete the CacheD.dat file.
  • Once the CacheD.dat file is deleted, the program would either prompt the user to reboot the system manually or it would reboot the system automatically (I am unsure whether or not you can issue a reboot command using LPP).
  • Once the system is rebooted, viola, the icon cache is refreshed, and the home menu theme is gone as a result.
Based on the documentation for LPP here, I know that there are a few commands for finding a folder normally and in the extdata, and of course for deleting files, but I am unsure if something like this is possible. I figure that deleting the file as CacheD.dat is simpler than deleting the file by navigating all the way to the 00000005 file. I don't know if this is also the case with programming.

Like I said before, I don't know too much programming knowledge (I've only dabbled with python a bit and took a course on Basic back in high school), so I only vaguely know where to start with this. If someone could offer some guidance on where to start and how to try these commands safely, that would be wonderful. Despite not knowing what to code right now, I would really like to do it myself since it would be a learning exercise and something new to do for me outside of graphic romhacking work!
 

tiduscrying

that butt...
OP
Member
Joined
Jun 12, 2012
Messages
509
Trophies
1
Location
HELL
Website
tiduscrying.wordpress.com
XP
2,312
Country
United States
Okay, so I have done a lot of work and pretty much figured the program out, but it has one kink. It doesn't delete the file... I am trying to figure it out, but I think I don't have it pointed at the file properly or something along those lines. Here is the current code, if anyone is interested.

Code:
local white = Color.new(255,255,255)
local red = Color.new(255,0,0)
local green = Color.new(0,255,0)
local archive
local archive2
local pad = Controls.read()
local oldpad = pad
local reg = System.getRegion()
if reg == 1 then
    archive = 0x000002cd
    archive2 = 0x0000008f
elseif reg == 2 then
    archive = 0x000002ce
    archive2 = 0x00000098
else
    archive = 0x000002cc
    archive2 = 0x00000082
end


function main()
   Screen.refresh()
   Screen.clear(TOP_SCREEN)
   Screen.debugPrint(5,5, "Icon-Cache Deleter", white, TOP_SCREEN)
   Screen.debugPrint(10,20, "Icon cache AND theme(s) will reset.", red, TOP_SCREEN)
   Screen.debugPrint(10,35, "Press A to continue, B to exit.", red, TOP_SCREEN)
   Screen.debugPrint(30,200, "v0.1", white, TOP_SCREEN)
   Screen.debugPrint(30,215, "by tiduscrying", white, TOP_SCREEN)
   Screen.waitVblankStart()
   Screen.flip()
   while true do
       pad = Controls.read()
       if Controls.check(pad,KEY_B) then
       Screen.waitVblankStart()
       Screen.flip()
       System.exit()
       elseif Controls.check(pad,KEY_A) then
           System.deleteFile("/CacheD.dat",archive2)
           Screen.debugPrint(10,50, "Icon-cache has been cleared", green, TOP_SCREEN)
           Screen.debugPrint(10,65, "Press START to reboot.", green, TOP_SCREEN)
           while true do
               pad = Controls.read()
               if Controls.check(pad,KEY_START) then
               System.reboot()
           end
       end
   end
end
end
main()

The program crashes, complaining that the line "System.deleteFile("/CacheD.dat",archive2)" is an invalid argument. When I remove the "archive2" but then I don't think it is deleting the file at all. It is just looking at the root of the SD card for the file and "deleting" something that doesn't exist.

So all in all, close, so close, but I'm not there yet.
 
  • Like
Reactions: Deleted User

You may also like...

General chit-chat
Help Users
  • No one is chatting at the moment.
    KenniesNewName @ KenniesNewName: Brought to you by Raycon