]> git.sesse.net Git - vlc/blobdiff - src/config/file.c
Fix use of --data-path
[vlc] / src / config / file.c
index 84ebec6abcdb33d39f5f1d0b55742e4698a1be34..db1128dc266597eada44da777a956e3e3393ef18 100644 (file)
@@ -32,7 +32,7 @@
 #include <sys/stat.h>
 #ifdef __APPLE__
 #   include <xlocale.h>
-#else
+#elif defined(HAVE_USELOCALE)
 #include <locale.h>
 #endif
 
@@ -44,8 +44,6 @@
 #include "configuration.h"
 #include "modules/modules.h"
 
-static char *ConfigKeyToString( int );
-
 static inline char *strdupnull (const char *src)
 {
     return src ? strdup (src) : NULL;
@@ -56,7 +54,8 @@ static inline char *strdupnull (const char *src)
  */
 static char *config_GetConfigFile( vlc_object_t *obj )
 {
-    char *psz_file = config_GetPsz( obj, "config" );
+    char *psz_file = var_CreateGetNonEmptyString( obj, "config" );
+    var_Destroy( obj, "config" );
     if( psz_file == NULL )
     {
         char *psz_dir = config_GetUserDir( VLC_CONFIG_DIR );
@@ -92,7 +91,7 @@ static FILE *config_OpenConfigFile( vlc_object_t *p_obj )
         char *psz_old;
 
         if( home != NULL
-         && asprintf( &psz_old, "%s" DIR_SEP CONFIG_DIR DIR_SEP CONFIG_FILE,
+         && asprintf( &psz_old, "%s/.vlc/" CONFIG_FILE,
                       home ) != -1 )
         {
             p_stream = utf8_fopen( psz_old, "rt" );
@@ -103,7 +102,7 @@ static FILE *config_OpenConfigFile( vlc_object_t *p_obj )
                 msg_Info( p_obj->p_libvlc, "Found old config file at %s. "
                           "VLC will now use %s.", psz_old, psz_filename );
                 char *psz_readme;
-                if( asprintf(&psz_readme,"%s"DIR_SEP CONFIG_DIR DIR_SEP"README",
+                if( asprintf(&psz_readme,"%s/.vlc/README",
                              home ) != -1 )
                 {
                     FILE *p_readme = utf8_fopen( psz_readme, "wt" );
@@ -120,6 +119,10 @@ static FILE *config_OpenConfigFile( vlc_object_t *p_obj )
                     }
                     free( psz_readme );
                 }
+                /* Remove the old configuration file so that --reset-config
+                 * can work properly. Fortunately, Linux allows removing
+                 * open files - with most filesystems. */
+                unlink( psz_old );
             }
             free( psz_old );
         }
@@ -522,13 +525,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
         goto error;
     }
 
-    if (asprintf (&temporary, "%s.%u", permanent,
-#ifdef UNDER_CE
-                  GetCurrentProcessId ()
-#else
-                  getpid ()
-#endif
-                 ) == -1)
+    if (asprintf (&temporary, "%s.%u", permanent, getpid ()) == -1)
     {
         temporary = NULL;
         module_list_free (list);
@@ -688,7 +685,11 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
      */
     fflush (file); /* Flush from run-time */
 #ifndef WIN32
+#ifdef __APPLE__
+    fsync (fd); /* Flush from OS */
+#else
     fdatasync (fd); /* Flush from OS */
+#endif
     /* Atomically replace the file... */
     if (utf8_rename (temporary, permanent))
         utf8_unlink (temporary);
@@ -752,69 +753,3 @@ int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name )
 {
     return SaveConfigFile( p_this, psz_module_name, false );
 }
-
-int ConfigStringToKey( const char *psz_key )
-{
-    int i_key = 0;
-    size_t i;
-    const char *psz_parser = strchr( psz_key, '-' );
-    while( psz_parser && psz_parser != psz_key )
-    {
-        for( i = 0; i < vlc_num_modifiers; ++i )
-        {
-            if( !strncasecmp( vlc_modifiers[i].psz_key_string, psz_key,
-                              strlen( vlc_modifiers[i].psz_key_string ) ) )
-            {
-                i_key |= vlc_modifiers[i].i_key_code;
-            }
-        }
-        psz_key = psz_parser + 1;
-        psz_parser = strchr( psz_key, '-' );
-    }
-    for( i = 0; i < vlc_num_keys; ++i )
-    {
-        if( !strcasecmp( vlc_keys[i].psz_key_string, psz_key ) )
-        {
-            i_key |= vlc_keys[i].i_key_code;
-            break;
-        }
-    }
-    return i_key;
-}
-
-char *ConfigKeyToString( int i_key )
-{
-    // Worst case appears to be 45 characters:
-    // "Command-Meta-Ctrl-Shift-Alt-Browser Favorites"
-    enum { keylen=64 };
-    char *psz_key = malloc( keylen );
-    char *p;
-    size_t index;
-
-    if ( !psz_key )
-    {
-        return NULL;
-    }
-    *psz_key = '\0';
-    p = psz_key;
-
-    for( index = 0; index < vlc_num_modifiers; ++index )
-    {
-        if( i_key & vlc_modifiers[index].i_key_code )
-        {
-            p += snprintf( p, keylen-(psz_key-p), "%s-",
-                           vlc_modifiers[index].psz_key_string );
-        }
-    }
-    for( index = 0; index < vlc_num_keys; ++index )
-    {
-        if( (int)( i_key & ~KEY_MODIFIER ) == vlc_keys[index].i_key_code )
-        {
-            p += snprintf( p, keylen-(psz_key-p), "%s",
-                           vlc_keys[index].psz_key_string );
-            break;
-        }
-    }
-    return psz_key;
-}
-