Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

fileutil.cpp

Go to the documentation of this file.
00001 /* 00002 * wxChecksums 00003 * Copyright (C) 2003-2004 Julien Couot 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 /** 00021 * \file fileutil.cpp 00022 * File utilities. 00023 */ 00024 00025 00026 //--------------------------------------------------------------------------- 00027 // For compilers that support precompilation, includes "wx.h". 00028 #include <wx/wxprec.h> 00029 00030 #ifdef __BORLANDC__ 00031 #pragma hdrstop 00032 #endif 00033 00034 #ifndef WX_PRECOMP 00035 // Include your minimal set of headers here, or wx.h 00036 #include <wx/wx.h> 00037 #endif 00038 #include <wx/filename.h> 00039 00040 #include "fileutil.hpp" 00041 #include "checksumfactory.hpp" 00042 #include "fdftlmk.hpp" 00043 #include "sumfile.hpp" 00044 #include "md5file.hpp" 00045 #include "sfvfile.hpp" 00046 00047 #include "compat.hpp" 00048 //--------------------------------------------------------------------------- 00049 00050 00051 /// The C++ standard namespace. 00052 using namespace std; 00053 00054 00055 /** 00056 * Gets a filter for the known types of checksums' files. 00057 * 00058 * - First entry contains all known types of checksums' files. 00059 * - Next entries are all the known types listed in the order defined in the 00060 * <CODE>SumFileFactory::SumFileType</CODE> enumeration. 00061 * - Last entry is all the files. 00062 * 00063 * @return A filter for the known types of checksums' files. 00064 */ 00065 wxFileDialogFilterMaker getFilterForKnownTypesOfChecksumsFiles() 00066 { 00067 wxFileDialogFilterMaker fltMaker; 00068 fltMaker.AddFilter(_("Known checksums files"), wxT("sfv|md5")); 00069 for (int i = 0; i < SumFileFactory::getSumFilesCount(); i++) 00070 fltMaker.AddFilter(SumFileFactory::getSumFileDescription(i), SumFileFactory::getSumFileExtension(i)); 00071 fltMaker.AddFilter(_("All the files"), wxT("*")); 00072 00073 return fltMaker; 00074 } 00075 //--------------------------------------------------------------------------- 00076 00077 00078 /** 00079 * Opens and read the given checksum file. 00080 * 00081 * This function tries to choose the checksum file format with : 00082 * - The file extension first. 00083 * - The order of priority next (tries all the known formats). 00084 * 00085 * The caller must delete the returned object with the operator 00086 * <CODE>delete</CODE>. 00087 * 00088 * @param fileName Name of the file to open. 00089 * @return A pointer on the checksum file that is been read or 00090 * <CODE>NULL</CODE> on failure. The caller must delete the returned 00091 * object with the operator <CODE>delete</CODE>. 00092 */ 00093 SumFile* openChecksumFile(const wxFileName& fileName) 00094 { 00095 if (::wxDirExists(fileName.GetFullPath())) 00096 // File is a directory, bye. 00097 return NULL; 00098 00099 bool hasTrySFV = false; 00100 bool hasTryMD5 = false; 00101 wxString ext = fileName.GetExt(); 00102 00103 if (ext.CmpNoCase(wxT("sfv")) == 0) 00104 { 00105 hasTrySFV = true; 00106 SFVFile* f = new SFVFile(); 00107 if (f->read(fileName)) 00108 return f; 00109 else 00110 delete f; 00111 } 00112 else if (ext.CmpNoCase(wxT("md5")) == 0) 00113 { 00114 hasTryMD5 = true; 00115 MD5File* f = new MD5File(); 00116 if (f->read(fileName)) 00117 return f; 00118 else 00119 delete f; 00120 } 00121 00122 if (!hasTryMD5) 00123 { 00124 hasTryMD5 = true; 00125 MD5File* f = new MD5File(); 00126 if (f->read(fileName)) 00127 return f; 00128 else 00129 delete f; 00130 } 00131 00132 if (!hasTrySFV) 00133 { 00134 hasTrySFV = true; 00135 SFVFile* f = new SFVFile(); 00136 if (f->read(fileName)) 00137 return f; 00138 else 00139 delete f; 00140 } 00141 00142 return NULL; 00143 } 00144 //---------------------------------------------------------------------------

Generated on Sun May 30 13:37:44 2004 for wxChecksums by doxygen 1.3.7