svnno****@sourc*****
svnno****@sourc*****
2014年 10月 1日 (水) 14:47:10 JST
Revision: 5671 http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5671 Author: maya Date: 2014-10-01 14:46:33 +0900 (Wed, 01 Oct 2014) Log Message: ----------- Cygwin のインストール先を探す方法を変更した Modified Paths: -------------- trunk/cygterm/cyglaunch.c trunk/installer/cygtool/cygtool.c trunk/installer/release/TERATERM.INI trunk/teraterm/teraterm/vtwin.cpp -------------- next part -------------- Modified: trunk/cygterm/cyglaunch.c =================================================================== --- trunk/cygterm/cyglaunch.c 2014-10-01 05:12:16 UTC (rev 5670) +++ trunk/cygterm/cyglaunch.c 2014-10-01 05:46:33 UTC (rev 5671) @@ -23,7 +23,7 @@ // void OnCygwinConnection(char *CygwinDirectory, char *cmdline) { - char file[MAX_PATH]; + char file[MAX_PATH], *filename; char c, *envptr, *envbuff; int envbufflen; char *exename = "cygterm.exe"; @@ -31,38 +31,31 @@ STARTUPINFO si; PROCESS_INFORMATION pi; - envptr = getenv("PATH"); - if (strstr(envptr, "cygwin\\bin") != NULL) { - goto found_path; + if (strlen(CygwinDirectory) > 0) { + if (SearchPath(CygwinDirectory, "bin\\cygwin1", ".dll", sizeof(file), file, &filename) > 0) { + goto found_dll; + } } - if (strstr(envptr, "cygwin64\\bin") != NULL) { + + if (SearchPath(NULL, "cygwin1", ".dll", sizeof(file), file, &filename) > 0) { goto found_path; } - _snprintf(file, MAX_PATH, "%s\\bin", CygwinDirectory); - if (GetFileAttributes(file) != -1) { // open success - goto found_dll; - } - - strcpy(file, "C:\\cygwin\\bin"); for (c = 'C' ; c <= 'Z' ; c++) { - file[0] = c; - if (GetFileAttributes(file) != -1) { // open success + char tmp[MAX_PATH]; + sprintf(tmp, "%c:\\cygwin\\bin;%c:\\cygwin64\\bin", c, c); + if (SearchPath(tmp, "cygwin1", ".dll", sizeof(file), file, &filename) > 0) { goto found_dll; } } - strcpy(file, "C:\\cygwin64\\bin"); - for (c = 'C' ; c <= 'Z' ; c++) { - file[0] = c; - if (GetFileAttributes(file) != -1) { // open success - goto found_dll; - } - } MessageBox(NULL, "Can't find Cygwin directory.", "ERROR", MB_OK | MB_ICONWARNING); return; found_dll:; + envptr = getenv("PATH"); + file[strlen(file)-12] = '\0'; // delete "\\cygwin1.dll" + MessageBox(NULL, file, "a", MB_OK); if (envptr != NULL) { envbufflen = strlen(file) + strlen(envptr) + 7; // "PATH="(5) + ";"(1) + NUL(1) if ((envbuff=malloc(envbufflen)) == NULL) { Modified: trunk/installer/cygtool/cygtool.c =================================================================== --- trunk/installer/cygtool/cygtool.c 2014-10-01 05:12:16 UTC (rev 5670) +++ trunk/installer/cygtool/cygtool.c 2014-10-01 05:46:33 UTC (rev 5671) @@ -7,67 +7,44 @@ int __stdcall FindCygwinPath(char *CygwinDirectory, char *Dir, int Dirlen) { - char c, *envptr, *p, *p2; + char file[MAX_PATH], *filename; + char c; - envptr = getenv("PATH"); - if (envptr == NULL) { - return 0; - } + if (strlen(CygwinDirectory) > 0) { + if (SearchPath(CygwinDirectory, "bin\\cygwin1", ".dll", sizeof(file), file, &filename) > 0) { #ifdef EXE - printf(" PATH => %s\n", envptr); + printf(" %s from CygwinDirectory\n", file); #endif - if ((p = strstr(envptr, "cygwin\\bin")) != NULL) { - goto found_path; + goto found_dll; + } } - if ((p = strstr(envptr, "cygwin64\\bin")) != NULL) { - goto found_path; - } - _snprintf_s(Dir, Dirlen, _TRUNCATE, "%s\\bin", CygwinDirectory); - if (GetFileAttributes(Dir) != -1) { // open success + if (SearchPath(NULL, "cygwin1", ".dll", sizeof(file), file, &filename) > 0) { +#ifdef EXE + printf(" %s from PATH\n", file); goto found_dll; +#endif } - _snprintf_s(Dir, Dirlen, _TRUNCATE, "C:\\cygwin\\bin"); for (c = 'C' ; c <= 'Z' ; c++) { - Dir[0] = c; - if (GetFileAttributes(Dir) != -1) { // open success + char tmp[MAX_PATH]; + sprintf(tmp, "%c:\\cygwin\\bin;%c:\\cygwin64\\bin", c, c); + if (SearchPath(tmp, "cygwin1", ".dll", sizeof(file), file, &filename) > 0) { +#ifdef EXE + printf(" %s from %c:\\\n", file, c); +#endif goto found_dll; } } - _snprintf_s(Dir, Dirlen, _TRUNCATE, "C:\\cygwin64\\bin"); - for (c = 'C' ; c <= 'Z' ; c++) { - Dir[0] = c; - if (GetFileAttributes(Dir) != -1) { // open success - goto found_dll; - } - } return 0; found_dll:; - Dir[strlen(Dir)-4] = '\0'; // delete "\\bin" - return 1; - -found_path:; - if ((p2 = strchr(p, ';')) == NULL) { - p2 += strlen(p); + memset(Dir, '\0', Dirlen); + if (Dirlen <= strlen(file) - 16) { + return 0; } - else { - p2--; - } - while (envptr < p) { - p--; - if (*p == ';') { - p++; - break; - } - } - strncpy_s(Dir, Dirlen, p, _TRUNCATE); - if (p2 - p < Dirlen-1) { - Dir[p2 - p + 1] = '\0'; - } - Dir[strlen(Dir)-4] = '\0'; // delete "\\bin" + memcpy(Dir, file, strlen(file) - 16); // delete "\\bin\\cygwin1.dll" return 1; } @@ -157,7 +134,7 @@ int res; printf("FindCygwinPath()\n"); - res = FindCygwinPath("C:\\cygwin", file, file_len); + res = FindCygwinPath("", file, file_len); printf(" result => %d\n", res); if (!res) { printf("\n"); Modified: trunk/installer/release/TERATERM.INI =================================================================== --- trunk/installer/release/TERATERM.INI 2014-10-01 05:12:16 UTC (rev 5670) +++ trunk/installer/release/TERATERM.INI 2014-10-01 05:46:33 UTC (rev 5671) @@ -103,7 +103,7 @@ AlphaBlend=255 ; Cygwin install path -CygwinDirectory=c:\cygwin +CygwinDirectory= ; Viewlog Editor path ViewlogEditor=notepad.exe Modified: trunk/teraterm/teraterm/vtwin.cpp =================================================================== --- trunk/teraterm/teraterm/vtwin.cpp 2014-10-01 05:12:16 UTC (rev 5670) +++ trunk/teraterm/teraterm/vtwin.cpp 2014-10-01 05:46:33 UTC (rev 5671) @@ -3727,7 +3727,7 @@ // void CVTWindow::OnCygwinConnection() { - char file[MAX_PATH]; + char file[MAX_PATH], *filename; char c, *envptr, *envbuff=NULL; int envbufflen; char *exename = "cygterm.exe"; @@ -3736,33 +3736,23 @@ PROCESS_INFORMATION pi; char uimsg[MAX_UIMSG]; - envptr = getenv("PATH"); - if (strstr(envptr, "cygwin\\bin") != NULL) { - goto found_path; + if (strlen(ts.CygwinDirectory) > 0) { + if (SearchPath(ts.CygwinDirectory, "bin\\cygwin1", ".dll", sizeof(file), file, &filename) > 0) { + goto found_dll; + } } - if (strstr(envptr, "cygwin64\\bin") != NULL) { + + if (SearchPath(NULL, "cygwin1", ".dll", sizeof(file), file, &filename) > 0) { goto found_path; } - _snprintf_s(file, sizeof(file), _TRUNCATE, "%s\\bin", ts.CygwinDirectory); - if (GetFileAttributes(file) != -1) { // open success - goto found_dll; - } - - _snprintf_s(file, sizeof(file), _TRUNCATE, "C:\\cygwin\\bin"); for (c = 'C' ; c <= 'Z' ; c++) { - file[0] = c; - if (GetFileAttributes(file) != -1) { // open success + char tmp[MAX_PATH]; + sprintf(tmp, "%c:\\cygwin\\bin;%c:\\cygwin64\\bin", c, c); + if (SearchPath(tmp, "cygwin1", ".dll", sizeof(file), file, &filename) > 0) { goto found_dll; } } - _snprintf_s(file, sizeof(file), _TRUNCATE, "C:\\cygwin64\\bin"); - for (c = 'C' ; c <= 'Z' ; c++) { - file[0] = c; - if (GetFileAttributes(file) != -1) { // open success - goto found_dll; - } - } get_lang_msg("MSG_ERROR", uimsg, sizeof(uimsg), "ERROR", ts.UILanguageFile); get_lang_msg("MSG_FIND_CYGTERM_DIR_ERROR", ts.UIMsg, sizeof(ts.UIMsg), @@ -3771,6 +3761,8 @@ return; found_dll:; + envptr = getenv("PATH"); + file[strlen(file)-12] = '\0'; // delete "\\cygwin1.dll" if (envptr != NULL) { envbufflen = strlen(file) + strlen(envptr) + 7; // "PATH="(5) + ";"(1) + NUL(1) if ((envbuff = (char *)malloc(envbufflen)) == NULL) {