From 97875226e59a1b301aa73b8965714529147f58e5 Mon Sep 17 00:00:00 2001 From: amate Date: Tue, 20 Apr 2021 23:41:10 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=BBreadme.md=E3=81=A8About=E7=94=BB?= =?UTF-8?q?=E9=9D=A2=E3=81=AB=E3=82=A4=E3=83=99=E3=83=B3=E3=83=88=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=BF=E3=81=AE=E5=8F=96=E5=BE=97=E5=85=83=E3=81=AE?= =?UTF-8?q?=E5=87=BA=E5=85=B8=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・std::ifstreamなどにwstringを渡すようにした ・高DPI環境で動作しないのを修正 #5 ・UmaUmaCruise.exeが置かれるフォルダまでのパスにunicodeが含まれていると警告ダイアログを表示するようにした ->readme.mdに詳細を記載 ・ptess->Initに tessdataフォルダへのパスを渡すようにした #5 ・起動時に::SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED);を実行するようにした ->高DPI対応 ・根岸ステークス/Sの表記ゆれを修正 #1 --- UmaCruise/AboutDlg.cpp | 8 +++++++- UmaCruise/AboutDlg.h | 5 ++++- UmaCruise/Config.cpp | 8 ++++---- UmaCruise/ConfigDlg.cpp | 2 +- UmaCruise/MainDlg.cpp | 27 ++++++++++++++++++++------- UmaCruise/RaceDateLibrary.cpp | 2 +- UmaCruise/TesseractWrapper.cpp | 3 ++- UmaCruise/UmaCruise.cpp | 2 ++ UmaCruise/UmaCruise.rc | 7 +++++-- UmaCruise/UmaCruise.vcxproj | 4 ++++ UmaCruise/UmaEventLibrary.cpp | 6 +++--- UmaCruise/UmaTextRecognizer.cpp | 10 +++++++--- UmaCruise/resource.h | 3 ++- UmaCruise/stdafx.h | 8 ++++---- UmaLibrary/RaceDataLibrary.json | 2 +- readme.md | 13 +++++++++++++ 16 files changed, 80 insertions(+), 30 deletions(-) diff --git a/UmaCruise/AboutDlg.cpp b/UmaCruise/AboutDlg.cpp index fdfc0df..ddb5d78 100644 --- a/UmaCruise/AboutDlg.cpp +++ b/UmaCruise/AboutDlg.cpp @@ -79,6 +79,12 @@ LRESULT CAboutDlg::OnCloseCmd(WORD, WORD wID, HWND, BOOL&) return 0; } +LRESULT CAboutDlg::OnLinkClick(int, LPNMHDR, BOOL&) +{ + ::ShellExecute(NULL, nullptr, L"https://gamerch.com/umamusume/", nullptr, nullptr, SW_NORMAL); + return LRESULT(); +} + LRESULT CAboutDlg::OnOCR(WORD, WORD, HWND, BOOL&) { const int index = m_cmbTestBounds.GetCurSel(); @@ -93,7 +99,7 @@ LRESULT CAboutDlg::OnOCR(WORD, WORD, HWND, BOOL&) CRect rcBounds; if (index != kDirect) { json jsonCommon; - std::ifstream ifs((GetExeDirectory() / L"Common.json").string()); + std::ifstream ifs((GetExeDirectory() / L"Common.json").wstring()); ATLASSERT(ifs); if (!ifs) { return 0; diff --git a/UmaCruise/AboutDlg.h b/UmaCruise/AboutDlg.h index 98989b6..090e8f1 100644 --- a/UmaCruise/AboutDlg.h +++ b/UmaCruise/AboutDlg.h @@ -8,7 +8,7 @@ class PreviewWindow; #include "resource.h" -constexpr LPCWSTR kAppVersion = L"v1.1"; +constexpr LPCWSTR kAppVersion = L"v1.2"; class CAboutDlg : public CDialogImpl { @@ -21,6 +21,7 @@ class CAboutDlg : public CDialogImpl MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) COMMAND_ID_HANDLER(IDOK, OnCloseCmd) COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd) + NOTIFY_HANDLER(IDC_SYSLINK1, NM_CLICK, OnLinkClick) COMMAND_ID_HANDLER(IDC_BUTTON_OCR, OnOCR) END_MSG_MAP() @@ -32,6 +33,8 @@ class CAboutDlg : public CDialogImpl LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnLinkClick(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/); + LRESULT OnOCR(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); private: diff --git a/UmaCruise/Config.cpp b/UmaCruise/Config.cpp index becf40f..0cb298f 100644 --- a/UmaCruise/Config.cpp +++ b/UmaCruise/Config.cpp @@ -13,7 +13,7 @@ using namespace CodeConvert; bool Config::LoadConfig() { - std::ifstream fs((GetExeDirectory() / "setting.json").string()); + std::ifstream fs((GetExeDirectory() / "setting.json").wstring()); if (!fs) { return true; } @@ -33,7 +33,7 @@ bool Config::LoadConfig() void Config::SaveConfig() { - std::ifstream ifs((GetExeDirectory() / "setting.json").string()); + std::ifstream ifs((GetExeDirectory() / "setting.json").wstring()); if (!ifs) { ATLASSERT(FALSE); ERROR_LOG << L"SaveConfig failed: !fs"; @@ -47,6 +47,6 @@ void Config::SaveConfig() jsonSetting["Config"]["AutoStart"] = autoStart; jsonSetting["Config"]["StopUpdatePreviewOnTraining"] = stopUpdatePreviewOnTraining; - std::ofstream ofs((GetExeDirectory() / "setting.json").string()); - ofs << jsonSetting; + std::ofstream ofs((GetExeDirectory() / "setting.json").wstring()); + ofs << jsonSetting.dump(4); } diff --git a/UmaCruise/ConfigDlg.cpp b/UmaCruise/ConfigDlg.cpp index 5f9a206..e51d724 100644 --- a/UmaCruise/ConfigDlg.cpp +++ b/UmaCruise/ConfigDlg.cpp @@ -59,7 +59,7 @@ LRESULT ConfigDlg::OnCancel(WORD, WORD, HWND, BOOL&) void ConfigDlg::OnCheckUmaLibrary(UINT uNotifyCode, int nID, CWindow wndCtl) { try { - std::ifstream ifs((GetExeDirectory() / "Common.json").string()); + std::ifstream ifs((GetExeDirectory() / "Common.json").wstring()); ATLASSERT(ifs); if (!ifs) { MessageBox(L"Common.json ̓ǂݍ݂Ɏs"); diff --git a/UmaCruise/MainDlg.cpp b/UmaCruise/MainDlg.cpp index c6196bc..660382b 100644 --- a/UmaCruise/MainDlg.cpp +++ b/UmaCruise/MainDlg.cpp @@ -22,12 +22,16 @@ bool SaveWindowScreenShot(HWND hWndTarget, const std::wstring& filePath) { CWindowDC dc(NULL/*hWndTarget*/); + ::SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); + CRect rcWindow; ::GetWindowRect(hWndTarget, &rcWindow); CRect rcClient; ::GetClientRect(hWndTarget, rcClient); + ::SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED); + CRect rcAdjustClient = rcWindow; const int topMargin = (rcWindow.Height() - rcClient.Height() - GetSystemMetrics(SM_CXFRAME) * 2 - GetSystemMetrics(SM_CYCAPTION)) / 2; rcAdjustClient.top += GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CYCAPTION) + topMargin; @@ -135,6 +139,15 @@ LRESULT CMainDlg::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&) UIAddChildWindowContainer(m_hWnd); + // tH_pX̕R[h`FbN + auto exeDir = GetExeDirectory().wstring(); + auto sjisDir = ShiftJISfromUTF16(exeDir); + auto sjis_utf16exeDir = UTF16fromShiftJIS(sjisDir); + if (exeDir != sjis_utf16exeDir) { + //ERROR_LOG << L"exeDir contain unicode"; + MessageBox(L"tH_unicode܂܂Ă̂Ő퓮삵܂B\nƐ󂢊Kw(C:\\)ȂǂɃtH_ړĂB", L"G[", MB_ICONERROR); + } + m_config.LoadConfig(); DoDataExchange(DDX_LOAD); @@ -198,7 +211,7 @@ LRESULT CMainDlg::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&) try { { - std::ifstream ifs((GetExeDirectory() / "Common.json").string()); + std::ifstream ifs((GetExeDirectory() / "Common.json").wstring()); ATLASSERT(ifs); if (!ifs) { ERROR_LOG << L"Common.json ݂܂..."; @@ -212,7 +225,7 @@ LRESULT CMainDlg::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&) } } - std::ifstream fs((GetExeDirectory() / "setting.json").string()); + std::ifstream fs((GetExeDirectory() / "setting.json").wstring()); if (fs) { json jsonSetting; fs >> jsonSetting; @@ -313,7 +326,7 @@ LRESULT CMainDlg::OnCancel(WORD, WORD wID, HWND, BOOL&) DoDataExchange(DDX_SAVE); json jsonSetting; - std::ifstream fs((GetExeDirectory() / "setting.json").string()); + std::ifstream fs((GetExeDirectory() / "setting.json").wstring()); if (fs) { fs >> jsonSetting; } @@ -341,8 +354,8 @@ LRESULT CMainDlg::OnCancel(WORD, WORD wID, HWND, BOOL&) jsonSetting["MainDlg"]["ShowRaceAfterCurrentDate"] = m_showRaceAfterCurrentDate; jsonSetting["MainDlg"]["RaceMatchState"] = _GetRaceMatchState(); - std::ofstream ofs((GetExeDirectory() / "setting.json").string()); - ofs << jsonSetting; + std::ofstream ofs((GetExeDirectory() / "setting.json").wstring()); + ofs << jsonSetting.dump(4); DestroyWindow(); ::PostQuitMessage(0); @@ -581,7 +594,7 @@ void CMainDlg::OnEventRevision(UINT uNotifyCode, int nID, CWindow wndCtl) return; } { - std::ifstream ifs((GetExeDirectory() / "UmaMusumeLibraryRevision.json").string()); + std::ifstream ifs((GetExeDirectory() / "UmaMusumeLibraryRevision.json").wstring()); ATLASSERT(ifs); if (!ifs) { MessageBox(L"UmaMusumeLibraryRevision.json ̓ǂݍ݂Ɏs"); @@ -618,7 +631,7 @@ void CMainDlg::OnEventRevision(UINT uNotifyCode, int nID, CWindow wndCtl) } // ۑ - std::ofstream ofs((GetExeDirectory() / "UmaMusumeLibraryRevision.json").string()); + std::ofstream ofs((GetExeDirectory() / "UmaMusumeLibraryRevision.json").wstring()); ATLASSERT(ofs); if (!ofs) { MessageBox(L"UmaMusumeLibraryRevision.json ̃I[vɎs"); diff --git a/UmaCruise/RaceDateLibrary.cpp b/UmaCruise/RaceDateLibrary.cpp index 866d254..3898b5f 100644 --- a/UmaCruise/RaceDateLibrary.cpp +++ b/UmaCruise/RaceDateLibrary.cpp @@ -32,7 +32,7 @@ bool RaceDateLibrary::LoadRaceDataLibrary() ATLASSERT(m_allTurnList.size()); m_turnOrderedRaceList.resize(m_allTurnList.size()); - std::ifstream ifs((GetExeDirectory() / L"RaceDataLibrary.json").string()); + std::ifstream ifs((GetExeDirectory() / L"RaceDataLibrary.json").wstring()); ATLASSERT(ifs); if (!ifs) { throw std::runtime_error("RaceDataLibrary.json ̓ǂݍ݂Ɏs"); diff --git a/UmaCruise/TesseractWrapper.cpp b/UmaCruise/TesseractWrapper.cpp index ab36432..9b92bdf 100644 --- a/UmaCruise/TesseractWrapper.cpp +++ b/UmaCruise/TesseractWrapper.cpp @@ -41,7 +41,8 @@ namespace TesseractWrapper { auto& ptess = s_threadTess[::GetCurrentThreadId()]; if (!ptess) { ptess.reset(new tesseract::TessBaseAPI); - if (ptess->Init(NULL, "jpn")) { + auto dbFolderPath = GetExeDirectory() / L"tessdata"; + if (ptess->Init(dbFolderPath.string().c_str(), "jpn")) { ERROR_LOG << L"Could not initialize tesseract."; return L""; } diff --git a/UmaCruise/UmaCruise.cpp b/UmaCruise/UmaCruise.cpp index b807915..64a2cda 100644 --- a/UmaCruise/UmaCruise.cpp +++ b/UmaCruise/UmaCruise.cpp @@ -55,6 +55,8 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lp TesseractWrapper::TesseractInit(); WinHTTPWrapper::InitWinHTTP(); + ::SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED); + int nRet = Run(lpstrCmdLine, nCmdShow); WinHTTPWrapper::TermWinHTTP(); diff --git a/UmaCruise/UmaCruise.rc b/UmaCruise/UmaCruise.rc index f4236f6..fbc6dc2 100644 --- a/UmaCruise/UmaCruise.rc +++ b/UmaCruise/UmaCruise.rc @@ -24,7 +24,7 @@ LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT // Dialog // -IDD_ABOUTBOX DIALOGEX 0, 0, 192, 222 +IDD_ABOUTBOX DIALOGEX 0, 0, 378, 222 STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_ACCEPTFILES CAPTION "About" @@ -39,6 +39,9 @@ BEGIN EDITTEXT IDC_EDIT_RESULT,18,132,156,60,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL PUSHBUTTON "OCR",IDC_BUTTON_OCR,18,198,66,18 CONTROL "",IDC_SLIDER_THRESHOLD,"msctls_trackbar32",TBS_AUTOTICKS | TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,90,200,84,12 + LTEXT "CxgIf[^(UmaMusumeLibrary.json)ɂ‚\n\nGamerchl^c""E}Uwiki""\nCxgf[^HāAĂ܂",IDC_STATIC,132,12,180,33 + CONTROL "URL:https://gamerch.com/umamusume/",IDC_SYSLINK1, + "SysLink",WS_TABSTOP,132,48,180,11 END IDD_MAINDLG DIALOGEX 0, 0, 570, 222 @@ -137,7 +140,7 @@ BEGIN IDD_ABOUTBOX, DIALOG BEGIN LEFTMARGIN, 7 - RIGHTMARGIN, 185 + RIGHTMARGIN, 371 TOPMARGIN, 7 BOTTOMMARGIN, 215 END diff --git a/UmaCruise/UmaCruise.vcxproj b/UmaCruise/UmaCruise.vcxproj index 5a5906d..b8177bf 100644 --- a/UmaCruise/UmaCruise.vcxproj +++ b/UmaCruise/UmaCruise.vcxproj @@ -21,6 +21,7 @@ 16.0 {EAA1B122-D050-4C8B-B9CB-1A6BFE424F65} + 10.0 @@ -72,6 +73,7 @@ true $(SolutionDir)opencv\include;$(SolutionDir)tesseract\include;$(IncludePath) $(SolutionDir)opencv\x64\lib;$(SolutionDir)tesseract\debug\lib;$(LibraryPath) + $(SolutionDir)$(Platform)\$(Configuration)\ false @@ -142,6 +144,8 @@ $(IntDir)/UmaCruise.tlb + + diff --git a/UmaCruise/UmaEventLibrary.cpp b/UmaCruise/UmaEventLibrary.cpp index 3e160dd..dbfa8fa 100644 --- a/UmaCruise/UmaEventLibrary.cpp +++ b/UmaCruise/UmaEventLibrary.cpp @@ -98,7 +98,7 @@ bool UmaEventLibrary::LoadUmaMusumeLibrary() }; { // UmaMusumeLibrary.json - std::ifstream ifs((GetExeDirectory() / "UmaMusumeLibrary.json").string()); + std::ifstream ifs((GetExeDirectory() / "UmaMusumeLibrary.json").wstring()); ATLASSERT(ifs); if (!ifs) { throw std::runtime_error("UmaMusumeLibrary.json ̓ǂݍ݂Ɏs"); @@ -126,7 +126,7 @@ bool UmaEventLibrary::LoadUmaMusumeLibrary() funcLoad(jsonLibrary, "Support", m_supportEventList); } { // UmaMusumeLibraryRevision.json - std::ifstream ifs((GetExeDirectory() / "UmaMusumeLibraryRevision.json").string()); + std::ifstream ifs((GetExeDirectory() / "UmaMusumeLibraryRevision.json").wstring()); ATLASSERT(ifs); if (!ifs) { throw std::runtime_error("UmaMusumeLibraryRevision.json ̓ǂݍ݂Ɏs"); @@ -167,7 +167,7 @@ bool UmaEventLibrary::LoadUmaMusumeLibrary() } } { - std::ifstream ifs((GetExeDirectory() / L"Common.json").string()); + std::ifstream ifs((GetExeDirectory() / L"Common.json").wstring()); ATLASSERT(ifs); if (!ifs) { throw std::runtime_error("Common.json ̓ǂݍ݂Ɏs"); diff --git a/UmaCruise/UmaTextRecognizer.cpp b/UmaCruise/UmaTextRecognizer.cpp index 8d9279d..91e6041 100644 --- a/UmaCruise/UmaTextRecognizer.cpp +++ b/UmaCruise/UmaTextRecognizer.cpp @@ -39,8 +39,8 @@ void SavePointSizeFromJson(json& json, const std::string& key, const CPoint& pt, cv::Mat GdiPlusBitmapToOpenCvMat(Gdiplus::Bitmap* bmp) { auto format = bmp->GetPixelFormat(); - //if (format != PixelFormat24bppRGB) - // return cv::Mat(); + if (format != PixelFormat24bppRGB) + return cv::Mat(); int wd = bmp->GetWidth(); int hgt = bmp->GetHeight(); @@ -117,7 +117,7 @@ CRect GetTextBounds(cv::Mat cutImage, const CRect& rcBounds) bool UmaTextRecognizer::LoadSetting() { - std::ifstream ifs((GetExeDirectory() / L"Common.json").string()); + std::ifstream ifs((GetExeDirectory() / L"Common.json").wstring()); ATLASSERT(ifs); if (!ifs) { ERROR_LOG << L"LoadSetting failed"; @@ -162,12 +162,16 @@ std::unique_ptr UmaTextRecognizer::ScreenShot() CWindowDC dc(NULL/*hWndTarget*/); // desktop + ::SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); + CRect rcWindow; ::GetWindowRect(hwndTarget, &rcWindow); CRect rcClient; ::GetClientRect(hwndTarget, rcClient); + ::SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED); + CRect rcAdjustClient = rcWindow; const int topMargin = (rcWindow.Height() - rcClient.Height() - GetSystemMetrics(SM_CXFRAME) * 2 - GetSystemMetrics(SM_CYCAPTION)) / 2; rcAdjustClient.top += GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CYCAPTION) + topMargin; diff --git a/UmaCruise/resource.h b/UmaCruise/resource.h index 748a24f..25d6c99 100644 --- a/UmaCruise/resource.h +++ b/UmaCruise/resource.h @@ -33,6 +33,7 @@ #define IDC_BUTTON1 1038 #define IDC_BUTTON_CHECK_UMALIBRARY 1038 #define IDC_STATIC_ABOUT 1039 +#define IDC_SYSLINK1 1040 #define IDC_EDIT_OPTION1 1500 #define IDC_EDIT_OPTION2 1501 #define IDC_EDIT_OPTION3 1502 @@ -69,7 +70,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 207 #define _APS_NEXT_COMMAND_VALUE 32775 -#define _APS_NEXT_CONTROL_VALUE 1040 +#define _APS_NEXT_CONTROL_VALUE 1041 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/UmaCruise/stdafx.h b/UmaCruise/stdafx.h index 3225398..7125405 100644 --- a/UmaCruise/stdafx.h +++ b/UmaCruise/stdafx.h @@ -6,10 +6,10 @@ #pragma once // Change these values to use different versions -#define WINVER 0x0601 -#define _WIN32_WINNT 0x0601 -#define _WIN32_IE 0x0700 -#define _RICHEDIT_VER 0x0500 +//#define WINVER 0x0601 +//#define _WIN32_WINNT 0x0601 +//#define _WIN32_IE 0x0700 +//#define _RICHEDIT_VER 0x0500 #include #include diff --git a/UmaLibrary/RaceDataLibrary.json b/UmaLibrary/RaceDataLibrary.json index 92d8914..56f0f76 100644 --- a/UmaLibrary/RaceDataLibrary.json +++ b/UmaLibrary/RaceDataLibrary.json @@ -1245,7 +1245,7 @@ ] }, { - "Name": "根岸ステークス", + "Name": "根岸S", "Location": "東京", "GroundCondition": "ダート", "DistanceClass": "短距離", diff --git a/readme.md b/readme.md index 523004b..0f4c7b2 100644 --- a/readme.md +++ b/readme.md @@ -12,6 +12,15 @@ ・Windows10 home 64bit バージョン 20H2 ※64bit版でしか動作しません +※注意 +UmaUmaCruise.exeが置かれるフォルダまでのパスにunicodeが含まれていると強制終了します +例: + C:\🐎🐎Cruise\UmaUmaCruise.exe +->unicode(絵文字🐎が含まれるので)ダメ + C:\UmaUmaCruise\UmaUmaCruise.exe +-> OK! +日本語なら多分大丈夫ですが、難しい漢字が含まれていると強制終了する可能性があります + ## ■使い方 起動した後に、[スタート]ボタンを押せば、自動的にDMM版ウマ娘のウィンドウを探し出し、イベント画面ならば選択肢の効果を表示します @@ -55,6 +64,10 @@ icon - ICON HOIHOI http://iconhoihoi.oops.jp/ +## ■イベント選択肢データ(UmaMusumeLibrary.json)について + +‎Gamerch様運営の"ウマ娘攻略wiki"からイベントデータを加工して、自動生成しています +URL:https://gamerch.com/umamusume/ ## ■著作権表示 Copyright (C) 2021 amate