GUIもワイド文字に対応

This commit is contained in:
lltcggie 2015-12-06 21:10:48 +09:00
parent f18584f781
commit b89194f1b8

View File

@ -35,6 +35,20 @@ const std::pair<int, int> DefaultCommonDivisorRange = {90, 140};
const char * const CropSizeListName = "crop_size_list.txt"; const char * const CropSizeListName = "crop_size_list.txt";
#ifdef UNICODE
typedef std::wstring tstring;
inline tstring getTString(const boost::filesystem::path& p)
{
return p.wstring();
}
#else
typedef std::string tstring;
inline tstring getTString(const boost::filesystem::path& p)
{
return p.string();
}
#endif
// http://stackoverflow.com/questions/10167382/boostfilesystem-get-relative-path // http://stackoverflow.com/questions/10167382/boostfilesystem-get-relative-path
boost::filesystem::path relativePath(const boost::filesystem::path &path, const boost::filesystem::path &relative_to) boost::filesystem::path relativePath(const boost::filesystem::path &path, const boost::filesystem::path &relative_to)
{ {
@ -103,30 +117,30 @@ private:
std::vector<int> CropSizeList; std::vector<int> CropSizeList;
std::string input_str; tstring input_str;
std::string output_str; tstring output_str;
std::string mode; std::string mode;
int noise_level; int noise_level;
double scale_ratio; double scale_ratio;
std::string model_dir; tstring model_dir;
std::string process; std::string process;
std::string outputExt; tstring outputExt;
std::string inputFileExt; tstring inputFileExt;
bool use_tta; bool use_tta;
int crop_size; int crop_size;
int batch_size; int batch_size;
std::vector<std::string> extList; std::vector<tstring> extList;
std::thread processThread; std::thread processThread;
std::atomic_bool cancelFlag; std::atomic_bool cancelFlag;
std::string autoSetAddName; tstring autoSetAddName;
bool isLastError; bool isLastError;
std::string logMessage; tstring logMessage;
std::string usedProcess; std::string usedProcess;
std::chrono::system_clock::duration cuDNNCheckTime; std::chrono::system_clock::duration cuDNNCheckTime;
@ -134,16 +148,36 @@ private:
std::chrono::system_clock::duration ProcessTime; std::chrono::system_clock::duration ProcessTime;
private: private:
std::string AddName() const static tstring to_tstring(int val)
{ {
std::string addstr("(" + mode + ")"); #ifdef UNICODE
return std::to_wstring(val);
#else
return std::to_string(val);
#endif
}
tstring AddName() const
{
tstring addstr(TEXT("("));
if (mode == "noise")
addstr += TEXT("noise");
else if (mode == "scale")
addstr += TEXT("scale");
else if (mode == "noise_scale")
addstr += TEXT("noise_scale");
else if (mode == "auto_scale")
addstr += TEXT("auto_scale");
addstr += TEXT(")");
if (mode.find("noise") != mode.npos || mode.find("auto_scale") != mode.npos) if (mode.find("noise") != mode.npos || mode.find("auto_scale") != mode.npos)
addstr += "(Level" + std::to_string(noise_level) + ")"; addstr += TEXT("(Level") + to_tstring(noise_level) + TEXT(")");
if (use_tta) if (use_tta)
addstr += "(tta)"; addstr += TEXT("(tta)");
if (mode.find("scale") != mode.npos) if (mode.find("scale") != mode.npos)
addstr += "(x" + std::to_string(scale_ratio) + ")"; addstr += TEXT("(x") + to_tstring(scale_ratio) + TEXT(")");
return addstr; return addstr;
} }
@ -153,17 +187,17 @@ private:
bool ret = true; bool ret = true;
{ {
char buf[AR_PATH_MAX] = ""; TCHAR buf[AR_PATH_MAX] = TEXT("");
GetWindowTextA(GetDlgItem(dh, IDC_EDIT_INPUT), buf, _countof(buf)); GetWindowText(GetDlgItem(dh, IDC_EDIT_INPUT), buf, _countof(buf));
buf[_countof(buf) - 1] = '\0'; buf[_countof(buf) - 1] = TEXT('\0');
input_str = buf; input_str = buf;
} }
{ {
char buf[AR_PATH_MAX] = ""; TCHAR buf[AR_PATH_MAX] = TEXT("");
GetWindowTextA(GetDlgItem(dh, IDC_EDIT_OUTPUT), buf, _countof(buf)); GetWindowText(GetDlgItem(dh, IDC_EDIT_OUTPUT), buf, _countof(buf));
buf[_countof(buf) - 1] = '\0'; buf[_countof(buf) - 1] = TEXT('\0');
output_str = buf; output_str = buf;
} }
@ -183,13 +217,13 @@ private:
noise_level = 2; noise_level = 2;
{ {
char buf[AR_PATH_MAX] = ""; TCHAR buf[AR_PATH_MAX] = TEXT("");
GetWindowTextA(GetDlgItem(dh, IDC_EDIT_SCALE_RATIO), buf, _countof(buf)); GetWindowText(GetDlgItem(dh, IDC_EDIT_SCALE_RATIO), buf, _countof(buf));
buf[_countof(buf) - 1] = '\0'; buf[_countof(buf) - 1] = TEXT('\0');
char *ptr = nullptr; TCHAR *ptr = nullptr;
scale_ratio = strtod(buf, &ptr); scale_ratio = _tcstod(buf, &ptr);
if (!ptr || *ptr != '\0' || scale_ratio <= 0.0) if (!ptr || *ptr != TEXT('\0') || scale_ratio <= 0.0)
{ {
scale_ratio = 2.0; scale_ratio = 2.0;
ret = false; ret = false;
@ -199,20 +233,20 @@ private:
} }
if (SendMessage(GetDlgItem(dh, IDC_RADIO_MODEL_RGB), BM_GETCHECK, 0, 0)) if (SendMessage(GetDlgItem(dh, IDC_RADIO_MODEL_RGB), BM_GETCHECK, 0, 0))
model_dir = "models/anime_style_art_rgb"; model_dir = TEXT("models/anime_style_art_rgb");
else if (SendMessage(GetDlgItem(dh, IDC_RADIO_MODEL_Y), BM_GETCHECK, 0, 0)) else if (SendMessage(GetDlgItem(dh, IDC_RADIO_MODEL_Y), BM_GETCHECK, 0, 0))
model_dir = "models/anime_style_art"; model_dir = TEXT("models/anime_style_art");
else else
model_dir = "models/photo"; model_dir = TEXT("models/photo");
{ {
char buf[AR_PATH_MAX] = ""; TCHAR buf[AR_PATH_MAX] = TEXT("");
GetWindowTextA(GetDlgItem(dh, IDC_EDIT_OUT_EXT), buf, _countof(buf)); GetWindowText(GetDlgItem(dh, IDC_EDIT_OUT_EXT), buf, _countof(buf));
buf[_countof(buf) - 1] = '\0'; buf[_countof(buf) - 1] = TEXT('\0');
outputExt = buf; outputExt = buf;
if (outputExt.length() > 0 && outputExt[0] != '.') if (outputExt.length() > 0 && outputExt[0] != TEXT('.'))
outputExt = "." + outputExt; outputExt = TEXT(".") + outputExt;
} }
if (SendMessage(GetDlgItem(dh, IDC_RADIO_MODE_CPU), BM_GETCHECK, 0, 0)) if (SendMessage(GetDlgItem(dh, IDC_RADIO_MODE_CPU), BM_GETCHECK, 0, 0))
@ -221,36 +255,36 @@ private:
process = "gpu"; process = "gpu";
{ {
char buf[AR_PATH_MAX] = ""; TCHAR buf[AR_PATH_MAX] = TEXT("");
GetWindowTextA(GetDlgItem(dh, IDC_EDIT_INPUT_EXT_LIST), buf, _countof(buf)); GetWindowText(GetDlgItem(dh, IDC_EDIT_INPUT_EXT_LIST), buf, _countof(buf));
buf[_countof(buf) - 1] = '\0'; buf[_countof(buf) - 1] = TEXT('\0');
inputFileExt = buf; inputFileExt = buf;
// input_extention_listを文字列の配列にする // input_extention_listを文字列の配列にする
typedef boost::char_separator<char> char_separator; typedef boost::char_separator<TCHAR> char_separator;
typedef boost::tokenizer<char_separator> tokenizer; typedef boost::tokenizer<char_separator, tstring::const_iterator, tstring> tokenizer;
char_separator sep(":", "", boost::drop_empty_tokens); char_separator sep(TEXT(":"), TEXT(""), boost::drop_empty_tokens);
tokenizer tokens(inputFileExt, sep); tokenizer tokens(inputFileExt, sep);
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) for (auto tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
{ {
std::string ext(*tok_iter); tstring ext(*tok_iter);
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
extList.push_back("." + ext); extList.push_back(TEXT(".") + ext);
} }
} }
if (!NotSyncCropSize) if (!NotSyncCropSize)
{ {
char buf[AR_PATH_MAX] = ""; TCHAR buf[AR_PATH_MAX] = TEXT("");
GetWindowTextA(GetDlgItem(dh, IDC_COMBO_CROP_SIZE), buf, _countof(buf)); GetWindowText(GetDlgItem(dh, IDC_COMBO_CROP_SIZE), buf, _countof(buf));
buf[_countof(buf) - 1] = '\0'; buf[_countof(buf) - 1] = TEXT('\0');
char *ptr = nullptr; TCHAR *ptr = nullptr;
crop_size = strtol (buf, &ptr, 10); crop_size = _tcstol(buf, &ptr, 10);
if (!ptr || *ptr != '\0' || crop_size <= 0) if (!ptr || *ptr != '\0' || crop_size <= 0)
{ {
crop_size = 128; crop_size = 128;
@ -278,8 +312,12 @@ private:
if (!boost::filesystem::is_directory(p)) if (!boost::filesystem::is_directory(p))
{ {
std::string ext(p.extension().string()); tstring ext(getTString(p.extension()));
#ifdef UNICODE
std::transform(ext.begin(), ext.end(), ext.begin(), ::towlower);
#else
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
#endif
if (std::find(extList.begin(), extList.end(), ext) != extList.end()) if (std::find(extList.begin(), extList.end(), ext) != extList.end())
{ {
auto mat = Waifu2x::LoadMat(p.string()); auto mat = Waifu2x::LoadMat(p.string());
@ -325,8 +363,8 @@ private:
{ {
const int n = list[i]; const int n = list[i];
std::string str(std::to_string(n)); tstring str(to_tstring(n));
SendMessageA(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str()); SendMessage(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str());
const int diff = abs(DefaultCommonDivisor - n); const int diff = abs(DefaultCommonDivisor - n);
if (DefaultCommonDivisorRange.first <= n && n <= DefaultCommonDivisorRange.second && diff < mindiff) if (DefaultCommonDivisorRange.first <= n && n <= DefaultCommonDivisorRange.second && diff < mindiff)
@ -336,15 +374,15 @@ private:
} }
} }
SendMessageA(hcrop, CB_ADDSTRING, 0, (LPARAM)"-----------------------"); SendMessage(hcrop, CB_ADDSTRING, 0, (LPARAM)TEXT("-----------------------"));
// CropSizeListの値を追加していく // CropSizeListの値を追加していく
mindiff = INT_MAX; mindiff = INT_MAX;
int defaultListIndex = -1; int defaultListIndex = -1;
for (const auto n : CropSizeList) for (const auto n : CropSizeList)
{ {
std::string str(std::to_string(n)); tstring str(to_tstring(n));
const int index = SendMessageA(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str()); const int index = SendMessage(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str());
const int diff = abs(DefaultCommonDivisor - n); const int diff = abs(DefaultCommonDivisor - n);
if (DefaultCommonDivisorRange.first <= n && n <= DefaultCommonDivisorRange.second && diff < mindiff) if (DefaultCommonDivisorRange.first <= n && n <= DefaultCommonDivisorRange.second && diff < mindiff)
@ -365,7 +403,7 @@ private:
{ {
const boost::filesystem::path input_path(boost::filesystem::absolute(input_str)); const boost::filesystem::path input_path(boost::filesystem::absolute(input_str));
std::vector<std::pair<std::string, std::string>> file_paths; std::vector<std::pair<tstring, tstring>> file_paths;
if (boost::filesystem::is_directory(input_path)) // input_pathがフォルダならそのディレクトリ以下の画像ファイルを一括変換 if (boost::filesystem::is_directory(input_path)) // input_pathがフォルダならそのディレクトリ以下の画像ファイルを一括変換
{ {
boost::filesystem::path output_path(output_str); boost::filesystem::path output_path(output_str);
@ -391,16 +429,21 @@ private:
{ {
if (!boost::filesystem::is_directory(p)) if (!boost::filesystem::is_directory(p))
{ {
std::string ext(p.extension().string()); tstring ext(getTString(p.extension()));
#ifdef UNICODE
std::transform(ext.begin(), ext.end(), ext.begin(), ::towlower);
#else
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
#endif
if (std::find(extList.begin(), extList.end(), ext) != extList.end()) if (std::find(extList.begin(), extList.end(), ext) != extList.end())
{ {
const auto out_relative = relativePath(p, input_path); const auto out_relative = relativePath(p, input_path);
const auto out_absolute = output_path / out_relative; const auto out_absolute = output_path / out_relative;
const auto out = (out_absolute.branch_path() / out_absolute.stem()).string() + outputExt; const auto out = getTString(out_absolute.branch_path() / out_absolute.stem()) + outputExt;
file_paths.emplace_back(p.string(), out); file_paths.emplace_back(getTString(p), out);
} }
} }
} }
@ -494,20 +537,20 @@ private:
SyncMember(true); SyncMember(true);
const boost::filesystem::path output_path(output_str); const boost::filesystem::path output_path(output_str);
std::string stem; tstring stem;
if (!boost::filesystem::is_directory(input_str)) if (!boost::filesystem::is_directory(input_str))
stem = output_path.stem().string(); stem = getTString(output_path.stem());
else else
stem = output_path.filename().string(); stem = getTString(output_path.filename());
if (stem.length() > 0 && stem.length() >= autoSetAddName.length()) if (stem.length() > 0 && stem.length() >= autoSetAddName.length())
{ {
const std::string base = stem.substr(0, stem.length() - autoSetAddName.length()); const tstring base = stem.substr(0, stem.length() - autoSetAddName.length());
stem.erase(0, base.length()); stem.erase(0, base.length());
if (stem == autoSetAddName) if (stem == autoSetAddName)
{ {
const std::string addstr(AddName()); const tstring addstr(AddName());
autoSetAddName = addstr; autoSetAddName = addstr;
boost::filesystem::path new_out_path; boost::filesystem::path new_out_path;
@ -516,36 +559,36 @@ private:
else else
new_out_path = output_path.branch_path() / (base + addstr); new_out_path = output_path.branch_path() / (base + addstr);
SetWindowTextA(GetDlgItem(dh, IDC_EDIT_OUTPUT), new_out_path.string().c_str()); SetWindowText(GetDlgItem(dh, IDC_EDIT_OUTPUT), getTString(new_out_path).c_str());
} }
} }
} }
void AddLogMessage(const char *msg) void AddLogMessage(const TCHAR *msg)
{ {
if (logMessage.length() == 0) if (logMessage.length() == 0)
logMessage += msg; logMessage += msg;
else else
logMessage += std::string("\r\n") + msg; logMessage += tstring(TEXT("\r\n")) + msg;
SetWindowTextA(GetDlgItem(dh, IDC_EDIT_LOG), logMessage.c_str()); SetWindowText(GetDlgItem(dh, IDC_EDIT_LOG), logMessage.c_str());
} }
void Waifu2xTime() void Waifu2xTime()
{ {
char msg[1024 * 2]; TCHAR msg[1024 * 2];
char *ptr = msg; TCHAR *ptr = msg;
{ {
std::string p(usedProcess); tstring p;
if (p == "cpu") if (usedProcess == "cpu")
p = "CPU"; p = TEXT("CPU");
else if (p == "gpu") else if (usedProcess == "gpu")
p = "CUDA"; p = TEXT("CUDA");
else if (p == "cudnn") else // if (p == "cudnn")
p = "cuDNN"; p = TEXT("cuDNN");
ptr += sprintf(ptr, "使用プロセッサーモード: %s\r\n", p.c_str()); ptr += _stprintf(ptr, TEXT("使用プロセッサーモード: %s\r\n"), p.c_str());
} }
{ {
@ -554,7 +597,7 @@ private:
const int sec = t % 60; t /= 60; const int sec = t % 60; t /= 60;
const int min = t % 60; t /= 60; const int min = t % 60; t /= 60;
const int hour = (int)t; const int hour = (int)t;
ptr += sprintf(ptr, "処理時間: %02d:%02d:%02d.%d\r\n", hour, min, sec, msec); ptr += _stprintf(ptr, TEXT("処理時間: %02d:%02d:%02d.%d\r\n"), hour, min, sec, msec);
} }
{ {
@ -563,7 +606,7 @@ private:
const int sec = t % 60; t /= 60; const int sec = t % 60; t /= 60;
const int min = t % 60; t /= 60; const int min = t % 60; t /= 60;
const int hour = (int)t; const int hour = (int)t;
ptr += sprintf(ptr, "初期化時間: %02d:%02d:%02d.%d\r\n", hour, min, sec, msec); ptr += _stprintf(ptr, TEXT("初期化時間: %02d:%02d:%02d.%d\r\n"), hour, min, sec, msec);
} }
if (process == "gpu" || process == "cudnn") if (process == "gpu" || process == "cudnn")
@ -573,14 +616,15 @@ private:
const int sec = t % 60; t /= 60; const int sec = t % 60; t /= 60;
const int min = t % 60; t /= 60; const int min = t % 60; t /= 60;
const int hour = (int)t; const int hour = (int)t;
ptr += sprintf(ptr, "cuDNNチェック時間: %02d:%02d:%02d.%d", hour, min, sec, msec); ptr += _stprintf(ptr, TEXT("cuDNNチェック時間: %02d:%02d:%02d.%d"), hour, min, sec, msec);
} }
AddLogMessage(msg); AddLogMessage(msg);
} }
public: public:
DialogEvent() : dh(nullptr), mode("noise_scale"), noise_level(1), scale_ratio(2.0), model_dir("models/anime_style_art_rgb"), process("gpu"), outputExt("png"), inputFileExt("png:jpg:jpeg:tif:tiff:bmp:tga"), DialogEvent() : dh(nullptr), mode("noise_scale"), noise_level(1), scale_ratio(2.0), model_dir(TEXT("models/anime_style_art_rgb")),
process("gpu"), outputExt(TEXT("png")), inputFileExt(TEXT("png:jpg:jpeg:tif:tiff:bmp:tga")),
use_tta(false), crop_size(128), batch_size(1), isLastError(false) use_tta(false), crop_size(128), batch_size(1), isLastError(false)
{ {
} }
@ -635,7 +679,7 @@ public:
EnableWindow(GetDlgItem(dh, IDC_BUTTON_EXEC), FALSE); EnableWindow(GetDlgItem(dh, IDC_BUTTON_EXEC), FALSE);
EnableWindow(GetDlgItem(dh, IDC_BUTTON_CHECK_CUDNN), FALSE); EnableWindow(GetDlgItem(dh, IDC_BUTTON_CHECK_CUDNN), FALSE);
SetWindowTextA(GetDlgItem(hWnd, IDC_EDIT_LOG), ""); SetWindowText(GetDlgItem(hWnd, IDC_EDIT_LOG), TEXT(""));
logMessage.clear(); logMessage.clear();
} }
@ -649,13 +693,13 @@ public:
if (!isLastError) if (!isLastError)
{ {
if (!cancelFlag) if (!cancelFlag)
AddLogMessage("変換に成功しました"); AddLogMessage(TEXT("変換に成功しました"));
Waifu2xTime(); Waifu2xTime();
MessageBeep(MB_ICONASTERISK); MessageBeep(MB_ICONASTERISK);
} }
else else
MessageBoxA(dh, "エラーが発生しました", "エラー", MB_OK | MB_ICONERROR); MessageBox(dh, TEXT("エラーが発生しました"), TEXT("エラー"), MB_OK | MB_ICONERROR);
} }
void OnDialogEnd(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData) void OnDialogEnd(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
@ -671,9 +715,9 @@ public:
const boost::filesystem::path *p = (const boost::filesystem::path *)wParam; const boost::filesystem::path *p = (const boost::filesystem::path *)wParam;
// 出力フォルダ「%s」の作成に失敗しました\n", out_absolute.string().c_str()); // 出力フォルダ「%s」の作成に失敗しました\n", out_absolute.string().c_str());
std::wstring msg(L"出力フォルダ\r\n"); tstring msg(TEXT("出力フォルダ\r\n"));
msg += p->wstring(); msg += getTString(*p);
msg += L"\r\nの作成に失敗しました"; msg += TEXT("\r\nの作成に失敗しました");
MessageBox(dh, msg.c_str(), TEXT("エラー"), MB_OK | MB_ICONERROR); MessageBox(dh, msg.c_str(), TEXT("エラー"), MB_OK | MB_ICONERROR);
@ -686,49 +730,49 @@ public:
if (ret != Waifu2x::eWaifu2xError_OK) if (ret != Waifu2x::eWaifu2xError_OK)
{ {
char msg[1024] = ""; TCHAR msg[1024] = TEXT("");
if (lParam == 0) if (lParam == 0)
{ {
switch (ret) switch (ret)
{ {
case Waifu2x::eWaifu2xError_Cancel: case Waifu2x::eWaifu2xError_Cancel:
sprintf(msg, "キャンセルされました"); _stprintf(msg, TEXT("キャンセルされました"));
break; break;
case Waifu2x::eWaifu2xError_InvalidParameter: case Waifu2x::eWaifu2xError_InvalidParameter:
sprintf(msg, "パラメータが不正です"); _stprintf(msg, TEXT("パラメータが不正です"));
break; break;
case Waifu2x::eWaifu2xError_FailedOpenModelFile: case Waifu2x::eWaifu2xError_FailedOpenModelFile:
sprintf(msg, "モデルファイルが開けませんでした"); _stprintf(msg, TEXT("モデルファイルが開けませんでした"));
break; break;
case Waifu2x::eWaifu2xError_FailedParseModelFile: case Waifu2x::eWaifu2xError_FailedParseModelFile:
sprintf(msg, "モデルファイルが壊れています"); _stprintf(msg, TEXT("モデルファイルが壊れています"));
break; break;
case Waifu2x::eWaifu2xError_FailedConstructModel: case Waifu2x::eWaifu2xError_FailedConstructModel:
sprintf(msg, "ネットワークの構築に失敗しました"); _stprintf(msg, TEXT("ネットワークの構築に失敗しました"));
break; break;
} }
} }
else else
{ {
const auto &fp = *(const std::pair<std::string, std::string> *)lParam; const auto &fp = *(const std::pair<tstring, tstring> *)lParam;
switch (ret) switch (ret)
{ {
case Waifu2x::eWaifu2xError_Cancel: case Waifu2x::eWaifu2xError_Cancel:
sprintf(msg, "キャンセルされました"); _stprintf(msg, TEXT("キャンセルされました"));
break; break;
case Waifu2x::eWaifu2xError_InvalidParameter: case Waifu2x::eWaifu2xError_InvalidParameter:
sprintf(msg, "パラメータが不正です"); _stprintf(msg, TEXT("パラメータが不正です"));
break; break;
case Waifu2x::eWaifu2xError_FailedOpenInputFile: case Waifu2x::eWaifu2xError_FailedOpenInputFile:
sprintf(msg, "入力画像「%s」が開けませんでした", fp.first.c_str()); _stprintf(msg, TEXT("入力画像「%s」が開けませんでした"), fp.first.c_str());
break; break;
case Waifu2x::eWaifu2xError_FailedOpenOutputFile: case Waifu2x::eWaifu2xError_FailedOpenOutputFile:
sprintf(msg, "出力画像を「%s」に書き込めませんでした", fp.second.c_str()); _stprintf(msg, TEXT("出力画像を「%s」に書き込めませんでした"), fp.second.c_str());
break; break;
case Waifu2x::eWaifu2xError_FailedProcessCaffe: case Waifu2x::eWaifu2xError_FailedProcessCaffe:
sprintf(msg, "補間処理に失敗しました"); _stprintf(msg, TEXT("補間処理に失敗しました"));
break; break;
} }
} }
@ -751,10 +795,10 @@ public:
EnableWindow(GetDlgItem(dh, IDC_BUTTON_CANCEL), FALSE); EnableWindow(GetDlgItem(dh, IDC_BUTTON_CANCEL), FALSE);
char text[] = "2.00"; TCHAR text[] = TEXT("2.00");
SetWindowTextA(GetDlgItem(hWnd, IDC_EDIT_SCALE_RATIO), text); SetWindowText(GetDlgItem(hWnd, IDC_EDIT_SCALE_RATIO), text);
SetWindowTextA(GetDlgItem(hWnd, IDC_EDIT_OUT_EXT), outputExt.c_str()); SetWindowText(GetDlgItem(hWnd, IDC_EDIT_OUT_EXT), outputExt.c_str());
SetWindowTextA(GetDlgItem(hWnd, IDC_EDIT_INPUT_EXT_LIST), inputFileExt.c_str()); SetWindowText(GetDlgItem(hWnd, IDC_EDIT_INPUT_EXT_LIST), inputFileExt.c_str());
std::ifstream ifs(CropSizeListName); std::ifstream ifs(CropSizeListName);
if (ifs) if (ifs)
@ -847,13 +891,13 @@ public:
// ここで渡されるhWndはIDC_EDITのHWND(コントロールのイベントだから) // ここで渡されるhWndはIDC_EDITのHWND(コントロールのイベントだから)
LRESULT DropInput(HWND hWnd, WPARAM wParam, LPARAM lParam, WNDPROC OrgSubWnd, LPVOID lpData) LRESULT DropInput(HWND hWnd, WPARAM wParam, LPARAM lParam, WNDPROC OrgSubWnd, LPVOID lpData)
{ {
char szTmp[AR_PATH_MAX]; TCHAR szTmp[AR_PATH_MAX];
// ドロップされたファイル数を取得 // ドロップされたファイル数を取得
UINT FileNum = DragQueryFileA((HDROP)wParam, 0xFFFFFFFF, szTmp, _countof(szTmp)); UINT FileNum = DragQueryFile((HDROP)wParam, 0xFFFFFFFF, szTmp, _countof(szTmp));
if (FileNum >= 1) if (FileNum >= 1)
{ {
DragQueryFileA((HDROP)wParam, 0, szTmp, _countof(szTmp)); DragQueryFile((HDROP)wParam, 0, szTmp, _countof(szTmp));
boost::filesystem::path path(szTmp); boost::filesystem::path path(szTmp);
@ -870,33 +914,32 @@ public:
{ {
HWND ho = GetDlgItem(dh, IDC_EDIT_OUTPUT); HWND ho = GetDlgItem(dh, IDC_EDIT_OUTPUT);
const std::string addstr(AddName()); const tstring addstr(AddName());
autoSetAddName = AddName(); autoSetAddName = AddName();
auto str = (path.branch_path() / (path.stem().string() + addstr)).string(); const auto str = getTString(path.branch_path() / (path.stem().wstring() + addstr));
SetWindowText(ho, str.c_str());
SetWindowTextA(ho, str.c_str()); SetWindowText(hWnd, szTmp);
SetWindowTextA(hWnd, szTmp);
} }
else else
{ {
HWND ho = GetDlgItem(dh, IDC_EDIT_OUTPUT); HWND ho = GetDlgItem(dh, IDC_EDIT_OUTPUT);
std::string outputFileName = szTmp; tstring outputFileName = szTmp;
const auto tailDot = outputFileName.find_last_of('.'); const auto tailDot = outputFileName.find_last_of('.');
if (tailDot != outputFileName.npos) if (tailDot != outputFileName.npos)
outputFileName.erase(tailDot, outputFileName.length()); outputFileName.erase(tailDot, outputFileName.length());
const std::string addstr(AddName()); const tstring addstr(AddName());
autoSetAddName = addstr; autoSetAddName = addstr;
outputFileName += addstr + outputExt; outputFileName += addstr + outputExt;
SetWindowTextA(ho, outputFileName.c_str()); SetWindowText(ho, outputFileName.c_str());
SetWindowTextA(hWnd, szTmp); SetWindowText(hWnd, szTmp);
} }
SetCropSizeList(path); SetCropSizeList(path);