Skip to content

ROM Deletion Improvement#2399

Merged
JoeMatt merged 2 commits intoProvenance-Emu:developfrom
pabloarista:feature/rom-delete-improvement
Mar 1, 2025
Merged

ROM Deletion Improvement#2399
JoeMatt merged 2 commits intoProvenance-Emu:developfrom
pabloarista:feature/rom-delete-improvement

Conversation

@pabloarista
Copy link
Contributor

@pabloarista pabloarista commented Mar 1, 2025

User description

What does this PR do

  1. Adds confirmation when deleting a ROM
  2. Clears game cache when deleting a ROM which fixes the issue if the user re-adds the same ROM without restarting the app
  3. Deletes all related files that are sometimes not associated to PVGame
  4. Deletes json file when deleting save state that was previously being kept
  5. Adds a fix in the Atari 800 core when using an mfi controller that is lacking the L3/R3 buttons
  6. Adds localization to PVUI
  7. Adds extension for easily accessing localization strings
  8. Adds to alert functions to add different kinds of alerts

Where should the reviewer start

  1. Easiest place to start is the Atari800 changes that just adds the nil checks

How should this be manually tested

  1. Add a multi-disc ROM and delete it. Confirmation SHOULD appear. Confirm that all files are deleted after confirming. Re-add the same game without restarting the app. it SHOULD be added again.
  2. Add a save state and delete it. Confirm that all save files for that save state are deleted
  3. Play an Atari game on an MFI controller that is lacking L3/R3 buttons. It should NOT crash

Any background context you want to provide

  1. Found these as I was working on another PR. Just adding them as a separate PR to NOT bloat the next PR

What are the relevant tickets

N/A

Screenshots (important for UI changes)

CEA9D930-57BC-488D-AEF1-5269D052D384_1_101_o

Questions

Do you want any tests for any of these changes? I don't think any of these would require any specific tests, but I can if required.


PR Type

Enhancement, Bug fix, Tests


Description

  • Added confirmation dialog for deleting ROMs with localization support.

  • Enhanced ROM deletion to remove related files and JSON save states.

  • Fixed Atari 800 core crash for MFI controllers missing L3/R3 buttons.

  • Introduced localization extensions and new alert functions for UI.


Changes walkthrough 📝

Relevant files
Enhancement
RomDatabase.swift
Enhanced ROM deletion logic and cache handling                     

PVLibrary/Sources/PVLibrary/Database/Realm Database/RomDatabase.swift

  • Added cache reloading after ROM deletion.
  • Enhanced deletion logic for related files and JSON save states.
  • Introduced logic to delete files with similar titles for multi-disc
    ROMs.
  • +74/-10 
    PVRootViewController+DelegateMethods.swift
    Added confirmation dialog for ROM deletion                             

    PVUI/Sources/PVSwiftUI/RootView/PVRootViewController+DelegateMethods.swift

  • Added confirmation dialog for ROM deletion.
  • Integrated localized messages for delete confirmation.
  • +8/-4     
    UIViewController+Alerts.swift
    Added localized alert functions for UI                                     

    PVUI/Sources/PVUIBase/UIViewController+Alerts.swift

  • Added new alert functions for delete confirmation.
  • Enhanced localization support for alert messages.
  • +51/-8   
    Localizable.strings
    Added localization strings for alerts                                       

    PVUI/Sources/PVSwiftUI/Resources/en.lproj/Localizable.strings

  • Added localization strings for delete confirmation and alerts.
  • Included keys for "Delete", "Cancel", "Error", and "Warning".
  • +7/-0     
    Bug fix
    PVAtari800Bridge.m
    Fixed MFI controller crash in Atari 800 core                         

    Cores/Atari800/Sources/PVAtari800Bridge/PVAtari800Bridge.m

  • Fixed crash for MFI controllers missing L3/R3 buttons.
  • Added nil checks for thumbstick button access.
  • +2/-2     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • …d confirmation of deleting roms; added extensions to simplify localization; added fix for deleting multi disc/track files that don't always get deleted
    @qodo-code-review
    Copy link

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    The deleteFilesWithSimilarTitle function silently catches and logs file deletion errors without propagating them up. This could mask important deletion failures.

    do {
        try fileManager.removeItem(at: currentChildUrl)
    } catch {
        ELOG("error deleting file: \(currentChildUrl)")
    }
    Memory Leak

    The alert completion handlers are captured strongly which could potentially cause retain cycles if the completion blocks capture self.

    alert.addAction(UIAlertAction(title: actualDefaultActionTitle, style: defaultActionStyle) { _ in
        completion?()
    })
    if let actualSecondaryActionTitle = secondaryActionTitle {
        alert.addAction(UIAlertAction(title: actualSecondaryActionTitle, style: secondaryActionStyle) { _ in
            secondaryCompletion?()
        })
    }

    @qodo-code-review
    Copy link

    qodo-code-review bot commented Mar 1, 2025

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Security
    Validate directory path before deletion

    Add a guard check for the directory path validity before attempting to delete
    similar title files to prevent potential crashes with malformed paths.

    PVLibrary/Sources/PVLibrary/Database/Realm Database/RomDatabase.swift [871-877]

     func deleteFilesWithSimilarTitle(_ gameFileUrl: URL) {
         let fileManager: FileManager = .default
         let parentDirectory = gameFileUrl.deletingLastPathComponent()
    -    guard fileManager.fileExists(atPath: parentDirectory.pathDecoded)
    +    guard !parentDirectory.pathDecoded.isEmpty,
    +          fileManager.fileExists(atPath: parentDirectory.pathDecoded)
         else {
    +        ELOG("Invalid parent directory path")
             return
         }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion adds crucial path validation before file deletion operations, which helps prevent potential security issues and crashes from malformed paths. This is important for system stability and security.

    Medium
    Possible issue
    Add error handling for cache reload

    Add error handling for the cache reload operation in the defer block to prevent
    potential crashes if the reload fails.

    PVLibrary/Sources/PVLibrary/Database/Realm Database/RomDatabase.swift [765-767]

     defer {//reload the cache, so if this ROM is added again, it can be added
    -    RomDatabase.reloadGamesCache()
    +    do {
    +        try RomDatabase.reloadGamesCache()
    +    } catch {
    +        ELOG("Failed to reload games cache: \(error.localizedDescription)")
    +    }
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion adds important error handling for the cache reload operation, which could prevent silent failures and help with debugging. This improves the robustness of the code.

    Medium
    • Update

    @JoeMatt JoeMatt merged commit 62370fb into Provenance-Emu:develop Mar 1, 2025
    2 of 7 checks passed
    @pabloarista pabloarista deleted the feature/rom-delete-improvement branch March 1, 2025 21:13
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants