[fdo-commits] r661 - in branches/3.2.x/Utilities/Common: Inc Src

svn_fdo at osgeo.org svn_fdo at osgeo.org
Wed Jan 24 15:49:10 EST 2007


Author: gregboone
Date: 2007-01-24 15:49:10 -0500 (Wed, 24 Jan 2007)
New Revision: 661

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

Modified: branches/3.2.x/Utilities/Common/Inc/FdoCommonFile.h
===================================================================
--- branches/3.2.x/Utilities/Common/Inc/FdoCommonFile.h	2007-01-24 20:43:07 UTC (rev 660)
+++ branches/3.2.x/Utilities/Common/Inc/FdoCommonFile.h	2007-01-24 20:49:10 UTC (rev 661)
@@ -586,6 +586,16 @@
 	static bool IsAbsolutePath(const wchar_t *pFilename);
 
     /// \brief
+    /// Determines the directory and filename parts from the specified path.
+    /// 
+    /// \param path 
+    /// The path.
+    /// 
+    /// Returns nothing.
+    /// 
+    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: branches/3.2.x/Utilities/Common/Src/FdoCommonFile.cpp
===================================================================
--- branches/3.2.x/Utilities/Common/Src/FdoCommonFile.cpp	2007-01-24 20:43:07 UTC (rev 660)
+++ branches/3.2.x/Utilities/Common/Src/FdoCommonFile.cpp	2007-01-24 20:49:10 UTC (rev 661)
@@ -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