Snowy Спасибо, твой пример оччень помог! Но народ всеравно ничего не архивируется, создается архив размером в 22кб пустой. посмотрите плиз код проги чего там не так?
| Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, ComCtrls, StdCtrls, Buttons, ShellAPI,VCLZip;
type TForm1 = class(TForm) MainMenu1: TMainMenu; File1: TMenuItem; N1: TMenuItem; Exit1: TMenuItem; Help1: TMenuItem; Abut1: TMenuItem; www1: TMenuItem; GroupBox1: TGroupBox; BitBtn1: TBitBtn; BitBtn2: TBitBtn; StatusBar1: TStatusBar; ListView1: TListView; OpenDialog1: TOpenDialog; BitBtn3: TBitBtn; CheckBox1: TCheckBox; Label1: TLabel; Edit1: TEdit; ProgressBar1: TProgressBar; Label2: TLabel; Edit3: TEdit; procedure BitBtn1Click(Sender: TObject); procedure BitBtn2Click(Sender: TObject); procedure BitBtn3Click(Sender: TObject); procedure Jar1Progress(Sender: TObject; ProgressByFile, ProgressByArchive: Byte); private { Private declarations } public { Public declarations } end;
var Form1: TForm1; zip: TVCLZip;
implementation
{$R *.dfm}
Procedure AddDir(Dir:string); // äîáàâèòü êàòàëîã ñî âñåìè ôàéëàìè â ñïèñîê var SearchRec:TSearchRec; begin if Dir<>'' then if Dir[length(Dir)]<>'\' then Dir:=Dir+'\'; if FindFirst(Dir+'*.*', faAnyFile, SearchRec)=0 then repeat if (SearchRec.name='.') or (SearchRec.name='..') then continue; if (SearchRec.Attr and faDirectory)<>0 then AddDir(Dir+SearchRec.name) else zip.FilesList.Add(Dir+SearchRec.name); until FindNext(SearchRec)<>0; FindClose(SearchRec); end;
function GetFileSize(FileName: String): Integer; var FS: TFileStream; begin try FS := TFileStream.Create(Filename, fmOpenRead); except Result := -1; end; if Result <> -1 then Result := FS.Size; FS.Free; end;
procedure TForm1.BitBtn1Click(Sender: TObject); var s:integer; begin OpenDialog1.Execute; if Length(OpenDialog1.FileName)>0 then begin s:=ListView1.Items.Count; ListView1.Items.Add; ListView1.Items.Item[s].SubItems.Add(OpenDialog1.FileName); ListView1.Items.Item[s].SubItems.Add(FloatToStr(GetFileSize(OpenDialog1.FileName))); Edit1.Text:=IntToStr(StrToInt(Edit1.Text)+(GetFileSize(OpenDialog1.FileName) div 1024)); end; end;
procedure TForm1.BitBtn2Click(Sender: TObject); var bit:string; begin bit:=Copy(ListView1.Items.Item[ListView1.Selected.Index].SubItems.DelimitedText,Pos(',',ListView1.Items.Item[ListView1.Selected.Index].SubItems.DelimitedText)+1,Length(ListView1.Items.Item[ListView1.Selected.Index].SubItems.DelimitedText)-Pos(',',ListView1.Items.Item[ListView1.Selected.Index].SubItems.DelimitedText)+1); Edit1.Text:=IntToStr(StrToInt(Edit1.Text)-(StrToInt(bit) div 1024)); ListView1.Selected.Delete; end;
procedure TForm1.BitBtn3Click(Sender: TObject); var book,Zbook,Arxiv,jadf:TStringList; Pyt,Bit,Dir,BName:String; i,j:integer; begin book:=TStringList.Create;//Îáúåêò äëÿ ñîõðàíåíèÿ êíèã Zbook:=TStringList.Create;//çàãëàâíûé ôàéë Arxiv:=TStringList.Create;//Ñïèñîê àðõèâèðóåìûõ ôàéëîâ Pyt:={GetCurrentDir;}ExtractFilePath(Application.ExeName);//Ïóòü ê ïàïêå ñ ïðîãðàììîé! if CheckBox1.Checked=true then begin book.LoadFromFile(Pyt+'help.txt'); book.SaveToFile(Pyt+'\books\help.txt'); ZBook.Add('help.txt|Help|6061'); end; for i:=0 to ListView1.Items.Count-1 do begin bit:=Copy(ListView1.Items.Item[i].SubItems.DelimitedText,Pos(',',ListView1.Items.Item[i].SubItems.DelimitedText)+1,Length(ListView1.Items.Item[i].SubItems.DelimitedText)-Pos(',',ListView1.Items.Item[i].SubItems.DelimitedText)+1); Dir:=Copy(ListView1.Items.Item[i].SubItems.DelimitedText,2,Length(ListView1.Items.Item[i].SubItems.DelimitedText)-(Length(Bit)+3)); BName:=Copy(Dir,LastDeLimiter('\',Dir)+1,Length(Dir)-LastDeLimiter('\',Dir)); ZBook.Add('book'+IntToStr(i)+'.txt|'+BName+'|'+Bit); book.LoadFromFile(dir); book.SaveToFile(Pyt+'\books\book'+IntToStr(i)+'.txt'); end; ZBook.SaveToFile(Pyt+'\books\_books.txt'); book.Free; Zbook.Free; Arxiv.LoadFromFile(Pyt+'\Files.t'); {:::::::::::::::::::::::::::::::} //Ñîçäàíèå àðõèâà! zip:=TVCLZip.Create(Form1); // ñîçäàåì îáúåêò //zip.PackLevel:=9; // óðîâåíü êîìïðåññèè - ìàêñèìàëüíûé zip.ZipName:=Pyt+'\'+Edit3.Text+'.zip'; // èìÿ àðõèâà zip.StorePaths:=true; // ãîâîðèì, ÷òîáû ñîõðàíÿë ñ ïîëíûìè ïóòÿìè AddDir('META-INF'); // äîáàâèòü â ñïèñîê êàòàëîê test ñî âñåìè ïîäêàòàëîãàìè AddDir('icons'); AddDir('fonts'); AddDir('books'); zip.FilesList.AddStrings(Arxiv); zip.Zip; // ïàêóåì zip.Free; // óíè÷òîæàåì îáúåêò
{:::::::::::::::::::::::::::::::} jadf:=TStringList.Create; jadf.Add('MIDlet-Name: Bookmobile'); jadf.Add('MIDlet-1: Bookmobile, /icons/icon.png, Bookmobile'); jadf.Add('MIDlet-Icon: /icons/icon.png'); jadf.Add('MIDlet-Version: 1.1.6'); jadf.Add('MIDlet-Vendor: Zlo'); jadf.Add('MicroEdition-Configuration: CLDC-1.0'); jadf.Add('MicroEdition-Profile: MIDP-1.0'); jadf.Add('MIDlet-Description: User friendly book reader'); jadf.Add('MIDlet-Jar-URL: '+Edit3.Text+'.jar'); jadf.Add('MIDlet-Jar-Size: '+IntToStr(GetFileSize(pyt+'\'+Edit3.Text+'.zip'))); jadf.Add(''); jadf.Add('');
Arxiv.Free; jadf.Free; end;
end.
| |