Skip to content

Commit

Permalink
・readme.mdとAbout画面にイベントデータの取得元の出典を追加
Browse files Browse the repository at this point in the history
・std::ifstreamなどにwstringを渡すようにした
・高DPI環境で動作しないのを修正 #5
・UmaUmaCruise.exeが置かれるフォルダまでのパスにunicodeが含まれていると警告ダイアログを表示するようにした
->readme.mdに詳細を記載
・ptess->Initに tessdataフォルダへのパスを渡すようにした #5
・起動時に::SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED);を実行するようにした
->高DPI対応
・根岸ステークス/Sの表記ゆれを修正 #1
  • Loading branch information
amate committed Apr 20, 2021
1 parent 34d91de commit 9787522
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 30 deletions.
8 changes: 7 additions & 1 deletion UmaCruise/AboutDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion UmaCruise/AboutDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<CAboutDlg>
{
Expand All @@ -21,6 +21,7 @@ class CAboutDlg : public CDialogImpl<CAboutDlg>
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()

Expand All @@ -32,6 +33,8 @@ class CAboutDlg : public CDialogImpl<CAboutDlg>
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:
Expand Down
8 changes: 4 additions & 4 deletions UmaCruise/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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";
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion UmaCruise/ConfigDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 の読み込みに失敗");
Expand Down
27 changes: 20 additions & 7 deletions UmaCruise/MainDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -135,6 +139,15 @@ LRESULT CMainDlg::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&)

UIAddChildWindowContainer(m_hWnd);

// フォルダパスの文字コードチェック
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"フォルダ名にunicodeが含まれているので正常動作しません。\nもっと浅い階層(C:\\)などにフォルダを移動させてください。", L"エラー", MB_ICONERROR);
}

m_config.LoadConfig();

DoDataExchange(DDX_LOAD);
Expand Down Expand Up @@ -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 が存在しません...";
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 の読み込みに失敗");
Expand Down Expand Up @@ -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 のオープンに失敗");
Expand Down
2 changes: 1 addition & 1 deletion UmaCruise/RaceDateLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 の読み込みに失敗");
Expand Down
3 changes: 2 additions & 1 deletion UmaCruise/TesseractWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"";
}
Expand Down
2 changes: 2 additions & 0 deletions UmaCruise/UmaCruise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions UmaCruise/UmaCruise.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 "���C�x���g�I�����f�[�^(UmaMusumeLibrary.json)�ɂ‚���\n\nGamerch�l�^�c��""�E�}���U��wiki""����\n�C�x���g�f�[�^�����H���āA�����������Ă��܂�",IDC_STATIC,132,12,180,33
CONTROL "URL:<a>https://gamerch.com/umamusume/</a>",IDC_SYSLINK1,
"SysLink",WS_TABSTOP,132,48,180,11
END

IDD_MAINDLG DIALOGEX 0, 0, 570, 222
Expand Down Expand Up @@ -137,7 +140,7 @@ BEGIN
IDD_ABOUTBOX, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 185
RIGHTMARGIN, 371
TOPMARGIN, 7
BOTTOMMARGIN, 215
END
Expand Down
4 changes: 4 additions & 0 deletions UmaCruise/UmaCruise.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{EAA1B122-D050-4C8B-B9CB-1A6BFE424F65}</ProjectGuid>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down Expand Up @@ -72,6 +73,7 @@
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(SolutionDir)opencv\include;$(SolutionDir)tesseract\include;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)opencv\x64\lib;$(SolutionDir)tesseract\debug\lib;$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
Expand Down Expand Up @@ -142,6 +144,8 @@
<TypeLibraryName>$(IntDir)/UmaCruise.tlb</TypeLibraryName>
<DllDataFileName />
</Midl>
<Manifest />
<Manifest />
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
Expand Down
6 changes: 3 additions & 3 deletions UmaCruise/UmaEventLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 の読み込みに失敗");
Expand Down Expand Up @@ -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 の読み込みに失敗");
Expand Down Expand Up @@ -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 の読み込みに失敗");
Expand Down
10 changes: 7 additions & 3 deletions UmaCruise/UmaTextRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -162,12 +162,16 @@ std::unique_ptr<Gdiplus::Bitmap> 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;
Expand Down
3 changes: 2 additions & 1 deletion UmaCruise/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions UmaCruise/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <atlbase.h>
#include <atlapp.h>
Expand Down
2 changes: 1 addition & 1 deletion UmaLibrary/RaceDataLibrary.json
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@
]
},
{
"Name": "根岸ステークス",
"Name": "根岸S",
"Location": "東京",
"GroundCondition": "ダート",
"DistanceClass": "短距離",
Expand Down
13 changes: 13 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
・Windows10 home 64bit バージョン 20H2
※64bit版でしか動作しません

※注意
UmaUmaCruise.exeが置かれるフォルダまでのパスにunicodeが含まれていると強制終了します
例:
C:\🐎🐎Cruise\UmaUmaCruise.exe
->unicode(絵文字🐎が含まれるので)ダメ
C:\UmaUmaCruise\UmaUmaCruise.exe
-> OK!
日本語なら多分大丈夫ですが、難しい漢字が含まれていると強制終了する可能性があります

## ■使い方
起動した後に、[スタート]ボタンを押せば、自動的にDMM版ウマ娘のウィンドウを探し出し、イベント画面ならば選択肢の効果を表示します

Expand Down Expand Up @@ -55,6 +64,10 @@ icon
- ICON HOIHOI
http://iconhoihoi.oops.jp/

## ■イベント選択肢データ(UmaMusumeLibrary.json)について

‎Gamerch様運営の"ウマ娘攻略wiki"からイベントデータを加工して、自動生成しています
URL:https://gamerch.com/umamusume/

## ■著作権表示
Copyright (C) 2021 amate
Expand Down

0 comments on commit 9787522

Please sign in to comment.