Skip to content
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.

GNOME, filesystem size, clipboard and VRAM #60

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
9 changes: 9 additions & 0 deletions OCEmu.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Desktop Entry]
Exec=/usr/bin/lua $OCEMU_PATH/src/boot.lua
GenericName=OCEmu
Icon=$OCEMU_PATH/icon.png
Name=OCEmu
Path=$OCEMU_PATH/src
StartupNotify=true
Terminal=false
Type=Application
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 36 additions & 5 deletions src/component/filesystem.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
local address, _, directory, label, readonly, speed = ...
local address, _, directory, label, readonly, speed, size = ...
size = size or math.huge
local usedSize = 0
compCheckArg(1,directory,"string","nil")
compCheckArg(2,label,"string","nil")
compCheckArg(3,readonly,"boolean")
Expand Down Expand Up @@ -49,6 +51,32 @@ local writeCosts = {1/1, 1/2, 1/3, 1/4, 1/5, 1/6}
local mai = {}
local obj = {}

local function getAllFiles(dirPath, tab)
tab = tab or {}
local items = elsa.filesystem.getDirectoryItems(directory .. dirPath)
for k, v in pairs(items) do
if elsa.filesystem.isDirectory(directory .. dirPath .. "/" .. v) then
getAllFiles(dirPath .. "/" .. v, tab)
else
table.insert(tab, directory .. dirPath .. "/" .. v)
end
end
return tab
end

local function calcUsedSpace()
local files = getAllFiles("/")
usedSize = 0
for k, v in pairs(files) do
local path = v
usedSize = usedSize + 512 -- default OC emulation of "file info"
usedSize = usedSize + elsa.filesystem.getSize(v)
end
return usedSize
end

calcUsedSpace() -- get used space

mai.read = {direct = true, limit = 15, doc = "function(handle:number, count:number):string or nil -- Reads up to the specified amount of data from an open file descriptor with the specified handle. Returns nil when EOF is reached."}
function obj.read(handle, count)
--TODO
Expand Down Expand Up @@ -79,9 +107,8 @@ end

mai.spaceUsed = {direct = true, doc = "function():number -- The currently used capacity of the file system, in bytes."}
function obj.spaceUsed()
--STUB
cprint("filesystem.spaceUsed")
return 0
return usedSize
end

mai.rename = {doc = "function(from:string, to:string):boolean -- Renames/moves an object from the first specified absolute path in the file system to the second."}
Expand Down Expand Up @@ -131,6 +158,11 @@ function obj.write(handle, value)
if handles[handle] == nil or (handles[handle][2] ~= "w" and handles[handle][2] ~= "a") then
return nil, "bad file descriptor"
end
local len = value:len()
if usedSize + len > size then
return nil, "not enough space" -- todo use OC error message
end
usedSize = usedSize + len -- if sucedded, add to used space.
handles[handle][1]:write(value)
return true
end
Expand Down Expand Up @@ -176,9 +208,8 @@ end

mai.spaceTotal = {direct = true, doc = "function():number -- The overall capacity of the file system, in bytes."}
function obj.spaceTotal()
--STUB
cprint("filesystem.spaceTotal")
return math.huge
return size
end

mai.getLabel = {direct = true, doc = "function():string -- Get the current label of the file system."}
Expand Down
Loading