Homebrew LPP Not Deleting Directory

  • Thread starter Deleted User
  • Start date
  • Views 1,073
  • Replies 13
D

Deleted User

Guest
OP
I am trying to make an application an in order to do so I need it to delete a directory before moving on and downloading/extracting a file. However it does not seem to work. Am I making a silly mistake?

Currently I am able to download and extract my zips properly. However deleting the old directory is kicking me a bit as it seems to not want to work

Here is my current code


Code:
-- runs update
            pad = Controls.read()
                if Controls.check(pad,KEY_X) then

    -- Deletes the old directory
    System.deleteDirectory("/saltysd")

    -- Downloads new zip
    Network.downloadFile("http://placeholderurl","/placeholder.zip")
    
    -- Extracts zips
    System.extractZIP("/placeholder.zip",System.currentDirectory().."/")
    
    -- Deletes the temp file
    System.deleteFile("/placeholder.zip")
 

The Real Jdbye

*is birb*
Member
Joined
Mar 17, 2010
Messages
23,252
Trophies
4
Location
Space
XP
13,806
Country
Norway
I am trying to make an application an in order to do so I need it to delete a directory before moving on and downloading/extracting a file. However it does not seem to work. Am I making a silly mistake?

Currently I am able to download and extract my zips properly. However deleting the old directory is kicking me a bit as it seems to not want to work

Here is my current code


Code:
-- runs update
            pad = Controls.read()
                if Controls.check(pad,KEY_X) then

    -- Deletes the old directory
    System.deleteDirectory("/saltysd")

    -- Downloads new zip
    Network.downloadFile("http://placeholderurl","/placeholder.zip")
   
    -- Extracts zips
    System.extractZIP("/placeholder.zip",System.currentDirectory().."/")
   
    -- Deletes the temp file
    System.deleteFile("/placeholder.zip")
Is the directory empty? It probably has to be empty first. At least that's how it usually works when deleting directories from code. I don't know if it works like that in Lua specifically though.
 
D

Deleted User

Guest
OP
Is the directory empty? It probably has to be empty first. At least that's how it usually works when deleting directories from code. I don't know if it works like that in Lua specifically though.
The directory is not empty. How would one delete a directory in lua?
 

tech3475

Well-Known Member
Member
Joined
Jun 12, 2009
Messages
3,653
Trophies
2
XP
6,037
Country
You need to implement a way to delete the files to delete the directory, not familiar with lua but there seems to be a way to implement it by using something called ifs.

http://stackoverflow.com/questions/37835565/lua-delete-non-empty-directory

Edit:

Btw, Im not Joking, but Google is always useful at times when I need to find techniques or code for something Im not familiar with, although stackoverflow is often the site I end up on.
 
Last edited by tech3475,
  • Like
Reactions: gnmmarechal
D

Deleted User

Guest
OP
You need to implement a way to delete the files to delete the directory, not familiar with lua but there seems to be a way to implement it by using something called ifs.

http://stackoverflow.com/questions/37835565/lua-delete-non-empty-directory

Edit:

Btw, Im not Joking, but Google is always useful at times when I need to find techniques or code for something Im not familiar with, although stackoverflow is often the site I end up on.
Thank you very much. I did indeed get it. Now I just need to solve one more bug that this generated lol once the directory gets deleted my system "crashes" and is forced to restart lol

This is how I fixed it if anyone is interested

I added this right before the main loop before everything else runs and then called the function before removing my directory. While its a bit slow(directory is 30mb+) it works...sorta just need to find why my system crashes lol
Code:
function deleteDirContents(dir)
    local cont = System.listDirectory(dir)
    for _, v in pairs(cont) do
        if v.directory then
            deleteDirContents(dir.."/"..v.name)
            System.deleteDirectory(dir.."/"..v.name)
        else
            System.deleteFile(dir.."/"..v.name)
        end
    end
end


EDIT: RIP guess I added the function wrong..that broke errything lol the system seems to be crashing when it goes to extract the zip file now..
 
Last edited by ,
D

Deleted User

Guest
OP
Hmm you could modify lpp-3ds to use the ctrulib function that deletes directories recursively (non empty)
I'd honestly have no idea at where to start to accomplish that lol

Right now Im trying to figure out why the app crashing during zip extraction(either from update or just install) since it onlymhappened when I added this function.

So even if A is pressed which just downloads and extracts the zip. That even crashes now during extraction when it worked previously

Code:
            pad = Controls.read()
                if Controls.check(pad,KEY_X) then




    -- Deletes the old modpack
    deleteDirContents("/saltysd")
    System.deleteDirectory("/saltysd")

function deleteDirContents(dir)
    local cont = System.listDirectory(dir)
    for _, v in pairs(cont) do
        if v.directory then
            deleteDirContents(dir.."/"..v.name)
            System.deleteDirectory(dir.."/"..v.name)
        else
            System.deleteFile(dir.."/"..v.name)
        end
    end
end
 

gnmmarechal

Well-Known Member
Member
GBAtemp Patron
Joined
Jul 13, 2014
Messages
6,038
Trophies
2
Age
25
Location
https://gs2012.xyz
Website
gs2012.xyz
XP
5,986
Country
Portugal
I'd honestly have no idea at where to start to accomplish that lol

Right now Im trying to figure out why the app crashing during zip extraction(either from update or just install) since it onlymhappened when I added this function.

So even if A is pressed which just downloads and extracts the zip. That even crashes now during extraction when it worked previously

Code:
            pad = Controls.read()
                if Controls.check(pad,KEY_X) then




    -- Deletes the old modpack
    deleteDirContents("/saltysd")
    System.deleteDirectory("/saltysd")

function deleteDirContents(dir)
    local cont = System.listDirectory(dir)
    for _, v in pairs(cont) do
        if v.directory then
            deleteDirContents(dir.."/"..v.name)
            System.deleteDirectory(dir.."/"..v.name)
        else
            System.deleteFile(dir.."/"..v.name)
        end
    end
end
I have had trouble with some zips when making my updaters. You could check them, I guess, the code is not awesome and I will most likely eventually rewrite it. but, it works.
 
  • Like
Reactions: Deleted User
D

Deleted User

Guest
OP
I have had trouble with some zips when making my updaters. You could check them, I guess, the code is not awesome and I will most likely eventually rewrite it. but, it works.
Thank you very much. Your examples helped a ton. Now I just need to figure out a new bug. My LPP app now wants to crash whenever it goes to extract the downloaded zip file.(when it worked perfectly before) So I attempted to remove the deletedir function and revert my changes.

You wouldn't happen to know what would cause this would you? This is my current code

For clarification. The zip does still download. So this is only happening during extraction

Code:
-- Colours
local white = Color.new(255,255,255)
local yellow = Color.new(255,205,66)
local red = Color.new(255,0,0)
local green = Color.new(55,255,0)

-- Functions

while true do
    -- Writes menu options on screen
    Screen.waitVblankStart()
    Screen.refresh()
    Screen.debugPrint(5,10, "Welcome to the Zenith Installer/updater!", red, TOP_SCREEN)
    Screen.debugPrint(60,90, "Press A to install the modpack", white, TOP_SCREEN)
    Screen.debugPrint(60,110, "Press X to update the modpack", white, TOP_SCREEN)
    Screen.debugPrint(60,130, "Press START to exit", white, TOP_SCREEN)
    Screen.flip()

    -- Check controls
    local pad = Controls.read()

    -- Installs modpack
    if Controls.check(pad, KEY_A) then
        -- Downloads modpack
        Network.downloadFile("http://placeholder.com","/placeholder.zip")
        
        -- Extracts modpack
        System.extractZIP("/placeholder.zip", System.currentDirectory() .. "/")
        
        -- Deletes the temp file
        System.deleteFile("/placeholder.zip")

        --displays status on bottom screen
        Screen.waitVblankStart()
        Screen.debugPrint(60,90, "Modpack installed!", green, BOTTOM_SCREEN)
        Screen.debugPrint(60,110, "You can now exit the app", green, BOTTOM_SCREEN)
    -- Return update the modpack
    elseif Controls.check(pad, KEY_X) then
        -- Deletes the old modpack
        System.deleteDirectory(("/saltysd"))

        -- Downloads update
        Network.downloadFile("http://placeholder.com","/placeholder.zip")
        
        -- Extracts update
        System.extractZIP("/placeholder.zip",System.currentDirectory().."/")
        
        -- Deletes the temp file
        System.deleteFile("/placeholder.zip")

        --displays status on bottom screen
        Screen.waitVblankStart()
        Screen.debugPrint(60,90, "Modpack succesfully updated!", green, BOTTOM_SCREEN)
        Screen.debugPrint(60,110, "You can now exit the app", green, BOTTOM_SCREEN)
    -- Return HBL
    elseif Controls.check(pad, KEY_START) then
        Screen.waitVblankStart()
        Screen.flip()
        System.exit()
    end
end
 

gnmmarechal

Well-Known Member
Member
GBAtemp Patron
Joined
Jul 13, 2014
Messages
6,038
Trophies
2
Age
25
Location
https://gs2012.xyz
Website
gs2012.xyz
XP
5,986
Country
Portugal
Thank you very much. Your examples helped a ton. Now I just need to figure out a new bug. My LPP app now wants to crash whenever it goes to extract the downloaded zip file.(when it worked perfectly before) So I attempted to remove the deletedir function and revert my changes.

You wouldn't happen to know what would cause this would you? This is my current code

For clarification. The zip does still download. So this is only happening during extraction

Code:
-- Colours
local white = Color.new(255,255,255)
local yellow = Color.new(255,205,66)
local red = Color.new(255,0,0)
local green = Color.new(55,255,0)

-- Functions

while true do
    -- Writes menu options on screen
    Screen.waitVblankStart()
    Screen.refresh()
    Screen.debugPrint(5,10, "Welcome to the Zenith Installer/updater!", red, TOP_SCREEN)
    Screen.debugPrint(60,90, "Press A to install the modpack", white, TOP_SCREEN)
    Screen.debugPrint(60,110, "Press X to update the modpack", white, TOP_SCREEN)
    Screen.debugPrint(60,130, "Press START to exit", white, TOP_SCREEN)
    Screen.flip()

    -- Check controls
    local pad = Controls.read()

    -- Installs modpack
    if Controls.check(pad, KEY_A) then
        -- Downloads modpack
        Network.downloadFile("http://placeholder.com","/placeholder.zip")
       
        -- Extracts modpack
        System.extractZIP("/placeholder.zip", System.currentDirectory() .. "/")
       
        -- Deletes the temp file
        System.deleteFile("/placeholder.zip")

        --displays status on bottom screen
        Screen.waitVblankStart()
        Screen.debugPrint(60,90, "Modpack installed!", green, BOTTOM_SCREEN)
        Screen.debugPrint(60,110, "You can now exit the app", green, BOTTOM_SCREEN)
    -- Return update the modpack
    elseif Controls.check(pad, KEY_X) then
        -- Deletes the old modpack
        System.deleteDirectory(("/saltysd"))

        -- Downloads update
        Network.downloadFile("http://placeholder.com","/placeholder.zip")
       
        -- Extracts update
        System.extractZIP("/placeholder.zip",System.currentDirectory().."/")
       
        -- Deletes the temp file
        System.deleteFile("/placeholder.zip")

        --displays status on bottom screen
        Screen.waitVblankStart()
        Screen.debugPrint(60,90, "Modpack succesfully updated!", green, BOTTOM_SCREEN)
        Screen.debugPrint(60,110, "You can now exit the app", green, BOTTOM_SCREEN)
    -- Return HBL
    elseif Controls.check(pad, KEY_START) then
        Screen.waitVblankStart()
        Screen.flip()
        System.exit()
    end
end
hmm... maybe test unzipping it from a local file first, to see if the issue is in the downloaded file.
 

gnmmarechal

Well-Known Member
Member
GBAtemp Patron
Joined
Jul 13, 2014
Messages
6,038
Trophies
2
Age
25
Location
https://gs2012.xyz
Website
gs2012.xyz
XP
5,986
Country
Portugal
I see thanks for clarifying. I had it skip the download step just now to go from the file locally and same issue.
try using a different zip such as the ones for Luma3DS and Corbenik and see if the error persists. Some zips don't work for some reason.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • Maximumbeans @ Maximumbeans:
    I think that's why I focus on just enjoying single player experiences that aren't too competitive
  • Maximumbeans @ Maximumbeans:
    How are you doing?
  • SylverReZ @ SylverReZ:
    There's also this thing where I'm hyperfocused at night and cannot get to sleep.
  • SylverReZ @ SylverReZ:
    @Maximumbeans, I'm doing alright, thanks.
    +1
  • Maximumbeans @ Maximumbeans:
    That must be rough. Productive I'm sure but hard to balance with daily life
    +1
  • SylverReZ @ SylverReZ:
    @Maximumbeans, Indeed. I've been working on getting this Infecutus chip to work on my PS2. But after soldering, I realised that a plastic piece was missing from the power ribbon cable to the power and eject buttons.
  • SylverReZ @ SylverReZ:
    Now I could go with soldering the contacts from the cable to the connector on the mobo, but doesn't sound like a good permanent solution.
  • Maximumbeans @ Maximumbeans:
    Man, that's beyond my brain :rofl: I'm no good with hardware for now. I'd like to get into hardmods in future though
  • SylverReZ @ SylverReZ:
    @Maximumbeans, Maybe start practice soldering. Get a cheap-ass soldering iron and follow some good YouTube tutorials.
    +1
  • SylverReZ @ SylverReZ:
    Least my experience has gotten better than over a decade ago. My iron would constantly bump into components and break them.
  • Maximumbeans @ Maximumbeans:
    Sounds good. I actually did soldering but like 16 years ago for school so uuuuh probably rusty haha
  • SylverReZ @ SylverReZ:
    @Maximumbeans, Same here. I did soldering at school from a teacher who I honestly liked since he had plenty of good electronics experience.
    +1
  • Maximumbeans @ Maximumbeans:
    I wish I could play chess well
    +1
  • Maximumbeans @ Maximumbeans:
    Useless but a true art
    +1
  • SylverReZ @ SylverReZ:
    @Maximumbeans, I had a friend who had a glass chess set for their birthday.
  • SylverReZ @ SylverReZ:
    It was like all clear and fancy. Tbf I'm not too experienced with chess, but would like to learn someday.
  • Maximumbeans @ Maximumbeans:
    That sounds really cool
  • Maximumbeans @ Maximumbeans:
    I know the basics but no strategy at all :rofl:
  • Veho @ Veho:
    Watch chess streamers on Twitch and you'll pick up a thing or two.
  • Veho @ Veho:
    Not to mention there's an infinite number of chess games for every possible platform.
  • DinohScene @ DinohScene:
    just play it, get beaten a few times and start dominating
  • K3Nv2 @ K3Nv2:
    Nude chess is best
  • DinohScene @ DinohScene:
    strip checkers > nude chess
  • K3Nv2 @ K3Nv2:
    Nude checkers get jumped
    K3Nv2 @ K3Nv2: Nude checkers get jumped