Afterwarp Development  

Go Back   Afterwarp Development > Software/Game Development > Published Resources
Published Resources Post any source code, images and tools here that you want to share with the community.

Reply
 
Thread Tools Display Modes
  (#1) Old
The Wicked Flea The Wicked Flea is offline
Honoured
The Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud of
 
The Wicked Flea's Avatar
 
Posts: 692
Join Date: Oct 2005
Location: world.usa.find('East Coast');
Post Asphyre4 Zip-Archive Handler - 20-Jan-2007, 14:31

The new archive manager in the latest Asphyre 4 snapshots is very flexible. I could have used something that needed a DLL, but instead I decided to reuse the Turbo Power Abbrevia library, which was released under the MPL1.1 license. You do not need to worry about application bloat due to the size of the library, because the small unit I have put together only takes advantage of the UnZip functionality. My demonstration application only takes about 500kb.

Unlike the current implementations of 7-Zip and SQX, this Zip archive extension can extract to any stream. Because of this loading is marginally faster. As the Archive functionality advances I will update this unit to include password protection functionality.

The only line of code you must add to your game is, aside from using the unit, this:
Code:
RegisterZip('.zip');
And you can change the extension to anything you so desire.

For those who want just the unit, it is under the MPL license. The archive with an example program you may download here (1.5mb). Thanks go to Yuriy and Huasoft for helping me get my demo application rendering, as this was the first beta attempt of mine.

Code:
unit AsphyreArcZip;
//---------------------------------------------------------------------------
// AsphyreArcZip.pas                                   Modified: 19-Jan-2007
// Archive Wrapper for ZIP file format                           Version 1.0
// Author: Robert "The Wicked Flea" Kosek
//         http://www.thewickedflea.com
//---------------------------------------------------------------------------
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is AsphyreArcZip.pas
//
// The Initial Developer of the Original Code is Robert Kosek
// Portions created by the Initial Developer are Copyright (C) 2007
// the Initial Developer. All Rights Reserved.
//---------------------------------------------------------------------------
interface

{$HINTS OFF}

uses Classes, SysUtils, AsphyreAsserts, MediaUtils, AsphyreArchives,
     AbUnzper, AbZipTyp, AbExcept;

type
  TAsphyreArchiveZip = class(TAsphyreCustomArchive)
    protected
      FArchive: TAbUnZipper;
      function GetItemCount: Integer; override;
      function GetItemName(Num: Integer): string; override;
      function OpenArchive(const FileName: string): Boolean; override;
      procedure CloseArchive(); override;
      procedure DoCreate(); override;
      destructor Destroy(); override;
    public
      function ExtractToDisk(const ItemName, DestPath: string): Boolean; override;
      function ExtractToStream(const ItemName: string; Stream: TStream): Boolean; override;
  end;

procedure RegisterZip(const Ext: string);

implementation

procedure RegisterZip(const Ext: string);
begin
  ArchiveManager.RegisterExt(Ext, TAsphyreArchiveZip);
end;

{ TAsphyreArchiveZip }

procedure TAsphyreArchiveZip.CloseArchive;
begin
  FArchive.CloseArchive;
end;

procedure TAsphyreArchiveZip.DoCreate;
begin
  inherited;

  FAttributes := [];
  FArchive := TAbUnZipper.Create(nil);
end;

destructor TAsphyreArchiveZip.Destroy;
begin
  with FArchive do begin
    CloseArchive;
    Free;
  end;

  inherited;
end;

function TAsphyreArchiveZip.ExtractToDisk(const ItemName, DestPath: string): Boolean;
var F: TFileStream;
begin
  Result := True;

  F := TFileStream.Create(MakeValidPath(DestPath) + MakeValidFileName(ItemName),
                          fmCreate or fmShareExclusive);
  try
    try
      FArchive.ExtractToStream(ItemName,F);
    except on E: EAbException do
      begin
        result := false;
        raise e;
      end;
    end;
  finally
    F.Free;
  end;
end;

function TAsphyreArchiveZip.ExtractToStream(const ItemName: string;
  Stream: TStream): Boolean;
begin
  Result := True;
  try
    FArchive.ExtractToStream(ItemName,Stream);
  except on E: EAbException do
    begin
      Result := False;
      raise E;
    end;
  end;
end;

function TAsphyreArchiveZip.GetItemCount: Integer;
begin
  Assert((FArchive <> nil)and(FArchive.FileName <> ''), msgArchiveNotOpened);

  Result := FArchive.Count;
end;

function TAsphyreArchiveZip.GetItemName(Num: Integer): string;
begin
  Assert((FArchive <> nil)and(FArchive.FileName <> ''), msgArchiveNotOpened);

  Result := FArchive.Items[Num].FileName;
end;

function TAsphyreArchiveZip.OpenArchive(const FileName: string): Boolean;
begin
  Result := True;
  try
    FArchive.OpenArchive(FileName);
  except on E: EAbException do
    begin
      Result := False;
      raise E;
    end;
  end;
end;

end.


"If we knew what we were doing, it wouldn't be called research, would it?"
-- Albert Einstein

IntelliArchiver 1.00 RC1 is here!
Finished Projects: Just DIE Already!, Asphyre 4 Zip Archive Handler
Reply With Quote
  (#2) Old
The Wicked Flea The Wicked Flea is offline
Honoured
The Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud of
 
The Wicked Flea's Avatar
 
Posts: 692
Join Date: Oct 2005
Location: world.usa.find('East Coast');
20-Jan-2007, 15:24

Note: I have updated the archive copy as I used a function in a way that would make fullscreen mode unstable. To correct this as well as exemplify a simple Asphyre4 application I have updated the demo. Archive functionality has not changed.


"If we knew what we were doing, it wouldn't be called research, would it?"
-- Albert Einstein

IntelliArchiver 1.00 RC1 is here!
Finished Projects: Just DIE Already!, Asphyre 4 Zip Archive Handler
Reply With Quote
  (#3) Old
wagenheimer wagenheimer is offline
Honoured
wagenheimer is on a distinguished road
 
wagenheimer's Avatar
 
Posts: 298
Join Date: Dec 2005
Location: Brazil
Send a message via ICQ to wagenheimer Send a message via MSN to wagenheimer Send a message via Skype™ to wagenheimer
19-Jun-2007, 20:51

It is possible to load files in a subfolder inside the Zip? How must i set this on XML?

And Passoworded Zips , are already working?

Thanks
Reply With Quote
  (#4) Old
The Wicked Flea The Wicked Flea is offline
Honoured
The Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud of
 
The Wicked Flea's Avatar
 
Posts: 692
Join Date: Oct 2005
Location: world.usa.find('East Coast');
19-Jun-2007, 21:37

For files in a subfolder you have it structured as normal, then in the XML file you load it instead of just a plain file, you prefix it with the directory. Like so: "resources.zip | mesh\actor1.x"

Passworded zip files aren't working right now, but I could create an "OnAskForPassword" event that you can pass in initialization. Would you like that?


"If we knew what we were doing, it wouldn't be called research, would it?"
-- Albert Einstein

IntelliArchiver 1.00 RC1 is here!
Finished Projects: Just DIE Already!, Asphyre 4 Zip Archive Handler
Reply With Quote
  (#5) Old
wagenheimer wagenheimer is offline
Honoured
wagenheimer is on a distinguished road
 
wagenheimer's Avatar
 
Posts: 298
Join Date: Dec 2005
Location: Brazil
Send a message via ICQ to wagenheimer Send a message via MSN to wagenheimer Send a message via Skype™ to wagenheimer
19-Jun-2007, 21:47

Hummm!! I would love!!
So i need to pass the password in this event and it will work?

Thanks!
Reply With Quote
  (#6) Old
The Wicked Flea The Wicked Flea is offline
Honoured
The Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud ofThe Wicked Flea has much to be proud of
 
The Wicked Flea's Avatar
 
Posts: 692
Join Date: Oct 2005
Location: world.usa.find('East Coast');
20-Jun-2007, 00:12

Basically you would create a function that returns the password, and then pass the function to the "RegisterZip" function. Then the function you defined would get called whenever a password is needed.

That's a bit generic, but I'll experiment with getting that functional. And updating a demo to Asphyre 4.1.


"If we knew what we were doing, it wouldn't be called research, would it?"
-- Albert Einstein

IntelliArchiver 1.00 RC1 is here!
Finished Projects: Just DIE Already!, Asphyre 4 Zip Archive Handler
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Specification of new archive format for Asphyre 4 lifepower Development 9 17-Jan-2007 13:29



vBulletin® is copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com
Copyright (c) 2000 - 2008 Afterwarp Development. All rights reserved.