Changeset 6924


Ignore:
Timestamp:
Oct 19, 2008, 5:43:04 PM (12 years ago)
Author:
charles
Message:

further win32 portability fixes from Spry

Location:
trunk/libtransmission
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/Makefile.am

    r6798 r6924  
    151151        echo '#define USERAGENT_PREFIX      "'@USERAGENT_PREFIX@'"' >> version.h
    152152        echo '#define SVN_REVISION          "'`svn info | grep "Revision" | awk -F': ' '{print $$2}'`'"' >> version.h
     153        echo '#define SVN_REVISION_NUM      '`svn info | grep "Revision" | awk -F': ' '{print $$2}'`'' >> version.h
    153154        echo '#define SHORT_VERSION_STRING  "'@USERAGENT_PREFIX@'"' >> version.h
    154155        echo '#define LONG_VERSION_STRING   "'@USERAGENT_PREFIX@' ('`svn info | grep "Revision" | awk -F': ' '{print $$2}'`')"' >> version.h
  • trunk/libtransmission/fdlimit.c

    r6906 r6924  
    490490
    491491    tr_free( gFd );
     492    gFd = NULL;
    492493}
    493494
  • trunk/libtransmission/net.h

    r6906 r6924  
    2929 #include <inttypes.h>
    3030 #include <winsock2.h>
    31 typedef int socklen_t;
    32 typedef uint16_t tr_port_t;
     31 typedef int socklen_t;
     32 typedef uint16_t tr_port_t;
    3333#elif defined( __BEOS__ )
    3434 #include <sys/socket.h>
    3535 #include <netinet/in.h>
    36 typedef unsigned short tr_port_t;
    37 typedef int socklen_t;
     36 typedef unsigned short tr_port_t;
     37 typedef int socklen_t;
    3838#else
    3939 #include <sys/types.h>
     
    4141 #include <netinet/in.h>
    4242 #include <arpa/inet.h>
    43 typedef in_port_t tr_port_t;
     43 typedef in_port_t tr_port_t;
    4444#endif
    4545
  • trunk/libtransmission/platform.c

    r6902 r6924  
    466466                              "Application Support", "Transmission", NULL );
    467467#elif defined( WIN32 )
    468             char appdata[MAX_PATH_LENGTH];
    469             SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, appdata );
    470             s = tr_buildPath( appdata, "Transmission", NULL );
     468            char configDir[MAX_PATH_LENGTH];
     469            GetModuleFileName( GetModuleHandle( NULL ), configDir, sizeof( configDir ) );
     470            s = tr_buildPath( basename( configDir ), "Transmission", NULL );
    471471#else
    472472            if( ( s = getenv( "XDG_CONFIG_HOME" ) ) )
     
    514514        else
    515515        {
     516
    516517#ifdef SYS_DARWIN
    517             CFURLRef     appURL = CFBundleCopyBundleURL(
    518                 CFBundleGetMainBundle( ) );
    519             CFStringRef  appRef = CFURLCopyFileSystemPath(
    520                 appURL, kCFURLPOSIXPathStyle );
    521             const char * appString = CFStringGetCStringPtr(
    522                  appRef, CFStringGetFastestEncoding( appRef ) );
     518
     519            CFURLRef appURL = CFBundleCopyBundleURL( CFBundleGetMainBundle( ) );
     520            CFStringRef appRef = CFURLCopyFileSystemPath( appURL,
     521                                                        kCFURLPOSIXPathStyle );
     522            const char * appString = CFStringGetCStringPtr( appRef,
     523                                         CFStringGetFastestEncoding( appRef ) );
    523524            CFRelease( appURL );
    524525            CFRelease( appRef );
    525526
    526527            s = tr_buildPath( appString, "Contents", "Resources", "web", NULL );
    527 #elif defined( WIN32 )
    528 
    529  #warning hey win32 people is this good or is there a better implementation of the next four lines
    530             char appdata[MAX_PATH_LENGTH];
    531             SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, appdata );
    532             s = tr_buildPath( appdata, "Transmission", NULL );
    533 #else
     528
     529#elif defined( WIN32 )
     530
     531            /* SHGetFolderPath explicitly requires MAX_PATH length */
     532            char dir[MAX_PATH];
     533           
     534            /* Generally, Web interface should be stored in a Web subdir of
     535             * calling executable dir. */
     536
     537            if( s == NULL ) {
     538                /* First, we should check personal AppData/Transmission/Web */
     539                SHGetFolderPath( NULL, CSIDL_COMMON_APPDATA, NULL, 0, dir );
     540                s = tr_buildPath( dir, "Transmission", "Web", NULL );
     541                if( !isClutchDir( s ) ) {
     542                    tr_free( s );
     543                    s = NULL;
     544                }
     545            }
     546
     547            if( s == NULL ) {
     548                /* check personal AppData */
     549                SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, dir );
     550                s = tr_buildPath( dir, "Transmission", "Web", NULL );
     551                if( !isClutchDir( s ) ) {
     552                    tr_free( s );
     553                    s = NULL;
     554                }
     555            }
     556
     557            if( s == NULL) {
     558                /* check calling module place */
     559                GetModuleFileName( GetModuleHandle( NULL ), dir, sizeof( dir ) );
     560                s = tr_buildPath( dirname( dir ), "Web", NULL );
     561                if( !isClutchDir( s ) ) {
     562                    tr_free( s );
     563                    s = NULL;
     564                }
     565            }
     566
     567#else /* everyone else, follow the XDG spec */
     568
    534569            tr_list *candidates = NULL, *l;
    535570
     
    574609
    575610            tr_list_free( &candidates, tr_free );
    576 #endif
     611
     612#endif
     613
    577614        }
    578615    }
  • trunk/libtransmission/transmission.h

    r6897 r6924  
    6363 *   "$HOME/Library/Application Support/Transmission" is returned.
    6464 * - otherwise, if we're running on WIN32,
    65  *   "$CSIDL_APPDATA/Transmission" is returned.
     65 *   "$EXE_FOLDER/Transmission" is returned.
    6666 * - otherwise, if XDG_CONFIG_HOME is set,
    6767 *   "$XDG_CONFIG_HOME/transmission" is returned.
  • trunk/libtransmission/utils.c

    r6907 r6924  
    5656static tr_msg_list ** messageQueueTail = &messageQueue;
    5757
     58#ifndef WIN32
     59    /* make null versions of these win32 functions */
     60    static int IsDebuggerPresent( void ) { return FALSE; }
     61    static void OutputDebugString( const void * unused UNUSED ) { }
     62#endif
     63
    5864void
    5965tr_msgInit( void )
     
    157163**/
    158164
     165static struct tm *
     166tr_localtime_r( time_t *_clock, struct tm *_result )
     167{
     168#ifdef HAVE_LOCALTIME_R
     169    return localtime_r( _clock, _result );
     170#else
     171    struct tm *p = localtime( _clock );
     172    if( p )
     173        *(_result) = *p;
     174    return p;
     175#endif
     176}
     177
    159178char*
    160179tr_getLogTimeStr( char * buf,
     
    170189    gettimeofday( &tv, NULL );
    171190
    172 #ifdef WIN32
    173     now_tm = *localtime( &now );
    174 #else
    175     localtime_r( &now, &now_tm );
    176 #endif
     191    tr_localtime_r( &now, &now_tm );
    177192    strftime( tmp, sizeof( tmp ), "%H:%M:%S", &now_tm );
    178193    milliseconds = (int)( tv.tv_usec / 1000 );
     
    190205{
    191206    FILE * fp = tr_getLog( );
    192 #ifdef WIN32
    193207    if( fp || IsDebuggerPresent( ) )
    194 #else
    195     if( fp )
    196 #endif
    197208    {
    198209        va_list           args;
     
    209220        va_end( args );
    210221        evbuffer_add_printf( buf, " (%s:%d)\n", base, line );
    211 #ifdef WIN32
    212222        OutputDebugString( EVBUFFER_DATA( buf ) );
    213223        if(fp)
    214 #endif
    215         (void) fwrite( EVBUFFER_DATA( buf ), 1, EVBUFFER_LENGTH( buf ), fp );
     224            (void) fwrite( EVBUFFER_DATA( buf ), 1, EVBUFFER_LENGTH( buf ), fp );
    216225
    217226        tr_free( base );
     
    255264        evbuffer_add_vprintf( buf, fmt, ap );
    256265        va_end( ap );
     266
     267        OutputDebugString( EVBUFFER_DATA( buf ) );
    257268
    258269        if( EVBUFFER_LENGTH( buf ) )
Note: See TracChangeset for help on using the changeset viewer.