[ENH] Saving image to some other directory

Tim Rowledge rowledge at interval.com
Wed Mar 24 02:53:00 UTC 1999


Some time ago we had a discussion about using default images when people (I
think mainly for unix users) try to start squeak without specifying an image
name. Various suggestions were made about how to provide the default image, but
one of the problems seemed to be the saving of the image in the users' home (or
wherever) directory. Typically we wouldn't want to have them save their 'used'
image over, or even near, the 'virgin' image.

One option would be to copy the default image and changelog to their default
directory and then start it. Another would be to make it possible to save the
image using not just a new name, but a new directory.

This small changeset allows just that. The dialogue has the full path of the
image name, and you can edit it to any reasonable path for your system.

I think that we now need to make the image detect that it is a virgin (no rude
jokes please - perhaps it could check for write permission on the changelog as
a test) and if so, alert the user that the image should be saved to their local
directory. Thus 'squeak' would run, discover no specified image name, run the
default and immediately get the user to saveAs in their local place. On Acorn,
Mac and Windows, the virgin image/changelog and sources could feasibly be bound
to the VM, making it seem like a single file to end users. I dare say some
equivalent trick can be done on unix.

Of course, if only we all had gigabit/s net links, the default files could be
off on a server...

tim 

-- 
Strange OpCodes: FLR: Flash Lights Randomly
Tim Rowledge:  rowledge at interval.com (w)  +1 (650) 842-6110 (w)
 tim at sumeru.stanford.edu (h)  <http://sumeru.stanford.edu/tim>

'From Squeak 2.0 of May 22, 1998 on 7 June 1998 at 10:20:51 pm'!
"Change Set:		saveElsewhere
Date:			7 June 1998
Author:			Tim Rowledge <tim at sumeru.stanford.edu>

Make it possible to save your image/changes into a different directory than the current one - the entire image name is presented in the save as dialogue and you can change any or all parts of the pathname.

This would be particularly useful for saving a user image into the users directoy after startinga default image from some default directory"!


!FileDirectory methodsFor: 'file operations' stamp: 'TPR 6/7/1998 21:39'!
copyFileNamed: fileName1 toFileNamed: fileName2
	"Copy the contents of the existing file with the first name into a new file with the second name. Both files are assumed to be in this directory."
	"FileDirectory default copyFileNamed: 'todo.txt' toFileNamed: 'todocopy.txt'"

	| file1 file2 |
	file1 _ self readOnlyFileNamed: fileName1.
	file2 _ self newFileNamed: fileName2.
	file1 copyToFileStream: file2
! !


!FileStream methodsFor: 'accessing' stamp: 'TPR 6/7/1998 21:37'!
copyToFileStream: fileStream2
	"Copy my contents into fileStream2"

	| buffer |
	buffer _ String new: 50000.
	[self atEnd] whileFalse:
		[fileStream2 nextPutAll: (self nextInto: buffer)].
	self close.
	fileStream2 close.
! !


!SystemDictionary methodsFor: 'snapshot and quit' stamp: 'TPR 6/7/1998 22:10'!
saveAs
	| dir newName newImageName newChangesName newDir |

	dir _ FileDirectory default.

	newName _ FillInTheBlank
		request: 'New File Name?'
		initialAnswer: Smalltalk imageName.

	newName isEmpty ifTrue:[^self].

	newName = Smalltalk imageName
		ifTrue:[^self snapshot: true andQuit: false].

	FileDirectory splitName: newName to:[ :path :fn|
		newDir _ FileDirectory on: path.
		newImageName _ (FileDirectory baseNameFor: fn),
			FileDirectory dot,
			FileDirectory imageSuffix.
	
	newChangesName _ (FileDirectory baseNameFor: fn),
			FileDirectory dot,
			FileDirectory changeSuffix].


	((newDir includesKey: newImageName) or:

	 [newDir includesKey: newChangesName]) ifTrue: [
		^ self notify: (newDir fullNameFor: newImageName), ' is already in use. Please choose another name.'].

	(dir readOnlyFileNamed: self changesName) copyToFileStream: (newDir newFileNamed: newChangesName).
	self logChange: '----SAVEAS ', (newDir fullNameFor: newImageName), '----', Date dateAndTimeNow printString.

	self imageName: (newDir fullNameFor: newImageName).
	LastImageName _ self imageName.

	self closeSourceFiles; openSourceFiles.
	"so SNAPSHOT appears in new changes file"

	self snapshot: true andQuit: false.
! !





More information about the Squeak-dev mailing list