00001 #include "stdafx.h"
00002 #include "logger.h"
00003
00004 #include "string"
00005 #include "algorithm"
00006
00007 #include "globals.h"
00008 extern Globals global_vars;
00009
00010 bool existsFile( const char * src_name)
00011 {
00012 std::ifstream input_file( src_name, std::ios_base::in);
00013 if ( !input_file.is_open())
00014 return false;
00015
00016 input_file.close();
00017 return true;
00018 }
00019
00020 int makeFileCopy( const char * src_name, const char * dst_name)
00021 {
00022 char buff[4096];
00023
00024 std::ifstream input_file( src_name, std::ios_base::in);
00025 std::ofstream output_file( dst_name, std::ios_base::out);
00026 if ( !input_file.is_open())
00027 return 2;
00028 if ( !output_file.is_open())
00029 return 3;
00030
00031 while ( !input_file.eof())
00032 {
00033 input_file.read( buff, 4096);
00034 output_file.write( buff, input_file.gcount());
00035 }
00036
00037 input_file.close();
00038 output_file.close();
00039 return 1;
00040 }
00041
00042 int makeFileMove( const char * src_name, const char * dst_name)
00043 {
00044 if( !fileExists( src_name)) return 1;
00045
00046 BOOL dres = TRUE;
00047 if( fileExists( dst_name))
00048 {
00049 dres = DeleteFile( dst_name);
00050 }
00051
00052 if( !dres) return 0;
00053
00054
00055 dres = MoveFile( src_name, dst_name);
00056 return dres == TRUE? 1: 0;
00057 }
00058
00059
00060 bool fileExists( const char * file)
00061 {
00062 bool res = false;
00063 CFileStatus stat;
00064 if( file
00065 && CFile::GetStatus( file, stat))
00066 {
00067 if( (stat.m_attribute & CFile::directory) == 0
00068 && (stat.m_attribute & CFile::readOnly) == 0)
00069 {
00070 res = true;
00071 }
00072 }
00073
00074 return res;
00075 }
00076
00077 std::string shortFileName( const std::string& long_name)
00078 {
00079 std::string::size_type pos = long_name.rfind( '\\');
00080 if ( pos != std::string::npos)
00081 {
00082 std::string short_name;
00083 if ( pos + 1 < long_name.length())
00084 short_name = long_name.substr( pos + 1);
00085 else
00086 short_name = "insert_your_specialized_header_filename_here.h";
00087
00088 return short_name;
00089 }
00090
00091 return long_name;
00092 }
00093
00094 std::string cutExtension( const std::string& filename)
00095 {
00096 std::string::size_type p = filename.rfind( ".");
00097 if ( p != std::string::npos)
00098 return filename.substr( 0, p);
00099
00100 return filename;
00101 }
00102
00103 std::string capitalizeString( const std::string& name)
00104 {
00105 std::string capitalized_name = name;
00106 std::transform( capitalized_name.begin(), capitalized_name.end(), capitalized_name.begin(), toupper);
00107 return capitalized_name;
00108 }
00109
00110 bool directoryExists( const char * dir)
00111 {
00112 bool res = false;
00113 CFileStatus stat;
00114 if( dir
00115 && CFile::GetStatus( dir, stat))
00116 {
00117 if( (stat.m_attribute & CFile::directory) == CFile::directory
00118 && (stat.m_attribute & CFile::readOnly) == 0)
00119 {
00120 res = true;
00121 }
00122 }
00123
00124 return res;
00125 }
00126
00127 bool directoryCreate( const char * dir)
00128 {
00129 return CreateDirectory( dir, NULL) == TRUE;
00130 }