music: Auto-configure a music pack directory.

Currently the user has to create a music pack directory themselves and
configure the path to it in the setup tool. To make configuration
simpler, just create a directory automatically along with a README file
about how to use it, since the user can now just dump files in this
directory.

Part of #1051.
This commit is contained in:
Simon Howard 2018-10-21 19:30:44 -04:00
parent 8c43337af2
commit ceb3e49189
4 changed files with 48 additions and 1 deletions

View file

@ -187,7 +187,7 @@ static void InitMusicModule(void)
//
void I_InitSound(boolean use_sfx_prefix)
{
{
boolean nosound, nosfx, nomusic;
//!
@ -214,6 +214,9 @@ void I_InitSound(boolean use_sfx_prefix)
nomusic = M_CheckParm("-nomusic") > 0;
// Auto configure the music pack directory.
M_SetMusicPackDir();
// Initialize the sound and music subsystems.
if (!nosound && !screensaver_mode)

View file

@ -2211,6 +2211,45 @@ void M_SetConfigDir(const char *dir)
M_MakeDirectory(configdir);
}
#define MUSIC_PACK_README \
"Extract music packs into this directory in .flac or .ogg format;\n" \
"they will be automatically loaded based on filename to replace the\n" \
"in-game music with high quality versions.\n\n" \
"For more information check here:\n\n" \
" <https://www.chocolate-doom.org/wiki/index.php/Digital_music_packs>\n\n"
// Set the value of music_pack_path if it is currently empty, and create
// the directory if necessary.
void M_SetMusicPackDir(void)
{
const char *current_path;
char *prefdir, *music_pack_path, *readme_path;
current_path = M_GetStringVariable("music_pack_path");
if (current_path != NULL && strlen(current_path) > 0)
{
return;
}
prefdir = SDL_GetPrefPath("", PACKAGE_TARNAME);
music_pack_path = M_StringJoin(prefdir, "music-packs", NULL);
M_MakeDirectory(prefdir);
M_MakeDirectory(music_pack_path);
M_SetVariable("music_pack_path", music_pack_path);
// We write a README file with some basic instructions on how to use
// the directory.
readme_path = M_StringJoin(music_pack_path, DIR_SEPARATOR_S,
"README.txt", NULL);
M_WriteFile(readme_path, MUSIC_PACK_README, strlen(MUSIC_PACK_README));
free(readme_path);
free(music_pack_path);
free(prefdir);
}
//
// Calculate the path to the directory to use to store save games.
// Creates the directory as necessary.

View file

@ -26,6 +26,7 @@ void M_LoadDefaults(void);
void M_SaveDefaults(void);
void M_SaveDefaultsAlternate(const char *main, const char *extra);
void M_SetConfigDir(const char *dir);
void M_SetMusicPackDir(void);
void M_BindIntVariable(const char *name, int *variable);
void M_BindFloatVariable(const char *name, float *variable);
void M_BindStringVariable(const char *name, char **variable);

View file

@ -262,6 +262,10 @@ static void InitConfig(void)
SetPlayerNameDefault();
M_LoadDefaults();
// Create and configure the music pack directory if it does not
// already exist.
M_SetMusicPackDir();
}
//