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.
This commit is contained in:
parent
6764d05ccc
commit
6a6d49eaf8
3 changed files with 25 additions and 15 deletions
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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.");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue