やりたいこと
ゲームのドキュメント(html)にゲーム内からアクセスしたい。
つまり下記のような感じ。
main.cpp
if (Internet::IsConnected()) {
Internet::LaunchWebBrowser(L"http://aini-bellwood.jp/game/signbordfactory/manual/index.html");
}
else {
//ここでローカルのhtmlを読みたい
}
ためしたこと
Internet::LaunchWebBrowserにローカルファイルのパスを入れる
main.cpp
Internet::LaunchWebBrowser(FileSystem::InitialPath() + L"doc/index.html");
これはもちろん無理。
ドキュメントに「url:http:// もしくは https:// で始まる URL」と書いてある。
IEを外部プロセスとして立ち上げる
main.cpp
String tmpStr = FileSystem::InitialPath() + L"doc/index.html";
tmpStr = tmpStr.replace(L"/", L"\\");
Optional<ProcessInfo> process = System::CreateProcess(L"C:/Program Files/Internet Explorer/iexplore.exe", L"-new " + tmpStr);
一応動いた。でもこれはあまりにも乱暴なのでやりたくない…。
ここでTwitterに助けを求めた。
system関数を使う
main.cpp
system(".\\doc\\index.html");
なるほど!!かしこい!!!
でももうちょいスマートにならんかな…ということでReputeless氏に聞いてみた。
System::LaunchFile()を使う。
main.cpp
System::LaunchFile(L".\\doc\\index.html", LaunchVerb::Open);
はい!瞬殺!!
FileSystemしか見てなかったから全く気づかなかったよ…。
まとめ
ということでこんな形に落ち着いた。
今後もこれでいく。
main.cpp
if (Internet::IsConnected()) {
Internet::LaunchWebBrowser(L"http://aini-bellwood.jp/game/signbordfactory/manual/index.html");
}
else {
System::LaunchFile(L".\\doc\\index.html", LaunchVerb::Open);
}