OSDN Git Service

プロパティファイル作成周りの更新
authorqwerty2501 <riot313@gmail.com>
Thu, 9 Feb 2012 13:30:26 +0000 (22:30 +0900)
committerqwerty2501 <riot313@gmail.com>
Thu, 9 Feb 2012 13:30:26 +0000 (22:30 +0900)
nlite.suo
nlite/nlite_common.cpp
nlite/nlite_property.cpp

index bc610d1..6fbcf6e 100644 (file)
Binary files a/nlite.suo and b/nlite.suo differ
index fcf96b1..84710f7 100644 (file)
@@ -57,10 +57,69 @@ Property nliteProperty;
 
  BOOL SurelyCreate(LPCTSTR dir,BOOL bFile){
 
+        
+
         BOOL rslt = FALSE;
+        std::vector<TCHAR> buf(_tcslen(dir) + 1);
+        _tcscpy(&buf[0],dir);
+
+
+        if( (PathFileExists(dir) && (!bFile || !::PathIsDirectory( dir )))){
+
+                goto success;
+        }
+
+        LPTSTR startPtr = &buf[0];
+        LPTSTR indexPtr = startPtr;
+        LPTSTR cmpPtr;
+        do {
+
+                cmpPtr = _tcsstr(indexPtr,TEXT("\\"));
+
+                if(cmpPtr == NULL){
+                       
+                        if(bFile == TRUE){
+                               CAtlFile file;
+                               if( file.Create(startPtr,0,0,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL) != S_OK){
+
+                                       goto err;
+
+                               }
+                        } else {
+
+                                ::CreateDirectory(startPtr,0);
+                        }
+
+                        break;
 
 
+                }else if(indexPtr == cmpPtr){
+                        break;
+
+                }
+
+                cmpPtr[0] = TEXT('\0');
+                ::CreateDirectory(startPtr,0);
+                cmpPtr[0] = TEXT('\\');
+                cmpPtr++;
+                indexPtr = cmpPtr;
+                
+
+        }while(indexPtr[0] != TEXT('\0'));
+
+success:
+
+
+        rslt = TRUE;
+
+end:
+
         return rslt;
+
+
+err:
+        rslt = FALSE;
+        goto end;
  }
 
 const CApplicationInfo * appInfo = NULL;
index 888130b..9bf41c6 100644 (file)
@@ -172,46 +172,30 @@ namespace nlite{
 
        VOID Property::CreatePropertyFile(){
 
-               propertyPath = appLocalPath;
-
-               propertyPath += TEXT("\\qwerty_nico");
-
-               if(PathIsDirectory(propertyPath) == FALSE){
-
-                       if(CreateDirectory(propertyPath,NULL) == 0){
-                               throw Exception(TEXT("\90Ý\92è\83t\83@\83C\83\8b\8dì\90¬\82É\8e¸\94s\82µ\82Ü\82µ\82½"),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
-                       }
-
-               }
+               CString iniFile;
+               iniFile = appLocalPath;
+               iniFile += TEXT("\\qwerty_nico\\nlite.ini");
+               SurelyCreate(iniFile,TRUE);
+               
 
-               propertyPath += TEXT("\\nlite");
+               TCHAR propertyBuf[_MAX_PATH];
+               LPCTSTR sectionName = TEXT("property");
+               LPCTSTR keyName = TEXT("dir");
+               ::GetPrivateProfileString(sectionName,keyName,TEXT(""),propertyBuf,ARRAY_LENGTH(propertyBuf),iniFile);
 
-               if(PathIsDirectory(propertyPath) == FALSE){
+               if((_tcslen(propertyBuf) == 0) || !((PathFileExists(propertyBuf) &&  !::PathIsDirectory( propertyBuf )))){
+                       propertyPath = appLocalPath;
+                       propertyPath += TEXT("\\qwerty_nico\\nlite\\property.xml");
 
-                       if(CreateDirectory(propertyPath,NULL) == 0){
-                               throw Exception(TEXT("\90Ý\92è\83t\83@\83C\83\8b\8dì\90¬\82É\8e¸\94s\82µ\82Ü\82µ\82½"),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
-                       }
+                       ::WritePrivateProfileString(sectionName,keyName,propertyPath,iniFile);
+               } else {
+                       propertyPath = propertyBuf;
 
                }
 
-               propertyPath += TEXT("\\property.xml");
-
-
-               if(PathFileExists(propertyPath)== FALSE || PathIsDirectory(propertyPath) == TRUE){
-
-                       HANDLE hPropertyxml =   CreateFile(propertyPath,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
-
-                       if(hPropertyxml == INVALID_HANDLE_VALUE ){
-
-                               throw Exception(TEXT("\90Ý\92è\83t\83@\83C\83\8b\8dì\90¬\82É\8e¸\94s\82µ\82Ü\82µ\82½"),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
-
-                       }
-
-
-                       CloseHandle(hPropertyxml);
-
-               }
+               SurelyCreate(propertyPath,TRUE);
 
+               
                return;
        }