/////////////////////////////////////////////////////////////////////////////
// Name:        fs_wxz.cpp
// Purpose:     wxWxzFSHandler
// Author:      Francesco Montorsi
// Modified by:
// Created:     2007-1-17
// RCS-ID:      $Id: fs_wxz.cpp,v 1.1 2007/01/18 00:01:29 frm Exp $
// Copyright:   (c) Francesco Montorsi
// Licence:     wxWidgets licence
/////////////////////////////////////////////////////////////////////////////


// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

// includes
#include <wx/filesys.h>
#include "wxp/fs_wxz.h"


// ----------------------------------------------------------------------------
// wxWxzFSHandler
// ----------------------------------------------------------------------------

IMPLEMENT_DYNAMIC_CLASS(wxWxzFSHandler, wxFileSystemHandler)

bool wxWxzFSHandler::CanOpen(const wxString& location)
{
    wxString p = GetProtocol(location);
    return p == wxT("wxz");
}

wxFSFile* wxWxzFSHandler::OpenFile(wxFileSystem& fs, const wxString& location)
{
    wxString right = GetRightLocation(location);
    wxString left = GetLeftLocation(location);
    /*
    wxString protocol = GetProtocol(location);
    wxString key = left + wxT("#") + protocol + wxT(":");*/

    // just look at the left location to understand which type of
    // archive is this "WXZ"
    wxString ext = wxFileName(left).GetExt();

    // exception: if the file is "name.tar.gz" we want to consider as
    // extension the entire ".tar.gz"
    wxString newloc;
    if (left.EndsWith(wxT(".tar.gz")))
    {
        // for .tar.gz archives we need to create
        // the location in the form:
        //     srchive.tar.gz#gzip:#tar:filename
        newloc = left + wxT("#gzip:#tar:") + right;
    }
    else
    {
        // for ZIPs it's easier:
        newloc = left + wxT("#") + ext + wxT(":") + right;
    }

    // open this file using the other file system handlers
    wxFileSystem temp;
    return temp.OpenFile(newloc);
}

wxString wxWxzFSHandler::FindFirst(const wxString& spec, int flags)
{
    return wxEmptyString;
}

wxString wxWxzFSHandler::FindNext()
{
    return wxEmptyString;
}


