Copying a file from a local directory to the LOVE save directory

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Madrayken
Party member
Posts: 126
Joined: Sun May 04, 2014 4:21 pm
Location: Oakland CA
Contact:

Copying a file from a local directory to the LOVE save directory

Post by Madrayken »

Hi folks,

Moonring does a lot of copying of directories to enable the save-game functionality, and to create backups.
My levels are held as .pngs, the level data is held as .csvs and the player data is held as a serialised .sav file.
I literally backup a directory from my game's 'level' directory (held as part of the .love file) to a location in the LOVE save directory.
As far as I can tell, Love2D lacks any form of file copy, so I have to load in every piece of data, decode it, recode it and save it again! This seems more than a bit ridiculous. What am I missing here?

Any help much appreciated... both by me and a ton of new players!

- Dene
Discord: https://discord.gg/tYfHgXc
Bandcamp: https://madrayken.bandcamp.com/
Twitter: @Fluttermind
MrFariator
Party member
Posts: 559
Joined: Wed Oct 05, 2016 11:53 am

Re: Copying a file from a local directory to the LOVE save directory

Post by MrFariator »

You could potentially use os.execute, and run some copy commands to transfer those files over. These commands may be platform specifc, like using robocopy on windows. This method may flash a command prompt on users' screens, but if you mean to do the file transfers as a one-time thing (eg. when first launching the game), it might not be so bad.

There's probably better approaches with FFI, but above is what I've used personally when I've needed to copy files back and forth in bulk.

Out of curiosity though, what's the purpose behind copying the level data over to the save file folder?
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Copying a file from a local directory to the LOVE save directory

Post by slime »

Something like this will copy a file without doing any decoding or encoding, only reading and writing:

Code: Select all

local data = love.filesystem.read(readpath)
love.filesystem.write(writepath, data)
It will load the whole file into memory at once, but you can avoid that if you want by using a File object and copying a chunk at a time.

However, love.filesystem is designed to transparently handle situations where you have initial data shipped with the game that might be replaced by saved data later. If something exists in the same relative path in the game's source directory (.love) as it does in the game's save directory, then by default love will prioritize reading from the save directory's version of the file instead of the source directory - which means (for example) you can have a default settings file shipped with the game, and save a modified version to the same relative path when a user modifies their settings and everything will work without needing to manage a separate relative path for the default settings versus modified ones. That behaviour can be changed in love.conf or love.filesystem.setIdentity.

That being said, I wouldn't think you'd need to do any copying at all of levels (those png files), but I don't have a full understanding of what your game does with levels.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests