[Ttssh2-commit] [4671] getspecialfolder マクロコマンドを追加

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2011年 10月 13日 (木) 19:23:09 JST


Revision: 4671
          http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=4671
Author:   maya
Date:     2011-10-13 19:23:09 +0900 (Thu, 13 Oct 2011)

Log Message:
-----------
getspecialfolder マクロコマンドを追加

Modified Paths:
--------------
    trunk/teraterm/common/helpid.h
    trunk/teraterm/ttpmacro/ttl.c
    trunk/teraterm/ttpmacro/ttmlib.c
    trunk/teraterm/ttpmacro/ttmlib.h
    trunk/teraterm/ttpmacro/ttmparse.c
    trunk/teraterm/ttpmacro/ttmparse.h


-------------- next part --------------
Modified: trunk/teraterm/common/helpid.h
===================================================================
--- trunk/teraterm/common/helpid.h	2011-10-13 10:22:39 UTC (rev 4670)
+++ trunk/teraterm/common/helpid.h	2011-10-13 10:23:09 UTC (rev 4671)
@@ -221,6 +221,7 @@
 #define HlpMacroCommandGetfileattr      92189
 #define HlpMacroCommandGethostname      92141
 #define HlpMacroCommandGetpassword      92046
+#define HlpMacroCommandGetspecialfolder 92195
 #define HlpMacroCommandGettime          92047
 #define HlpMacroCommandGettitle         92048
 #define HlpMacroCommandGetttdir         92140

Modified: trunk/teraterm/ttpmacro/ttl.c
===================================================================
--- trunk/teraterm/ttpmacro/ttl.c	2011-10-13 10:22:39 UTC (rev 4670)
+++ trunk/teraterm/ttpmacro/ttl.c	2011-10-13 10:23:09 UTC (rev 4671)
@@ -2069,6 +2069,30 @@
 	return Err;
 }
 
+WORD TTLGetSpecialFolder()
+{
+	WORD Err;
+	TVarId VarId;
+	TStrVal type;
+	int result;
+
+	Err = 0;
+	GetStrVar(&VarId,&Err);
+	if (Err!=0) return Err;
+
+	GetStrVal(type,&Err);
+	if ((Err==0) && (GetFirstChar()!=0))
+		Err = ErrSyntax;
+	if (Err!=0) {
+		return Err;
+	}
+
+	result = GetSpecialFolder(StrVarPtr(VarId), sizeof(TStrVal), type);
+	SetResult(result);
+
+	return Err;
+}
+
 WORD TTLGetTime(WORD mode)
 {
 	WORD Err;
@@ -4887,6 +4911,8 @@
 			Err = TTLGetHostname(); break;
 		case RsvGetPassword:
 			Err = TTLGetPassword(); break;
+		case RsvGetSpecialFolder:
+			Err = TTLGetSpecialFolder(); break;
 		case RsvGetTitle:
 			Err = TTLGetTitle(); break;
 		case RsvGetTTDir:

Modified: trunk/teraterm/ttpmacro/ttmlib.c
===================================================================
--- trunk/teraterm/ttpmacro/ttmlib.c	2011-10-13 10:22:39 UTC (rev 4670)
+++ trunk/teraterm/ttpmacro/ttmlib.c	2011-10-13 10:23:09 UTC (rev 4671)
@@ -8,7 +8,8 @@
 #include "ttlib.h"
 #include <string.h>
 #include <direct.h>
-
+#include <Shlobj.h>
+#include <stdio.h>
 static char CurrentDir[MAXPATHLEN];
 
 void CalcTextExtent(HDC DC, PCHAR Text, LPSIZE s)
@@ -84,3 +85,134 @@
   strncat_s(FName,destlen,Temp,_TRUNCATE);
   return TRUE;
 }
+
+int DoGetSpecialFolder(int CSIDL, PCHAR KEY, PCHAR dest, int dest_len)
+{
+	OSVERSIONINFO osvi;
+	LONG result;
+	HKEY hKey;
+	DWORD disposition, len, type;
+
+	char Path[MAX_PATH] = "";
+	LPITEMIDLIST pidl;
+
+	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+	GetVersionEx(&osvi);
+	if ( (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion == 4) ||
+	     (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) ) {
+		switch (CSIDL) {
+			case CSIDL_COMMON_DESKTOPDIRECTORY:
+			case CSIDL_COMMON_STARTMENU:
+			case CSIDL_COMMON_PROGRAMS:
+			case CSIDL_COMMON_STARTUP:
+				return 0;
+		}
+		result = RegCreateKeyEx(HKEY_CURRENT_USER,
+		                        "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
+		                        0,
+		                        "",
+		                        REG_OPTION_NON_VOLATILE,
+		                        KEY_READ,
+		                        NULL,
+		                        &hKey,
+		                        &disposition);
+		if (result != ERROR_SUCCESS) {
+			return 0;
+		}
+
+		len = sizeof(Path);
+		result = RegQueryValueEx(hKey, KEY, NULL, &type, Path, &len);
+		if (result != ERROR_SUCCESS) {
+			return 0;
+		}
+
+		RegCloseKey(hKey);
+	}
+	else {
+		if (SHGetSpecialFolderLocation(NULL, CSIDL, &pidl) != NOERROR) {
+			return 0;
+		}
+
+		SHGetPathFromIDList(pidl, Path);
+		CoTaskMemFree(pidl);
+	}
+
+	strncpy_s(dest, dest_len, Path, _TRUNCATE);
+	return 1;
+}
+
+int GetSpecialFolder(PCHAR dest, int dest_len, PCHAR type)
+{
+	int CSIDL;
+	char REGKEY[256];
+
+	if (_stricmp(type, "AllUsersDesktop") == 0) {
+		CSIDL = CSIDL_COMMON_DESKTOPDIRECTORY;
+		strncpy_s(REGKEY, sizeof(REGKEY), "", _TRUNCATE);
+	}
+	else if (_stricmp(type, "AllUsersStartMenu") == 0) {
+		CSIDL = CSIDL_COMMON_STARTMENU;
+		strncpy_s(REGKEY, sizeof(REGKEY), "", _TRUNCATE);
+	}
+	else if (_stricmp(type, "AllUsersPrograms") == 0) {
+		CSIDL = CSIDL_COMMON_PROGRAMS;
+		strncpy_s(REGKEY, sizeof(REGKEY), "", _TRUNCATE);
+	}
+	else if (_stricmp(type, "AllUsersStartup") == 0) {
+		CSIDL = CSIDL_COMMON_STARTUP;
+		strncpy_s(REGKEY, sizeof(REGKEY), "", _TRUNCATE);
+	}
+	else if (_stricmp(type, "Desktop") == 0) {
+		CSIDL = CSIDL_DESKTOPDIRECTORY;
+		strncpy_s(REGKEY, sizeof(REGKEY), "Desktop", _TRUNCATE);
+	}
+	else if (_stricmp(type, "Favorites") == 0) {
+		CSIDL = CSIDL_FAVORITES;
+		strncpy_s(REGKEY, sizeof(REGKEY), "Favorites", _TRUNCATE);
+	}
+	else if (_stricmp(type, "Fonts") == 0) {
+		CSIDL = CSIDL_FONTS;
+		strncpy_s(REGKEY, sizeof(REGKEY), "Fonts", _TRUNCATE);
+	}
+	else if (_stricmp(type, "MyDocuments") == 0) {
+		CSIDL = CSIDL_PERSONAL;
+		strncpy_s(REGKEY, sizeof(REGKEY), "Personal", _TRUNCATE);
+	}
+	else if (_stricmp(type, "NetHood") == 0) {
+		CSIDL = CSIDL_NETHOOD;
+		strncpy_s(REGKEY, sizeof(REGKEY), "NetHood", _TRUNCATE);
+	}
+	else if (_stricmp(type, "PrintHood") == 0) {
+		CSIDL = CSIDL_PRINTHOOD;
+		strncpy_s(REGKEY, sizeof(REGKEY), "PrintHood", _TRUNCATE);
+	}
+	else if (_stricmp(type, "Programs") == 0) {
+		CSIDL = CSIDL_PROGRAMS;
+		strncpy_s(REGKEY, sizeof(REGKEY), "Programs", _TRUNCATE);
+	}
+	else if (_stricmp(type, "Recent") == 0) {
+		CSIDL = CSIDL_RECENT;
+		strncpy_s(REGKEY, sizeof(REGKEY), "Recent", _TRUNCATE);
+	}
+	else if (_stricmp(type, "SendTo") == 0) {
+		CSIDL = CSIDL_SENDTO;
+		strncpy_s(REGKEY, sizeof(REGKEY), "SendTo", _TRUNCATE);
+	}
+	else if (_stricmp(type, "StartMenu") == 0) {
+		CSIDL = CSIDL_STARTMENU;
+		strncpy_s(REGKEY, sizeof(REGKEY), "Start Menu", _TRUNCATE);
+	}
+	else if (_stricmp(type, "Startup") == 0) {
+		CSIDL = CSIDL_STARTUP;
+		strncpy_s(REGKEY, sizeof(REGKEY), "Startup", _TRUNCATE);
+	}
+	else if (_stricmp(type, "Templates") == 0) {
+		CSIDL = CSIDL_TEMPLATES;
+		strncpy_s(REGKEY, sizeof(REGKEY), "Templates", _TRUNCATE);
+	}
+
+	if (!DoGetSpecialFolder(CSIDL, REGKEY, dest, dest_len)) {
+		return 0;
+	}
+	return 1;
+}

Modified: trunk/teraterm/ttpmacro/ttmlib.h
===================================================================
--- trunk/teraterm/ttpmacro/ttmlib.h	2011-10-13 10:22:39 UTC (rev 4670)
+++ trunk/teraterm/ttpmacro/ttmlib.h	2011-10-13 10:23:09 UTC (rev 4671)
@@ -14,6 +14,7 @@
 void TTMGetDir(PCHAR Dir, int destlen);
 void TTMSetDir(PCHAR Dir);
 int GetAbsPath(PCHAR FName, int destlen);
+int GetSpecialFolder(PCHAR Text);
 
 #ifdef __cplusplus
 }

Modified: trunk/teraterm/ttpmacro/ttmparse.c
===================================================================
--- trunk/teraterm/ttpmacro/ttmparse.c	2011-10-13 10:22:39 UTC (rev 4670)
+++ trunk/teraterm/ttpmacro/ttmparse.c	2011-10-13 10:23:09 UTC (rev 4671)
@@ -223,6 +223,7 @@
 		else if (_stricmp(Str,"getfileattr")==0) *WordId = RsvGetFileAttr;
 		else if (_stricmp(Str,"gethostname")==0) *WordId = RsvGetHostname;
 		else if (_stricmp(Str,"getpassword")==0) *WordId = RsvGetPassword;
+		else if (_stricmp(Str,"getspecialfolder")==0) *WordId = RsvGetSpecialFolder;
 		else if (_stricmp(Str,"gettime")==0) *WordId = RsvGetTime;
 		else if (_stricmp(Str,"gettitle")==0) *WordId = RsvGetTitle;
 		else if (_stricmp(Str,"getttdir")==0) *WordId = RsvGetTTDir;

Modified: trunk/teraterm/ttpmacro/ttmparse.h
===================================================================
--- trunk/teraterm/ttpmacro/ttmparse.h	2011-10-13 10:22:39 UTC (rev 4670)
+++ trunk/teraterm/ttpmacro/ttmparse.h	2011-10-13 10:23:09 UTC (rev 4671)
@@ -217,6 +217,7 @@
 #define RsvFolderDelete 192
 #define RsvFolderSearch 193
 #define RsvExpandEnv    194
+#define RsvGetSpecialFolder  195
 
 #define RsvOperator     1000
 #define RsvBNot         1001



Ttssh2-commit メーリングリストの案内
Back to archive index