00001
00002
00003
00004
00005
00006 #include "vmsFileUtil.h"
00007 #include <shlobj.h>
00008
00009 void vmsFileUtil::MakePathOK(LPSTR szPath, bool bNeedBackslashAtEnd)
00010 {
00011 LPSTR psz = szPath;
00012 while (*psz)
00013 {
00014 if (*psz == '/')
00015 *psz = '\\';
00016 psz++;
00017 }
00018
00019 if (bNeedBackslashAtEnd && psz [-1] != '\\')
00020 {
00021 psz [0] = '\\';
00022 psz [1] = 0;
00023 }
00024 }
00025
00026 void vmsFileUtil::GetAppDataPath(LPCSTR pszAppName, LPSTR szPath)
00027 {
00028 LPITEMIDLIST pidl = NULL;
00029 SHGetSpecialFolderLocation (NULL, CSIDL_APPDATA, &pidl);
00030 SHGetPathFromIDList (pidl, szPath);
00031
00032 vmsFileUtil::MakePathOK (szPath);
00033 lstrcat (szPath, pszAppName);
00034 lstrcat (szPath, "\\");
00035 }
00036
00037 void vmsFileUtil::BuildPathToFile(LPCSTR pszPathName)
00038 {
00039 BuildPath (GetPathFromPathName (pszPathName));
00040 }
00041
00042 fsString vmsFileUtil::GetPathFromPathName(LPCSTR pszPathName)
00043 {
00044 char szPath [MAX_PATH];
00045 lstrcpy (szPath, pszPathName);
00046 MakePathOK (szPath, false);
00047 LPSTR psz = strrchr (szPath, '\\');
00048 if (psz == NULL)
00049 return "";
00050 *psz = 0;
00051 return szPath;
00052 }
00053
00054 void vmsFileUtil::BuildPath(LPCSTR pszPath)
00055 {
00056 char szPath [MAX_PATH];
00057 lstrcpy (szPath, pszPath);
00058 MakePathOK (szPath, true);
00059 LPSTR psz = szPath;
00060 if (psz [1] == ':')
00061 psz += 3;
00062
00063 while (*psz)
00064 {
00065 char szPathNow [MAX_PATH];
00066 psz = strchr (psz, '\\') + 1;
00067 lstrcpyn (szPathNow, szPath, psz - szPath);
00068 if (FALSE == CreateDirectory (szPathNow, NULL) &&
00069 ERROR_ALREADY_EXISTS != GetLastError ())
00070 throw GetLastError ();
00071 }
00072 }