Skip to content

Commit

Permalink
fix: Support dFILE
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsci committed Sep 24, 2024
1 parent d22c5e4 commit 1e3d24a
Show file tree
Hide file tree
Showing 12 changed files with 452 additions and 73 deletions.
10 changes: 10 additions & 0 deletions OpoLua/Model/FileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ protocol FileSystem {

func prepare() throws
func set(sharedDrive: String, url: URL, readonly: Bool)
func getSharedDrives() -> [String]
func hostUrl(for path: String) -> (URL, Bool)? // The bool is whether this is a readonly location
func guestPath(for url: URL) -> String?

Expand All @@ -32,6 +33,13 @@ protocol FileSystem {
extension FileSystem {

func perform(_ operation: Fs.Operation) -> Fs.Result {
if case .disks = operation.type {
// disks doesn't have a path associated so handle that here and return before the path check
var result = ["C"]
result.append(contentsOf: getSharedDrives())
return .strings(result)
}

guard let (nativePath, readonly) = hostUrl(for: operation.path) else {
return .err(.notReady)
}
Expand All @@ -50,6 +58,8 @@ extension FileSystem {
} else {
return .err(.notFound)
}
case .disks:
fatalError("Shouldn't get here!")
case .delete:
print("DELETE '\(operation.path)'")
// Note, should not support wildcards or deleting directories
Expand Down
4 changes: 4 additions & 0 deletions OpoLua/Model/ObjectFileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class ObjectFileSystem: FileSystem {
func prepare() throws {
}

func getSharedDrives() -> [String] {
return Array(sharedDrives.keys).sorted()
}

func set(sharedDrive: String, url: URL, readonly: Bool) {
sharedDrives[sharedDrive] = url
}
Expand Down
4 changes: 4 additions & 0 deletions OpoLua/Model/SystemFileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class SystemFileSystem: FileSystem {
try fileManager.createDirectory(at: rootUrl.appendingPathComponent("c"), withIntermediateDirectories: true)
}

func getSharedDrives() -> [String] {
return Array(sharedDrives.keys).sorted()
}

func set(sharedDrive: String, url: URL, readonly: Bool) {
sharedDrives[sharedDrive] = (url, readonly)
}
Expand Down
Binary file modified examples/Tests/dialog.opo
Binary file not shown.
157 changes: 101 additions & 56 deletions examples/Tests/dialog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
DECLARE EXTERNAL
INCLUDE "const.oph"

EXTERNAL loop%:

PROC main:
GLOBAL choice%
LOCAL cont%
Expand All @@ -7,57 +12,6 @@ PROC main:
ENDWH
ENDP

PROC loop%:
LOCAL dlg%
dINIT "Dialog test", 0
dTEXT "", "Pick a dialog type to test"
REM dTEXT "", "", $800
dCHOICE choice%, "Choose", "long,float,edit,checkbox,text,..."
dCHOICE choice%, "", "password,empty,date,time,..."
dCHOICE choice%, "", "buttons,bareButtons,cancelDlg,..."
dCHOICE choice%, "", "editmulti,file"
dBUTTONS "OK", 13, "Cancel", -(512 + %q)
choice% = 2
dlg% = DIALOG
PRINT "Dialog returned ", dlg%
PRINT "Choice was ", choice%
IF dlg% = 0
PRINT "(dialog cancelled)"
GET
RETURN 0
ELSEIF choice% = 1
longDlg:
ELSEIF choice% = 2
floatDlg:
ELSEIF choice% = 3
editDlg:
ELSEIF choice% = 4
checkDlg:
ELSEIF choice% = 5
textDlg:
ELSEIF choice% = 6
xDlg:
ELSEIF choice% = 7
emptyDlg:
ELSEIF choice% = 8
dateDlg:
ELSEIF choice% = 9
timeDlg:
ELSEIF choice% = 10
buttonDlg:
ELSEIF choice% = 11
bareButtonDlg:
ELSEIF choice% = 12
cancelDlg:
ELSEIF choice% = 13
editMultiDlg:
ELSEIF choice% = 14
fileDlg:
ENDIF

RETURN 1
ENDP

PROC buttonDlg:
LOCAL result%
dINIT "Buttons"
Expand Down Expand Up @@ -213,11 +167,102 @@ PROC editMultiDlg:
ENDP

PROC fileDlg:
LOCAL f$(255)
dINIT "File dialog"
dFILE f$, "File", 0
DIALOG
PRINT "Dialog returned", f$
LOCAL f$(255), type%, showz%, onlydir%, allowEmpty%
LOCAL result%, flags%
result% = 1
allowEmpty% = 1
type% = 1

WHILE result%
flags% = 0
IF allowEmpty%
flags% = flags% OR KDFileAllowNullStrings%
ENDIF
IF type% = 1
REM open file
ELSEIF type% = 2
REM save file (+ query)
flags% = flags% OR KDFileEditBox% OR KDFileEditorQueryExisting%
ELSEIF type% = 3
REM save file (-query)
flags% = flags% OR KDFileEditBox%
ELSEIF type% = 4
REM New file
flags% = flags% OR KDFileEditBox% OR KDFileEditorDisallowExisting%
ENDIF
IF showz%
flags% = flags% OR KDFileSelectorWithRom%
ENDIF
IF onlydir%
REM these two flags appear too broken for me to figure out what they should do.
REM flags% = flags% OR KDFileAllowFolders% OR KDFileFoldersOnly%
ENDIF

dINIT "File dialog", KDlgButRight% OR KDlgDensePack%
dFILE f$, "File,Dir,Drive", flags%
REM dCHECKBOX edit%, "Allow text entry"
dCHOICE type%, "Type", "Open file,Save file (query),Save file (overwrite),New file"
dCHECKBOX showz%, "Show Z:"
REM dCHECKBOX onlydir%, "Only directories"
dCHECKBOX allowEmpty%, "Allow empty"
dBUTTONS "OK", KDButtonEnter% + KDButtonNoLabel%, "Cancel", -(KDButtonEsc% + KDButtonNoLabel%)
result% = DIALOG

CLS
PRINT "Result is", result%, f$
ENDWH

GET
ENDP

PROC loop%:
LOCAL dlg%
EXTERNAL choice%
dINIT "Dialog test", 0
dTEXT "", "Pick a dialog type to test"
REM dTEXT "", "", $800
dCHOICE choice%, "Choose", "long,float,edit,checkbox,text,..."
dCHOICE choice%, "", "password,empty,date,time,..."
dCHOICE choice%, "", "buttons,bareButtons,cancelDlg,..."
dCHOICE choice%, "", "editmulti,file"
dBUTTONS "OK", 13, "Cancel", -(512 + %q)
choice% = 2
dlg% = DIALOG
PRINT "Dialog returned ", dlg%
PRINT "Choice was ", choice%
IF dlg% = 0
PRINT "(dialog cancelled)"
GET
RETURN 0
ELSEIF choice% = 1
longDlg:
ELSEIF choice% = 2
floatDlg:
ELSEIF choice% = 3
editDlg:
ELSEIF choice% = 4
checkDlg:
ELSEIF choice% = 5
textDlg:
ELSEIF choice% = 6
xDlg:
ELSEIF choice% = 7
emptyDlg:
ELSEIF choice% = 8
dateDlg:
ELSEIF choice% = 9
timeDlg:
ELSEIF choice% = 10
buttonDlg:
ELSEIF choice% = 11
bareButtonDlg:
ELSEIF choice% = 12
cancelDlg:
ELSEIF choice% = 13
editMultiDlg:
ELSEIF choice% = 14
fileDlg:
ENDIF

RETURN 1
ENDP
2 changes: 2 additions & 0 deletions src/defaultiohandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ function fsop(cmd, path, ...)
else
return nil, KErrNotExists
end
elseif cmd == "disks" then
return { "C", "Z" }
elseif cmd == "delete" then
printf("delete %s\n", filename)
local ok, err, errno = os.remove(filename)
Expand Down
Loading

0 comments on commit 1e3d24a

Please sign in to comment.