From: qwerty2501 Date: Thu, 9 Feb 2012 13:30:26 +0000 (+0900) Subject: プロパティファイル作成周りの更新 X-Git-Tag: v0.002~2^2~12 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=361ec599ffc3f57061441a07bdc2dc8d166d75a5;p=nlite%2Fnlite.git プロパティファイル作成周りの更新 --- diff --git a/nlite.suo b/nlite.suo index bc610d1..6fbcf6e 100644 Binary files a/nlite.suo and b/nlite.suo differ diff --git a/nlite/nlite_common.cpp b/nlite/nlite_common.cpp index fcf96b1..84710f7 100644 --- a/nlite/nlite_common.cpp +++ b/nlite/nlite_common.cpp @@ -57,10 +57,69 @@ Property nliteProperty; BOOL SurelyCreate(LPCTSTR dir,BOOL bFile){ + + BOOL rslt = FALSE; + std::vector 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; diff --git a/nlite/nlite_property.cpp b/nlite/nlite_property.cpp index 888130b..9bf41c6 100644 --- a/nlite/nlite_property.cpp +++ b/nlite/nlite_property.cpp @@ -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("Ý’èƒtƒ@ƒCƒ‹ì¬‚ÉŽ¸”s‚µ‚Ü‚µ‚½"),__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("Ý’èƒtƒ@ƒCƒ‹ì¬‚ÉŽ¸”s‚µ‚Ü‚µ‚½"),__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("Ý’èƒtƒ@ƒCƒ‹ì¬‚ÉŽ¸”s‚µ‚Ü‚µ‚½"),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__)); - - } - - - CloseHandle(hPropertyxml); - - } + SurelyCreate(propertyPath,TRUE); + return; }