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;
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;
}