[ttssh2-commit] [9727] ポータブル版のフォルダを考慮

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2022年 2月 6日 (日) 22:56:49 JST


Revision: 9727
          https://osdn.net/projects/ttssh2/scm/svn/commits/9727
Author:   zmatsuo
Date:     2022-02-06 22:56:49 +0900 (Sun, 06 Feb 2022)
Log Message:
-----------
ポータブル版のフォルダを考慮

- ポータブル版の判定
  - ExeDirW() (exe があるフォルダ)に portable.ini というファイルがあるとき
- ポータブル版の時の動作
  - HomeDirW() は ExeDirW() と同じフォルダを返す
  - LogDirW() は ExeDirW() + "\log" を返す

ticket #43493

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

Modified Paths:
--------------
    trunk/installer/makearchive.bat
    trunk/teraterm/common/ttlib.h
    trunk/teraterm/common/ttlib_static_cpp.cpp
    trunk/teraterm/teraterm/ttdebug.cpp
    trunk/teraterm/ttpcmn/ttcmn.c
    trunk/ttssh2/ttxssh/ttxssh.c

-------------- next part --------------
Modified: trunk/installer/makearchive.bat
===================================================================
--- trunk/installer/makearchive.bat	2022-02-06 04:16:30 UTC (rev 9726)
+++ trunk/installer/makearchive.bat	2022-02-06 13:56:49 UTC (rev 9727)
@@ -98,6 +98,7 @@
 
 if "%release%"=="yes" (
 copy nul %dst%\ttpmenu.ini
+copy nul %dst%\portable.ini
 )
 
 exit /b

Modified: trunk/teraterm/common/ttlib.h
===================================================================
--- trunk/teraterm/common/ttlib.h	2022-02-06 04:16:30 UTC (rev 9726)
+++ trunk/teraterm/common/ttlib.h	2022-02-06 13:56:49 UTC (rev 9727)
@@ -94,7 +94,7 @@
 wchar_t *GetDownloadFolderW(void);
 wchar_t *GetHomeDirW(HINSTANCE hInst);
 wchar_t *GetExeDirW(HINSTANCE hInst);
-wchar_t* GetLogDirW(void);
+wchar_t* GetLogDirW(HINSTANCE hInst);
 wchar_t *GetDefaultFNameW(const wchar_t *home, const wchar_t *file);
 wchar_t *GetDefaultSetupFNameW(const wchar_t *home);
 void GetUILanguageFileFull(const char *HomeDir, const char *UILanguageFileRel,

Modified: trunk/teraterm/common/ttlib_static_cpp.cpp
===================================================================
--- trunk/teraterm/common/ttlib_static_cpp.cpp	2022-02-06 04:16:30 UTC (rev 9726)
+++ trunk/teraterm/common/ttlib_static_cpp.cpp	2022-02-06 13:56:49 UTC (rev 9727)
@@ -902,13 +902,18 @@
 	return dir;
 }
 
+#define PORTABLE_FILENAME L"portable.ini"
+
 /*
  * Get home directory
  *		\x8Cl\x97p\x90ݒ\xE8\x83t\x83@\x83C\x83\x8B\x83t\x83H\x83\x8B\x83_\x8E擾
  *		ttypes.HomeDirW \x82Ɠ\xAF\x88\xEA
  *		TERATERM.INI \x82Ȃǂ\xAA\x82\xA8\x82\xA2\x82Ă\xA0\x82\xE9\x83t\x83H\x83\x8B\x83_
- *		ttermpro.exe \x82\xAA\x82\xA0\x82\xE9\x83t\x83H\x83\x8B\x83_\x82\xCD GetExeDirW() \x82Ŏ擾
- *		%APPDATA%\teraterm5 (%USERPROFILE%\AppData\Roaming\teraterm5)
+ *		ttermpro.exe \x82\xAA\x82\xA0\x82\xE9\x83t\x83H\x83\x8B\x83_\x82\xCD GetHomeDirW() \x82ł͂Ȃ\xAD GetExeDirW() \x82Ŏ擾\x82ł\xAB\x82\xE9
+ *		ExeDirW \x82\xC9 portable.ini \x82\xAA\x82\xA0\x82\xE9\x8Fꍇ
+ *			ExeDirW
+ *		ExeDirW \x82\xC9 portable.ini \x82\xAA\x82Ȃ\xA2\x8Fꍇ
+ *			%APPDATA%\teraterm5 (%USERPROFILE%\AppData\Roaming\teraterm5)
  *
  * @param[in]		hInst		WinMain()\x82\xCC HINSTANCE \x82܂\xBD\x82\xCD NULL
  * @return			HomeDir		\x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82邱\x82\xC6
@@ -916,8 +921,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;
+	}
+	free(portable_file);
 	_SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &path);
-	wchar_t *ret = NULL;
 	awcscats(&ret, path, L"\\teraterm5", NULL);
 	free(path);
 	return ret;
@@ -927,16 +941,30 @@
  * Get log directory
  *		\x83\x8D\x83O\x95ۑ\xB6\x83t\x83H\x83\x8B\x83_\x8E擾
  *		ttypes.LogDirW \x82Ɠ\xAF\x88\xEA
- *		%LOCALAPPDATA%\teraterm5 (%USERPROFILE%\AppData\Local\teraterm5)
+ *		ExeDirW \x82\xC9 portable.ini \x82\xAA\x82\xA0\x82\xE9\x8Fꍇ
+ *			ExeDirW\log
+ *		ExeDirW \x82\xC9 portable.ini \x82\xAA\x82Ȃ\xA2\x8Fꍇ
+ *			%LOCALAPPDATA%\teraterm5 (%USERPROFILE%\AppData\Local\teraterm5)
  *
  * @param[in]		hInst		WinMain()\x82\xCC HINSTANCE \x82܂\xBD\x82\xCD NULL
  * @return			LogDir		\x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82邱\x82\xC6
  */
-wchar_t* GetLogDirW(void)
+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) {
+		awcscats(&ret, ExeDirW, L"\\log", NULL);
+		free(portable_file);
+		free(ExeDirW);
+		return ret;
+	}
+	free(portable_file);
 	_SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &path);
-	wchar_t *ret = NULL;
 	awcscats(&ret, path, L"\\teraterm5", NULL);
 	free(path);
 	return ret;

Modified: trunk/teraterm/teraterm/ttdebug.cpp
===================================================================
--- trunk/teraterm/teraterm/ttdebug.cpp	2022-02-06 04:16:30 UTC (rev 9726)
+++ trunk/teraterm/teraterm/ttdebug.cpp	2022-02-06 13:56:49 UTC (rev 9727)
@@ -283,7 +283,7 @@
 		return;
 	}
 
-	logdir = GetLogDirW();
+	logdir = GetLogDirW(NULL);
 	awcscats(&dumpfile, logdir, L"\\", filename, NULL);
 	HANDLE file = CreateFileW(dumpfile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
 	free(dumpfile);

Modified: trunk/teraterm/ttpcmn/ttcmn.c
===================================================================
--- trunk/teraterm/ttpcmn/ttcmn.c	2022-02-06 04:16:30 UTC (rev 9726)
+++ trunk/teraterm/ttpcmn/ttcmn.c	2022-02-06 13:56:49 UTC (rev 9727)
@@ -202,7 +202,7 @@
 	ts->ExeDirW = GetExeDirW(hInst);
 
 	// LogDir
-	ts->LogDirW = GetLogDirW();
+	ts->LogDirW = GetLogDirW(hInst);
 	CreateDirectoryW(ts->LogDirW, NULL);
 
 	// HomeDir

Modified: trunk/ttssh2/ttxssh/ttxssh.c
===================================================================
--- trunk/ttssh2/ttxssh/ttxssh.c	2022-02-06 04:16:30 UTC (rev 9726)
+++ trunk/ttssh2/ttxssh/ttxssh.c	2022-02-06 13:56:49 UTC (rev 9727)
@@ -2565,7 +2565,7 @@
 		return _wcsdup(basename);
 	}
 
-	path = GetLogDirW();
+	path = GetLogDirW(NULL);
 	awcscats(&path, L"\\", basename, NULL);
 	return path;
 }


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