[fdo-commits] r662 - in trunk/Utilities/Common: Inc Src

svn_fdo at osgeo.org svn_fdo at osgeo.org
Wed Jan 24 16:01:04 EST 2007


Author: gregboone
Date: 2007-01-24 16:01:04 -0500 (Wed, 24 Jan 2007)
New Revision: 662

Modified:
   trunk/Utilities/Common/Inc/FdoCommonFile.h
   trunk/Utilities/Common/Src/FdoCommonFile.cpp
Log:
Add new Method: FdoCommonFile::GetFileDirectoryAndName(const wchar_t *location, FdoStringP& directory, FdoStringP& filename)

Modified: trunk/Utilities/Common/Inc/FdoCommonFile.h
===================================================================
--- trunk/Utilities/Common/Inc/FdoCommonFile.h	2007-01-24 20:49:10 UTC (rev 661)
+++ trunk/Utilities/Common/Inc/FdoCommonFile.h	2007-01-24 21:01:04 UTC (rev 662)
@@ -557,6 +557,7 @@
     /// \param path 
     /// The relative path.
     /// 
+    /// \return
     /// Returns absolute path if can be transformed or passed parameter
     /// otherwise.
     /// 
@@ -580,12 +581,25 @@
     /// \param path 
     /// The path.
     /// 
+    /// \return
     /// Returns true if the specified name points to an absolute directory and false
     /// otherwise.
     /// 
 	static bool IsAbsolutePath(const wchar_t *pFilename);
 
     /// \brief
+    /// Determines the directory and filename parts from the specified path.
+    /// 
+    /// \param path 
+    /// The path.
+    /// 
+    /// \return
+    /// Returns true if the specified loaction points to a directory and false
+    /// otherwise.
+    /// 
+    static bool GetFileDirectoryAndName(const wchar_t *location, FdoStringP& directory, FdoStringP& name);
+
+    /// \brief
     /// Changes the read-write access mode of a file.
     /// On Windows this sets/clears the read-only flag.
     /// On Linux this only sets/clears the file's owner write flag.

Modified: trunk/Utilities/Common/Src/FdoCommonFile.cpp
===================================================================
--- trunk/Utilities/Common/Src/FdoCommonFile.cpp	2007-01-24 20:49:10 UTC (rev 661)
+++ trunk/Utilities/Common/Src/FdoCommonFile.cpp	2007-01-24 21:01:04 UTC (rev 662)
@@ -1129,6 +1129,59 @@
 #endif
 }
 
+bool FdoCommonFile::GetFileDirectoryAndName(const wchar_t *location, FdoStringP& directory, FdoStringP& filename)
+{
+#ifndef _WIN32
+    struct stat my_stat;
+    char* mbLocation = NULL;
+    wide_to_multibyte(mbLocation, location);
+    if (0 != stat (mbLocation, &my_stat))
+        return false;
+#else
+    DWORD attributes = GetFileAttributesW (location);
+    if ((INVALID_FILE_ATTRIBUTES == attributes))
+        return false;
+#endif
+
+    // Extract the file name and path from location. There are two kinds of delimiters, 
+    // The last one appears would be selected to extract the file name.
+    // e.g. location1="c:\\path1/test.bmp", index would be set at "/".
+    const wchar_t* pdest = wcsrchr(location, FILE_PATH_DELIMITER); // L'\\'
+    const wchar_t* pdest2 = wcsrchr(location, FILE_PATH_DELIMITER2); // L'/'
+
+    int index = (int)(pdest - location);
+    int index2 = (int)(pdest2 - location);
+
+    if (index2 > index) {
+        index = index2;
+        pdest = pdest2;
+    }
+
+    // extract the filename
+    if (pdest) {
+        wchar_t lfilename[500];
+#ifdef _WIN32            
+        wcscpy_s(lfilename, 500, pdest + 1);
+#else
+        lfilename = pdest+1;
+#endif
+        filename = lfilename;
+    }
+
+    // extract the directory name
+    if (index) {
+        wchar_t path[500];
+#ifdef _WIN32            
+        wcsncpy_s(path, 500, location, index);
+#else
+        wcsncpy(path, location, index);
+#endif
+        directory = path;
+    }
+
+    return true;
+}
+
 void FdoCommonFile::Chmod(FdoString* filePath, bool bReadWrite)
 {
 #ifdef _WIN32



More information about the fdo-commits mailing list