home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
installabl.tcl
< prev
next >
Wrap
Text File
|
1997-03-18
|
8KB
|
331 lines
#---------------------------------------------------------------------------
#
# (c) Cayenne Software Inc. 1997
#
# File: @(#)installabl.tcl /main/hindenburg/2
# Author: <generated>
# Description: VCM integration file
#---------------------------------------------------------------------------
# SccsId = @(#)installabl.tcl /main/hindenburg/2 18 Mar 1997 Copyright 1997 Cayenne Software Inc.
# Start user added include file section
# End user added include file section
# This class represents installable cutomization files.
# Each instance is one file, the attibutes specify
# how the file must be installed.
Class InstallableCustomFile : {GCObject} {
method destructor
constructor
method sourcePath
method customFileVersion
method createCustomFileVersion
method writeFrom
method readTo
method filterCopy
method appendSection
method removeSection
method delete
method install
method unInstall
method manager
# Name of the customization file.
#
attribute name
# Type of the customization file
#
attribute type
# List of levels if file cannot be installed
# on all levels, empty otherwise.
#
attribute level
# Where to install from.
#
attribute source
# Prefix that is used to distinguish between
# source files with the same name.
#
attribute sourcePrefix
# Method that yields a temporaray file
# with the source file.
#
attribute sourceMethod
# If incremental is 0, installation overwrites any existing files and
# uninstall deletes.
# Otherwise install appends to a file,
# and uninstall just removes this part.
# In case of a new file the behavior is similar.
#
attribute incremental
attribute _manager
}
method InstallableCustomFile::destructor {this} {
# Start destructor user section
# End destructor user section
}
constructor InstallableCustomFile {class this name type manager} {
set this [GCObject::constructor $class $this]
$this name $name
$this type $type
$this manager $manager
return $this
}
# Returns the source path for this file.
#
method InstallableCustomFile::sourcePath {this} {
# check source method first. This will yield a temp file.
if { [$this sourceMethod] != "" } {
set tmpFile [eval [$this sourceMethod]]
return $tmpFile
}
set sourceFile [$this source]
# if source is a directory then we must still append the file name
if [file isdirectory $sourceFile] {
set prefixName "[$this sourcePrefix][$this name]"
set sourceFile [path_name concat $sourceFile $prefixName [$this type]]
}
return $sourceFile
}
# Returns corresponding customFileVersion if it exists.
#
method InstallableCustomFile::customFileVersion {this} {
set customLevel [[ClientContext::global] currentCustomLevel]
set name [$this name]
set type [$this type]
return [$customLevel findCustomFileVersion $name $type]
}
# Creates corresponding custom file version.
#
method InstallableCustomFile::createCustomFileVersion {this} {
set customLevel [[ClientContext::global] currentCustomLevel]
set name [$this name]
set type [$this type]
return [$customLevel createCustomFileVersion $name $type]
}
# Write the customization file using the
# specified path as source.
#
method InstallableCustomFile::writeFrom {this path} {
set customFile [$this customFileVersion]
# if customization file does not exist create it
if [$customFile isNil] {
set customFile [$this createCustomFileVersion]
}
# edit and upload contents
$customFile edit
$customFile upLoad $path
$customFile quit
}
# Read contents of customization file to path.
#
method InstallableCustomFile::readTo {this path} {
set customFile [$this customFileVersion]
if [$customFile isNil] {
return
}
$customFile downLoad $path
}
# Copy 'registerObject' definitions from 'from'
# to 'to', filtering any elements that also occur in 'filter'.
# Mode specifies the open mode for 'to'.
#
method InstallableCustomFile::filterCopy {this from to filter {mode w}} {
if { $filter != "" } {
set filterDesc [open $filter r]
set filterContents [read $filterDesc]
close $filterDesc
} else {
set filterContents "None"
}
set fromDesc [open $from r]
set toDesc [open $to $mode]
# parse variables: definition is current definition
# inDefinition states whether we are in a definition
set definition ""
set inDefinition 0
while { [gets $fromDesc line] >= 0 } {
# get start of a registerObject definition
if [regexp ^registerObject $line] {
set inDefinition 1
}
if $inDefinition {
if { $definition == "" } {
set definition $line
} else {
append definition "\n$line"
}
# end of definition: append if a new one
if [regexp ^\} $line] {
set inDefinition 0
if { [string first $definition $filterContents] == -1 } {
puts $toDesc $definition
}
set definition ""
}
}
}
close $fromDesc
close $toDesc
}
# Read the contents of path and insert in the file
# if they did not yet exist there.
#
method InstallableCustomFile::appendSection {this path} {
$this filterCopy [$this sourcePath] $path $path a
# remove sourcePath for temp files
if { [$this sourceMethod] != "" } {
BasicFS::removeFile $sourcePath
}
return
}
# Returns path of temporary file containing
# the contents of path minus the contents of source.
#
method InstallableCustomFile::removeSection {this path} {
set destFile [BasicFS::tmpFile]
$this filterCopy $path $destFile [$this sourcePath]
BasicFS::removeFile $path
# remove sourcePath for temp files
if { [$this sourceMethod] != "" } {
BasicFS::removeFile $sourcePath
}
return $destFile
}
# Deletes the customization file from the
# current level.
#
method InstallableCustomFile::delete {this} {
set customLevel [[ClientContext::global] currentCustomLevel]
set name [$this name]
set type [$this type]
set customFile [$customLevel findCustomFileVersion $name $type]
if [$customFile isNil] {
return
}
$customLevel remove $customFile
}
# Install the file at the current custom level.
#
method InstallableCustomFile::install {this} {
if { ![$this incremental] } {
set sourcePath [$this sourcePath]
$this writeFrom $sourcePath
# if a source method was specified sourcePath is a temp file
if { [$this sourceMethod] != "" } {
BasicFS::removeFile $sourcePath
}
return
}
# create custom file if it did not exists, otherwise fill temp file
# with old contents
set tmpFile [BasicFS::tmpFile]
if [[$this customFileVersion] isNil] {
$this createCustomFileVersion
} else {
$this readTo $tmpFile
}
# append section to the file
$this appendSection $tmpFile
# install
$this writeFrom $tmpFile
BasicFS::removeFile $tmpFile
}
# Uninstall file from current custom level.
#
method InstallableCustomFile::unInstall {this} {
if { ![$this incremental] } {
$this delete
return
}
# get old contents
set tmpFile [BasicFS::tmpFile]
$this readTo $tmpFile
# remove my contents
set tmpFile [$this removeSection $tmpFile]
# if file is empty delete. otherwise write to file
set tmpDesc [open $tmpFile r]
set tmpContents [read $tmpDesc]
close $tmpDesc
if [regexp {[A-Za-z]} $tmpContents] {
$this writeFrom $tmpFile
} else {
$this delete
}
BasicFS::removeFile $tmpFile
}
# Do not delete this line -- regeneration end marker
method InstallableCustomFile::manager {this args} {
if {$args == ""} {
return [$this _manager]
}
set ref [$this _manager]
if {$ref != ""} {
[$ref _customFileSet] removeValue $this
}
set obj [lindex $args 0]
if {$obj != ""} {
[$obj _customFileSet] append $this
}
$this _manager $obj
}