home *** CD-ROM | disk | FTP | other *** search
/ Stickerpedia Stickerbook / Stickerbook.iso / pc / DATA / objects.cxt / 00023_Script_oFileIO < prev    next >
Text File  |  2003-03-19  |  5KB  |  213 lines

  1. --¨
  2. oFileIO
  3.  
  4.  
  5. global  oHQ
  6. global  oFileIO
  7.  
  8.  
  9.  
  10.  
  11. property  pxFileIO
  12. property  pDefaultPath
  13. property  pLastFileIOStatus
  14.  
  15. on new me
  16.   pxFileIO = new(xtra "fileIO")
  17.   if not objectP(pxFileIO) then handleError oHQ, ["object FileIO can't instantiate Xtra fileIO"]
  18.   pDefaultPath = the pathname
  19.   -- addObject me
  20.   -- updateProgressBar ("Object loading", oFileIO && "status #ok")
  21.   
  22.   return me  
  23. end
  24.  
  25.  
  26.  
  27.  
  28. on showProps me, outPutTo
  29.   showProps oHQ, me, outPutTo
  30. end
  31.  
  32.  
  33.  
  34. on getFile me, path, fileName
  35.   retVal = #error
  36.   if path = #default then set path = pDefaultPath
  37.   
  38.   closeFile pxFileIO
  39.   openFile pxFileIO, (path & fileName),1
  40.   setPosition pxFileIO, 0
  41.   retVal = readFile (pxFileIO)
  42.   closeFile pxFileIO
  43.   
  44.   fileIOFail me
  45.   return retVal
  46. end
  47.  
  48.  
  49.  
  50. on writeFile me, path, fileName, contents
  51.   
  52.   if path = #default then set path = pDefaultPath
  53.   
  54.   --  closeFile pxFileIO
  55.   openFile pxFileIO, (path & fileName), 0
  56.   
  57.   -- we want to replace the contents completely
  58.   -- this doesn't happen if we just do a writestring
  59.   -- writestring only replaces as many characters as are written
  60.   -- if there were originally 20 and we write 10, chars 11 to 20 remain
  61.   
  62.   delete pxFileIO
  63.   closeFile pxFileIO
  64.   createFile pxFileIO, (path & fileName)
  65.   if the platForm starts "Mac" then setFinderInfo(pxfileIO, "TEXT R*ch")
  66.   
  67.   
  68.   -- now we are ready to write:
  69.   
  70.   openFile pxFileIO, (path & fileName),0
  71.   setPosition pxFileIO,0
  72.   writeString (pxFileIO, "")  
  73.   writeString (pxFileIO, string(contents))  
  74.   closeFile pxFileIO
  75.   
  76.   fileIOFail me
  77. end
  78.  
  79.  
  80.  
  81.  
  82. on deleteFile me, path, fileName
  83.   
  84.   if path = #default then set path = pDefaultPath
  85.   
  86.   closeFile pxFileIO
  87.   openFile pxFileIO, (path & fileName), 0
  88.   
  89.   
  90.   delete pxFileIO
  91.   closeFile pxFileIO
  92.   
  93.   fileIOFail me
  94. end
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. on fileIOFail me
  106.   fileIOStatus = status(pxFileIO)
  107.   -- put "fileIOStatus: " & fileIOStatus
  108.   if fileIOStatus > 1 then
  109.     set retVal = 1
  110.     pLastFileIOStatus = "OK"
  111.   else
  112.     retVal = 0
  113.   end if
  114.   
  115.   case fileIOStatus of 
  116.     1:     set pLastFileIOStatus = "Memory allocation failure"
  117.     -33:   set pLastFileIOStatus = "File directory full"
  118.     -34:   set pLastFileIOStatus = "Volume full"
  119.     -35:   set pLastFileIOStatus = "Volume not found"
  120.     -36:   set pLastFileIOStatus = "I/O Error"
  121.     -37:   set pLastFileIOStatus = "Bad file name"
  122.     -38:   set pLastFileIOStatus = "File not open"
  123.     -42:   set pLastFileIOStatus = "Too many files open"
  124.     -43:   set pLastFileIOStatus = "File not found"
  125.     -56:   set pLastFileIOStatus = "No such drive"
  126.     -65:   set pLastFileIOStatus = "No disk in drive"
  127.     -120:  set pLastFileIOStatus = "Directory not found"
  128.     -121:  set pLastFileIOStatus = "Instance has an open file"
  129.     -122:  set pLastFileIOStatus = "File already exists"
  130.     -123:  set pLastFileIOStatus = "File is opened read-only"
  131.     -124:  set pLastFileIOStatus = " File is opened write-only"
  132.       
  133.   end case
  134.   
  135.   -- put pLastFileIOStatus
  136.   
  137.   return retVal
  138.   
  139. end
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152. -- FILEIO --
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160. --put mMessageList(Xtra "fileIO")
  161.  
  162. --new object me -- create a new child instance
  163.  
  164. --fileName object me -- return fileName string of the open file
  165.  
  166. --status object me -- return the error code of the last method called
  167.  
  168. --error object me, int error -- return the error string of the error
  169.  
  170. --setFilterMask object me, string mask -- set the filter mask for dialogs
  171.  
  172. --openFile object me, string fileName, int mode -- opens named file. valid modes: 0=r/w 1=r 2=w
  173.  
  174. --closeFile object me -- close the file
  175.  
  176. --displayOpen object me -- displays an open dialog and returns the selected fileName to lingo
  177.  
  178. --displaySave object me, string title, string defaultFileName -- displays save dialog and returns selected fileName to lingo
  179.  
  180. --createFile object me, string fileName -- creates a new file called fileName
  181.  
  182. --setPosition object me, int position -- set the file position
  183.  
  184. --getPosition object me -- get the file position
  185.  
  186. --getLength object me -- get the length of the open file
  187.  
  188. --writeChar object me, string theChar -- write a single character (by ASCII code) to the file
  189.  
  190. --writeString object me, string theString -- write a null-terminated string to the file
  191.  
  192. --readChar object me -- read the next character of the file and return it as an ASCII code value
  193.  
  194. --readLine object me -- read the next line of the file (including the next RETURN) and return as a string
  195.  
  196. --readFile object me -- read from current position to EOF and return as a string
  197.  
  198. --readWord object me -- read the next word of the file and return it as a string
  199.  
  200. --readToken object me, string skip, string break -- read the next token and return it as a string
  201.  
  202. --getFinderInfo object me -- get the finder info for the open file (Mac Only)
  203.  
  204. --setFinderInfo object me, string attributes -- set the finder info for the open file (Mac Only)
  205.  
  206. --delete object me -- deletes the open file
  207.  
  208. --* getOSDirectory -- returns the full path to the Mac System Folder or Windows Directory
  209.  
  210. --+ version xtraRef -- display fileIO version and build information in the message window
  211.  
  212.  
  213.