[Ttssh2-commit] [4506] 不要なコードを整理。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2011年 6月 20日 (月) 09:00:04 JST


Revision: 4506
          http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=4506
Author:   doda
Date:     2011-06-20 09:00:03 +0900 (Mon, 20 Jun 2011)

Log Message:
-----------
不要なコードを整理。

Modified Paths:
--------------
    trunk/teraterm/teraterm/ttermpro.vcproj
    trunk/teraterm/teraterm/winjump.c


-------------- next part --------------
Modified: trunk/teraterm/teraterm/ttermpro.vcproj
===================================================================
--- trunk/teraterm/teraterm/ttermpro.vcproj	2011-06-18 11:57:17 UTC (rev 4505)
+++ trunk/teraterm/teraterm/ttermpro.vcproj	2011-06-20 00:00:03 UTC (rev 4506)
@@ -83,7 +83,7 @@
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
 				AdditionalLibraryDirectories="..\debug"
-				DelayLoadDLLs="imagehlp.dll;user32.dll"
+				DelayLoadDLLs="imagehlp.dll;user32.dll;shell32.dll"
 				GenerateDebugInformation="true"
 				ProgramDatabaseFile="..\Debug/ttermpro.pdb"
 				SubSystem="2"
@@ -183,7 +183,7 @@
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
 				AdditionalLibraryDirectories="..\release"
-				DelayLoadDLLs="imagehlp.dll;user32.dll"
+				DelayLoadDLLs="imagehlp.dll;user32.dll;shell32.dll"
 				GenerateDebugInformation="true"
 				ProgramDatabaseFile="..\Release/ttermpro.pdb"
 				SubSystem="2"

Modified: trunk/teraterm/teraterm/winjump.c
===================================================================
--- trunk/teraterm/teraterm/winjump.c	2011-06-18 11:57:17 UTC (rev 4505)
+++ trunk/teraterm/teraterm/winjump.c	2011-06-20 00:00:03 UTC (rev 4506)
@@ -21,6 +21,8 @@
 #include <windows.h>
 #include <assert.h>
 #include <stdio.h>
+#include <string.h>
+#include <shlobj.h>
 
 #include "winjump.h"
 #include "teraterm.h"
@@ -50,8 +52,6 @@
 #define PropVariantInit(pvar) memset((pvar),0,sizeof(PROPVARIANT))
 #endif
 
-#define IID_IShellLink IID_IShellLinkA
-
 typedef struct ICustomDestinationListVtbl {
     HRESULT ( __stdcall *QueryInterface ) (
         /* [in] ICustomDestinationList*/ void *This,
@@ -237,11 +237,6 @@
 
 } IShellLinkVtbl;
 
-typedef struct IShellLink
-{
-    IShellLinkVtbl *lpVtbl;
-} IShellLink;
-
 typedef struct IObjectCollectionVtbl
 {
     HRESULT ( __stdcall *QueryInterface )(
@@ -364,11 +359,8 @@
     (void **)(void *)((obj) + (sizeof((obj)-(type **)(obj))) \
 		            - (sizeof((obj)-(type **)(obj))))
 
-static char putty_path[2048];
+// LPCWSTR AppID = L"TeraTermProject.TeraTerm.ttermpro";
 
-#define JUMPLISTREG_OK 0
-#define sfree free
-
 static char *IniFile = NULL;
 
 BOOL isJumpListSupported(void)
@@ -386,16 +378,6 @@
 		return TRUE;
 }
 
-int add_to_jumplist_registry(const char *item)
-{
-	return JUMPLISTREG_OK;
-}
-
-int remove_from_jumplist_registry(const char *item)
-{
-	return JUMPLISTREG_OK;
-}
-
 /*
  * Function to make an IShellLink describing a particular PuTTY
  * command. If 'appname' is null, the command run will be the one
@@ -416,16 +398,27 @@
                                    const char *sessionname)
 {
     IShellLink *ret;
-    char *app_path, *param_string, *desc_string;
+    char *app_path, *param_string, *desc_string, *tmp_ptr;
+    static char tt_path[2048];
     //void *psettings_tmp;
     IPropertyStore *pPS;
     PROPVARIANT pv;
+    int len;
 
     /* Retrieve path to executable. */
-    if (!putty_path[0])
-        GetModuleFileName(NULL, putty_path, sizeof(putty_path) - 1);
+    if (!tt_path[0])
+        GetModuleFileName(NULL, tt_path, sizeof(tt_path) - 1);
 
-    app_path = _strdup(putty_path);
+    if (appname) {
+	tmp_ptr = strrchr(tt_path, '\\');
+	len = (tmp_ptr - tt_path) + strlen(appname) + 2;
+	app_path = malloc(len);
+	strncpy_s(app_path, len, tt_path, (tmp_ptr - tt_path + 1));
+	strcat_s(app_path, len, appname);
+    }
+    else {
+	app_path = _strdup(tt_path);
+    }
 
     /* Create the new item. */
     if (!SUCCEEDED(CoCreateInstance(&CLSID_ShellLink, NULL,
@@ -438,37 +431,38 @@
 
 	param_string = _strdup(sessionname);
     ret->lpVtbl->SetArguments(ret, param_string);
-    sfree(param_string);
+    free(param_string);
 
 	desc_string = _strdup("Connect to Tera Term session");
     ret->lpVtbl->SetDescription(ret, desc_string);
-    sfree(desc_string);
+    free(desc_string);
 
     ret->lpVtbl->SetIconLocation(ret, app_path, 0);
 
     /* To set the link title, we require the property store of the link. */
-    if (SUCCEEDED(ret->lpVtbl->QueryInterface(ret,
-                                              COMPTR(IPropertyStore, &pPS)))) {
-        PropVariantInit(&pv);
-        pv.vt = VT_LPSTR;
-        pv.pszVal = _strdup(sessionname);
-        pPS->lpVtbl->SetValue(pPS, &PKEY_Title, &pv);
-        sfree(pv.pszVal);
-        pPS->lpVtbl->Commit(pPS);
-        pPS->lpVtbl->Release(pPS);
+    if (SUCCEEDED(ret->lpVtbl->QueryInterface(ret, COMPTR(IPropertyStore, &pPS)))) {
+	PropVariantInit(&pv);
+	pv.vt = VT_LPSTR;
+	pv.pszVal = _strdup(sessionname);
+	pPS->lpVtbl->SetValue(pPS, &PKEY_Title, &pv);
+	free(pv.pszVal);
+	pPS->lpVtbl->Commit(pPS);
+	pPS->lpVtbl->Release(pPS);
     }
 
-    sfree(app_path);
-
     return ret;
 }
 
 /* Updates jumplist from registry. */
 static void update_jumplist_from_registry(void)
 {
-    const char *piterator;
+    char EntName[128];
+    char TempHost[1024];
+
+    const char *piterator = TempHost;
     UINT num_items;
     UINT nremoved;
+    int i;
 
     /* Variables used by the cleanup code must be initialised to NULL,
      * so that we don't try to free or release them if they were never
@@ -480,11 +474,6 @@
     IObjectArray *pRemoved = NULL;
     int need_abort = FALSE;
 
-	char EntName[128];
-	char TempHost[1024];
-	int i;
-
-
     /*
      * Create an ICustomDestinationList: the top-level object which
      * deals with jump list management.
@@ -506,7 +495,7 @@
         goto cleanup;
     need_abort = TRUE;
     if (!SUCCEEDED(pRemoved->lpVtbl->GetCount(pRemoved, &nremoved)))
-        nremoved = 0;
+	nremoved = 0;
 
     /*
      * Create an object collection to form the 'Recent Sessions'
@@ -521,60 +510,54 @@
      * Go through the jump list entries from the registry and add each
      * one to the collection.
      */
-	i = 1;
-	do {
-		_snprintf_s(EntName, sizeof(EntName), _TRUNCATE, "Host%d", i);
-		GetPrivateProfileString("Hosts",EntName,"",
-		                        TempHost,sizeof(TempHost), IniFile);
-		if ( strlen(TempHost) > 0 ) {
-			piterator = TempHost;
-		} else {
-			continue;
-		}
+    for (i=1; i<=MAX_JUMPLIST_ITEMS; i++) {
+	_snprintf_s(EntName, sizeof(EntName), _TRUNCATE, "Host%d", i);
+	GetPrivateProfileString("Hosts", EntName, "", TempHost, sizeof(TempHost), IniFile);
+	if (strlen(TempHost) == 0) {
+	    break;
+	}
 
-		OutputDebugPrintf("%s\n", piterator);
-        link = make_shell_link(NULL, piterator);
-        if (link) {
-            UINT i;
-            int found;
+	OutputDebugPrintf("%s\n", piterator);
+	link = make_shell_link(NULL, piterator);
+	if (link) {
+	    UINT j;
+	    int found;
 
-            /*
-             * Check that the link isn't in the user-removed list.
-             */
-            for (i = 0, found = FALSE; i < nremoved && !found; i++) {
-                IShellLink *rlink;
-                if (SUCCEEDED(pRemoved->lpVtbl->GetAt
-                              (pRemoved, i, COMPTR(IShellLink, &rlink)))) {
-                    char desc1[2048], desc2[2048];
-                    if (SUCCEEDED(link->lpVtbl->GetDescription
-                                  (link, desc1, sizeof(desc1)-1)) &&
-                        SUCCEEDED(rlink->lpVtbl->GetDescription
-                                  (rlink, desc2, sizeof(desc2)-1)) &&
-                        !strcmp(desc1, desc2)) {
-                        found = TRUE;
-                    }
-                    rlink->lpVtbl->Release(rlink);
-                }
-            }
+	    /*
+	     * Check that the link isn't in the user-removed list.
+	     */
+	    for (j = 0, found = FALSE; j < nremoved && !found; j++) {
+		IShellLink *rlink;
+		if (SUCCEEDED(pRemoved->lpVtbl->GetAt
+			      (pRemoved, j, COMPTR(IShellLink, &rlink)))) {
+		    char desc1[2048], desc2[2048];
+		    if (SUCCEEDED(link->lpVtbl->GetDescription
+		                  (link, desc1, sizeof(desc1)-1)) &&
+		        SUCCEEDED(rlink->lpVtbl->GetDescription
+			          (rlink, desc2, sizeof(desc2)-1)) &&
+		        !strcmp(desc1, desc2)) {
+			found = TRUE;
+		    }
+		    rlink->lpVtbl->Release(rlink);
+		}
+	    }
 
-            if (!found) {
-                collection->lpVtbl->AddObject(collection, link);
-            }
+	    if (!found) {
+		collection->lpVtbl->AddObject(collection, link);
+	    }
 
-            link->lpVtbl->Release(link);
-            link = NULL;
-        }
+	    link->lpVtbl->Release(link);
+	    link = NULL;
+	}
+    }
 
-		i++;
-	} while ((i <= MAX_JUMPLIST_ITEMS) && (strlen(TempHost)>0));
-
     /*
      * Get the array form of the collection we've just constructed,
      * and put it in the jump list.
      */
     if (!SUCCEEDED(collection->lpVtbl->QueryInterface
                    (collection, COMPTR(IObjectArray, &array))))
-        goto cleanup;
+	goto cleanup;
 
     pCDL->lpVtbl->AppendCategory(pCDL, L"Recent Sessions", array);
 
@@ -585,7 +568,7 @@
     if (!SUCCEEDED(CoCreateInstance(&CLSID_EnumerableObjectCollection,
                                     NULL, CLSCTX_INPROC_SERVER,
                                     COMPTR(IObjectCollection, &collection))))
-        goto cleanup;
+	goto cleanup;
 
     /*
      * Get the array form of the collection we've just constructed,
@@ -593,7 +576,7 @@
      */
     if (!SUCCEEDED(collection->lpVtbl->QueryInterface
                    (collection, COMPTR(IObjectArray, &array))))
-        goto cleanup;
+	goto cleanup;
 
     pCDL->lpVtbl->AddUserTasks(pCDL, array);
 
@@ -613,7 +596,7 @@
     if (!SUCCEEDED(CoCreateInstance(&CLSID_EnumerableObjectCollection,
                                     NULL, CLSCTX_INPROC_SERVER,
                                     COMPTR(IObjectCollection, &collection))))
-        goto cleanup;
+	goto cleanup;
 
     /*
      * Get the array form of the collection we've just constructed,
@@ -621,7 +604,7 @@
      */
     if (!SUCCEEDED(collection->lpVtbl->QueryInterface
                    (collection, COMPTR(IObjectArray, &array))))
-        goto cleanup;
+	goto cleanup;
 
     pCDL->lpVtbl->AddUserTasks(pCDL, array);
 
@@ -652,6 +635,17 @@
     if (link) link->lpVtbl->Release(link);
 }
 
+void add_to_recent_docs(const char * const sessionname)
+{
+    IShellLink *link = NULL;
+
+    link = make_shell_link(NULL, sessionname);
+
+    SHAddToRecentDocs(6 /* SHARD_LINK */, link);
+
+    return;
+}
+
 /* Clears the entire jumplist. */
 void clear_jumplist(void)
 {
@@ -659,8 +653,8 @@
 
     if (CoCreateInstance(&CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER,
                          COMPTR(ICustomDestinationList, &pCDL)) == S_OK) {
-        pCDL->lpVtbl->DeleteList(pCDL, NULL);
-        pCDL->lpVtbl->Release(pCDL);
+	pCDL->lpVtbl->DeleteList(pCDL, NULL);
+	pCDL->lpVtbl->Release(pCDL);
     }
 
 }
@@ -669,28 +663,22 @@
 void add_session_to_jumplist(const char * const sessionname, char *inifile)
 {
     if (!isJumpListSupported())
-        return;                        /* do nothing on pre-Win7 systems */
+	return;                        /* do nothing on pre-Win7 systems */
 
+//    add_to_recent_docs(sessionname);
+
     IniFile = inifile;
 
-    if (add_to_jumplist_registry(sessionname) == JUMPLISTREG_OK) {
-        update_jumplist_from_registry();
-    } else {
-        /* Make sure we don't leave the jumplist dangling. */
-        clear_jumplist();
-    }
+    update_jumplist_from_registry();
+    return;
 }
 
 /* Removes a saved session from the Windows jumplist. */
 void remove_session_from_jumplist(const char * const sessionname)
 {
     if (!isJumpListSupported())
-        return;                        /* do nothing on pre-Win7 systems */
+	return;                        /* do nothing on pre-Win7 systems */
 
-    if (remove_from_jumplist_registry(sessionname) == JUMPLISTREG_OK) {
-        update_jumplist_from_registry();
-    } else {
-        /* Make sure we don't leave the jumplist dangling. */
-        clear_jumplist();
-    }
+    update_jumplist_from_registry();
+    return;
 }



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