home *** CD-ROM | disk | FTP | other *** search
/ LineOne ISP Sign-Up 5 / LineOne.iso / assets / cxt / scripts / parentScripts.cst / 00071_CDROMservice parent.ls < prev    next >
Encoding:
Text File  |  2001-01-27  |  5.5 KB  |  199 lines

  1. -- 2001.01.27
  2. -- Clive Green <clivegreen@atlas.co.uk>
  3.  
  4. ------------------------------------------------------------------------------------------------------
  5.  
  6. -- taps into features of the Buddy API Xtra:
  7.  
  8. ------------------------------------------------------------------------------------------------------
  9.  
  10. -- declare properties:
  11. property main           -- main code directory object
  12. property dataManager    -- data storage facility
  13. property buddyManager   -- buddyAPI manager
  14.  
  15. property cdTitle        -- the (Macintosh) CD-ROM desktop title
  16. property defaultCDtitle -- default value for cdTitle
  17. property rootPrefix     -- runtime CD-ROM path prefix string (ie: "F:\" or "LineOne:")
  18.  
  19. ------------------------------------------------------------------------------------------------------
  20.  
  21. on new me,L
  22.   
  23.   -- (1) extract and check arguments:
  24.   
  25.   -- check for a parameter list:
  26.   if ilk(L) <> #propList then return [#error:#noParamListSupplied, #msg:"CDROMservice:new"]
  27.   
  28.   -- a reference to the parent codebase is REQUIRED:
  29.   main = L[#main]
  30.   if (ilk(main) <> #instance) then return [#error:#noMainObjectSupplied, #msg:"CDROMservice:new"]
  31.   
  32.   --------------------
  33.   
  34.   -- (2) obtain locally required features and services:
  35.   
  36.   -- get the data manager:
  37.   dm = main.getDataManager()
  38.   if (ilk(dm) <> #instance) then return dm
  39.   
  40.   dataManager = dm
  41.   
  42.   -- use the buddyAPIxtra controller:
  43.   xm = main.getXtrasManager() 
  44.   if (ilk(xm) <> #instance) then return xm
  45.   
  46.   bm = xm.getBuddyAPIxtra()
  47.   if (ilk(bm) <> #instance) then return bm
  48.   
  49.   buddyManager = bm
  50.   
  51.   --------------------
  52.   
  53.   -- (3) store literals:
  54.   defaultCDtitle = "LineOne"
  55.   cdTitle = defaultCDtitle
  56.   
  57.   --------------------
  58.   
  59.   -- (4) what is the disc name for this title? (used for Mac versions of the programme):
  60.   d = dataManager.getData([#set:#settings, #item:#titling])
  61.   t = d[#cdTitle]
  62.   
  63.   -- override default cd title with a custom one if this is found
  64.   if stringP(t) then cdTitle = t
  65.   
  66.   --------------------  
  67.   
  68.   -- pass back validated manager object to the caller:
  69.   return me
  70.   
  71.   ----------------------------------------------------------------------------------------------------
  72.   
  73. on launchCDfile me,L
  74.   
  75.   -- we need a parameter listing:
  76.   if ilk(L) <> #propList then return ┬¼
  77.   [#error:#noParamListSupplied, #msg:"CDROMservice :launchCDfile"]
  78.   
  79.   -- extract the filePath supplied: 
  80.   f = L[#filePath]
  81.   
  82.   if not stringP(f) then return ┬¼
  83.   [#error:#badFilePathSupplied, #msg:"CDROMservice :launchCDfile"]
  84.   
  85.   -- in what manner should the file be opened?
  86.   s = L[#state]
  87.   if not stringP(s) then s = "Normal"
  88.   
  89.   --------------------
  90.   
  91.   -- we also need a correctly identified CD-ROM to continue!
  92.   if voidP(rootPrefix) then return ┬¼
  93.   [#error:#CDmissing, #msg:"CDROMservice:launchCDfile"]
  94.   
  95.   --------------------
  96.   
  97.   -- attempt to launch from the correct CD
  98.   L[#filePath] = rootPrefix & f
  99.   return buddyManager.launchFile(L)
  100.   
  101.   ----------------------------------------------------------------------------------------------------
  102.   
  103. on matchingCDfound me
  104.   
  105.   -- this is a development cheat:
  106.   if the SHIFTDOWN then
  107.     
  108.     -- use the local path instead of a mounted CD:
  109.     rootPrefix = dataManager.getRootPath()
  110.     return 1
  111.     
  112.   end if
  113.   
  114.   --------------------
  115.   
  116.   -- we first need to find a mounted CD-ROM with a specific director file on it.
  117.   -- this file is addressed as a miaw, and asked to return its version information
  118.   -- if the version info matches with what we know locally, then we have found our CD
  119.   
  120.   -- (1) compile a linear list of CD-ROM drive letters or names:
  121.   CDROMdrives = []
  122.   
  123.   -- CD-ROM location varies according to platform:
  124.   um = main.getUtilityMethods()
  125.   p  = um.thePlatform()
  126.   
  127.   if (p = #PC) then
  128.     
  129.     repeat with i = charToNum("A") to charToNum("Z")
  130.       
  131.       -- get ith drive letter:
  132.       d = numToChar(i)  
  133.       
  134.       -- we want CD-ROM drives only:
  135.       if buddyManager.driveIsCDROM(d) then add CDROMdrives,(d & ":\")
  136.       
  137.     end repeat
  138.     
  139.   else
  140.     
  141.     -- on the Mac, we can specify the CD title exactly:
  142.     CDROMdrives = [cdTitle & ":"]
  143.     
  144.   end if
  145.   
  146.   --------------------
  147.   
  148.   -- (2) obtain the partial filePath to the 'version' miaw:
  149.   dL = dataManager.getData([#set:#filePaths, #item:#version])
  150.   fp = dL[#filePath]
  151.   
  152.   -- parse the path for the current platform:
  153.   um = main.getUtilityMethods()
  154.   fp = um.parseFilePath(fp)
  155.   
  156.   --------------------
  157.   
  158.   -- (3) now we need to check all currently mounted CD-ROMs for the existence of our
  159.   -- version file fp:
  160.   repeat with i in CDROMdrives
  161.     
  162.     -- compile a full filePath to our prospective version file:
  163.     f = i & fp
  164.     
  165.     -- does this file exist?
  166.     f = buddyManager.fileExists(f)
  167.     if not stringP(f) then next repeat
  168.     
  169.     -- we found our file! now test whether the version it specifies is correct:
  170.     if not me.matchedVersionString(f) then next repeat
  171.     
  172.     -- success! now we know our CD-ROM root:
  173.     rootPrefix = i
  174.     
  175.     -- flag success to the caller
  176.     return 1
  177.     
  178.   end repeat
  179.   
  180.   -- if we got here, then no CORRECT version movie on a mounted CD was found:
  181.   return 0
  182.   
  183.   ----------------------------------------------------------------------------------------------------
  184.   
  185. on matchedVersionString me,f
  186.   
  187.   -- ask the director movie file f for its version string:
  188.   w = window(f)
  189.   tell w to v = getVersionDataString()
  190.   
  191.   -- dispose:
  192.   forget w
  193.   
  194.   --------------------
  195.   
  196.   -- tell the caller whether we have a match:
  197.   return (field("versionDataString") = v) 
  198.   
  199.   ----------------------------------------------------------------------------------------------------