예제 #1
0
/* Return the path to the Android SDK root installation.
 *
 * (*pFromEnv) will be set to 1 if it comes from the $ANDROID_SDK_ROOT
 * environment variable, or 0 otherwise.
 *
 * Caller must free() returned string.
 */
char*
path_getSdkRoot( char *pFromEnv )
{
    const char*  env;
    char*        sdkPath;
    char         temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);

    /* If ANDROID_SDK_ROOT is defined is must point to a directory
     * containing a valid SDK installation.
     */
#define  SDK_ROOT_ENV  "ANDROID_SDK_ROOT"

    env = getenv(SDK_ROOT_ENV);
    if (env != NULL && env[0] != 0) {
        if (path_exists(env)) {
            D("found " SDK_ROOT_ENV ": %s", env);
            *pFromEnv = 1;
            return ASTRDUP(env);
        }
        D(SDK_ROOT_ENV " points to unknown directory: %s", env);
    }

    *pFromEnv = 0;

    /* We assume the emulator binary is under tools/ so use its
     * parent as the Android SDK root.
     */
    (void) bufprint_app_dir(temp, end);
    sdkPath = path_parent(temp, 1);
    if (sdkPath == NULL) {
        derror("can't find root of SDK directory");
        return NULL;
    }
    D("found SDK root at %s", sdkPath);
    return sdkPath;
}
예제 #2
0
/* Create a new AUserConfig object from a given AvdInfo */
AUserConfig*
auserConfig_new( AvdInfo*  info )
{
    AUserConfig*  uc;
    char          inAndroidBuild = avdInfo_inAndroidBuild(info);
    char          needUUID = 1;
    char          temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);
    char*         parentPath;
    IniFile*      ini = NULL;

    ANEW0(uc);

    /* If we are in the Android build system, store the configuration
     * in ~/.android/emulator-user.ini. otherwise, store it in the file
     * emulator-user.ini in the AVD's content directory.
     */
    if (inAndroidBuild) {
        p = bufprint_config_file(temp, end, USER_CONFIG_FILE);
    } else {
        p = bufprint(temp, end, "%s/%s", avdInfo_getContentPath(info), 
                     USER_CONFIG_FILE);
    }

    /* handle the unexpected */
    if (p >= end) {
        /* Hmmm, something is weird, let's use a temporary file instead */
        p = bufprint_temp_file(temp, end, USER_CONFIG_FILE);
        if (p >= end) {
            derror("Weird: Cannot create temporary user-config file?");
            exit(2);
        }
        dwarning("Weird: Content path too long, using temporary user-config.");
    }

    uc->iniPath = ASTRDUP(temp);
    DD("looking user-config in: %s", uc->iniPath);


    /* ensure that the parent directory exists */
    parentPath = path_parent(uc->iniPath, 1);
    if (parentPath == NULL) {
        derror("Weird: Can't find parent of user-config file: %s",
               uc->iniPath);
        exit(2);
    }

    if (!path_exists(parentPath)) {
        if (!inAndroidBuild) {
            derror("Weird: No content path for this AVD: %s", parentPath);
            exit(2);
        }
        DD("creating missing directory: %s", parentPath);
        if (path_mkdir_if_needed(parentPath, 0755) < 0) {
            derror("Using empty user-config, can't create %s: %s",
                   parentPath, strerror(errno));
            exit(2);
        }
    }

    if (path_exists(uc->iniPath)) {
        DD("reading user-config file");
        ini = iniFile_newFromFile(uc->iniPath);
        if (ini == NULL) {
            dwarning("Can't read user-config file: %s\nUsing default values",
                     uc->iniPath);
        }
    }

    if (ini != NULL) {
        uc->windowX = iniFile_getInteger(ini, KEY_WINDOW_X, DEFAULT_X);
        DD("    found %s = %d", KEY_WINDOW_X, uc->windowX);

        uc->windowY = iniFile_getInteger(ini, KEY_WINDOW_Y, DEFAULT_Y);
        DD("    found %s = %d", KEY_WINDOW_Y, uc->windowY);

        if (iniFile_getValue(ini, KEY_UUID) != NULL) {
            uc->uuid = (uint64_t) iniFile_getInt64(ini, KEY_UUID, 0LL);
            needUUID = 0;
            DD("    found %s = %lld", KEY_UUID, uc->uuid);
        }

        iniFile_free(ini);
    }
    else {
        uc->windowX = DEFAULT_X;
        uc->windowY = DEFAULT_Y;
        uc->changed = 1;
    }

    /* Generate a 64-bit UUID if necessary. We simply take the
     * current time, which avoids any privacy-related value.
     */
    if (needUUID) {
        struct timeval  tm;

        gettimeofday( &tm, NULL );
        uc->uuid    = (uint64_t)tm.tv_sec*1000 + tm.tv_usec/1000;
        uc->changed = 1;
        DD("    Generated UUID = %lld", uc->uuid);
    }

    return uc;
}
예제 #3
0
파일: info.c 프로젝트: bindassdost/razrd
void
avdInfo_getSkinInfo( AvdInfo*  i, char** pSkinName, char** pSkinDir )
{
    char*  skinName = NULL;
    char*  skinPath;
    char   temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);

    *pSkinName = NULL;
    *pSkinDir  = NULL;

    /* First, see if the config.ini contains a SKIN_PATH entry that
     * names the full directory path for the skin.
     */
    if (i->configIni != NULL ) {
        skinPath = iniFile_getString( i->configIni, SKIN_PATH, NULL );
        if (skinPath != NULL) {
            /* If this skin name is magic or a direct directory path
            * we have our result right here.
            */
            if (_getSkinPathFromName(skinPath, i->sdkRootPath,
                                     pSkinName, pSkinDir )) {
                AFREE(skinPath);
                return;
            }
        }

        /* The SKIN_PATH entry was not valid, so look at SKIN_NAME */
        D("Warning: config.ini contains invalid %s entry: %s", SKIN_PATH, skinPath);
        AFREE(skinPath);

        skinName = iniFile_getString( i->configIni, SKIN_NAME, NULL );
    }

    if (skinName == NULL) {
        /* If there is no skin listed in the config.ini, try to see if
         * there is one single 'skin' directory in the content directory.
         */
        p = bufprint(temp, end, "%s/skin", i->contentPath);
        if (p < end && _checkSkinPath(temp)) {
            D("using skin content from %s", temp);
            AFREE(i->skinName);
            *pSkinName = ASTRDUP("skin");
            *pSkinDir  = ASTRDUP(i->contentPath);
            return;
        }

        /* otherwise, use the default name */
        skinName = ASTRDUP(SKIN_DEFAULT);
    }

    /* now try to find the skin directory for that name -
     */
    do {
        /* first try the content directory, i.e. $CONTENT/skins/<name> */
        skinPath = _checkSkinSkinsDir(i->contentPath, skinName);
        if (skinPath != NULL)
            break;

#define  PREBUILT_SKINS_ROOT "development/tools/emulator"

        /* if we are in the Android build, try the prebuilt directory */
        if (i->inAndroidBuild) {
            p = bufprint( temp, end, "%s/%s",
                        i->androidBuildRoot, PREBUILT_SKINS_ROOT );
            if (p < end) {
                skinPath = _checkSkinSkinsDir(temp, skinName);
                if (skinPath != NULL)
                    break;
            }

            /* or in the parent directory of the system dir */
            {
                char* parentDir = path_parent(i->androidOut, 1);
                if (parentDir != NULL) {
                    skinPath = _checkSkinSkinsDir(parentDir, skinName);
                    AFREE(parentDir);
                    if (skinPath != NULL)
                        break;
                }
            }
        }

        /* look in the search paths. For each <dir> in the list,
         * look into <dir>/../skins/<name>/ */
        {
            int  nn;
            for (nn = 0; nn < i->numSearchPaths; nn++) {
                char*  parentDir = path_parent(i->searchPaths[nn], 1);
                if (parentDir == NULL)
                    continue;
                skinPath = _checkSkinSkinsDir(parentDir, skinName);
                AFREE(parentDir);
                if (skinPath != NULL)
                  break;
            }
            if (nn < i->numSearchPaths)
                break;
        }

        /* We didn't find anything ! */
        *pSkinName = skinName;
        return;

    } while (0);

    if (path_split(skinPath, pSkinDir, pSkinName) < 0) {
        derror("weird skin path: %s", skinPath);
        AFREE(skinPath);
        return;
    }
    DD("found skin '%s' in directory: %s", *pSkinName, *pSkinDir);
    AFREE(skinPath);
    return;
}
예제 #4
0
const char *search(const char *source, const char *_header, time_t *time)
{
	PATHNAME f[1];
	char buf[MAXJPATH];
	char buf2[MAXSYM], *header = buf2;
	char buf3[MAXJPATH];
	int system = (_header[0] == '<');
	LIST *list = searchdirs->next;
	
	/* D support */
	int dMode=0;
	int fnlen=strlen(source);
	if(source[fnlen-2]=='.' && source[fnlen-1]=='d')
		dMode=1;

	/* <foo.h> --> foo.h */
	strcpy(header, _header + 1);
	header[strlen(header) - 1] = '\0';

	/* src/foo.c --> src */
	path_parse(source, f);
	path_parent(f);
	path_build(f, buf3, 1);

	/* C::B patch: Fix bug with usage of root folder */
# if PATH_DELIM == '\\'
	/* Special case for D:/ - dirname is D:/, not "D:" */
	if ((strlen(buf3)==3) && (buf3[1]==':') && ((buf3[2]=='\\') || (buf3[2]=='/')))
		buf3[2] = 0;
# endif

	if (DEBUG_SEARCH)
		printf( "search %s\n  included by %s\n", _header, source);

#ifdef SEARCH_OPTIM
	{
		char key[MAXJPATH] = "";
		SEARCH search, *s = &search;
		if (!system)
		{
			strcpy(key, buf3);
			strcat(key, ",");
		}
		strcat(key, _header);
		s->key = key;
		if (!searchhash)
			searchhash = hashinit(sizeof(SEARCH), "search");
		if (hashcheck(searchhash, (HASHDATA **)&s))
		{
			if (DEBUG_SEARCH)
				printf("  %s: %s [CACHED]\n", _header, s->time ? s->path : "*missing*" );
			*time = s->time;
			return s->path;
		}
	}
#endif

	/* If this is "foo.h" not <foo.h> then set the first search directory
	 * to the including file's directory */
	if (!system)
	{
		searchdirs->string = buf3;
		list = searchdirs;
	}

	path_parse(header, f);

	f->f_grist.ptr = 0;
	f->f_grist.len = 0;
	
	for (; list; list = list->next)
	{
		f->f_root.ptr = list->string;
		f->f_root.len = strlen(list->string);

		path_build(f, buf, 1);

{
PATHSPLIT f;
char buf2[MAXJPATH];
path_split(buf, &f);
path_normalize(&f, NULL);
path_tostring(&f, buf2);
strcpy(buf, buf2);
}

		if (DEBUG_SEARCH)
			printf("  %s: %s [TRY]\n", _header, buf);

		timestamp(buf, time);

#ifdef SEARCH_OPTIM
		if (*time)
		{
			char key[MAXJPATH] = "";
			SEARCH search, *s = &search;
			if (!system)
			{
				strcpy(key, buf3);
				strcat(key, ",");
			}
			strcat(key, _header);
			s->key = newstr(key);
			s->time = *time;
			s->path = newstr(buf);
			(void) hashenter(searchhash, (HASHDATA **)&s);
		}
#endif

		if (*time)
			return newstr(buf);
	}

	if(!dMode)
	{
#ifdef SEARCH_OPTIM
		/* remember that this file could not be found */
		{
			char key[MAXJPATH] = "";
			SEARCH search, *s = &search;
			if (!system)
			{
				strcpy(key, buf3);
				strcat(key, ",");
			}
			strcat(key, _header);
			s->key = newstr(key);
			s->time = 0;
			s->path = NULL;
			(void) hashenter(searchhash, (HASHDATA **)&s);
		}
#endif

		/* C compilers do *not* look in the current directory for #include files */
		*time = 0;
		return NULL;
	}
	/* D support (look in current directory) */
	else
	{
		f->f_root.ptr = 0;
		f->f_root.len = 0;

		path_build( f, buf, 1 );

{
PATHSPLIT f;
char buf2[MAXJPATH];
path_split(buf, &f);
path_normalize(&f, NULL);
path_tostring(&f, buf2);
strcpy(buf, buf2);
}

		if( DEBUG_SEARCH )
			printf( "search %s: %s\n", _header, buf );

		timestamp( buf, time );


#ifdef SEARCH_OPTIM
		if (*time)
		{
			char key[MAXJPATH] = "";
			SEARCH search, *s = &search;
			if (!system)
			{
				strcpy(key, buf3);
				strcat(key, ",");
			}
			strcat(key, _header);
			s->key = newstr(key);
			s->time = *time;
			s->path = newstr(buf);
			(void) hashenter(searchhash, (HASHDATA **)&s);
		}
#endif

		if (*time)
			return newstr(buf);
		
#ifdef SEARCH_OPTIM
		/* remember that this file could not be found */
		{
			char key[MAXJPATH] = "";
			SEARCH search, *s = &search;
			if (!system)
			{
				strcpy(key, buf3);
				strcat(key, ",");
			}
			strcat(key, _header);
			s->key = newstr(key);
			s->time = 0;
			s->path = NULL;
			(void) hashenter(searchhash, (HASHDATA **)&s);
		}
#endif

		*time = 0;
		return NULL;
	}
}
예제 #5
0
파일: timestamp.c 프로젝트: NeoAnomaly/xray
void
timestamp( 
	char	*target,
	time_t	*time )
{
	PATHNAME f1, f2;
	BINDING	binding, *b = &binding;
	string buf[1];

# ifdef DOWNSHIFT_PATHS
        string path; 
	char *p;

        string_copy( &path, target );
        p = path.value;

	do
            *p = tolower( *p );
	while( *p++ );

	target = path.value;
# endif
        string_new( buf );

	if( !bindhash )
	    bindhash = hashinit( sizeof( BINDING ), "bindings" );

	/* Quick path - is it there? */

	b->name = target;
	b->time = b->flags = 0;
	b->progress = BIND_INIT;

	if( hashenter( bindhash, (HASHDATA **)&b ) )
	    b->name = newstr( target );		/* never freed */

	if( b->progress != BIND_INIT )
	    goto afterscanning;

	b->progress = BIND_NOENTRY;

	/* Not found - have to scan for it */

	path_parse( target, &f1 );

	/* Scan directory if not already done so */

	{
	    BINDING binding, *b = &binding;

	    f2 = f1;
	    f2.f_grist.len = 0;
	    path_parent( &f2 );
	    path_build( &f2, buf, 0 );

	    b->name = buf->value;
	    b->time = b->flags = 0;
	    b->progress = BIND_INIT;

	    if( hashenter( bindhash, (HASHDATA **)&b ) )
		b->name = newstr( buf->value );	/* never freed */

	    if( !( b->flags & BIND_SCANNED ) )
	    {
		file_dirscan( buf->value, time_enter, bindhash );
		b->flags |= BIND_SCANNED;
	    }
	}

	/* Scan archive if not already done so */

	if( f1.f_member.len )
	{
	    BINDING binding, *b = &binding;

	    f2 = f1;
	    f2.f_grist.len = 0;
	    f2.f_member.len = 0;
            string_truncate( buf, 0 );
	    path_build( &f2, buf, 0 );

	    b->name = buf->value;
	    b->time = b->flags = 0;
	    b->progress = BIND_INIT;

	    if( hashenter( bindhash, (HASHDATA **)&b ) )
		b->name = newstr( buf->value );	/* never freed */

	    if( !( b->flags & BIND_SCANNED ) )
	    {
		file_archscan( buf->value, time_enter, bindhash );
		b->flags |= BIND_SCANNED;
	    }
	}

    afterscanning:

	if( b->progress == BIND_SPOTTED )
	{
	    if( file_time( b->name, &b->time ) < 0 )
		b->progress = BIND_MISSING;
	    else
		b->progress = BIND_FOUND;
	}

	*time = b->progress == BIND_FOUND ? b->time : 0;
        string_free( buf );
# ifdef DOWNSHIFT_PATHS
        string_free( &path );
#endif
}