Updated 2012-11-18 23:55:14 by RLE

By default starkits are read-only. You must give the -writeable flag to sdx when doing the wrap for (i.e. creating) your starkit if yo want it to be writeable.

You make your starkit writeable by doing it at wrap time:
  sdx wrap app.kit -writeable

"-writeable" starkits automatically commit changes every 5 seconds.

TR Here is an example of a program that modifies its own contents using a writeable starkit. It is like 'tar'. Just download the script below and do
 sdx qwrap TarKit.tcl
 sdx unwrap TarKit.kit
 sdx wrap TarKit -writable

This produces the starkit named 'TarKit'.
  package require Tk 8.4

 # this is the list of files in the archive:
 set myFiles [list]

 # this is the directory where we store the files:
 if {! [file exists [file join $starkit::topdir data]]} {
         file mkdir [file join $starkit::topdir data]
 }

 # copy a file into the starkit vfs:
 proc FileStore {} {
         global myFiles
         set data {}
         set file [tk_getOpenFile]
         if {[string length $file]} {
                 file copy $file [file join $starkit::topdir data]
                 # update the listbox contents:
                 lappend myFiles [file tail $file]
                 set myFiles [lsort $myFiles]
         }
 }

 # copy a file from the starkit vfs back into the real world:
 proc FileExtract {} {
         set index [.archive.lst curselection]
         if {[llength $index] == 0} {
                 tk_messageBox -title "Ups" \
                 -message "You must select a file for this action." \
                 -type ok -icon info
                 return
         }
         set file [.archive.lst get $index]
         if {[string length $file]} {
                 set destination [tk_getSaveFile -initialfile $file]
                 if {[string length $destination]} {
                         file copy [file join $starkit::topdir data $file] $destination
                 }
         }
 }

 wm title . "TarKit"

 # list the conents of the archive here:
 labelframe .archive -text "File archive"
 pack .archive -side right -padx 5 -pady 5 -fill both -expand 1
 listbox .archive.lst -listvar myFiles
 pack .archive.lst -padx 2 -pady 2 -fill both -expand 1

 # these are the possible actions:
 labelframe .actions -text "Actions"
 pack .actions -side left -padx 5 -pady 5 -fill both -expand 1
 foreach {btn cmd text} {
         store FileStore "Add a file"
         extract FileExtract "Extract selected file"
         quit exit "Quit"
 } {
         button .actions.$btn -command $cmd -text $text -width 20
         pack .actions.$btn -padx 5 -pady 2
 }

 # initialize the listbox with the currently stores files:
 foreach file [lsort [glob -nocomplain [file join $starkit::topdir data *]]] {
         lappend myFiles [file tail $file]
 }

Hmm, after having used that a bit, I thought it was time for something more useful --> TarKit.
 #! tclkit
 package require mk4vfs
 mk4vfs::mount mykit mykit.kit
 cd mykit
 glob *
 cd lib/app-mykit
 # Can I just update the file here?

What is the above code trying to accomplish? What is the glob for? Probably a transcript of an interactive session, "puts [glob *]" would be less confusing.

05Feb03 Jeff Smith - "HeadsUp" [1] is an example of single-file website - i.e. tclhttpd wrapped up as starkit, with user data inside.

male 2004-09-03:

Using the option -writable with sdx is no problem with starkits, but what about starpacks?

They seem not to work!

Any hint, suggestion, ...?

Thanks!

Duoas 2008-10-31 Yoinks! Old question!

Starpacks cannot update themselves directly, due to restrictions from some OSes, notably Windows, which do not permit an executable's image to be modified while it is running. While there are ways around this, you are better off just using a separate configuration or data file. Starpacks are for convenience with distribution and installation; once installed there is no reason you cannot use external files or the registry|~/.myapp/* or whatever.

Darel Finkbeiner - Can you use this to write metakit data right into the StarKit? Currently I'm keeping external metakit databases for the information my program needs. I'd like to wrap that all up in the StarKit and make any changes needed at run-time. Can someone give an example of this?

27oct04 jcw - You can, you just need to get hold of the name of the open datafile in Mk4tcl, i.e. see what "puts [mk::file open]" prints. All of a starkit resides in a MK view called "dirs". You can add other views as needed, through MK's on-the-fly restructuring. Keep in mind that by storing code and data in one file, you'll need to think about how to distribute updates without losing data, as a simple file replacement will no longer work. IIRC, SDX's starsync mechanism does the right thing, i.e. altering only the dirs view and leaving all other data as is.

tb Also, TclTalk relies heavily on this feature, to save data into its starkit at runtime. This way it tries to be something similar to a Smalltalk image.

Sexy Starkits