'From Squeakland 3.1.4295 of 24 August 2001 [latest update: #68] on 29 October 2001 at 6:01:20 pm'! "Change Set: prjSaveFix-mir Date: 29 October 2001 Author: Michael Rueger Fixes some more problems with saving projects to local discs. Also includes a workaround for some projects with invalid resource paths."! !Project methodsFor: 'accessing'! renameTo: newName | oldBase | newName = self name ifFalse: [ oldBase _ self resourceDirectoryName. version _ nil. self resourceManager adjustToRename: self resourceDirectoryName from: oldBase. self changeSet name: newName. ].! ! !ResourceCollector methodsFor: 'resource writing' stamp: 'mir 10/26/2001 15:31'! writeResourceForm: aForm fromLocator: aLocator "The given form has been externalized before. If it was reasonably compressed, use the bits of the original data - this allows us to recycle GIF, JPEG, PNG etc. data without using the internal compression (which is in most cases inferior). If necessary the data will be retrieved from its URL location. This retrieval is done only if the resouce comes from either * the local disk (in which case the file has never been published) * the browser cache (in which case we don't cache the resource locally) In any other case we will *not* attempt to retrieve it, because doing so can cause the system to connect to the network which is probably not what we want. It should be a rare case anyways; could only happen if one clears the squeak cache selectively." | fName fStream url data | "Try to be smart about the name of the file" fName _ (aLocator urlString includes: $:) ifTrue: [ url _ aLocator urlString asUrl. url path last] ifFalse: [aLocator urlString]. fName isEmptyOrNil ifFalse:[fName _ fName asFileName]. (fName isEmptyOrNil or:[localDirectory isAFileNamed: fName]) ifTrue:[ "bad luck -- duplicate name" fName _ localDirectory nextNameFor:'resource' extension: (FileDirectory extensionFor: aLocator urlString)]. "Let's see if we have cached it locally" ResourceManager lookupCachedResource: self baseUrl , aLocator urlString ifPresentDo:[:stream | data _ stream upToEnd]. "Check if the cache entry is without qualifying baseUrl. Workaround for older versions." data ifNil:[ ResourceManager lookupCachedResource: aLocator urlString ifPresentDo:[:stream | data _ stream upToEnd]]. data ifNil:[ "We don't have it cached locally. Retrieve it from its original location." ((url notNil and: [url hasRemoteContents]) and:[HTTPClient isRunningInBrowser not]) ifTrue:[^nil]. "see note above" data _ HTTPLoader default retrieveContentsFor: aLocator urlString. data ifNil:[^nil]. data _ data content. ]. data size > aForm bits byteSize ifTrue:[^nil]. fStream _ localDirectory newFileNamed: fName. fStream nextPutAll: data. fStream close. ^{fName. data size}! ! !ResourceLocator methodsFor: 'accessing'! adjustToDownloadUrl: downloadUrl "Adjust to the fully qualified URL for this resource." self urlString: (ResourceLocator make: self urlString relativeTo: downloadUrl) unescapePercents! ! !ResourceLocator class methodsFor: 'utilities'! make: newURLString relativeTo: oldURLString "Local file refs are not handled well, so work around here" ^((oldURLString includesSubString: '://') not and: [(newURLString includesSubString: '://') not]) ifTrue: [oldURLString , (UnixFileDirectory localNameFor: newURLString)] ifFalse: [(newURLString asUrlRelativeTo: oldURLString asUrl) toText]! ! !ResourceManager methodsFor: 'accessing'! adjustToNewServer: newResourceUrl from: oldResourceUrl "Adjust the resource manager to the current download location. A project might have been moved manually to a different location or server." | urlMap oldUrl newUrl | newResourceUrl isEmptyOrNil ifTrue: [^self]. urlMap _ Dictionary new. self resourceMap keysDo: [:locator | "Local file refs are not handled well, so work around here" oldUrl _ ResourceLocator make: locator urlString relativeTo: oldResourceUrl. newUrl _ ResourceLocator make: locator urlString relativeTo: newResourceUrl. oldUrl ~= newUrl ifTrue: [urlMap at: oldUrl asString unescapePercents put: newUrl asString unescapePercents]]. self resourceMap rehash. unloaded rehash. urlMap keysAndValuesDo: [:old :new | ResourceManager renameCachedResource: old to: new]! !