LPP Not Deleting Directory

Discussion in '3DS - Homebrew Development and Emulators' started by Sasori, Apr 24, 2017.

  1. Sasori
    OP

    Sasori GBAtemp Maniac

    Member
    1,377
    800
    Jan 28, 2015
    United States
    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")
     
  2. The Real Jdbye

    The Real Jdbye Always Remember 30/07/08

    Member
    GBAtemp Patron
    The Real Jdbye is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    12,087
    5,165
    Mar 17, 2010
    Norway
    Alola
    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.
     
  3. Sasori
    OP

    Sasori GBAtemp Maniac

    Member
    1,377
    800
    Jan 28, 2015
    United States
    The directory is not empty. How would one delete a directory in lua?
     
  4. tech3475

    tech3475 GBAtemp Advanced Fan

    Member
    656
    287
    Jun 12, 2009
    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, Apr 24, 2017
    gnmmarechal likes this.
  5. Sasori
    OP

    Sasori GBAtemp Maniac

    Member
    1,377
    800
    Jan 28, 2015
    United States
    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 Sasori, Apr 24, 2017
  6. erman1337

    erman1337 GBAtemp Maniac

    Member
    1,211
    931
    Sep 27, 2015
    Belgium
    Brussels
    Hmm you could modify lpp-3ds to use the ctrulib function that deletes directories recursively (non empty)
     
  7. Sasori
    OP

    Sasori GBAtemp Maniac

    Member
    1,377
    800
    Jan 28, 2015
    United States
    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
     
  8. gnmmarechal

    gnmmarechal Kirigiri > Naoto

    Member
    GBAtemp Patron
    gnmmarechal is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    4,664
    2,821
    Jul 13, 2014
    Portugal
    https://gs2012.xyz
    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.
     
    Sasori likes this.
  9. Sasori
    OP

    Sasori GBAtemp Maniac

    Member
    1,377
    800
    Jan 28, 2015
    United States
    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
     
  10. gnmmarechal

    gnmmarechal Kirigiri > Naoto

    Member
    GBAtemp Patron
    gnmmarechal is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    4,664
    2,821
    Jul 13, 2014
    Portugal
    https://gs2012.xyz
    hmm... maybe test unzipping it from a local file first, to see if the issue is in the downloaded file.
     
  11. Sasori
    OP

    Sasori GBAtemp Maniac

    Member
    1,377
    800
    Jan 28, 2015
    United States
  12. gnmmarechal

    gnmmarechal Kirigiri > Naoto

    Member
    GBAtemp Patron
    gnmmarechal is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    4,664
    2,821
    Jul 13, 2014
    Portugal
    https://gs2012.xyz
  13. Sasori
    OP

    Sasori GBAtemp Maniac

    Member
    1,377
    800
    Jan 28, 2015
    United States
    I see thanks for clarifying. I had it skip the download step just now to go from the file locally and same issue.
     
  14. gnmmarechal

    gnmmarechal Kirigiri > Naoto

    Member
    GBAtemp Patron
    gnmmarechal is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    4,664
    2,821
    Jul 13, 2014
    Portugal
    https://gs2012.xyz
    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.