home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Stickerpedia Stickerbook
/
Stickerbook.iso
/
pc
/
DATA
/
objects.cxt
/
00023_Script_oFileIO
< prev
next >
Wrap
Text File
|
2003-03-19
|
5KB
|
213 lines
--¨
oFileIO
global oHQ
global oFileIO
property pxFileIO
property pDefaultPath
property pLastFileIOStatus
on new me
pxFileIO = new(xtra "fileIO")
if not objectP(pxFileIO) then handleError oHQ, ["object FileIO can't instantiate Xtra fileIO"]
pDefaultPath = the pathname
-- addObject me
-- updateProgressBar ("Object loading", oFileIO && "status #ok")
return me
end
on showProps me, outPutTo
showProps oHQ, me, outPutTo
end
on getFile me, path, fileName
retVal = #error
if path = #default then set path = pDefaultPath
closeFile pxFileIO
openFile pxFileIO, (path & fileName),1
setPosition pxFileIO, 0
retVal = readFile (pxFileIO)
closeFile pxFileIO
fileIOFail me
return retVal
end
on writeFile me, path, fileName, contents
if path = #default then set path = pDefaultPath
-- closeFile pxFileIO
openFile pxFileIO, (path & fileName), 0
-- we want to replace the contents completely
-- this doesn't happen if we just do a writestring
-- writestring only replaces as many characters as are written
-- if there were originally 20 and we write 10, chars 11 to 20 remain
delete pxFileIO
closeFile pxFileIO
createFile pxFileIO, (path & fileName)
if the platForm starts "Mac" then setFinderInfo(pxfileIO, "TEXT R*ch")
-- now we are ready to write:
openFile pxFileIO, (path & fileName),0
setPosition pxFileIO,0
writeString (pxFileIO, "")
writeString (pxFileIO, string(contents))
closeFile pxFileIO
fileIOFail me
end
on deleteFile me, path, fileName
if path = #default then set path = pDefaultPath
closeFile pxFileIO
openFile pxFileIO, (path & fileName), 0
delete pxFileIO
closeFile pxFileIO
fileIOFail me
end
on fileIOFail me
fileIOStatus = status(pxFileIO)
-- put "fileIOStatus: " & fileIOStatus
if fileIOStatus > 1 then
set retVal = 1
pLastFileIOStatus = "OK"
else
retVal = 0
end if
case fileIOStatus of
1: set pLastFileIOStatus = "Memory allocation failure"
-33: set pLastFileIOStatus = "File directory full"
-34: set pLastFileIOStatus = "Volume full"
-35: set pLastFileIOStatus = "Volume not found"
-36: set pLastFileIOStatus = "I/O Error"
-37: set pLastFileIOStatus = "Bad file name"
-38: set pLastFileIOStatus = "File not open"
-42: set pLastFileIOStatus = "Too many files open"
-43: set pLastFileIOStatus = "File not found"
-56: set pLastFileIOStatus = "No such drive"
-65: set pLastFileIOStatus = "No disk in drive"
-120: set pLastFileIOStatus = "Directory not found"
-121: set pLastFileIOStatus = "Instance has an open file"
-122: set pLastFileIOStatus = "File already exists"
-123: set pLastFileIOStatus = "File is opened read-only"
-124: set pLastFileIOStatus = " File is opened write-only"
end case
-- put pLastFileIOStatus
return retVal
end
-- FILEIO --
--put mMessageList(Xtra "fileIO")
--new object me -- create a new child instance
--fileName object me -- return fileName string of the open file
--status object me -- return the error code of the last method called
--error object me, int error -- return the error string of the error
--setFilterMask object me, string mask -- set the filter mask for dialogs
--openFile object me, string fileName, int mode -- opens named file. valid modes: 0=r/w 1=r 2=w
--closeFile object me -- close the file
--displayOpen object me -- displays an open dialog and returns the selected fileName to lingo
--displaySave object me, string title, string defaultFileName -- displays save dialog and returns selected fileName to lingo
--createFile object me, string fileName -- creates a new file called fileName
--setPosition object me, int position -- set the file position
--getPosition object me -- get the file position
--getLength object me -- get the length of the open file
--writeChar object me, string theChar -- write a single character (by ASCII code) to the file
--writeString object me, string theString -- write a null-terminated string to the file
--readChar object me -- read the next character of the file and return it as an ASCII code value
--readLine object me -- read the next line of the file (including the next RETURN) and return as a string
--readFile object me -- read from current position to EOF and return as a string
--readWord object me -- read the next word of the file and return it as a string
--readToken object me, string skip, string break -- read the next token and return it as a string
--getFinderInfo object me -- get the finder info for the open file (Mac Only)
--setFinderInfo object me, string attributes -- set the finder info for the open file (Mac Only)
--delete object me -- deletes the open file
--* getOSDirectory -- returns the full path to the Mac System Folder or Windows Directory
--+ version xtraRef -- display fileIO version and build information in the message window