• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision8470 (tree)
Time2020-01-11 00:50:02
Authorzmatsuo

Log Message

CheckUpdateプラグインを修正

- check updateメニューをhelpに移動
- メニューIDを変更
- m18n, (日本語のみ)追加

Change Summary

Incremental Difference

--- trunk/TTXSamples/TTXCheckUpdate/CMakeLists.txt (revision 8469)
+++ trunk/TTXSamples/TTXCheckUpdate/CMakeLists.txt (revision 8470)
@@ -49,3 +49,9 @@
4949 ttpcmn
5050 Wininet.lib
5151 )
52+
53+install(
54+ TARGETS TTXCheckUpdate
55+ RUNTIME
56+ DESTINATION .
57+ )
--- trunk/TTXSamples/TTXCheckUpdate/ttxcheckupdate.c (revision 8469)
+++ trunk/TTXSamples/TTXCheckUpdate/ttxcheckupdate.c (revision 8470)
@@ -1,4 +1,3 @@
1-?ソ/* -*- coding: utf-8-with-signature-dos -*- */
21
32 #include <stdlib.h>
43 #include <stdio.h>
@@ -13,6 +12,7 @@
1312 #include "codeconv.h"
1413 #include "compat_w95.h"
1514 #include "dlglib.h"
15+#include "i18n.h"
1616
1717 #include "resource.h"
1818 #include "parse.h"
@@ -19,7 +19,7 @@
1919 #include "getcontent.h"
2020
2121 #define ORDER 4000
22-#define ID_MENUITEM 6000
22+#define ID_MENUITEM 55900 // see reference/develop.txt
2323
2424 typedef struct {
2525 HANDLE hInst;
@@ -129,17 +129,21 @@
129129 BOOL result_bool;
130130 size_t json_size;
131131 char *json_ptr;
132+ const char *UILanguageFile = pvar->ts->UILanguageFile;
133+ wchar_t UIMsg[MAX_UIMSG];
132134
133- swprintf(buf, _countof(buf),
134- L"繝阪ャ繝医Ρ繝シ繧ッ縺ォ繧「繧ッ繧サ繧ケ縺励∪縺兔n"
135- L" %s\n"
136- L"繧医m縺励>縺ァ縺吶°?",
137- update_info_url);
135+ /* ファイルを取得してもok? */
136+ GetI18nStrW("TTXCheckUpdate", "MSG_CHECKUPDATE", UIMsg, _countof(UIMsg),
137+ L"Do you want to check update?\n"
138+ L" %s\n",
139+ UILanguageFile);
140+ swprintf(buf, _countof(buf), UIMsg, update_info_url);
138141 result_mb = MessageBoxW(hWnd, buf, L"Tera Term", MB_YESNO | MB_ICONEXCLAMATION);
139142 if (result_mb == IDNO) {
140143 return;
141144 }
142145
146+ /* ファイル取得、'\0'を追加する→ json文字列を作成 */
143147 swprintf(agent, _countof(agent), L"%s_%d", agent_base, pvar->ts->RunningVersion);
144148 result_bool = GetContent(update_info_url, agent, (void**)&json_raw_ptr, &json_raw_size);
145149 if (!result_bool) {
@@ -155,6 +159,7 @@
155159 json_raw_ptr = NULL;
156160 json_ptr[json_size - 1] = '\0';
157161
162+ /* jsonをパースする */
158163 pvar->versions = ParseJson(json_ptr, &pvar->versions_count);
159164 if (pvar->versions == NULL) {
160165 MessageBoxW(hWnd, L"parse error?", L"Tera Term", MB_OK | MB_ICONEXCLAMATION);
@@ -161,10 +166,12 @@
161166 return;
162167 }
163168
169+ /* ダイアログを出す */
164170 SetDialogFont(pvar->ts->DialogFontName, pvar->ts->DialogFontPoint, pvar->ts->DialogFontCharSet,
165171 pvar->ts->UILanguageFile, "Tera Term", "DLG_TAHOMA_FONT");
166172 TTDialogBoxParam(pvar->hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, DlgProc, (LPARAM)pvar);
167173
174+ /* 終了 */
168175 free(json_ptr);
169176 ParseFree(pvar->versions, pvar->versions_count);
170177 pvar->versions = NULL;
@@ -176,10 +183,45 @@
176183 pvar->cv = cv;
177184 }
178185
186+/**
187+ * メニューを追加する
188+ *
189+ * @param[in] menu メニューハンドル
190+ * @param[in] beforeItemID このIDのメニューの前にメニューを追加
191+ * @param[in] flags メニューflag (InsertMenuの第3引数)
192+ * @param[in] newItemID メニューID (InsertMenuの第4引数)
193+ * @param[in] text メニュー文字列 (InsertMenuの第5引数)
194+ *
195+ * TODO: ttlibに移動
196+ */
197+static void insertMenuBeforeItem(HMENU menu, WORD beforeItemID, WORD flags,
198+ WORD newItemID, char *text)
199+{
200+ int i, j;
201+
202+ for (i = GetMenuItemCount(menu) - 1; i >= 0; i--) {
203+ HMENU submenu = GetSubMenu(menu, i);
204+
205+ for (j = GetMenuItemCount(submenu) - 1; j >= 0; j--) {
206+ if (GetMenuItemID(submenu, j) == beforeItemID) {
207+ InsertMenu(submenu, j, MF_BYPOSITION | flags, newItemID, text);
208+ return;
209+ }
210+ }
211+ }
212+}
213+
179214 static void WINAPI TTXModifyMenu(HMENU menu)
180215 {
181- HMENU SetupMenu = GetSubMenu(menu, 0);
182- AppendMenu(SetupMenu, MF_ENABLED, ID_MENUITEM, "Check Update");
216+ static const DlgTextInfo MenuTextInfo[] = {
217+ { ID_MENUITEM, "MENU_CHECKUPDATE" },
218+ };
219+ const UINT ID_HELP_ABOUT = 50990;
220+ const char *UILanguageFile = pvar->ts->UILanguageFile;
221+
222+ insertMenuBeforeItem(menu, ID_HELP_ABOUT, MF_ENABLED, ID_MENUITEM, "Check &Update...");
223+
224+ SetI18MenuStrs("TTXCheckUpdate", menu, MenuTextInfo, _countof(MenuTextInfo), UILanguageFile);
183225 }
184226
185227 static int WINAPI TTXProcessCommand(HWND hWin, WORD cmd)
@@ -219,7 +261,7 @@
219261 }
220262
221263 if (!IsWindowsNTKernel()) {
222- // TODO Windows10莉・螟悶?∵悴讀懆ィシ
264+ // TODO Windows10以外、未検証
223265 return FALSE;
224266 }
225267
--- trunk/teraterm/common/i18n.c (revision 8469)
+++ trunk/teraterm/common/i18n.c (revision 8470)
@@ -211,12 +211,8 @@
211211 char uimsg[MAX_UIMSG];
212212 GetI18nStr(section, key, uimsg, sizeof(uimsg), NULL, UILanguageFile);
213213 if (uimsg[0] != '\0') {
214- if (nIDDlgItem < id_position_threshold) {
215- ModifyMenuA(hMenu, nIDDlgItem, MF_BYPOSITION, nIDDlgItem, uimsg);
216- }
217- else {
218- ModifyMenuA(hMenu, nIDDlgItem, MF_BYCOMMAND, nIDDlgItem, uimsg);
219- }
214+ UINT uFlags = (nIDDlgItem < id_position_threshold) ? MF_BYPOSITION : MF_BYCOMMAND;
215+ ModifyMenuA(hMenu, nIDDlgItem, uFlags, nIDDlgItem, uimsg);
220216 }
221217 else {
222218 if (nIDDlgItem < id_position_threshold) {
@@ -231,12 +227,8 @@
231227 wchar_t uimsg[MAX_UIMSG];
232228 GetI18nStrW(section, key, uimsg, _countof(uimsg), NULL, UILanguageFile);
233229 if (uimsg[0] != '\0') {
234- if (nIDDlgItem < id_position_threshold) {
235- pModifyMenuW(hMenu, nIDDlgItem, MF_BYPOSITION, nIDDlgItem, uimsg);
236- }
237- else {
238- pModifyMenuW(hMenu, nIDDlgItem, MF_BYCOMMAND, nIDDlgItem, uimsg);
239- }
230+ UINT uFlags = (nIDDlgItem < id_position_threshold) ? MF_BYPOSITION : MF_BYCOMMAND;
231+ pModifyMenuW(hMenu, nIDDlgItem, uFlags, nIDDlgItem, uimsg);
240232 }
241233 else {
242234 if (nIDDlgItem < id_position_threshold) {
Show on old repository browser