Skip to content

Commit 4981e7e

Browse files
committed
improve get_app_path_from_steam; force UTF-8 on windows
1 parent bafc832 commit 4981e7e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

package/launchdf.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ void remove_old_install(std::filesystem::path df_path)
312312
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nShowCmd) {
313313
#else
314314
int main(int argc, char* argv[]) {
315+
#endif
316+
#ifdef WIN32
317+
// force UTF-8
318+
std::setlocale(LC_ALL, ".utf8");
315319
#endif
316320
// initialize steam context
317321
if (SteamAPI_RestartAppIfNecessary(DFHACK_STEAM_APPID)) {
@@ -352,11 +356,12 @@ int main(int argc, char* argv[]) {
352356
// obtain DF and DFHack app paths
353357

354358
auto get_app_path_from_steam = [] (AppId_t appid) -> std::optional<std::filesystem::path> {
355-
char buf[2048] = "";
356-
int bytes = SteamApps()->GetAppInstallDir(appid, (char*)&buf, 2048);
359+
constexpr auto BUFSIZE = 2048;
360+
char buf[BUFSIZE] = "";
361+
int bytes = SteamApps()->GetAppInstallDir(appid, (char*)&buf, BUFSIZE);
357362
if (bytes <= 0)
358363
return std::nullopt;
359-
// steam API counts the null terminator in the byte count returned
364+
// steam API includes one or more null terminators after the path, so trim those off
360365
while (bytes && buf[bytes] == '\0') bytes--;
361366
return std::string(buf, bytes);
362367
};

0 commit comments

Comments
 (0)