Upstream tarball 10013
[amule.git] / src / libs / common / FileFunctions.h
blob5513e6d14fcc30a333d00082102944d1aec5b125
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2008 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #ifndef FILEFUNCTIONS_H
28 #define FILEFUNCTIONS_H
30 #include "../../Types.h"
31 #include "Path.h"
33 #include <wx/dir.h>
36 // Dir iterator: needed because wxWidget's wxFindNextFile and
37 // wxFindFirstFile are bugged like hell.
38 class CDirIterator : private wxDir
40 public:
41 enum FileType {
42 FileNoHidden = wxDIR_FILES,
43 DirNoHidden = wxDIR_DIRS,
44 File = wxDIR_FILES | wxDIR_HIDDEN,
45 Dir = wxDIR_DIRS | wxDIR_HIDDEN,
46 Any = wxDIR_FILES | wxDIR_DIRS | wxDIR_HIDDEN
49 CDirIterator(const CPath& dir);
50 ~CDirIterator();
52 CPath GetFirstFile(FileType type, const wxString& mask = wxEmptyString);
53 CPath GetNextFile();
55 bool HasSubDirs(const wxString& spec = wxEmptyString);
59 //! Filetypes understood by UnpackArchive
60 enum EFileType
62 //! Text files, will be left unchanged.
63 EFT_Text,
64 //! Zip archive, will be unpacked
65 EFT_Zip,
66 //! GZip archives, will be unpacked
67 EFT_GZip,
68 //! Met file, will be left unchanged.
69 EFT_Met,
70 //! Unknown filetype, will be left unchanged.
71 EFT_Unknown,
72 //! This is returned when trying to unpack a broken archive.
73 EFT_Error
77 typedef std::pair<bool, EFileType> UnpackResult;
79 /**
80 * Unpacks a single file from an archive, replacing the archive.
82 * @param file The archive.
83 * @param files An array of filenames (terminated by a NULL entry) which should be unpacked.
84 * @return The first value is true if the archive was unpacked, the second is the resulting filetype.
86 * If the file specified is not an archive, it will be left unchanged and
87 * the file-type returned. If it is a GZip archive, the archive will be
88 * unpacked and the new file will replace the archive. If the archive is a
89 * Zip archive, the first file found matching any in the files array (case-
90 * insensitive) will be unpacked and overwrite the archive.
92 UnpackResult UnpackArchive(const CPath& file, const wxChar* files[]);
94 #endif
95 // File_checked_for_headers