Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2005.09.25;
Скачать: CL | DM;

Вниз

Доработать >>>Соединить и сжать несколько файлов в один.<<<   Найти похожие ветки 

 
Windows ©   (2005-08-27 13:13) [0]

>>>Соединить и сжать несколько файлов в один.<<<
Вот листинг :

uses Zlib;

procedure CompressFiles(Files : TStrings; const Filename : String);
var
  infile, outfile, tmpFile : TFileStream;
  compr : TCompressionStream;
  i,l : Integer;
  s : String;
begin
  if Files.Count > 0 then
  begin
    outFile := TFileStream.Create(Filename,fmCreate);
    try
      { the number of files }
      l := Files.Count;
      outfile.Write(l,SizeOf(l));
      for i := 0 to Files.Count-1 do
      begin
        infile := TFileStream.Create(Files[i],fmOpenRead);
        try
          { the original filename }
          s := ExtractFilename(Files[i]);
          l := Length(s);
          outfile.Write(l,SizeOf(l));
          outfile.Write(s[1],l);
          { the original filesize }
          l := infile.Size;
          outfile.Write(l,SizeOf(l));
          { compress and store the file temporary}
          tmpFile := TFileStream.Create("tmp",fmCreate);
          compr := TCompressionStream.Create(clMax,tmpfile);
          try
            compr.CopyFrom(infile,l);
          finally
            compr.Free;
            tmpFile.Free;
          end;
          { append the compressed file to the destination file }
          tmpFile := TFileStream.Create("tmp",fmOpenRead);
          try
            outfile.CopyFrom(tmpFile,0);
          finally
            tmpFile.Free;
          end;
        finally
          infile.Free;
        end;
      end;
    finally
      outfile.Free;
    end;
    DeleteFile("tmp");
  end;
end;

procedure DecompressFiles(const Filename, DestDirectory : String);
var
  dest,s : String;
  decompr : TDecompressionStream;
  infile, outfile : TFilestream;
  i,l,c : Integer;
begin
  // IncludeTrailingPathDelimiter (D6/D7 only)
 dest := IncludeTrailingPathDelimiter(DestDirectory);
  infile := TFileStream.Create(Filename,fmOpenRead);
  try
    { number of files }
    infile.Read(c,SizeOf(c));
    for i := 1 to c do
    begin
      { read filename }
      infile.Read(l,SizeOf(l));
      SetLength(s,l);
      infile.Read(s[1],l);
      { read filesize }
      infile.Read(l,SizeOf(l));
      { decompress the files and store it }
      s := dest+s; //include the path
     outfile := TFileStream.Create(s,fmCreate);
      decompr := TDecompressionStream.Create(infile);
      try
        outfile.CopyFrom(decompr,l);
      finally
        outfile.Free;
        decompr.Free;
      end;
    end;
  finally
    infile.Free;
  end;
end;

Procedure Compress;
Begin
Memo1.Lines.Add("C:\1.exe");
Memo1.Lines.Add("C:\2.exe");
CompressFiles(Memo1.Lines,"C:\result.exe");
End;

Procedure DeCompress;
Begin
DecompressFiles("C:\result.exe", "C:\");
End;

Поясню, как работает программа, у меня...

Procedure Compress;
Склеивает и файлы C:\1.exe & C:\2.exe в один и сжимает.
Получается файл C:\Result.exe;

Procedure DeCompress;
Разъединяет файл C:\Result.exe
И сохраняте в дирректорию файлы, которые сжала предыдущая процедура.
Соответсвенно в дирректрии C:\ получаются прежние два файла.

Теперь, что касается вопроса.

Обе процедуры прекрасно работают.
Но как доработать код процедуры
   procedure CompressFiles(Files : TStrings; const Filename : String);
Так, чтобы результативный файл(C:\Result.exe) запускался, не просто досовским окошком, которое тут же исчезает, а запускал те два

файл. Сначала первый, потом второй.


 
XProger ©   (2005-08-27 13:25) [1]

а Result.exe твой винда хоть понимает чтобы запускать? ;)


 
Anatoly Podgoretsky ©   (2005-08-27 15:38) [2]

Windows ©   (27.08.05 13:13)  
Самозванец Windows это умеет делать.


 
Windows ©   (2005-08-27 16:06) [3]

"а Result.exe твой винда хоть понимает чтобы запускать? ;)"

Дак вот, я и пытаюсь у вас выяснить, как сделать так, чтобы она "Понимала..."


 
Anatoly Podgoretsky ©   (2005-08-27 16:20) [4]

Windows это делает по правой кнопке мыши.


 
Windows ©   (2005-08-27 18:19) [5]

Удалено модератором


 
Windows ©   (2005-08-28 09:18) [6]

Да, нормально...
Дак, люди, никто не может помочь???


 
Sam Stone ©   (2005-08-28 15:10) [7]

Не дай бог этот код будет работать так, как хочет автор ;)
Причем ведь есть такая возможность, если не ошибаюсь (*.rc)


 
pasha_golub ©   (2005-08-28 19:19) [8]

Windows ©   (28.08.05 09:18) [6]
Обычно животных с большими проблемами усыпляют... Чем же помочь Вам я не знаю.



Страницы: 1 вся ветка

Текущий архив: 2005.09.25;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.045 c
3-1123755014
Валерий
2005-08-11 14:10
2005.09.25
Непонятки с IN в динамическом SQL-е


4-1122710481
ink
2005-07-30 12:01
2005.09.25
взять текст из RichEdit


14-1125427940
SpecLab
2005-08-30 22:52
2005.09.25
Программирование графики в Windows 95...


2-1124377170
Viktop
2005-08-18 18:59
2005.09.25
Относительный путь к файлу


2-1124031074
TStas
2005-08-14 18:51
2005.09.25
Как зарегистрировать расширение?





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский