Skip to content

Filesystem Rework #953

Description

@bjornbytes

Goals

  • Make it easier to read/write absolute paths, since this is a common request.
  • Make the virtual filesystem easier to understand. It seems to be causing more pain/confusion than the benefits you get from layering archives. This intends to replace the virtual filesystem with a combination of Archive objects (for reading data from ZIP files) and @-aliases that can serve as a way to read data from common folder paths. This is a more explicit system that makes it clear which paths are being accessed. You can still recreate a virtual filesystem in Lua using Archive objects.
  • Relative require. It comes up frequently and is painful.
  • Ability to create ZIP archives, so we can add a lovr --package . command.
  • Miscellaneous things that have come up before: symlinks, drag-and-drop events.

Examples

-- Relative paths read from your source
lovr.filesystem.read('main.lua)
lovr.graphics.newTexture('texture.png')

-- @save folder
lovr.filesystem.write('gamestate.json', data) -- or @save/gamestate.json
lovr.filesystem.read('@save/gamestate.json')

-- Archive object
local archive = lovr.filesystem.newArchive('level.zip')
archive:getDirectoryItems('/')
archive:read('manifest.ini')

-- Relative require
local utils = require('./utils') -- TBD, maybe require('@local.utils'), '@self/utils', etc.

function lovr.filedropped(path)
  --
end

Notes

Absolute Paths

  • Reads with relative paths are relative to the source directory/archive.
  • Writes with relative paths are relative to the save directory.
    • Note: this breaks the symmetry where you can do lf.write('file.txt', 'asdf') followed by lf.read('file.txt') to get the contents back. I think this is okay.
  • Reads/writes support absolute paths.

Aliases

  • Remove mounted archives.
  • Add @-aliases for common paths. Paths can start with these, which get expanded to their full path, for convenience.
    • @source - lovr.filesystem.getSourceDirectory()
    • @save - lovr.filesystem.getSaveDirectory()
    • @executable - lovr.filesystem.getExecutablePath() with filename chopped off (just the directory)
  • Relative Require
    • Either allow ./ and ../ in require paths (though it doesn't work when using dotted module names) or make require expand aliases and add an alias that resolves to the directory containing the current file (@self? @parent? @dir? @local?)

Archive

  • Add Archive object that can be used to access contents of ZIP files. It's readonly, and supports methods like :read, :getDirectoryItems, :getSize, :getLastModified.
  • Add lovr.filesystem.compress({files}, destination) that creates a ZIP archive? Should be able to support both file paths and blob entries (maybe also strings). Would allow LÖVR to package projects.

Symlinks

  • lovr.filesystem.are/setSymlinksEnabled
  • lovr.filesystem.isSymlink
  • Skip or return error when accessing symlink when they're not enabled
  • Detect symlink loops

File Drop Events

  • lovr.filedropped(path) event
    • GLFW: glfwSetDropCallback
    • XCB: XDND
    • win32: WM_DROPFILES

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions