[ttssh2-commit] [9836] インストーラ内でのcygwinのパスの扱いをUnicode文字列に変更

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2022年 3月 25日 (金) 22:38:40 JST


Revision: 9836
          https://osdn.net/projects/ttssh2/scm/svn/commits/9836
Author:   zmatsuo
Date:     2022-03-25 22:38:40 +0900 (Fri, 25 Mar 2022)
Log Message:
-----------
インストーラ内でのcygwinのパスの扱いをUnicode文字列に変更

- r9832
- ticket #44171

Revision Links:
--------------
    https://osdn.net/projects/ttssh2/scm/svn/commits/9832

Ticket Links:
------------
    https://osdn.net/projects/ttssh2/tracker/detail/44171

Modified Paths:
--------------
    trunk/cygwin/CMakeLists.txt
    trunk/cygwin/cygtool/CMakeLists.txt
    trunk/cygwin/cygtool/cygtool.c
    trunk/installer/teraterm.iss

Added Paths:
-----------
    trunk/cygwin/cygtool/cygtool.h
    trunk/cygwin/cygtool/cygtool_tester.c

-------------- next part --------------
Modified: trunk/cygwin/CMakeLists.txt
===================================================================
--- trunk/cygwin/CMakeLists.txt	2022-03-25 13:32:47 UTC (rev 9835)
+++ trunk/cygwin/CMakeLists.txt	2022-03-25 13:38:40 UTC (rev 9836)
@@ -8,12 +8,33 @@
   cyglib
   PROPERTIES FOLDER cygwin)
 
-add_subdirectory(cygtool_build)
-set_target_properties(
-  cygtool_build
-  PROPERTIES FOLDER cygwin)
+if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+  # 32bit build
+  add_subdirectory(cygtool)
 
-add_subdirectory(cygterm_build)
-set_target_properties(
-  cygterm_build
-  PROPERTIES FOLDER cygwin)
+  set_target_properties(
+    cygtool
+    PROPERTIES
+    FOLDER cygwin
+    )
+  set_target_properties(
+    cygtool_tester
+    PROPERTIES
+    FOLDER cygwin
+    )
+else()
+  # 64bit build
+  if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0")
+    add_subdirectory(cygtool_build)
+    set_target_properties(
+      cygtool_build
+      PROPERTIES FOLDER cygwin)
+  endif()
+endif()
+
+if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0")
+  add_subdirectory(cygterm_build)
+  set_target_properties(
+    cygterm_build
+    PROPERTIES FOLDER cygwin)
+endif()

Modified: trunk/cygwin/cygtool/CMakeLists.txt
===================================================================
--- trunk/cygwin/cygtool/CMakeLists.txt	2022-03-25 13:32:47 UTC (rev 9835)
+++ trunk/cygwin/cygtool/CMakeLists.txt	2022-03-25 13:38:40 UTC (rev 9836)
@@ -1,6 +1,6 @@
 cmake_minimum_required(VERSION 3.11)
 
-set(PACKAGE_NAME "cygtool_dll")
+set(PACKAGE_NAME "cygtool")
 
 project(${PACKAGE_NAME})
 
@@ -54,19 +54,6 @@
   version
   )
 
-set_target_properties(
-  ${PACKAGE_NAME}
-  PROPERTIES
-  PREFIX ""
-  OUTPUT_NAME "cygtool"
-  )
-
-set_target_properties(
-  ${PACKAGE_NAME}
-  PROPERTIES
-  FOLDER installer
-  )
-
 target_include_directories(
   ${PACKAGE_NAME}
   PRIVATE
@@ -78,56 +65,26 @@
   DESTINATION .
   )
 
-if(false)
-  add_executable(
-    cygtool_exe
-    cygtool.c
-    )
+install(
+  TARGETS ${PACKAGE_NAME}
+  DESTINATION .
+  )
 
-  target_compile_options(
-    cygtool_exe
-    PRIVATE
-    -D EXE
-    -I ${CMAKE_CURRENT_LIST_DIR}/../../teraterm/common
-    )
+###### cygtool_tester
 
-  target_link_libraries(
-    cygtool_exe
-    PRIVATE
-    version
-    )
+add_executable(
+  cygtool_tester
+  cygtool_tester.c
+  )
 
-  set_target_properties(
-    cygtool_exe
-    PROPERTIES
-    OUTPUT_NAME "cygtool"
-    )
+target_compile_options(
+  cygtool_tester
+  PRIVATE
+  -I ${CMAKE_CURRENT_LIST_DIR}/../../teraterm/common
+  )
 
-  set_target_properties(
-    cygtool_exe
-    PROPERTIES
-    FOLDER installer
-    )
-endif()
-
-if(false)
-  add_custom_target(
-    cygtool ALL
-    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/cygtool.dll
-    )
-
-  file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cygtool_build)
-
-  add_custom_command(
-    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cygtool.dll
-    COMMAND ${CMAKE_COMMAND} -DCMAKE_GENERATOR=${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -P ${CMAKE_CURRENT_LIST_DIR}/cygtool/build_cygtool.cmake
-    COMMAND ${CMAKE_COMMAND} -E echo ${CMAKE_GENERATOR}
-    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cygtool_build
-    COMMENT Generate "${CMAKE_CURRENT_BINARY_DIR}/cygtool.dll"
-    )
-endif()
-
-install(
-  TARGETS ${PACKAGE_NAME}
-  DESTINATION .
+target_link_libraries(
+  cygtool_tester
+  PRIVATE
+  ${PACKAGE_NAME}
   )

Modified: trunk/cygwin/cygtool/cygtool.c
===================================================================
--- trunk/cygwin/cygtool/cygtool.c	2022-03-25 13:32:47 UTC (rev 9835)
+++ trunk/cygwin/cygtool/cygtool.c	2022-03-25 13:38:40 UTC (rev 9836)
@@ -1,11 +1,40 @@
+/*
+ * Copyright (C) 2014- TeraTerm Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
 
-#define _CRT_SECURE_NO_WARNINGS
 #include <windows.h>
 #include <stdio.h>
+#include <wchar.h>
 
-int __stdcall FindCygwinPath(char *CygwinDirectory, char *Dir, int Dirlen)
+#include "cygtool.h"
+
+int __stdcall FindCygwinPath(const wchar_t *CygwinDirectory, wchar_t *Dir, size_t Dirlen)
 {
-	char file[MAX_PATH], *filename;
+	wchar_t file[MAX_PATH], *filename;
 	char c;
 
 	/* zero-length string from Inno Setup is NULL */
@@ -13,30 +42,21 @@
 		goto search_path;
 	}
 
-	if (strlen(CygwinDirectory) > 0) {
-		if (SearchPath(CygwinDirectory, "bin\\cygwin1", ".dll", sizeof(file), file, &filename) > 0) {
-#ifdef EXE
-			printf("  %s from CygwinDirectory\n", file);
-#endif
+	if (CygwinDirectory[0] != 0) {
+		if (SearchPathW(CygwinDirectory, L"bin\\cygwin1", L".dll", _countof(file), file, &filename) > 0) {
 			goto found_dll;
 		}
 	}
 
 search_path:;
-	if (SearchPath(NULL, "cygwin1", ".dll", sizeof(file), file, &filename) > 0) {
-#ifdef EXE
-		printf("  %s from PATH\n", file);
-#endif
+	if (SearchPathW(NULL, L"cygwin1", L".dll", _countof(file), file, &filename) > 0) {
 		goto found_dll;
 	}
 
 	for (c = 'C' ; c <= 'Z' ; c++) {
-		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
+		wchar_t tmp[MAX_PATH];
+		swprintf(tmp, _countof(tmp), L"%c:\\cygwin\\bin;%c:\\cygwin64\\bin", c, c);
+		if (SearchPathW(tmp, L"cygwin1", L".dll", _countof(file), file, &filename) > 0) {
 			goto found_dll;
 		}
 	}
@@ -44,15 +64,15 @@
 	return 0;
 
 found_dll:;
-	memset(Dir, '\0', Dirlen);
-	if (Dirlen <= strlen(file) - 16) {
+	wmemset(Dir, '\0', Dirlen);
+	if (Dirlen <= wcslen(file) - 16) {
 		return 0;
 	}
-	memcpy(Dir, file, strlen(file) - 16); // delete "\\bin\\cygwin1.dll"
+	wmemcpy(Dir, file, wcslen(file) - 16); // delete "\\bin\\cygwin1.dll"
 	return 1;
 }
 
-int __stdcall PortableExecutableMachine(char *file)
+int __stdcall PortableExecutableMachine(const wchar_t *file)
 {
 	FILE *fp;
 	unsigned char buf[4];
@@ -59,7 +79,7 @@
 	long e_lfanew;
 	WORD Machine;
 
-	if ((fp = fopen(file, "rb")) == NULL) {
+	if (_wfopen_s(&fp, file, L"rb") != 0) {
 		return IMAGE_FILE_MACHINE_UNKNOWN;
 	}
 
@@ -73,9 +93,6 @@
 		return IMAGE_FILE_MACHINE_UNKNOWN;
 	}
 	e_lfanew = buf[0] + (buf[1] << 8) + (buf[1] << 16) + (buf[1] << 24);
-#ifdef EXE
-	printf("  e_lfanew => x%08x\n", e_lfanew);
-#endif
 
 	// IMAGE_NT_HEADERS32
 	//   DWORD Signature;
@@ -95,7 +112,7 @@
 	return Machine;
 }
 
-int __stdcall CygwinVersion(char *dll, int *major, int *minor)
+int __stdcall CygwinVersion(const wchar_t *dll, int *major, int *minor)
 {
 	DWORD dwSize;
 	DWORD dwHandle;
@@ -103,18 +120,18 @@
 	UINT uLen;
 	VS_FIXEDFILEINFO *pFileInfo;
 
-	dwSize = GetFileVersionInfoSize(dll, &dwHandle);
+	dwSize = GetFileVersionInfoSizeW(dll, &dwHandle);
 	if (dwSize == 0) {
 		return 0;
 	}
 
 	lpBuf = malloc(dwSize);
-	if (!GetFileVersionInfo(dll, dwHandle, dwSize, lpBuf)) {
+	if (!GetFileVersionInfoW(dll, dwHandle, dwSize, lpBuf)) {
 		free(lpBuf);
 		return 0;
 	}
 
-	if (!VerQueryValue(lpBuf, "\\", (LPVOID*)&pFileInfo, &uLen)) {
+	if (!VerQueryValueW(lpBuf, L"\\", (LPVOID*)&pFileInfo, &uLen)) {
 		free(lpBuf);
 		return 0;
 	}
@@ -127,59 +144,6 @@
 	return 1;
 }
 
-#ifdef EXE
-int main(void)
-{
-	char file[MAX_PATH];
-	char version[MAX_PATH];
-	int file_len = sizeof(file);
-	int version_major, version_minor;
-	int res;
-
-	printf("FindCygwinPath()\n");
-	res = FindCygwinPath("", file, file_len);
-	printf("  result => %d\n", res);
-	if (!res) {
-		printf("\n");
-		return -1;
-	}
-	printf("  Cygwin directory => %s\n", file);
-	printf("\n");
-
-	printf("PortableExecutableMachine()\n");
-	strncat_s(file, sizeof(file), "\\bin\\cygwin1.dll", _TRUNCATE);
-	printf("  Cygwin DLL => %s\n", file);
-	res = PortableExecutableMachine(file);
-	printf("  Machine => x%04x", res);
-	switch (res) {
-		case IMAGE_FILE_MACHINE_I386:
-			printf(" = %s\n", "IMAGE_FILE_MACHINE_I386");
-			break;
-		case IMAGE_FILE_MACHINE_AMD64:
-			printf(" = %s\n", "IMAGE_FILE_MACHINE_AMD64");
-			break;
-		default:
-			printf("\n");
-			return -1;
-			break;
-	}
-	printf("\n");
-
-	printf("CygwinVersion()\n");
-	printf("  Cygwin DLL => %s\n", file);
-	res = CygwinVersion(file, &version_major, &version_minor);
-	printf("  result => %d\n", res);
-	if (!res) {
-	printf("\n");
-		return -1;
-	}
-	printf("  version_major => %d\n", version_major);
-	printf("  version_minor => %d\n", version_minor);
-	printf("\n");
-
-	return 0;
-}
-#else
 BOOL WINAPI DllMain(HANDLE hInstance,
 		    ULONG ul_reason_for_call,
 		    LPVOID lpReserved)
@@ -200,4 +164,3 @@
   }
   return TRUE;
 }
-#endif

Added: trunk/cygwin/cygtool/cygtool.h
===================================================================
--- trunk/cygwin/cygtool/cygtool.h	                        (rev 0)
+++ trunk/cygwin/cygtool/cygtool.h	2022-03-25 13:38:40 UTC (rev 9836)
@@ -0,0 +1,4 @@
+
+int __stdcall FindCygwinPath(const wchar_t *CygwinDirectory, wchar_t *Dir, size_t Dirlen);
+int __stdcall PortableExecutableMachine(const wchar_t *file);
+int __stdcall CygwinVersion(const wchar_t *dll, int *major, int *minor);

Added: trunk/cygwin/cygtool/cygtool_tester.c
===================================================================
--- trunk/cygwin/cygtool/cygtool_tester.c	                        (rev 0)
+++ trunk/cygwin/cygtool/cygtool_tester.c	2022-03-25 13:38:40 UTC (rev 9836)
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2022- TeraTerm Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// cygtool.c \x82\xA9\x82番\x97\xA3
+
+#include <windows.h>
+#include <stdio.h>
+#include <wchar.h>
+
+#include "cygtool.h"
+
+int main(void)
+{
+	wchar_t file[MAX_PATH];
+	size_t file_len = _countof(file);
+	int version_major, version_minor;
+	int res;
+
+	printf("FindCygwinPath()\n");
+	res = FindCygwinPath(L"", file, file_len);
+	printf("  result => %d\n", res);
+	if (!res) {
+		printf("\n");
+		return -1;
+	}
+	printf("  Cygwin directory => %ls\n", file);
+	printf("\n");
+
+	printf("PortableExecutableMachine()\n");
+	wcsncat_s(file, _countof(file), L"\\bin\\cygwin1.dll", _TRUNCATE);
+	printf("  Cygwin DLL => %ls\n", file);
+	res = PortableExecutableMachine(file);
+	printf("  Machine => x%04x", res);
+	switch (res) {
+		case IMAGE_FILE_MACHINE_I386:
+			printf(" = %s\n", "IMAGE_FILE_MACHINE_I386");
+			break;
+		case IMAGE_FILE_MACHINE_AMD64:
+			printf(" = %s\n", "IMAGE_FILE_MACHINE_AMD64");
+			break;
+		default:
+			printf("\n");
+			return -1;
+			break;
+	}
+	printf("\n");
+
+	printf("CygwinVersion()\n");
+	printf("  Cygwin DLL => %ls\n", file);
+	res = CygwinVersion(file, &version_major, &version_minor);
+	printf("  result => %d\n", res);
+	if (!res) {
+	printf("\n");
+		return -1;
+	}
+	printf("  version_major => %d\n", version_major);
+	printf("  version_minor => %d\n", version_minor);
+	printf("\n");
+
+	return 0;
+}

Modified: trunk/installer/teraterm.iss
===================================================================
--- trunk/installer/teraterm.iss	2022-03-25 13:32:47 UTC (rev 9835)
+++ trunk/installer/teraterm.iss	2022-03-25 13:38:40 UTC (rev 9836)
@@ -336,10 +336,10 @@
 procedure SHChangeNotify(wEventId, uFlags, dwItem1, dwItem2: Integer);
 external 'SHCha****@shell***** stdcall';
 
-function FindCygwinPath(CygwinDirectory: AnsiString; CygwinDir: AnsiString; Dirlen: Cardinal): Integer;
+function FindCygwinPath(CygwinDirectory: String; CygwinDir: String; Dirlen: Cardinal): Integer;
 external 'FindCygwinPath @ files:cygtool.dll stdcall setuponly';
 
-function PortableExecutableMachine(CygwinDir: AnsiString): Integer;
+function PortableExecutableMachine(CygwinDir: String): Integer;
 external 'PortableExecutableMachine @ files:cygtool.dll stdcall setuponly';
 
 var
@@ -751,8 +751,8 @@
 procedure CurStepChanged(CurStep: TSetupStep);
 var
   iniFile : String;
-  CygDir  : AnsiString;
-  CygPath : AnsiString;
+  CygDir  : String;
+  CygPath : String;
   CygDll  : String;
   Cygterm : String;
   Res     : Integer;


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