Save deletion leaving mod data behind

Discuss coding questions, pull requests, and implementation details.
Post Reply
User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Save deletion leaving mod data behind

Post by Ralzar »

I ran into a problem while testing a mod which I assume is caused by this:

When you delete or write over a save in the DFU save/load menus, this only deletes/overwrites the standard DFU save data. The folder is left with whatever random mod savedata has been saved there. If you have a habit of cleaning up your saves to avoid too much bloat, this starts building up over time. So the folder SAVE10, for example, might have a bunch of mod data txt files from earlier characters and earlier DFU builds. This easily causes problems for mods in the future unless they make sure to code in handlers for this unexpected problem. But also, it causes all the SAVE** folders to remain with junk data even if you clean up the saves in DFU. You have to manually go in and delete the folders to be sure the save data is actually cleaned up.

I can not see any benefit to leaving the folder and a random assortment of mod data behind when the slot is implied by DFU to be ready for a fresh save? Would it not be a better option to just wipe the folder, or at least the folder contents, before writing new save data to it?

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Save deletion leaving mod data behind

Post by Ralzar »

As an example, I have been using SAVE0 as a blank save with no mods as a starting point for testing. The character and save was made in October by starting DFU with no mods, starting a new game and saving in privateers hold.

When I open the folder I see 6 mod files. One of them from february 2021.
Attachments
SAVE0.zip
(152.77 KiB) Downloaded 72 times

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Save deletion leaving mod data behind

Post by Interkarma »

I strongly believe we have an unspoken contract with user that DFU will delete its own save data and nothing else. Anything else in a save folder not put there by DFU belongs to the user.

If some files from mods are left behind, user can clean up manually at their discretion. This is better than naively deleting unknown files, because we don't know what else the user could have put in there.

We could add an event so mod is able to clean its own files, but that won't help if user has already disabled mod, or mod doesn't bother cleaning own save files.

Another option is to simply rename the folder after deleting core files (e.g. to SAVE0.deleted). This will preserve the contract of not deleting unknown files, while still freeing the SAVE index. Of course, will need to increment this because if user repeats action then we have SAVE0.deleted, SAVE0.deleted1, etc.

I'm not sure there's a totally satisfying solution, but when deleting files I'm going to choose safety over completeness every time. :)

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Save deletion leaving mod data behind

Post by Ralzar »

Yeah, if you wish to avoid deleting unknown files the real problem is that the folders get reused for new saves without being cleaned. Leading to junk data being mixed into the new save data.

An alternative solution would be to never create a new save using an existing folder. So if you delete SAVE10 in DFU, but some mod data is left, and you create a new save in DFU it sees SAVE10 folder already exists and creates SAVE11 instead.

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Save deletion leaving mod data behind

Post by Hazelnut »

I think I would prefer not to change DFU behaviour and simply provide an event for mods to delete their own data, though if mods are disabled/removed they wont actually do that and players will need to manually do it but it would be an improvement. Using a new folder each time means old folders will need manually cleaning which is not ideal.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

Post Reply