Revision: 9728 https://osdn.net/projects/ttssh2/scm/svn/commits/9728 Author: zmatsuo Date: 2022-02-06 22:57:00 +0900 (Sun, 06 Feb 2022) Log Message: ----------- IsPortableMode() 追加 - ポータブル版として動作するかを返す Modified Paths: -------------- trunk/cygwin/cygterm/sub.cpp trunk/teraterm/common/ttlib_static_cpp.cpp -------------- next part -------------- Modified: trunk/cygwin/cygterm/sub.cpp =================================================================== --- trunk/cygwin/cygterm/sub.cpp 2022-02-06 13:56:49 UTC (rev 9727) +++ trunk/cygwin/cygterm/sub.cpp 2022-02-06 13:57:00 UTC (rev 9728) @@ -223,8 +223,6 @@ */ BOOL IsPortableMode(void) { - return FALSE; -#if 0 static BOOL called = FALSE; static BOOL ret_val = FALSE; if (called == FALSE) { @@ -260,7 +258,6 @@ } } return ret_val; -#endif } // $APPDATA wchar_t Modified: trunk/teraterm/common/ttlib_static_cpp.cpp =================================================================== --- trunk/teraterm/common/ttlib_static_cpp.cpp 2022-02-06 13:56:49 UTC (rev 9727) +++ trunk/teraterm/common/ttlib_static_cpp.cpp 2022-02-06 13:57:00 UTC (rev 9728) @@ -904,6 +904,35 @@ #define PORTABLE_FILENAME L"portable.ini" +/** + * \x83|\x81[\x83^\x83u\x83\x8B\x94łƂ\xB5\x82ē\xAE\x8D삷\x82邩 + * + * @retval TRUE \x83|\x81[\x83^\x83u\x83\x8B\x94\xC5 + * @retval FALSE \x92ʏ\xED\x83C\x83\x93\x83X\x83g\x81[\x83\x8B\x94\xC5 + */ +BOOL IsPortableMode(void) +{ + static BOOL called = FALSE; + static BOOL ret_val = FALSE; + if (called == FALSE) { + called = TRUE; + wchar_t *exe_dir = GetExeDirW(NULL); + wchar_t *portable_ini = NULL; + awcscats(&portable_ini, exe_dir, L"\\", PORTABLE_FILENAME, NULL); + free(exe_dir); + DWORD r = GetFileAttributesW(portable_ini); + free(portable_ini); + if (r == INVALID_FILE_ATTRIBUTES) { + //\x83t\x83@\x83C\x83\x8B\x82\xAA\x91\xB6\x8D݂\xB5\x82Ȃ\xA2 + ret_val = FALSE; + } + else { + ret_val = TRUE; + } + } + return ret_val; +} + /* * Get home directory * \x8Cl\x97p\x90ݒ\xE8\x83t\x83@\x83C\x83\x8B\x83t\x83H\x83\x8B\x83_\x8E擾 @@ -920,21 +949,17 @@ */ wchar_t *GetHomeDirW(HINSTANCE hInst) { - wchar_t *path; - wchar_t *ret = NULL; - wchar_t *ExeDirW = GetExeDirW(hInst); - wchar_t *portable_file = NULL; - struct _stat s; - awcscats(&portable_file, ExeDirW, L"\\" PORTABLE_FILENAME, NULL); - if (_wstat(portable_file, &s) == 0) { - free(portable_file); - return ExeDirW; + if (IsPortableMode()) { + return GetExeDirW(hInst); } - free(portable_file); - _SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &path); - awcscats(&ret, path, L"\\teraterm5", NULL); - free(path); - return ret; + else { + wchar_t *path; + wchar_t *ret = NULL; + _SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &path); + awcscats(&ret, path, L"\\teraterm5", NULL); + free(path); + return ret; + } } /* @@ -951,23 +976,20 @@ */ wchar_t* GetLogDirW(HINSTANCE hInst) { - wchar_t *path; wchar_t *ret = NULL; - wchar_t *ExeDirW = GetExeDirW(hInst); - wchar_t *portable_file = NULL; - struct _stat s; - awcscats(&portable_file, ExeDirW, L"\\" PORTABLE_FILENAME, NULL); - if (_wstat(portable_file, &s) == 0) { + if (IsPortableMode()) { + wchar_t *ExeDirW = GetExeDirW(hInst); awcscats(&ret, ExeDirW, L"\\log", NULL); - free(portable_file); free(ExeDirW); return ret; } - free(portable_file); - _SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &path); - awcscats(&ret, path, L"\\teraterm5", NULL); - free(path); - return ret; + else { + wchar_t *path; + _SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &path); + awcscats(&ret, path, L"\\teraterm5", NULL); + free(path); + return ret; + } } /*