[delphizip] Versioning Ala Russell

  • From: Alistair George <bigal@xxxxxxxxxx>
  • To: delphizip@xxxxxxxxxxxxx
  • Date: Fri, 13 Dec 2002 17:51:41 +1300

Hello All,
Russell came up with a tidy bit of thread programming for versioning multiple
copies into the same archive {zip.AddOptions := [AddResetArchive,
AddArchiveOnly];}

There is a minor problem I have to figure out. The 'versioned' file needs to
have the version retained, otherwise there would be no reference from the 
central
directory. This means say using a stringgrid you can show the stripped file eg
several versions showing the same filename, but you must always have reference
to the file by its full name. Currently I do this by putting it into another
column of the stringgrid - easy to use but makes the columns a bit messy.
EG  to extract the below filename is used............|
myfile1.txt   myfiles\work\testgrid    1200      myfile1.txt
myfile1.txt   myfiles\work\testgrid    1207      myfile1.txt.#~4

Anyone got a better way to do the above? I'd prefer not to have the extra
column. If I can figure that out I'll post it here too.

The thread had me bamboozled for a while, but then the OnEvents were making it
more difficult. I got the threading working OK in myapp, but decided to go for
"normal" coding instead. For reference I include this below.

{var global}
var
  fSuffix: string;
  SuffixID: string = '.#~';
  SuffixIDLength = 3;


var
  s, f: LongInt;
  tval, Xval: integer;

begin

zipmaster1.FSpecArgs.Assign(richedit1.lines);
 {assign list before next}

    if (RxCheckListBox1.Checked[2]) then {zip.AddOptions := [AddResetArchive,
AddArchiveOnly];}
    begin
      try
 // make suffix
        tval := Count;
        Xval := 0;
        if Tval > 0 then
          repeat // should be first file checked
            dec(tval);
            fSuffix := ExtractFileExt(zipmaster1.DirEntry[tval].FileName);
            if Copy(fSuffix, 1, SuffixIDLength) = SuffixID then
              Xval := StrToIntDef(Copy(fSuffix, SuffixIDLength + 1, 8), -1);
          until (Xval >= 0) or (tval <= 1);
        if Xval < 0 then
          Xval := 0;
        inc(Xval);
        fSuffix := SuffixID + IntToStr(Xval);
    end;
    s := GetTickCount;
//WRITE
    try
      Add;
    except
      ShowMessage('Error in Add; Fatal DLL Exception in mainunit');
    end;
    richedit1.Lines.Clear;
    f := GetTickCount;
    TimeLabel.Caption := ShowLTime(s, f);

//You must set the Zipmaster.Onevent for OnsetNewName:

procedure TMainform.ZipMaster1SetNewName(Sender: TObject;
  var OldFileName: string; var IsChanged: Boolean);
var fn: string;
begin
//On Restore, removes the appended version string
  if (WriteZbtn.tag = 0) then
  begin
  // strip suffix
    fn := NoSuffix(OldFileName);
    if Length(fn) < Length(OldFileName) then
    begin
      OldFileName := fn;
      IsChanged := true;
    end;
  end
//On Write {zip.AddOptions := [AddResetArchive,
AddArchiveOnly];} appends the version string
  else
  if (WriteZbtn.tag = 1) and (RxCheckListBox1.Checked[2]) then
  begin
    OldFileName := OldFileName + fSuffix;
    IsChanged := true;
  end;
end;


Other related posts:

  • » [delphizip] Versioning Ala Russell