]> git.sesse.net Git - vlc/blobdiff - src/misc/win32_specific.c
Backported r11448.
[vlc] / src / misc / win32_specific.c
index 16c21b5f8005aba8ac8881b1436141e6f2319e46..4ce7914d00fcba48e968ccc9f4ba59c485a4ee98 100644 (file)
@@ -1,11 +1,11 @@
 /*****************************************************************************
  * win32_specific.c: Win32 specific features
  *****************************************************************************
- * Copyright (C) 2001 VideoLAN
- * $Id: win32_specific.c,v 1.26 2003/10/03 13:35:56 sam Exp $
+ * Copyright (C) 2001-2004 VideoLAN
+ * $Id$
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
- *          Gildas Bazin <gbazin@netcourrier.com>
+ *          Gildas Bazin <gbazin@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -25,6 +25,7 @@
 #include <stdlib.h>                                                /* free() */
 
 #include <vlc/vlc.h>
+#include <vlc/input.h>
 #include "vlc_playlist.h"
 
 #ifdef WIN32                       /* optind, getopt(), included in unistd.h */
 #endif
 
 #if !defined( UNDER_CE )
+#   include <io.h>
 #   include <fcntl.h>
-#   include <winsock2.h>
 #endif
 
+#include <winsock.h>
+
 /*****************************************************************************
  * system_Init: initialize winsock and misc other things.
  *****************************************************************************/
 void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
 {
-#if !defined( UNDER_CE )
     WSADATA Data;
 
     /* Get our full path */
-    if( ppsz_argv[0] )
+    char psz_path[MAX_PATH];
+    char *psz_vlc;
+
+#if defined( UNDER_CE )
+    wchar_t psz_wpath[MAX_PATH];
+    if( GetModuleFileName( NULL, psz_wpath, MAX_PATH ) )
     {
-        char psz_path[MAX_PATH];
-        char *psz_vlc;
+        WideCharToMultiByte( CP_ACP, 0, psz_wpath, -1,
+                             psz_path, MAX_PATH, NULL, NULL );
+    }
+    else psz_path[0] = '\0';
 
+#else
+    if( ppsz_argv[0] )
+    {
         GetFullPathName( ppsz_argv[0], MAX_PATH, psz_path, &psz_vlc );
-
-        if( psz_vlc > psz_path && psz_vlc[-1] == '\\' )
-        {
-            psz_vlc[-1] = '\0';
-            p_this->p_libvlc->psz_vlcpath = strdup( psz_path );
-        }
-        else
-        {
-            p_this->p_libvlc->psz_vlcpath = strdup( "" );
-        }
     }
-    else
+    else if( !GetModuleFileName( NULL, psz_path, MAX_PATH ) )
     {
-        p_this->p_libvlc->psz_vlcpath = strdup( "" );
+        psz_path[0] = '\0';
     }
+#endif
+
+    if( (psz_vlc = strrchr( psz_path, '\\' )) ) *psz_vlc = '\0';
+
+    p_this->p_libvlc->psz_vlcpath = strdup( psz_path );
 
     /* Set the default file-translation mode */
+#if !defined( UNDER_CE )
     _fmode = _O_BINARY;
     _setmode( _fileno( stdin ), _O_BINARY ); /* Needed for pipes */
+#endif
+
+    /* Call mdate() once to make sure it is initialized properly */
+    mdate();
 
     /* WinSock Library Init. */
     if( !WSAStartup( MAKEWORD( 2, 0 ), &Data ) )
@@ -105,9 +117,7 @@ void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
 
     fprintf( stderr, "error: can't initialize WinSocks\n" );
 
-    return; 
-
-#endif
+    return;
 }
 
 /*****************************************************************************
@@ -143,14 +153,14 @@ void system_Configure( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
     {
         HANDLE hmutex;
 
-        msg_Info( p_this, "One instance mode ENABLED");
+        msg_Info( p_this, "one instance mode ENABLED");
 
         /* Use a named mutex to check if another instance is already running */
-        if( ( hmutex = CreateMutex( NULL, TRUE, "VLC ipc "VERSION ) ) == NULL )
+        if( !( hmutex = CreateMutex( 0, TRUE, _T("VLC ipc ") _T(VERSION) ) ) )
         {
             /* Failed for some reason. Just ignore the option and go on as
              * normal. */
-            msg_Err( p_this, "One instance mode DISABLED "
+            msg_Err( p_this, "one instance mode DISABLED "
                      "(mutex couldn't be created)" );
             return;
         }
@@ -165,7 +175,7 @@ void system_Configure( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
             if( vlc_thread_create( p_helper, "IPC helper", IPCHelperThread,
                                    VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
             {
-                msg_Err( p_this, "One instance mode DISABLED "
+                msg_Err( p_this, "one instance mode DISABLED "
                          "(IPC helper thread couldn't be created)" );
 
             }
@@ -185,10 +195,9 @@ void system_Configure( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
 
             /* Locate the window created by the IPC helper thread of the
              * 1st instance */
-            if( ( ipcwindow = FindWindow( NULL, "VLC ipc "VERSION ) )
-                == NULL )
+            if( !( ipcwindow = FindWindow( 0, _T("VLC ipc ") _T(VERSION) ) ) )
             {
-                msg_Err( p_this, "One instance mode DISABLED "
+                msg_Err( p_this, "one instance mode DISABLED "
                          "(couldn't find 1st instance of program)" );
                 ReleaseMutex( hmutex );
                 return;
@@ -247,8 +256,8 @@ static void IPCHelperThread( vlc_object_t *p_this )
     MSG message;
 
     ipcwindow =
-        CreateWindow( "STATIC",                      /* name of window class */
-                  "VLC ipc "VERSION,                /* window title bar text */
+        CreateWindow( _T("STATIC"),                  /* name of window class */
+                  _T("VLC ipc ") _T(VERSION),       /* window title bar text */
                   0,                                         /* window style */
                   0,                                 /* default X coordinate */
                   0,                                 /* default Y coordinate */
@@ -318,10 +327,11 @@ LRESULT CALLBACK WMCOPYWNDPROC( HWND hwnd, UINT uMsg, WPARAM wParam,
                     i_options++;
                 }
 
-                playlist_Add( p_playlist, ppsz_argv[ i_opt ],
+                playlist_AddExt( p_playlist, ppsz_argv[i_opt],ppsz_argv[i_opt],
+                    PLAYLIST_APPEND | (i_opt? 0 : PLAYLIST_GO),
+                    PLAYLIST_END, -1,
                     (char const **)( i_options ? &ppsz_argv[i_opt+1] : NULL ),
-                    i_options, PLAYLIST_APPEND | (i_opt? 0 : PLAYLIST_GO),
-                    PLAYLIST_END );
+                    i_options );
 
                 i_opt += i_options;
             }
@@ -340,7 +350,5 @@ LRESULT CALLBACK WMCOPYWNDPROC( HWND hwnd, UINT uMsg, WPARAM wParam,
  *****************************************************************************/
 void system_End( vlc_t *p_this )
 {
-#if !defined( UNDER_CE )
     WSACleanup();
-#endif
 }