@@ -78,10 +78,13 @@ command revIDEExtensionDownloadAndInstall pExtensionPath, pType, pCallbackObject
7878 __extensionsChanged
7979end revIDEExtensionDownloadAndInstall
8080
81- command revIDEExtensionInstall pPackageLocation
81+ private function __extensionDependencyExists pExt
82+ return __extensionCacheID("name" , pExt ) is a number
83+ end __extensionDependencyExists
84+
85+ private command __extensionInstallPackage pPackageLocation
8286 if there is not a file pPackageLocation then
83- answer error "No package found at" && pPackageLocation
84- exit revIDEExtensionInstall
87+ throw "No package found at" && pPackageLocation
8588 end if
8689
8790 local tCacheIndex , tFromStore
@@ -92,12 +95,43 @@ command revIDEExtensionInstall pPackageLocation
9295 put false into tFromStore
9396 put the number of elements of sExtensions + 1 into tCacheIndex
9497 __extensionPropertySet tCacheIndex , "download_package_path" , pPackageLocation
98+ __extensionUpdateUIWithPackage tCacheIndex , pPackageLocation
9599 else
96100 put true into tFromStore
97101 end if
102+ __extensionPropertySet tCacheIndex , "downloaded_from_store" , tFromStore
103+ __extensionPropertySet tCacheIndex , "status" , "installing"
104+
105+ local tVerifyResult , tName
106+ __extensionDownloadVerify tCacheIndex
107+ put the result into tVerifyResult
108+ if tVerifyResult is not empty then
109+ __extensionCacheRemove tCacheIndex
110+ throw "Error installing extension" && pPackageLocation & return & the result
111+ end if
98112
113+ put __extensionPropertyGet(tCacheIndex , "name" ) into tName
114+
115+ # Fetch the dependency list (minus builtin modules) and ensure all
116+ # are loaded
117+ local tDeps
118+ put revIDEExtensionsOrderByDependency(tName ) into tDeps
119+ repeat for each line tExtension in tDeps
120+ # Skip the one we're installing
121+ if tExtension is tName then
122+ next repeat
123+ end if
124+ # Ensure dependency exists
125+ if not __extensionDependencyExists(tExtension ) then
126+ throw "Dependency" && tExtension && "not available. Please install before proceeding"
127+ end if
128+ end repeat
129+ __extensionInstall tCacheIndex , pPackageLocation
130+ end __extensionInstallPackage
131+
132+ command revIDEExtensionInstall pPackageLocation
99133 try
100- __extensionInstall tCacheIndex , pPackageLocation , tFromStore
134+ __extensionInstallPackage pPackageLocation
101135 catch tError
102136 answer error tError
103137 end try
@@ -288,14 +322,32 @@ private command __extensionDownloadBegin pExtensionUrl, pType, pCallbackObject,
288322 return tCacheIndex for value
289323end __extensionDownloadBegin
290324
325+ private command __extensionUpdateUIWithPackage pCacheIndex, pPath
326+ # Get initial name from file
327+ set the itemdel to "."
328+ local tName
329+ put pPath into tName
330+ delete the last item of tName
331+ repeat while the last item of tName is a number
332+ delete the last item of tName
333+ end repeat
334+ __extensionPropertySet pCacheIndex , "name" , tName
335+
336+ # Send update to refresh UI with new package installation
337+ doExtensionsChanged
338+ end __extensionUpdateUIWithPackage
339+
291340# Download the extension
292341private command __extensionDownload pCacheIndex
293342 # Check the file extension is correct
294343 local tURL
295344 put __extensionPropertyGet(pCacheIndex ,"package_url" ) into tURL
296345
297346 set the itemdel to "."
298- if the last item of tURL is not "lce" then return __extensionError(pCacheIndex ,"Could not download extension. The package must have the file extension 'lce':" && tURL )
347+ if the last item of tURL is not "lce" then
348+ return __extensionError(pCacheIndex , \
349+ "The package must have the file extension 'lce':" && tURL )
350+ end if
299351
300352 local tPackageFilePath
301353 set the itemdel to "/"
@@ -307,18 +359,7 @@ private command __extensionDownload pCacheIndex
307359 __extensionPropertySet pCacheIndex , "progress" , 0
308360 __extensionPropertySet pCacheIndex , "label" , tPackageFilePath
309361
310- # Put is a first stab at the name
311- set the itemdel to "."
312- local tName
313- put tPackageFilePath into tName
314- delete the last item of tName
315- repeat while the last item of tName is a number
316- delete the last item of tName
317- end repeat
318- __extensionPropertySet pCacheIndex , "name" , tName
319-
320- # Send update to refresh UI with new package installation
321- __extensionsChanged
362+ __extensionUpdateUIWithPackage pCacheIndex , tPackageFilePath
322363
323364 # Update progress
324365 __extensionSendProgressUpdate pCacheIndex , "Downloading" , 0
@@ -356,11 +397,18 @@ private command __extensionDownloadVerify pCacheIndex
356397 put __extensionPropertyGet(pCacheIndex , "download_package_path" ) into tExtensionPath
357398
358399 # Check the package exists
359- if there is not a file tExtensionPath then return __extensionError(pCacheIndex ,"Could not install extension. Package does not exists: " && tExtensionPath )
400+ if there is not a file tExtensionPath then
401+ return __extensionError(pCacheIndex , \
402+ "Package does not exist: " && tExtensionPath )
403+ end if
360404
361405 # Check the file extension is valid
362406 set the itemdel to "."
363- if the last item of tExtensionPath is not "lce" then return __extensionError(pCacheIndex ,"Could not install extension. The package extension '" & the last item of tExtensionPath & "' Is not valid. Must be 'lce'." )
407+ if the last item of tExtensionPath is not "lce" then
408+ return __extensionError(pCacheIndex , "The package extension '" & \
409+ the last item of tExtensionPath & "' is not valid." && \
410+ " Must be 'lce'." )
411+ end if
364412
365413 # Ensure the zip contains the things we expect
366414 local tManifestDataA
@@ -378,12 +426,7 @@ private command __extensionDownloadVerify pCacheIndex
378426 tManifestDataA ["name" ] & "." & tManifestDataA ["version" ]
379427end __extensionDownloadVerify
380428
381- private command __extensionInstall pCacheIndex, pPackage, pFromStore
382- __extensionDownloadVerify pCacheIndex
383- if the result is not empty then
384- throw "Error installing extension" && pPackage & return & the result
385- end if
386-
429+ private command __extensionInstall pCacheIndex, pPackage
387430 local tName , tTypeId , tInstallPath
388431 put __extensionPropertyGet(pCacheIndex , "name" ) into tName
389432 put __extensionPropertyGet(pCacheIndex , "type_id" ) into tTypeId
@@ -394,7 +437,7 @@ private command __extensionInstall pCacheIndex, pPackage, pFromStore
394437 __extensionInstallExtract pCacheIndex , tInstallPath , tTypeID , pPackage , 30
395438 __extensionInstallCopyInterfaceFile pCacheIndex , tName , tInstallPath , 50
396439 __extensionInstallLoad pCacheIndex , tName , tInstallPath , 80
397- __extensionInstallFinalise pCacheIndex , tTypeID , pFromStore
440+ __extensionInstallFinalise pCacheIndex , tTypeID
398441end __extensionInstall
399442
400443on __extensionInstallRemoveOlderVersions pCacheIndex, pName, pProgress
@@ -491,9 +534,9 @@ private command __extensionInstallLoad pCacheIndex, pName, pInstallFolder, pProg
491534end __extensionInstallLoad
492535
493536# Delete installation files and original package
494- on __extensionInstallFinalise pCacheIndex, pTypeId, pDeletePackage
537+ on __extensionInstallFinalise pCacheIndex, pTypeId
495538 # Delete temp package file
496- if pDeletePackage then
539+ if __extensionPropertyGet( pCacheIndex , "downloaded_from_store" ) then
497540 # Update progress
498541 __extensionSendProgressUpdate pCacheIndex , "Removing temp files" , 90
499542 local tTempInstallPackage
@@ -763,10 +806,9 @@ private command __extensionSetPropertyInfoFromManifest pID, pManifest
763806 put tPropertyInfo into sExtensionProperties [pID ]
764807end __extensionSetPropertyInfoFromManifest
765808
766- private command __extensionError pCacheIndex, pErrorMessage
809+ private function __extensionError pCacheIndex, pErrorMessage
767810 __extensionSendProgressUpdate pCacheIndex , "Error:" && pErrorMessage , 100
768- throw pErrorMessage
769- return empty
811+ return pErrorMessage
770812end __extensionError
771813
772814# Send notication that widget has been added/removed
@@ -901,6 +943,10 @@ private function __extensionCacheID pPropertyToSearch, pValue
901943 end repeat
902944end __extensionCacheID
903945
946+ private command __extensionCacheRemove pIndex
947+ delete variable sExtensions [pIndex ]
948+ end __extensionCacheRemove
949+
904950# Gets a property from the internal extension cache
905951function __extensionPropertyGet pCacheIndex, pProperty
906952 return sExtensions [pCacheIndex ][pProperty ]
0 commit comments