Update of /cvsroot/jsmooth/jsmooth/skeletons/util-core
In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv17420
Modified Files:
FileUtils.cpp FileUtils.h
Log Message:
added fileExists(string,string), getParent() and readFile() methods
Index: FileUtils.cpp
===================================================================
RCS file: /cvsroot/jsmooth/jsmooth/skeletons/util-core/FileUtils.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** FileUtils.cpp 2 Apr 2007 22:11:44 -0000 1.3
--- FileUtils.cpp 28 Apr 2007 08:47:27 -0000 1.4
***************
*** 49,52 ****
--- 49,58 ----
}
+ bool FileUtils::fileExists(const std::string& path, const std::string& filename)
+ {
+ std::string f = FileUtils::concFile(path, filename);
+ return fileExists(f);
+ }
+
vector<string> FileUtils::recursiveSearch(const string& pathdir, const string& pattern)
{
***************
*** 117,120 ****
--- 123,138 ----
}
+ std::string FileUtils::getParent(const std::string &path)
+ {
+ if (path[path.length()-1] == '\\')
+ return getParent( path.substr(0, path.size() - 1) );
+
+ int pos = path.rfind('\\', path.npos);
+ if (pos != path.npos)
+ return path.substr(0, pos+1);
+ else
+ return path;
+ }
+
std::string FileUtils::getComputerName()
{
***************
*** 159,160 ****
--- 177,208 ----
MoveFileEx(file.c_str(), 0, MOVEFILE_DELAY_UNTIL_REBOOT);
}
+
+ std::string FileUtils::readFile(const std::string& filename)
+ {
+ HANDLE f = CreateFile(filename.c_str(), GENERIC_READ,
+ FILE_SHARE_READ, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+
+ std::string result;
+
+ if (f != INVALID_HANDLE_VALUE)
+ {
+ char buffer[129];
+ DWORD hasread;
+ buffer[127] = 0;
+
+ do {
+ ReadFile(f, buffer, 127, &hasread, NULL);
+ buffer[hasread] = 0;
+ result += buffer;
+ } while (hasread > 0);
+
+ CloseHandle(f);
+ }
+ else
+ {
+ // printf("Can't open file %s\n",filename.c_str());
+ }
+
+ return result;
+ }
Index: FileUtils.h
===================================================================
RCS file: /cvsroot/jsmooth/jsmooth/skeletons/util-core/FileUtils.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** FileUtils.h 2 Apr 2007 22:11:44 -0000 1.3
--- FileUtils.h 28 Apr 2007 08:47:27 -0000 1.4
***************
*** 56,59 ****
--- 56,61 ----
static bool fileExists(const string& filename);
+ static bool fileExists(const std::string&path, const string& filename);
+
/**
* Lookup recursively for files matching a given pattern in a given
***************
*** 89,92 ****
--- 91,97 ----
static std::string getExecutablePath();
+
+ static std::string getParent(const std::string &path);
+
/**
* Returns the name of the executable binary that was used to start
***************
*** 112,115 ****
--- 117,122 ----
static bool isAbsolute(const std::string& filename);
+ static std::string readFile(const std::string& filename);
+
static void deleteOnReboot(std::string file);
|