source: trunk/libtransmission/platform.c @ 679

Last change on this file since 679 was 679, checked in by titer, 15 years ago

AmigaOS4 patch by Andrea Palmate

  • Property svn:keywords set to Date Rev Author Id
File size: 5.3 KB
Line 
1/******************************************************************************
2 * $Id: platform.c 679 2006-07-23 19:39:02Z titer $
3 *
4 * Copyright (c) 2005 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#ifdef SYS_BEOS
26  #include <fs_info.h>
27  #include <FindDirectory.h>
28#endif
29#include <sys/types.h>
30#include <dirent.h>
31
32#include "transmission.h"
33
34static void
35tr_migrateResume( const char *oldDirectory, const char *newDirectory )
36{
37    DIR * dirh;
38    struct dirent * dirp;
39    char oldFile[MAX_PATH_LENGTH];
40    char newFile[MAX_PATH_LENGTH];
41
42    if( ( dirh = opendir( oldDirectory ) ) )
43    {
44        while( ( dirp = readdir( dirh ) ) )
45        {
46            if( strncmp( "resume.", dirp->d_name, 7 ) )
47            {
48                continue;
49            }
50            snprintf( oldFile, MAX_PATH_LENGTH, "%s/%s",
51                      oldDirectory, dirp->d_name );
52            snprintf( newFile, MAX_PATH_LENGTH, "%s/%s",
53                      newDirectory, dirp->d_name );
54            rename( oldFile, newFile );
55        }
56
57        closedir( dirh );
58    }
59}
60
61char * tr_getPrefsDirectory()
62{
63    static char prefsDirectory[MAX_PATH_LENGTH];
64    static int  init = 0;
65
66    if( init )
67    {
68        return prefsDirectory;
69    }
70
71#ifdef SYS_BEOS
72        find_directory( B_USER_SETTINGS_DIRECTORY, dev_for_path("/boot"),
73                        true, prefsDirectory, MAX_PATH_LENGTH );
74        strcat( prefsDirectory, "/Transmission" );
75#elif defined( SYS_DARWIN )
76    snprintf( prefsDirectory, MAX_PATH_LENGTH,
77              "%s/Library/Caches/Transmission", getenv( "HOME" ) );
78#elif defined(__AMIGAOS4__)
79    snprintf( prefsDirectory, MAX_PATH_LENGTH, "PROGDIR:.transmission" );
80#else
81    snprintf( prefsDirectory, MAX_PATH_LENGTH, "%s/.transmission",
82              getenv( "HOME" ) );
83#endif
84
85    tr_mkdir( prefsDirectory );
86    init = 1;
87
88#ifdef SYS_DARWIN
89    char oldDirectory[MAX_PATH_LENGTH];
90    snprintf( oldDirectory, MAX_PATH_LENGTH, "%s/.transmission",
91              getenv( "HOME" ) );
92    tr_migrateResume( oldDirectory, prefsDirectory );
93    rmdir( oldDirectory );
94#endif
95
96    return prefsDirectory;
97}
98
99char * tr_getCacheDirectory()
100{
101    static char cacheDirectory[MAX_PATH_LENGTH];
102    static int  init = 0;
103
104    if( init )
105    {
106        return cacheDirectory;
107    }
108
109#ifdef SYS_BEOS
110    /* XXX hey Bryan, is this fine with you? */
111    snprintf( cacheDirectory, MAX_PATH_LENGTH, "%s/Cache",
112              tr_getPrefsDirectory() );
113#elif defined( SYS_DARWIN )
114    snprintf( cacheDirectory, MAX_PATH_LENGTH, "%s",
115              tr_getPrefsDirectory() );
116#else
117    snprintf( cacheDirectory, MAX_PATH_LENGTH, "%s/cache",
118              tr_getPrefsDirectory() );
119#endif
120
121    tr_mkdir( cacheDirectory );
122    init = 1;
123
124    if( strcmp( tr_getPrefsDirectory(), cacheDirectory ) )
125    {
126        tr_migrateResume( tr_getPrefsDirectory(), cacheDirectory );
127    }
128
129    return cacheDirectory;
130}
131
132char * tr_getTorrentsDirectory()
133{
134    static char torrentsDirectory[MAX_PATH_LENGTH];
135    static int  init = 0;
136
137    if( init )
138    {
139        return torrentsDirectory;
140    }
141
142#ifdef SYS_BEOS
143    /* XXX hey Bryan, is this fine with you? */
144    snprintf( torrentsDirectory, MAX_PATH_LENGTH, "%s/Torrents",
145              tr_getPrefsDirectory() );
146#elif defined( SYS_DARWIN )
147    snprintf( torrentsDirectory, MAX_PATH_LENGTH,
148              "%s/Library/Application Support/Transmission/Torrents",
149              getenv( "HOME" ) );
150#else
151    snprintf( torrentsDirectory, MAX_PATH_LENGTH, "%s/torrents",
152              tr_getPrefsDirectory() );
153#endif
154
155    tr_mkdir( torrentsDirectory );
156    init = 1;
157
158    return torrentsDirectory;
159}
160
161void tr_threadCreate( tr_thread_t * t, void (*func)(void *), void * arg )
162{
163#ifdef SYS_BEOS
164    *t = spawn_thread( (void *) func, "torrent-tx", B_NORMAL_PRIORITY, arg );
165    resume_thread( *t );
166#else
167    pthread_create( t, NULL, (void *) func, arg );
168#endif
169}
170
171void tr_threadJoin( tr_thread_t * t )
172{
173#ifdef SYS_BEOS
174    long exit;
175    wait_for_thread( *t, &exit );
176#else
177    pthread_join( *t, NULL );
178#endif
179}
180
181void tr_lockInit( tr_lock_t * l )
182{
183#ifdef SYS_BEOS
184    *l = create_sem( 1, "" );
185#else
186    pthread_mutex_init( l, NULL );
187#endif
188}
189
190void tr_lockClose( tr_lock_t * l )
191{
192#ifdef SYS_BEOS
193    delete_sem( *l );
194#else
195    pthread_mutex_destroy( l );
196#endif
197}
198
Note: See TracBrowser for help on using the repository browser.