commit 6a6d49eaf885c63039d708249a9be8afe7ee27db
Author: Simon Howard <fraggle@soulsphere.org>
AuthorDate: Mon Dec 17 09:07:20 2018 -0500
Commit: Simon Howard <fraggle@soulsphere.org>
CommitDate: Mon Dec 17 09:07:20 2018 -0500
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.
---
src/setup/execute.c | 23 ++++++++++++++++++++++-
src/setup/execute.h | 1 +
src/setup/sound.c | 16 ++--------------
3 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/src/setup/execute.c b/src/setup/execute.c
index 33472e76..c71886d7 100644
--- a/src/setup/execute.c
+++ b/src/setup/execute.c
@@ -143,8 +143,13 @@ void AddCmdLineParameter(execute_context_t *context, char *s, ...)
#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;
@@ -257,6 +262,22 @@ static int ExecuteCommand(const char *program, const char *arg)
#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.
diff --git a/src/setup/execute.h b/src/setup/execute.h
index febe411c..f3e90e3c 100644
--- a/src/setup/execute.h
+++ b/src/setup/execute.h
@@ -32,6 +32,7 @@ void AddCmdLineParameter(execute_context_t *context, char *s, ...) PRINTF_ATTR(2
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);
diff --git a/src/setup/sound.c b/src/setup/sound.c
index 52f02970..cae4ff39 100644
--- 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 txt_dropdown_list_t *OPLTypeSelector(void)
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.");
}