ref: 6a6d49eaf885c63039d708249a9be8afe7ee27db
parent: 6764d05ccc1510e6f092b07796f845479706ed78
author: Simon Howard <fraggle@soulsphere.org>
date: Mon Dec 17 04:07:20 EST 2018
setup: Fix bug opening music packs on Windows. The previous code was opening a command prompt instead of an Explorer window. I'm following the advice from this StackOverflow question on how to do this properly: <https://stackoverflow.com/questions/354902/open-in-explorer> Thanks to /u/Ohrami3 on Reddit for discovering this bug.
--- a/src/setup/execute.c
+++ b/src/setup/execute.c
@@ -143,8 +143,13 @@
#if defined(_WIN32)
-// Wait for the specified process to exit. Returns the exit code.
+boolean OpenFolder(const char *path)
+{
+ // "If the function succeeds, it returns a value greater than 32."
+ return ShellExecute(NULL, "open", path, NULL, NULL, SW_SHOWDEFAULT) > 32;
+}
+// Wait for the specified process to exit. Returns the exit code.
static unsigned int WaitForProcessExit(HANDLE subprocess)
{
DWORD exit_code;
@@ -256,6 +261,22 @@
}
#else
+
+boolean OpenFolder(const char *path)
+{
+ char *cmd;
+ int result;
+
+#if defined(__MACOSX__)
+ cmd = M_StringJoin("open \"", path, "\"", NULL);
+#else
+ cmd = M_StringJoin("xdg-open \"", path, "\"", NULL);
+#endif
+ result = system(cmd);
+ free(cmd);
+
+ return result == 0;
+}
// Given the specified program name, get the full path to the program,
// assuming that it is in the same directory as this program is.
--- a/src/setup/execute.h
+++ b/src/setup/execute.h
@@ -32,6 +32,7 @@
void PassThroughArguments(execute_context_t *context);
int ExecuteDoom(execute_context_t *context);
int FindInstalledIWADs(void);
+boolean OpenFolder(const char *path);
txt_window_action_t *TestConfigAction(void);
--- a/src/setup/sound.c
+++ b/src/setup/sound.c
@@ -22,6 +22,7 @@
#include "m_config.h"
#include "m_misc.h"
+#include "execute.h"
#include "mode.h"
#include "sound.h"
@@ -115,20 +116,7 @@
static void OpenMusicPackDir(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(unused))
{
- char *cmd;
- int result;
-
-#if defined(__MACOSX__)
- cmd = M_StringJoin("open \"", music_pack_path, "\"", NULL);
-#elif defined(_WIN32)
- cmd = M_StringJoin("start \"", music_pack_path, "\"", NULL);
-#else
- cmd = M_StringJoin("xdg-open \"", music_pack_path, "\"", NULL);
-#endif
- result = system(cmd);
- free(cmd);
-
- if (result != 0)
+ if (!OpenFolder(music_pack_path))
{
TXT_MessageBox("Error", "Failed to open music pack directory.");
}