[Ttssh2-commit] [5814] チケット #34943 設定フォルダを開く

svnno****@sourc***** svnno****@sourc*****
2015年 3月 6日 (金) 19:32:44 JST


Revision: 5814
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5814
Author:   yutakapon
Date:     2015-03-06 19:32:40 +0900 (Fri, 06 Mar 2015)
Log Message:
-----------
チケット #34943 設定フォルダを開く

Virtual Store先を開く処理の実装を完成させた。
設定ファイル一覧はこれから作る。

Ticket Links:
------------
    http://sourceforge.jp/projects/ttssh2/tracker/detail/34943

Modified Paths:
--------------
    trunk/teraterm/teraterm/vtwin.cpp

-------------- next part --------------
Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2015-03-05 11:45:24 UTC (rev 5813)
+++ trunk/teraterm/teraterm/vtwin.cpp	2015-03-06 10:32:40 UTC (rev 5814)
@@ -4580,9 +4580,10 @@
 // return TRUE: success
 //        FALSE: failure
 //
-static BOOL openVirtualStore(char *path, int pathlen)
+static BOOL openVirtualStore(char *path, char *filename)
 {
 	BOOL ret = FALSE;
+	int flag = 0;
 	char *s, **p;
 	char *virstore_env[] = {
 		"ProgramFiles",
@@ -4591,12 +4592,19 @@
 		NULL
 	};
 	char shPath[1024] = "";
+	char shFullPath[1024] = "";
 	LPITEMIDLIST pidl;
 	int CSIDL;
 	OSVERSIONINFO osvi;
 	HANDLE          hToken;
 	DWORD           dwLength;
 	TOKEN_ELEVATION tokenElevation;
+	LONG lRet;
+	HKEY hKey;
+	TCHAR lpData[256];
+	DWORD dwDataSize;
+	DWORD dwType;
+	BYTE bValue;
 
 	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
 	GetVersionEx(&osvi);
@@ -4604,21 +4612,47 @@
 	if (!(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion >= 6))
 		goto error;
 
-	// TODO: UAC\x82\xAA\x97L\x8C\xF8\x82\xA9\x82ǂ\xA4\x82\xA9\x81B
+	// UAC\x82\xAA\x97L\x8C\xF8\x82\xA9\x82ǂ\xA4\x82\xA9\x81B
 	// HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\x82\xCCEnableLUA(DWORD\x92l)\x82\xAA0\x82\xA9\x82ǂ\xA4\x82\xA9\x82Ŕ\xBB\x92f\x82ł\xAB\x82܂\xB7(0\x82\xCDUAC\x96\xB3\x8C\xF8\x81A1\x82\xCDUAC\x97L\x8C\xF8)\x81B
+	flag = 0;
+	lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+		TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"),
+		NULL, KEY_QUERY_VALUE, &hKey
+		);
+	if (lRet == ERROR_SUCCESS) {
+		dwDataSize = sizeof(lpData) / sizeof(lpData[0]);
+		lRet = RegQueryValueEx(
+			hKey,
+			TEXT("EnableLUA"),
+			0,
+			&dwType,
+			(LPBYTE)lpData,
+			&dwDataSize);
+		if (lRet == ERROR_SUCCESS) {
+			bValue = ((LPBYTE)lpData)[0];
+			if (bValue == 1)
+				// UAC\x82\xAA\x97L\x8C\xF8\x82̏ꍇ\x81AVirtual Store\x82\xAA\x93\xAD\x82\xAD\x81B
+				flag = 1;
+		}
+		RegCloseKey(hKey);
+	}
+	if (flag == 0)
+		goto error;
 
 	// UAC\x82\xAA\x97L\x8C\xF8\x8E\x9E\x81A\x83v\x83\x8D\x83Z\x83X\x82\xAA\x8AǗ\x9D\x8EҌ\xA0\x8C\xC0\x82ɏ\xB8\x8Ai\x82\xB5\x82Ă\xA2\x82邩\x81B
+	flag = 0;
 	if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_DEFAULT, &hToken)) {
 		if (GetTokenInformation(hToken, TokenElevation, &tokenElevation, sizeof(TOKEN_ELEVATION), &dwLength)) {
 			// (0\x82͏\xB8\x8Ai\x82\xB5\x82Ă\xA2\x82Ȃ\xA2\x81A\x94\xF10\x82͏\xB8\x8Ai\x82\xB5\x82Ă\xA2\x82\xE9)\x81B
-			if (tokenElevation.TokenIsElevated != 0) {
-				// \x8AǗ\x9D\x8EҌ\xA0\x8C\xC0\x82\xF0\x8E\x9D\x82\xC1\x82Ă\xA2\x82\xE9\x82̂ł\xA0\x82\xEA\x82΁AVirtual Store\x82͓\xAD\x82\xA9\x82Ȃ\xA2\x81B
-				CloseHandle(hToken);
-				goto error;
+			if (tokenElevation.TokenIsElevated == 0) {
+				// \x8AǗ\x9D\x8EҌ\xA0\x8C\xC0\x82\xF0\x8E\x9D\x82\xC1\x82Ă\xA2\x82Ȃ\xAF\x82\xEA\x82΁AVirtual Store\x82\xAA\x93\xAD\x82\xAD\x81B
+				flag = 1;
 			}
 		}
 		CloseHandle(hToken);
 	}
+	if (flag == 0)
+		goto error;
 
 	// Virtual Store\x91ΏۂƂȂ\xE9\x83t\x83H\x83\x8B\x83_\x82\xA9\x81B
 	p = virstore_env;
@@ -4648,6 +4682,13 @@
 	if (s != NULL) {
 		strncat_s(shPath, sizeof(shPath), s+1, _TRUNCATE);
 	}
+
+	// \x8DŌ\xE3\x82ɁAVirtual Store\x82Ƀt\x83@\x83C\x83\x8B\x82\xAA\x82\xA0\x82邩\x82ǂ\xA4\x82\xA9\x82𒲂ׂ\xE9\x81B
+	_snprintf_s(shFullPath, sizeof(shFullPath), "%s\\%s", shPath, filename);
+	if (_access(shFullPath, 0) != 0) {
+		goto error;
+	}
+
 	openDirectoryWithExplorer(shPath, sizeof(shPath));
 
 	ret = TRUE;
@@ -4668,12 +4709,13 @@
 void CVTWindow::OnOpenSetupDirectory()
 {
 	char path[MAX_PATH], inipath[MAX_PATH];
-//	char Temp[MAX_PATH];
+	char filename[MAX_PATH];
 
 	// \x90ݒ\xE8\x83t\x83@\x83C\x83\x8B(teraterm.ini)\x82̃p\x83X\x82\xF0\x8E擾\x82\xB7\x82\xE9\x81B
+	ExtractFileName(ts.SetupFName, filename, sizeof(filename));
 	ExtractDirName(ts.SetupFName, inipath);
-	openDirectoryWithExplorer(inipath, sizeof(inipath));
-	//openVirtualStore(inipath, sizeof(inipath));
+	//strcpy(inipath, "C:\\Program Files (x86)\\teraterm");
+	openVirtualStore(inipath, filename);
 
 #if 0
 	// cygterm.cfg



Ttssh2-commit メーリングリストの案内