• Main Page
  • Classes
  • Files
  • File List
  • File Members

Beesnest/Windows/DcFileUtil.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2007 Erez Bibi (erezbibi@users.sourceforge.net)
00003 This file is part of Beesnest.
00004 
00005 Beesnest is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 Beesnest 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 Beesnest; if not, write to the Free Software
00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 */
00019 
00020 /**
00021  * CdcFileUtil.cpp: implementation of the CdcFileUtil class.
00022  * for documentation see the header file.
00023  */
00024 
00025 #include "DcFileUtil.h"
00026 
00027 CdcString CdcFileUtil::sWorkPath;
00028 
00029 bool CdcFileUtil::OpenFile (const CdcString& file_name)
00030 {
00031     isFileFound = (stat (file_name.GetBuffer (), &oFileStatus) == 0);
00032     return isFileFound;
00033 }
00034 
00035 
00036 CdcHttpTime CdcFileUtil::GetFileLastModified (bool gmt)
00037 {
00038     if (isFileFound == false)
00039         throw (CdcExceptionFile ("File not found",
00040         DC_FILE_NOT_FOUND_EXP));
00041 
00042     return CdcHttpTime ((time_t)oFileStatus.st_mtime, gmt);
00043 }
00044 
00045 int CdcFileUtil::GetFileSize ()
00046 {
00047     if (isFileFound == false)
00048         throw (CdcExceptionFile ("File not found",
00049         DC_FILE_NOT_FOUND_EXP));
00050 
00051     return oFileStatus.st_size;
00052 }
00053 
00054 
00055 CdcString CdcFileUtil::GetProgramPath ()
00056 {
00057     if (sWorkPath.IsEmpty ())
00058     {
00059         char temp [BUFF_LEN];
00060         GetModuleFileName (0, temp, BUFF_LEN);
00061         *(strrchr (temp, '\\') + 1) = '\0';
00062         sWorkPath = temp;
00063     }
00064     return sWorkPath;
00065 }
00066 
00067 CdcString CdcFileUtil::GetWorkPath (const CdcString& path)
00068 {
00069     if (strlen (path) > 1 && path[1] == ':')
00070         return path;
00071     return GetProgramPath() + path;
00072 }
00073 
00074 
00075 
00076 t_files_vector CdcFileUtil::GetAllFilesInDir (const CdcString& dir_path,
00077                                               const CdcString& file_ext)
00078 {
00079     WIN32_FIND_DATA file_data;
00080     t_files_vector file_vct;
00081     CdcString files = dir_path + "*." + file_ext;
00082     int ret;
00083 
00084     /* Find the first file. */
00085     HANDLE hnd = FindFirstFile (files.GetBuffer (), &file_data);
00086     if (hnd == INVALID_HANDLE_VALUE)
00087         throw (CdcExceptionFile ("Cannot open files", DC_FILE_EXP));
00088 
00089     do
00090     {
00091         file_vct.push_back (dir_path + file_data.cFileName);
00092         /* End find the next one. */
00093         ret = FindNextFile (hnd, &file_data);
00094     }
00095     while (ret != 0);
00096 
00097     FindClose (hnd);
00098     return file_vct;
00099 }
00100 

Generated on Mon Oct 11 2010 16:23:25 for Beesnest by  doxygen 1.7.2