shithub: choc

Download patch

ref: ceb3e491892eb8facd2fac1ea7b09752fffc40f4
parent: 8c43337af2fb3ed5072d3ef0162c9d90eaba3b38
author: Simon Howard <fraggle@soulsphere.org>
date: Sun Oct 21 15:30:44 EDT 2018

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.

--- a/src/i_sound.c
+++ b/src/i_sound.c
@@ -187,7 +187,7 @@
 //
 
 void I_InitSound(boolean use_sfx_prefix)
-{  
+{
     boolean nosound, nosfx, nomusic;
 
     //!
@@ -213,6 +213,9 @@
     //
 
     nomusic = M_CheckParm("-nomusic") > 0;
+
+    // Auto configure the music pack directory.
+    M_SetMusicPackDir();
 
     // Initialize the sound and music subsystems.
 
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -2211,6 +2211,45 @@
     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.
--- a/src/m_config.h
+++ b/src/m_config.h
@@ -26,6 +26,7 @@
 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);
--- a/src/setup/mainmenu.c
+++ b/src/setup/mainmenu.c
@@ -262,6 +262,10 @@
     SetPlayerNameDefault();
 
     M_LoadDefaults();
+
+    // Create and configure the music pack directory if it does not
+    // already exist.
+    M_SetMusicPackDir();
 }
 
 //