テーマファイルの読み込み部分を Unicode 化
ticket #44048
@@ -42,6 +42,8 @@ | ||
42 | 42 | #include "setting.h" |
43 | 43 | #include "codeconv.h" |
44 | 44 | #include "libsusieplugin.h" |
45 | +#include "inifile_com.h" | |
46 | +#include "win32helper.h" | |
45 | 47 | |
46 | 48 | #include "vtdisp.h" |
47 | 49 |
@@ -1193,7 +1195,7 @@ | ||
1193 | 1195 | } |
1194 | 1196 | } |
1195 | 1197 | |
1196 | -static COLORREF BGGetColor(char *name, COLORREF defcolor, char *file) | |
1198 | +static COLORREF BGGetColor(const char *name, COLORREF defcolor, const wchar_t *file) | |
1197 | 1199 | { |
1198 | 1200 | unsigned int r, g, b; |
1199 | 1201 | char colorstr[256], defstr[256]; |
@@ -1201,7 +1203,7 @@ | ||
1201 | 1203 | _snprintf_s(defstr, sizeof(defstr), _TRUNCATE, "%d,%d,%d", GetRValue(defcolor), GetGValue(defcolor), |
1202 | 1204 | GetBValue(defcolor)); |
1203 | 1205 | |
1204 | - GetPrivateProfileString(BG_SECTION, name, defstr, colorstr, 255, file); | |
1206 | + GetPrivateProfileStringAFileW(BG_SECTION, name, defstr, colorstr, 255, file); | |
1205 | 1207 | |
1206 | 1208 | r = g = b = 0; |
1207 | 1209 |
@@ -1210,7 +1212,7 @@ | ||
1210 | 1212 | return RGB(r, g, b); |
1211 | 1213 | } |
1212 | 1214 | |
1213 | -static BG_PATTERN BGGetStrIndex(char *name, BG_PATTERN def, char *file, char **strList, int nList) | |
1215 | +static int BGGetStrIndex(const char *name, int def, const wchar_t *file, const char * const *strList, int nList) | |
1214 | 1216 | { |
1215 | 1217 | char defstr[64], str[64]; |
1216 | 1218 | int i; |
@@ -1218,7 +1220,7 @@ | ||
1218 | 1220 | def %= nList; |
1219 | 1221 | |
1220 | 1222 | strncpy_s(defstr, sizeof(defstr), strList[def], _TRUNCATE); |
1221 | - GetPrivateProfileString(BG_SECTION, name, defstr, str, 64, file); | |
1223 | + GetPrivateProfileStringAFileW(BG_SECTION, name, defstr, str, 64, file); | |
1222 | 1224 | |
1223 | 1225 | for (i = 0; i < nList; i++) |
1224 | 1226 | if (!_stricmp(str, strList[i])) |
@@ -1227,28 +1229,28 @@ | ||
1227 | 1229 | return 0; |
1228 | 1230 | } |
1229 | 1231 | |
1230 | -static BOOL BGGetOnOff(char *name, BOOL def, char *file) | |
1232 | +static BOOL BGGetOnOff(const char *name, BOOL def, const wchar_t *file) | |
1231 | 1233 | { |
1232 | - char *strList[2] = {"Off", "On"}; | |
1234 | + static const char * const strList[2] = {"Off", "On"}; | |
1233 | 1235 | |
1234 | 1236 | return BGGetStrIndex(name, def, file, strList, 2); |
1235 | 1237 | } |
1236 | 1238 | |
1237 | -static BG_PATTERN BGGetPattern(char *name, BG_PATTERN def, char *file) | |
1239 | +static BG_PATTERN BGGetPattern(const char *name, BG_PATTERN def, const wchar_t *file) | |
1238 | 1240 | { |
1239 | - char *strList[6] = {"stretch", "tile", "center", "fitwidth", "fitheight", "autofit"}; | |
1241 | + static const char *strList[6] = {"stretch", "tile", "center", "fitwidth", "fitheight", "autofit"}; | |
1240 | 1242 | |
1241 | 1243 | return BGGetStrIndex(name, def, file, strList, 6); |
1242 | 1244 | } |
1243 | 1245 | |
1244 | -static BG_TYPE BGGetType(char *name, BG_TYPE def, char *file) | |
1246 | +static BG_TYPE BGGetType(const char *name, BG_TYPE def, const wchar_t *file) | |
1245 | 1247 | { |
1246 | - char *strList[3] = {"color", "picture", "wallpaper"}; | |
1248 | + static const char *strList[3] = {"color", "picture", "wallpaper"}; | |
1247 | 1249 | |
1248 | 1250 | return BGGetStrIndex(name, def, file, strList, 3); |
1249 | 1251 | } |
1250 | 1252 | |
1251 | -static void BGReadTextColorConfig(char *file) | |
1253 | +static void BGReadTextColorConfig(const wchar_t *file) | |
1252 | 1254 | { |
1253 | 1255 | ANSIColor[IdFore] = BGGetColor("Fore", ANSIColor[IdFore], file); |
1254 | 1256 | ANSIColor[IdBack] = BGGetColor("Back", ANSIColor[IdBack], file); |
@@ -1286,7 +1288,7 @@ | ||
1286 | 1288 | /* end - ishizaki */ |
1287 | 1289 | } |
1288 | 1290 | |
1289 | -static void BGReadIniFile(char *file) | |
1291 | +static void BGReadIniFile(const wchar_t *file) | |
1290 | 1292 | { |
1291 | 1293 | char path[MAX_PATH]; |
1292 | 1294 |
@@ -1294,27 +1296,27 @@ | ||
1294 | 1296 | BGDest.pattern = BGGetPattern("BGPicturePattern", BGSrc1.pattern, file); |
1295 | 1297 | BGDest.color = BGGetColor("BGPictureBaseColor", BGSrc1.color, file); |
1296 | 1298 | |
1297 | - GetPrivateProfileString(BG_SECTION, "BGPictureFile", BGSrc1.file, path, MAX_PATH, file); | |
1299 | + GetPrivateProfileStringAFileW(BG_SECTION, "BGPictureFile", BGSrc1.file, path, MAX_PATH, file); | |
1298 | 1300 | RandomFile(path, BGDest.file, sizeof(BGDest.file)); |
1299 | 1301 | |
1300 | - BGSrc1.alpha = 255 - GetPrivateProfileInt(BG_SECTION, "BGPictureTone", 255 - BGSrc1.alpha, file); | |
1302 | + BGSrc1.alpha = 255 - GetPrivateProfileIntAFileW(BG_SECTION, "BGPictureTone", 255 - BGSrc1.alpha, file); | |
1301 | 1303 | |
1302 | 1304 | if (!strcmp(BGDest.file, "")) |
1303 | 1305 | BGSrc1.alpha = 255; |
1304 | 1306 | |
1305 | - BGSrc2.alpha = 255 - GetPrivateProfileInt(BG_SECTION, "BGFadeTone", 255 - BGSrc2.alpha, file); | |
1307 | + BGSrc2.alpha = 255 - GetPrivateProfileIntAFileW(BG_SECTION, "BGFadeTone", 255 - BGSrc2.alpha, file); | |
1306 | 1308 | BGSrc2.color = BGGetColor("BGFadeColor", BGSrc2.color, file); |
1307 | 1309 | |
1308 | - BGReverseTextAlpha = GetPrivateProfileInt(BG_SECTION, "BGReverseTextTone", BGReverseTextAlpha, file); | |
1310 | + BGReverseTextAlpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGReverseTextTone", BGReverseTextAlpha, file); | |
1309 | 1311 | |
1310 | 1312 | // Src1 の読み出し |
1311 | 1313 | BGSrc1.type = BGGetType("BGSrc1Type", BGSrc1.type, file); |
1312 | 1314 | BGSrc1.pattern = BGGetPattern("BGSrc1Pattern", BGSrc1.pattern, file); |
1313 | 1315 | BGSrc1.antiAlias = BGGetOnOff("BGSrc1AntiAlias", BGSrc1.antiAlias, file); |
1314 | - BGSrc1.alpha = GetPrivateProfileInt(BG_SECTION, "BGSrc1Alpha", BGSrc1.alpha, file); | |
1316 | + BGSrc1.alpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGSrc1Alpha", BGSrc1.alpha, file); | |
1315 | 1317 | BGSrc1.color = BGGetColor("BGSrc1Color", BGSrc1.color, file); |
1316 | 1318 | |
1317 | - GetPrivateProfileString(BG_SECTION, "BGSrc1File", BGSrc1.file, path, MAX_PATH, file); | |
1319 | + GetPrivateProfileStringAFileW(BG_SECTION, "BGSrc1File", BGSrc1.file, path, MAX_PATH, file); | |
1318 | 1320 | RandomFile(path, BGSrc1.file, sizeof(BGSrc1.file)); |
1319 | 1321 | |
1320 | 1322 | // Src2 の読み出し |
@@ -1321,10 +1323,10 @@ | ||
1321 | 1323 | BGSrc2.type = BGGetType("BGSrc2Type", BGSrc2.type, file); |
1322 | 1324 | BGSrc2.pattern = BGGetPattern("BGSrc2Pattern", BGSrc2.pattern, file); |
1323 | 1325 | BGSrc2.antiAlias = BGGetOnOff("BGSrc2AntiAlias", BGSrc2.antiAlias, file); |
1324 | - BGSrc2.alpha = GetPrivateProfileInt(BG_SECTION, "BGSrc2Alpha", BGSrc2.alpha, file); | |
1326 | + BGSrc2.alpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGSrc2Alpha", BGSrc2.alpha, file); | |
1325 | 1327 | BGSrc2.color = BGGetColor("BGSrc2Color", BGSrc2.color, file); |
1326 | 1328 | |
1327 | - GetPrivateProfileString(BG_SECTION, "BGSrc2File", BGSrc2.file, path, MAX_PATH, file); | |
1329 | + GetPrivateProfileStringAFileW(BG_SECTION, "BGSrc2File", BGSrc2.file, path, MAX_PATH, file); | |
1328 | 1330 | RandomFile(path, BGSrc2.file, sizeof(BGSrc2.file)); |
1329 | 1331 | |
1330 | 1332 | // Dest の読み出し |
@@ -1333,11 +1335,11 @@ | ||
1333 | 1335 | BGDest.antiAlias = BGGetOnOff("BGDestAntiAlias", BGDest.antiAlias, file); |
1334 | 1336 | BGDest.color = BGGetColor("BGDestColor", BGDest.color, file); |
1335 | 1337 | |
1336 | - GetPrivateProfileString(BG_SECTION, BG_DESTFILE, BGDest.file, path, MAX_PATH, file); | |
1338 | + GetPrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, BGDest.file, path, MAX_PATH, file); | |
1337 | 1339 | RandomFile(path, BGDest.file, sizeof(BGDest.file)); |
1338 | 1340 | |
1339 | 1341 | //その他読み出し |
1340 | - BGReverseTextAlpha = GetPrivateProfileInt(BG_SECTION, "BGReverseTextAlpha", BGReverseTextAlpha, file); | |
1342 | + BGReverseTextAlpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGReverseTextAlpha", BGReverseTextAlpha, file); | |
1341 | 1343 | BGReadTextColorConfig(file); |
1342 | 1344 | } |
1343 | 1345 |
@@ -1411,10 +1413,10 @@ | ||
1411 | 1413 | // 空の場合のみ、ディスクから読む。BGInitialize()が Tera Term 起動時以外にも、 |
1412 | 1414 | // Additional settings から呼び出されることがあるため。 |
1413 | 1415 | if (ts.EtermLookfeel.BGThemeFile[0] == '\0') { |
1414 | - ts.EtermLookfeel.BGEnable = BGEnable = BGGetOnOff("BGEnable", FALSE, ts.SetupFName); | |
1416 | + ts.EtermLookfeel.BGEnable = BGEnable = BGGetOnOff("BGEnable", FALSE, ts.SetupFNameW); | |
1415 | 1417 | } |
1416 | 1418 | else { |
1417 | - BGEnable = BGGetOnOff("BGEnable", FALSE, ts.SetupFName); | |
1419 | + BGEnable = BGGetOnOff("BGEnable", FALSE, ts.SetupFNameW); | |
1418 | 1420 | } |
1419 | 1421 | |
1420 | 1422 | GetPrivateProfileString(BG_SECTION, "BGSPIPath", "plugin", BGSPIPath, MAX_PATH, ts.SetupFName); |
@@ -1439,7 +1441,7 @@ | ||
1439 | 1441 | // Tera Termの起動時のみに初期化する。 |
1440 | 1442 | if (initialize_once) { |
1441 | 1443 | // Tera Term起動時に一度だけ読む。 |
1442 | - ts.EtermLookfeel.BGIgnoreThemeFile = BGGetOnOff("BGIgnoreThemeFile", FALSE, ts.SetupFName); | |
1444 | + ts.EtermLookfeel.BGIgnoreThemeFile = BGGetOnOff("BGIgnoreThemeFile", FALSE, ts.SetupFNameW); | |
1443 | 1445 | } |
1444 | 1446 | |
1445 | 1447 | if (!BGEnable) |
@@ -1485,10 +1487,10 @@ | ||
1485 | 1487 | BGReverseTextAlpha = 255; |
1486 | 1488 | |
1487 | 1489 | //設定の読み出し |
1488 | - BGReadIniFile(ts.SetupFName); | |
1490 | + BGReadIniFile(ts.SetupFNameW); | |
1489 | 1491 | |
1490 | 1492 | //コンフィグファイルの決定 |
1491 | - GetPrivateProfileString(BG_SECTION, "BGThemeFile", "", path, MAX_PATH, ts.SetupFName); | |
1493 | + GetPrivateProfileStringAFileW(BG_SECTION, "BGThemeFile", "", path, MAX_PATH, ts.SetupFNameW); | |
1492 | 1494 | RandomFile(path, config_file, sizeof(config_file)); |
1493 | 1495 | |
1494 | 1496 | // ImageFile.INIではない場合はランダムに選ぶ。 |
@@ -1501,17 +1503,22 @@ | ||
1501 | 1503 | |
1502 | 1504 | //設定のオーバーライド |
1503 | 1505 | if (strcmp(config_file, "")) { |
1504 | - char dir[MAX_PATH], prevDir[MAX_PATH]; | |
1506 | + wchar_t *dir; | |
1507 | + wchar_t *prevDir; | |
1505 | 1508 | |
1509 | + hGetCurrentDirectoryW(&prevDir); | |
1510 | + | |
1506 | 1511 | // INIファイルのあるディレクトリに一時的に移動 |
1507 | - GetCurrentDirectory(MAX_PATH, prevDir); | |
1512 | + wchar_t *config_fileW = ToWcharA(config_file); | |
1513 | + dir = ExtractDirNameW(config_fileW); | |
1514 | + SetCurrentDirectoryW(dir); | |
1515 | + free(dir); | |
1508 | 1516 | |
1509 | - ExtractDirName(config_file, dir); | |
1510 | - SetCurrentDirectory(dir); | |
1517 | + BGReadIniFile(config_fileW); | |
1511 | 1518 | |
1512 | - BGReadIniFile(config_file); | |
1513 | - | |
1514 | - SetCurrentDirectory(prevDir); | |
1519 | + // カレントフォルダを元に戻す | |
1520 | + SetCurrentDirectoryW(prevDir); | |
1521 | + free(prevDir); | |
1515 | 1522 | } |
1516 | 1523 | |
1517 | 1524 | //壁紙 or 背景をプリロード |