[Ttssh2-commit] [7674] GetHomeDir(),GetUILanguageFileFull()#ttlib.cを追加、同様な処理は関数を使用するようにした

Zurück zum Archiv-Index
scmno****@osdn***** scmno****@osdn*****
2019年 5月 14日 (火) 00:14:31 JST


Revision: 7674
          https://osdn.net/projects/ttssh2/scm/svn/commits/7674
Author:   zmatsuo
Date:     2019-05-14 00:14:30 +0900 (Tue, 14 May 2019)
Log Message:
-----------
GetHomeDir(),GetUILanguageFileFull()#ttlib.cを追加、同様な処理は関数を使用するようにした

Modified Paths:
--------------
    trunk/teraterm/common/ttlib.c
    trunk/teraterm/common/ttlib.h
    trunk/teraterm/ttpcmn/ttcmn.c
    trunk/teraterm/ttpdlg/ttdlg.c
    trunk/teraterm/ttpmacro/ttmacro.cpp
    trunk/teraterm/ttpmacro/ttmdlg.cpp
    trunk/teraterm/ttpmacro/ttmdlg.h
    trunk/teraterm/ttpset/ttset.c

-------------- next part --------------
Modified: trunk/teraterm/common/ttlib.c
===================================================================
--- trunk/teraterm/common/ttlib.c	2019-05-13 14:58:13 UTC (rev 7673)
+++ trunk/teraterm/common/ttlib.c	2019-05-13 15:14:30 UTC (rev 7674)
@@ -916,38 +916,69 @@
 	strncat_s(dest, destlen, file, _TRUNCATE);
 }
 
+/*
+ * Get home(exe,dll) directory
+ * @param[in]		hInst		WinMain()\x82\xCC HINSTANCE \x82܂\xBD\x82\xCD NULL
+ * @param[in,out]	HomeDir
+ * @param[out]		HomeDirLen
+ */
+void GetHomeDir(HINSTANCE hInst, char *HomeDir, size_t HomeDirLen)
+{
+	char Temp[MAX_PATH];
+	DWORD result = GetModuleFileName(NULL,Temp,sizeof(Temp));
+	if (result == 0 || result == _countof(Temp)) {
+		// \x83p\x83X\x82̎擾\x82Ɏ\xB8\x94s\x82\xB5\x82\xBD\x81B\x92v\x96\xBD\x93I\x81Aabort() \x82\xB7\x82\xE9\x81B
+		abort();
+		// \x82\xB1\x82\xB1\x82\xC5return\x82\xB5\x82Ă\xE0\x83v\x83\x89\x83O\x83C\x83\x93(ttpset.dll)\x82̃\x8D\x81[\x83h\x82Ɏ\xB8\x94s\x82\xB5\x82\xC4abort()\x82\xB7\x82\xE9
+	}
+	ExtractDirName(Temp, Temp);
+	strncpy_s(HomeDir, HomeDirLen, Temp, _TRUNCATE);
+}
+
 // \x83f\x83t\x83H\x83\x8B\x83g\x82\xCC TERATERM.INI \x82̃t\x83\x8B\x83p\x83X\x82\xF0 ttpmacro \x82\xA9\x82\xE7\x82\xE0
 // \x8E擾\x82\xB7\x82邽\x82߂ɒlj\xC1\x82\xB5\x82\xBD\x81B(2007.2.18 maya)
-void GetDefaultSetupFName(char *home, char *dest, int destlen)
+void GetDefaultSetupFName(const char *home, char *dest, int destlen)
 {
 	GetDefaultFName(home, "TERATERM.INI", dest, destlen);
 }
 
+/*
+ *	UILanguageFile\x82̃t\x83\x8B\x83p\x83X\x82\xF0\x8E擾\x82\xB7\x82\xE9
+ *
+ *	@param[in]		HomeDir					exe,dll\x82̑\xB6\x8D݂\xB7\x82\xE9\x83t\x83H\x83\x8B\x83_ GetHomeDir()\x82Ŏ擾\x82ł\xAB\x82\xE9
+ *	@param[in]		UILanguageFileRel		lng\x83t\x83@\x83C\x83\x8B\x81AHomeDir\x82\xA9\x82\xE7\x82̑\x8A\x91΃p\x83X
+ *	@param[in,out]	UILanguageFileFull		lng\x83t\x83@\x83C\x83\x8Bptr\x81A\x83t\x83\x8B\x83p\x83X
+ *	@param[in]		UILanguageFileFullLen	lng\x83t\x83@\x83C\x83\x8Blen\x81A\x83t\x83\x8B\x83p\x83X
+ */
+void GetUILanguageFileFull(const char *HomeDir, const char *UILanguageFileRel,
+						   char *UILanguageFileFull, size_t UILanguageFileFullLen)
+{
+	char CurDir[MAX_PATH];
+
+	/* Get UILanguageFile Full Path */
+	GetCurrentDirectory(sizeof(CurDir), CurDir);
+	SetCurrentDirectory(HomeDir);
+	_fullpath(UILanguageFileFull, UILanguageFileRel, UILanguageFileFullLen);
+	SetCurrentDirectory(CurDir);
+}
+
 void GetUILanguageFile(char *buf, int buflen)
 {
 	char HomeDir[MAX_PATH];
 	char Temp[MAX_PATH];
 	char SetupFName[MAX_PATH];
-	char CurDir[MAX_PATH];
 
 	/* Get home directory */
-	if (GetModuleFileName(NULL,Temp,sizeof(Temp)) == 0) {
-		memset(buf, 0, buflen);
-		return;
-	}
-	ExtractDirName(Temp, HomeDir);
+	GetHomeDir(NULL, HomeDir, sizeof(HomeDir));
 
 	/* Get SetupFName */
 	GetDefaultSetupFName(HomeDir, SetupFName, sizeof(SetupFName));
-	
+
 	/* Get LanguageFile name */
-	GetPrivateProfileString("Tera Term", "UILanguageFile", "",
+	GetPrivateProfileString("Tera Term", "UILanguageFile", "lang\\Default.lng",
 	                        Temp, sizeof(Temp), SetupFName);
 
-	GetCurrentDirectory(sizeof(CurDir), CurDir);
-	SetCurrentDirectory(HomeDir);
-	_fullpath(buf, Temp, buflen);
-	SetCurrentDirectory(CurDir);
+	GetUILanguageFileFull(HomeDir, Temp, buf, buflen);
 }
 
 // \x8Ew\x92肵\x82\xBD\x83G\x83\x93\x83g\x83\x8A\x82\xF0 teraterm.ini \x82\xA9\x82\xE7\x93ǂݎ\xE6\x82\xE9 (2009.3.23 yutaka)
@@ -958,11 +989,7 @@
 	char SetupFName[MAX_PATH];
 
 	/* Get home directory */
-	if (GetModuleFileName(NULL,Temp,sizeof(Temp)) == 0) {
-		strncpy_s(buf, buflen, "off", _TRUNCATE);
-		return;
-	}
-	ExtractDirName(Temp, HomeDir);
+	GetHomeDir(NULL, HomeDir, sizeof(HomeDir));
 
 	/* Get SetupFName */
 	GetDefaultSetupFName(HomeDir, SetupFName, sizeof(SetupFName));

Modified: trunk/teraterm/common/ttlib.h
===================================================================
--- trunk/teraterm/common/ttlib.h	2019-05-13 14:58:13 UTC (rev 7673)
+++ trunk/teraterm/common/ttlib.h	2019-05-13 15:14:30 UTC (rev 7674)
@@ -71,9 +71,12 @@
 void GetNthNum(PCHAR Source, int Nth, int far *Num);
 int GetNthNum2(PCHAR Source, int Nth, int defval);
 void GetDownloadFolder(char *dest, int destlen);
+void GetHomeDir(HINSTANCE hInst, char *HomeDir, size_t HomeDirLen);
 void GetDefaultFName(const char *home, const char *file, char *dest, int destlen);
-void GetDefaultSetupFName(char *home, char *dest, int destlen);
+void GetDefaultSetupFName(const char *home, char *dest, int destlen);
 void GetUILanguageFile(char *buf, int buflen);
+void GetUILanguageFileFull(const char *HomeDir, const char *UILanguageFileRel,
+						   char *UILanguageFileFull, size_t UILanguageFileFullLen);
 void GetOnOffEntryInifile(char *entry, char *buf, int buflen);
 void get_lang_msg(const char *key, PCHAR buf, int buf_len, const char *def, const char *iniFile);
 #if defined(UNICODE)

Modified: trunk/teraterm/ttpcmn/ttcmn.c
===================================================================
--- trunk/teraterm/ttpcmn/ttcmn.c	2019-05-13 14:58:13 UTC (rev 7673)
+++ trunk/teraterm/ttpcmn/ttcmn.c	2019-05-13 15:14:30 UTC (rev 7674)
@@ -103,8 +103,6 @@
 
 BOOL WINAPI StartTeraTerm(PTTSet ts)
 {
-	char Temp[MAX_PATH];
-
 	if (FirstInstance) {
 		// init window list
 		pm->NWin = 0;
@@ -122,10 +120,7 @@
 	// if (FirstInstance) { \x82̕\x94\x95\xAA\x82\xA9\x82\xE7\x88ړ\xAE (2008.3.13 maya)
 	// \x8BN\x93\xAE\x8E\x9E\x82ɂ́A\x8B\xA4\x97L\x83\x81\x83\x82\x83\x8A\x82\xCC HomeDir \x82\xC6 SetupFName \x82͋\xF3\x82ɂȂ\xE9
 	/* Get home directory */
-	if (GetModuleFileName(hInst,Temp,sizeof(Temp)) == 0) {
-		return TRUE;
-	}
-	ExtractDirName(Temp, ts->HomeDir);
+	GetHomeDir(hInst, ts->HomeDir, sizeof(ts->HomeDir));
 	_chdir(ts->HomeDir);
 	GetDefaultSetupFName(ts->HomeDir, ts->SetupFName, sizeof(ts->SetupFName));
 

Modified: trunk/teraterm/ttpdlg/ttdlg.c
===================================================================
--- trunk/teraterm/ttpdlg/ttdlg.c	2019-05-13 14:58:13 UTC (rev 7673)
+++ trunk/teraterm/ttpdlg/ttdlg.c	2019-05-13 15:14:30 UTC (rev 7674)
@@ -2644,15 +2644,11 @@
 						// \x8C\xBE\x8C\xEA\x83t\x83@\x83C\x83\x8B\x82\xAA\x95ύX\x82\xB3\x82\xEA\x82Ă\xA2\x82\xBD\x8Fꍇ
 						w = (WORD)GetCurSel(Dialog, IDC_GENLANG_UI);
 						if (1 <= w && w <= uilist_count && w != langui_sel) {
-							char CurDir[MAX_PATH];
-
 							_snprintf_s(ts->UILanguageFile_ini, sizeof(ts->UILanguageFile_ini), _TRUNCATE,
 								"%s\\%s", LANG_PATH, LangUIList[w - 1]);
 
-							GetCurrentDirectory(sizeof(CurDir), CurDir);
-							SetCurrentDirectory(ts->HomeDir);
-							_fullpath(ts->UILanguageFile, ts->UILanguageFile_ini, sizeof(ts->UILanguageFile));
-							SetCurrentDirectory(CurDir);
+							GetUILanguageFileFull(ts->HomeDir, ts->UILanguageFile_ini,
+												  ts->UILanguageFile, sizeof(ts->UILanguageFile));
 
 							// \x83^\x83C\x83g\x83\x8B\x82̍X\x90V\x82\xF0\x8Ds\x82\xA4\x81B(2014.2.23 yutaka)
 							PostMessage(GetParent(Dialog),WM_USER_CHANGETITLE,0,0);

Modified: trunk/teraterm/ttpmacro/ttmacro.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ttmacro.cpp	2019-05-13 14:58:13 UTC (rev 7673)
+++ trunk/teraterm/ttpmacro/ttmacro.cpp	2019-05-13 15:14:30 UTC (rev 7674)
@@ -71,26 +71,17 @@
 	return CtrlWnd;
 }
 
-static void GetDefaultSetupFName2(char *dest, int destlen)
+static void init()
 {
-	char HomeDir[MAX_PATH];
-	char Temp[MAX_PATH];
+	char UILanguageFileRel[MAX_PATH];
 
-	/* Get home directory */
-	if (GetModuleFileName(NULL,Temp,sizeof(Temp)) == 0) {
-		memset(dest, 0, destlen);
-		return;
-	}
-	ExtractDirName(Temp, HomeDir);
+	GetHomeDir(hInst, HomeDir, sizeof(HomeDir));
+	GetDefaultFName(HomeDir, "TERATERM.INI", SetupFName, sizeof(SetupFName));
+	GetPrivateProfileString("Tera Term", "UILanguageFile", "lang\\Default.lng",
+	                        UILanguageFileRel, sizeof(UILanguageFileRel), SetupFName);
+	GetUILanguageFileFull(HomeDir, UILanguageFileRel,
+						  UILanguageFile, sizeof(UILanguageFile));
 
-	GetDefaultFName(HomeDir, "TERATERM.INI", dest, destlen);
-}
-
-static void init()
-{
-	GetDefaultSetupFName2(SetupFName, sizeof(SetupFName));
-	GetUILanguageFile(UILanguageFile, sizeof(UILanguageFile));
-
 	DLLInit();
 	WinCompatInit();
 

Modified: trunk/teraterm/ttpmacro/ttmdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ttmdlg.cpp	2019-05-13 14:58:13 UTC (rev 7673)
+++ trunk/teraterm/ttpmacro/ttmdlg.cpp	2019-05-13 15:14:30 UTC (rev 7674)
@@ -59,7 +59,7 @@
 #define _strdup(s)	  _strdup_dbg((s), _NORMAL_BLOCK, __FILE__, __LINE__)
 #endif
 
-char HomeDir[MAXPATHLEN];
+char HomeDir[MAX_PATH];
 char FileName[MAX_PATH];
 char TopicName[11];
 char ShortName[MAX_PATH];
@@ -80,11 +80,7 @@
 	char Temp[MaxStrLen];
 	PCHAR start, cur, next;
 
-	// Get home directory
-	if (GetModuleFileName(GetInstance(), FileName,sizeof(FileName)) == 0) {
-		return;
-	}
-	ExtractDirName(FileName,HomeDir);
+	// go home directory
 	_chdir(HomeDir);
 
 	// Get command line parameters

Modified: trunk/teraterm/ttpmacro/ttmdlg.h
===================================================================
--- trunk/teraterm/ttpmacro/ttmdlg.h	2019-05-13 14:58:13 UTC (rev 7673)
+++ trunk/teraterm/ttpmacro/ttmdlg.h	2019-05-13 15:14:30 UTC (rev 7674)
@@ -50,7 +50,7 @@
 
 int OpenListDlg(PCHAR Text, PCHAR Caption, CHAR **Lists, int Selected);
 
-extern char HomeDir[MAXPATHLEN];
+extern char HomeDir[MAX_PATH];
 extern char FileName[MAX_PATH];
 extern char TopicName[11];
 extern char ShortName[MAX_PATH];

Modified: trunk/teraterm/ttpset/ttset.c
===================================================================
--- trunk/teraterm/ttpset/ttset.c	2019-05-13 14:58:13 UTC (rev 7673)
+++ trunk/teraterm/ttpset/ttset.c	2019-05-13 15:14:30 UTC (rev 7674)
@@ -1591,21 +1591,14 @@
 	                        Temp, sizeof(Temp), FName);
 	strncpy_s(ts->Locale, sizeof(ts->Locale), Temp, _TRUNCATE);
 
-	// UI language message file
+	// UI language message file (\x91\x8A\x91΃p\x83X)
 	GetPrivateProfileString(Section, "UILanguageFile", "lang\\Default.lng",
-	                        Temp, sizeof(Temp), FName);
-	{
-		char CurDir[MAX_PATH];
+	                        ts->UILanguageFile_ini, sizeof(ts->UILanguageFile_ini), FName);
 
-		// \x83t\x83\x8B\x83p\x83X\x89\xBB\x82\xB7\x82\xE9\x91O\x82ɓǂݍ\x9E\x82ݎ\x9E\x82̐ݒ\xE8\x82\xF0\x8E\xE6\x82\xC1\x82Ă\xA8\x82\xAD
-		strncpy_s(ts->UILanguageFile_ini, sizeof(ts->UILanguageFile_ini), Temp, _TRUNCATE);
+	// UI language message file (full path)
+	GetUILanguageFileFull(ts->HomeDir, ts->UILanguageFile_ini,
+						  ts->UILanguageFile, sizeof(ts->UILanguageFile));
 
-		GetCurrentDirectory(sizeof(CurDir), CurDir);
-		SetCurrentDirectory(ts->HomeDir);
-		_fullpath(ts->UILanguageFile, Temp, sizeof(ts->UILanguageFile));
-		SetCurrentDirectory(CurDir);
-	}
-
 	// Broadcast Command History (2007.3.3 maya)
 	ts->BroadcastCommandHistory =
 		GetOnOff(Section, "BroadcastCommandHistory", FName, FALSE);


Ttssh2-commit メーリングリストの案内
Zurück zum Archiv-Index