|
Post by Kevin on Feb 18, 2009 19:03:45 GMT -5
I can't understand some moments "Apply ExtractFilePath on each of these so that the 'C:' is removed." What's for ? Because when OnStartZip is run, the ZipHeader.Pathname won't have the volume information on it. It won't have 'C:'. And these variables are what is compared to the path (ZipHeader.Pathname) in OnStartZip to see which type of directory it is. "so you have the following variables set with the appropriate paths FavoritesPath ContactsPath MailPath" Do you mean FavoritesPath=\Users\User\Favorites ContactsPath=\Users\User\Contacts MailPath=\Users\User\AppData\Local\Microsoft\Windows Mail or something else ? Yes it could be these and probably normally would be. But as you say, they could be anything since, for instance the user can change where his favorites are stored, or XP has a different path. They contain whatever you obtained from the system for those three directories, but with the 'C:' removed as explained above. "So for instance, say the FavoritesPath is "\somedir\MyFavorites". if OnStartZip was called just before a Favorite was about to be zipped, the ZipHeader.Pathname coming in might look like "\users\Joe\MyFavorites\Links". When the above code is run it should end up "Favorites\Links"" I had reread it in about 10 times but still can't understand you. I cant understand how we turn "\somedir\MyFavorites" into "\users\Joe\MyFavorites\Links" ? As was discussed, these directories could be anywhere. I don't know your application so I don't know exactly what all the requirements are for unzipping. But, say what you have zipped for Favorites has 'Favorites\Links' as the path info. When you unzip, you would set your Destination to where ever you want the Favorites to go, for instance 'c:\users\Joe\MyFavorites'. If you have 'Favorites' as one of the entries in the RelativePathList property then when 'Favorites\Links' is unzipped, 'Favorites' will be stripped from the path info and the DestDir will be appended and the result will be 'c:\users\Joe\MyFavorites\Links'. Take a look at RelativePathList in the help file that might help explain some of this too. So as an example lets say for Favorites and Contacts you have 'c:\users\Joe\JoesFavorites\' as the Favorites directory 'c:\users\Joe\JoesContacts\' as the Contacts directory Zip it up and you will have, inside the zip file... 'Favorites\<subdir>' as path info in front of any files and subdirs from JoesFavorites 'Contacts\<subdir>' as path info in front of any files and subdirs from JoesContacts When you unzip, say you want to unzip to 'd:\users\Bob\MyFavorites' and 'd:\users\Bob\MyContacts' This would probably be best done in two unzip operations... 1. Set DestDir to 'd:\users\Bob\MyFavorites' FilesList.Add('Favorites\*'); UnZip; 2. Set DestDir to 'd:\users\Bob\MyContacts' FilesList.Add('Contacts'); UnZip; #1 above gets all files with "Favorites\" as the first part of the path info. 'Favorites' gets stripped (because it is in the RelativePathList), 'd:\users\Bob\MyFavortes' gets added (because it is the DestDir). Thus you have ' d:\users\Bob\MyFavorites\<subdir>\<file> that gets unzipped. #2 above does same thing but for Contacts. Does this make it more clear hopefully? Kevin
|
|
|
Post by Kevin on Feb 18, 2009 19:29:14 GMT -5
What path contain FavoritesPath here if (Pos(FavoritesPath,ZipHeader.Pathname) > 0) then ? "C:\Users\User\Favorites" trimmed to "\Users\User\Favorites" ? Yes.
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Feb 20, 2009 15:02:26 GMT -5
Well, I try to implement all of this and found that ZipHeader has not .Pathname
|
|
|
Post by Kevin on Feb 20, 2009 15:30:15 GMT -5
Oh, sorry, you are right, it is ZipHeader.Directory. Look in kpZipObj.pas at the properties for TZipHeaderInfo and you will see all the properties available to ZipHeader.
Kevin
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Feb 20, 2009 17:24:05 GMT -5
Well a bit clearer but... So I made as you said: .............. FavoritesPath:=UserFavorites; Delete(FavoritesPath,1,3); ContactsPath:=UserContacts; Delete(ContactsPath,1,3); MailPath:=ExcludeTrailingBackslash(StoreRoot); Delete(MailPath,1,3); Recurse := True; //* Yes Recurse directories */ StorePaths := True; //* Keep path information */ PackLevel := 1; //* Lowest level of compression */ NumberZipped := Zip; //* Return value of Zip is the actual number of files zipped */ FilesList.Add(UserFavorites+'\*.*'); FilesList.Add(UserContacts+'\*.*'); FilesList.Add(UserMail+'\*.*'); Zip; ......... procedure TfmMain.ZipperStartZip(Sender: TObject; FName: string; var ZipHeader: TZipHeaderInfo; var Skip: Boolean); var tmpstring:string; begin // Which type? if (Pos(FavoritesPath,ZipHeader.Directory) > 0) then begin tmpstring:=ZipHeader.Directory; Delete(tmpstring,0,Length(FavoritesPath)); ZipHeader.Directory:=tmpstring; ZipHeader.Directory := 'Favorites\' + ZipHeader.Directory; //Showmessage(ZipHeader.Directory); end else if (Pos(ContactsPath,ZipHeader.Directory) > 0) then begin // same as above but with ContactsPath tmpstring:=ZipHeader.Directory; Delete(tmpstring,0,Length(ContactsPath)); ZipHeader.Directory:=tmpstring; ZipHeader.Directory := 'Contacts\' + ZipHeader.Directory; end else if (Pos(MailPath,ZipHeader.Directory) > 0) then begin // same as above but with MailPath tmpstring:=ZipHeader.Directory; Delete(tmpstring,0,Length(MailPath)); ZipHeader.Directory:=tmpstring; ZipHeader.Directory := 'Windows Mail\' + ZipHeader.Directory; end
end;
And I get following paths (in zip file): "Contacts\Documents and Settings\User\Contacts\User.contact" "Documents and Settings\User\Contacts\" not excluded
|
|
|
Post by Kevin on Feb 20, 2009 19:30:01 GMT -5
Well, as I said, I did this off the top of my head without being able to test it. Did you do some debugging to see what you started out with for the three actual directories, what comes into the OnStartZip event for Directory and what the result of each Delete was? I am sure it will take some tweaking from the code that I posted.
Kevin
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Feb 21, 2009 5:07:27 GMT -5
Sorry,me but it's difficult to understand you, bkz I do not know english well,and you write a lot of difficult for understanding word combinations,phrase and not so much code or examples That's why I have to re read some phrases up to 10 times and still can't understand you want to say me. For example I still cant understand what should be a result in "So as an example lets say for Favorites and Contacts you have 'c:\users\Joe\JoesFavorites\' as the Favorites directory 'c:\users\Joe\JoesContacts\' as the Contacts directory Zip it up and you will have, inside the zip file... 'Favorites\<subdir>' as path info in front of any files and subdirs from JoesFavorites 'Contacts\<subdir>' as path info in front of any files and subdirs from JoesContacts" I can't imagine how it should be "'Favorites\<subdir>' as path info in front of any files and subdirs from JoesFavorites" please write example instead of description. So I get "Documents and Settings\User\Contacts\" at before tmpstring:=ZipHeader.Directory; and "Contacts\Documents and Settings\User\Contacts\" after "ZipHeader.Directory := 'Contacts\' + ZipHeader.Directory;" Bkz I cant understand what should I get, I can't debug and fix it
|
|
|
Post by Kevin on Feb 21, 2009 8:10:26 GMT -5
I can see one problem. In the following, you don't actually end up using tmpstring. This...
if (Pos(FavoritesPath,ZipHeader.Directory) > 0) then begin tmpstring:=ZipHeader.Directory; Delete(tmpstring,0,Length(FavoritesPath)); ZipHeader.Directory:=tmpstring; ZipHeader.Directory := 'Favorites\' + ZipHeader.Directory; //Showmessage(ZipHeader.Directory); end
Should be this (and same change for Contacts and Mail)...
if (Pos(FavoritesPath,ZipHeader.Directory) > 0) then begin tmpstring:=ZipHeader.Directory; Delete(tmpstring,0,Length(FavoritesPath)); ZipHeader.Directory := 'Favorites\' + tmpstring; //Showmessage(ZipHeader.Directory); end
Also, you have an extra call to zip. This probably doesn't affect anything but the first call to zip does not need to be there...
... PackLevel := 1; //* Lowest level of compression */ // remove -> NumberZipped := Zip; //* Return value of Zip is the actual number of files zipped */ FilesList.Add(UserFavorites+'\*.*'); FilesList.Add(UserContacts+'\*.*'); FilesList.Add(UserMail+'\*.*'); Zip;
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Feb 21, 2009 9:13:56 GMT -5
Just as you wrote: [quote author=admin board=VCLZipPro thread=285 post=1138 // Which type? if (Pos( FavoritesPath,ZipHeader.Pathname) > 0) then begin Delete(ZipHeader.Pathname,0,Length(FavoritesPath); ZipHeader.Pathname := 'Favorites\' + ZipHeader.Pathname; end Kevin [/quote] That's why I couldn't understand what do you want to get by " ZipHeader.Pathname := 'Favorites\' + ZipHeader.Pathname"
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Feb 21, 2009 9:23:59 GMT -5
But this modification gives nothing "So I get "Documents and Settings\User\Contacts\" at before tmpstring:=ZipHeader.Directory; and "Contacts\Documents and Settings\User\Contacts\" after "ZipHeader.Directory := 'Contacts\' + tmpstring;" is still actual.
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Feb 21, 2009 9:36:42 GMT -5
At last I got contents of all folders as wanted (content of "Contacts" folder in folder "Contacts" in zip file, and so on). Using just else if (Pos(ContactsPath,ZipHeader.Directory) > 0) then begin tmpstring:=ZipHeader.Directory; Delete(tmpstring,0,Length(ContactsPath)); ZipHeader.Directory:=tmpstring; [b]ZipHeader.Directory := 'Contacts\';[/b] end BUT I get EListError with message "Diplicate Object Index" and not all content of folders I need in zip file
|
|
|
Post by Kevin on Feb 21, 2009 19:04:49 GMT -5
Just as you wrote: [quote author=admin board=VCLZipPro thread=285 post=1138 // Which type? if (Pos( FavoritesPath,ZipHeader.Pathname) > 0) then begin Delete(ZipHeader.Pathname,0,Length(FavoritesPath); ZipHeader.Pathname := 'Favorites\' + ZipHeader.Pathname; end Kevin That's why I couldn't understand what do you want to get by " ZipHeader.Pathname := 'Favorites\' + ZipHeader.Pathname" [/quote] But I did not use a tempstring variable in my code. You added that.
|
|
|
Post by Kevin on Feb 21, 2009 19:14:44 GMT -5
At last I got contents of all folders as wanted (content of "Contacts" folder in folder "Contacts" in zip file, and so on). Using just else if (Pos(ContactsPath,ZipHeader.Directory) > 0) then begin tmpstring:=ZipHeader.Directory; Delete(tmpstring,0,Length(ContactsPath)); ZipHeader.Directory:=tmpstring; [b]ZipHeader.Directory := 'Contacts\';[/b] end BUT I get EListError with message "Diplicate Object Index" and not all content of folders I need in zip file You are removing any subdirectory information. Look at your last line: ZipHeader.Directory := 'Contacts\'; If there was a subdirectory then you are removing that. If there is a subdirectory under Favorites like Favorites\Links you are leaving out the Links part. This is why you need the following: tmpstring:=ZipHeader.Directory; Delete(tmpstring,0,Length(ContactsPath)); // removes all but any subdir if there is any ZipHeader.Directory:= 'Contacts\' + tmpstring; You are probably getting duplicates because there are probably files with the same name in different subdirectories. When you remove the subdirectory information then it is just the same filename twice.
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Feb 21, 2009 19:45:28 GMT -5
But I did not use a tempstring variable in my code. You added that. He-he, I had to do this bkz Delete() doesn't work with constants () and + string starts from 1-st position, not from 0 as aray for example so your a bit fixed an WORKING at last code looks like tmpstring:=ZipHeader.Directory; Delete(tmpstring,1,Length(ContactsPath)); ZipHeader.Directory := 'Contacts'+ tmpstring;
I had to exclude \ from 'Contacts\'+ tmpstring; bkz it was excessive. Now I really get 3 folders with proper structure and all folders and files there should be. So now there is only the last step - to unzip it I will try to do this tomorrow.. THANK YOU VERY MUCH
|
|
|
Post by Kevin on Feb 21, 2009 20:00:53 GMT -5
Very good! :-)
|
|