Exemplo n.º 1
0
static appenv *getappenv()
{
    #define SNAPSHOTS "snapshots"
    #define BACKUP "backup"
    #define SCREENSHOTS "screenshots"

    appenv *app = malloc(sizeof(appenv));
    pushobject(app, freeappenv);

    app->basedir = pathcombc(gethomedir(), "." PACKAGE);
    createdirectory(app->basedir);

    app->snapshots = pathcombc(strdups(app->basedir), SNAPSHOTS);
    createdirectory(app->snapshots);

    app->backup = pathcombc(strdups(app->basedir), BACKUP);
    createdirectory(app->backup);

    app->screenshots = pathcombc(strdups(app->basedir), SCREENSHOTS);
    createdirectory(app->screenshots);

#ifdef DEBUG
    app->debug = pathcombc(strdups(app->basedir), "debug");
    createdirectory(app->debug);
#endif

    return app;
}
Exemplo n.º 2
0
static BOOL defineSCIHOME(void)
{
#define BASEDIR ".Scilab"
    int ierr   = 0;
    int buflen = PATH_MAX;
    int iflag  = 0;
    char USERPATHSCILAB[PATH_MAX];
    char USERHOMESYSTEM[PATH_MAX];

    C2F(getenvc)(&ierr, "HOME", USERHOMESYSTEM, &buflen, &iflag);
    if (ierr)
    {
        return FALSE;
    }

    /* Set SCIHOME environment variable */
    snprintf(USERPATHSCILAB, sizeof(USERPATHSCILAB), "%s%s%s",
             USERHOMESYSTEM, DIR_SEPARATOR, BASEDIR);
    snprintf(SCIHOMEPATH, sizeof(SCIHOMEPATH), "%s%s%s", USERPATHSCILAB,
             DIR_SEPARATOR, SCI_VERSION_STRING);

    /* creates directory if it does not exists */
    if (!isdir(SCIHOMEPATH))
    {
        if (!isdir(USERPATHSCILAB))
        {
            createdirectory(USERPATHSCILAB);
        }
        if (createdirectory(SCIHOMEPATH))
        {
            return TRUE;
        }
    }
    else
    {
        return TRUE;
    }

    return FALSE;
}
Exemplo n.º 3
0
static BOOL defineSCIHOME(void)
{
#define BASEDIR "Scilab"
    int ierr = 0;
    int buflen = PATH_MAX;
    int iflag = 0;

    char USERPATHSCILAB[PATH_MAX];

    char USERHOMESYSTEM[PATH_MAX];
    char *SHORTUSERHOMESYSTEM = NULL;

    BOOL bConverted = FALSE;

    C2F(getenvc)(&ierr, "APPDATA", USERHOMESYSTEM, &buflen, &iflag);

    /* if APPDATA not found we try with USERPROFILE */
    if (ierr)
    {
        C2F(getenvc)(&ierr, "USERPROFILE", USERHOMESYSTEM, &buflen, &iflag);
    }

    /* convert long path to short path format : remove some special characters */
    SHORTUSERHOMESYSTEM = getshortpathname(USERHOMESYSTEM, &bConverted);
    if (SHORTUSERHOMESYSTEM)
    {
        if (!isdir(SHORTUSERHOMESYSTEM))
        {
            /* last chance, we try to get default all users profile */
            C2F(getenvc)(&ierr, "ALLUSERSPROFILE", USERHOMESYSTEM, &buflen, &iflag);
            if (ierr)
            {
                FREE(SHORTUSERHOMESYSTEM);
                SHORTUSERHOMESYSTEM = NULL;
                return FALSE;
            }

            /* convert long path to short path format : remove some special characters */
            SHORTUSERHOMESYSTEM = getshortpathname(USERHOMESYSTEM, &bConverted);

            if ( (!SHORTUSERHOMESYSTEM) || (!isdir(SHORTUSERHOMESYSTEM)) )
            {
                if (SHORTUSERHOMESYSTEM)
                {
                    FREE(SHORTUSERHOMESYSTEM);
                    SHORTUSERHOMESYSTEM = NULL;
                }
                return FALSE;
            }
        }
    }
    else
    {
        if (SHORTUSERHOMESYSTEM)
        {
            FREE(SHORTUSERHOMESYSTEM);
            SHORTUSERHOMESYSTEM = NULL;
        }
        return FALSE;
    }

    /* checks that directory exists */
    strcpy(USERHOMESYSTEM, SHORTUSERHOMESYSTEM);
    if (SHORTUSERHOMESYSTEM)
    {
        FREE(SHORTUSERHOMESYSTEM);
        SHORTUSERHOMESYSTEM = NULL;
    }


    /* Set SCIHOME environment variable */
    snprintf(USERPATHSCILAB, sizeof(USERPATHSCILAB), "%s%s%s",
             USERHOMESYSTEM, DIR_SEPARATOR, BASEDIR);
    snprintf(SCIHOMEPATH, sizeof(SCIHOMEPATH), "%s%s%s", USERPATHSCILAB,
             DIR_SEPARATOR, SCI_VERSION_STRING);

    /* creates directory if it does not exists */
    if (!isdir(SCIHOMEPATH))
    {
        if (!isdir(USERPATHSCILAB))
        {
            createdirectory(USERPATHSCILAB);
        }
        if (createdirectory(SCIHOMEPATH))
        {
            return TRUE;
        }
    }
    else
    {
        return TRUE;
    }

    return FALSE;
}
Exemplo n.º 4
0
bool atcommand_createnavigationlua_sub(void) {
	int global_mob_idx = 17104;
	int n=0;
	int m;
	int mobidx, npcidx, warpidx;
	FILE *fp_mob, *fp_map, *fp_link, *fp_npc, *fp_npcdist, *fp_linkdist;
	int nlink = 0, nnpc = 0;

	struct s_map_npcdata *map_npcdata = NULL;

	struct walkpath_data_navi wpd;
	memset(&wpd, '\0', sizeof(wpd));

	ShowStatus("Creating navigation LUA files. This can take several minutes.\n");

	if (!createdirectory(DIRECTORYNAME)) {
		ShowError("do_navigationlua: Unable to create output directory.\n");
		return false;
	}

	fp_mob = fopen(DIRECTORYNAME PATHSEP_STR "navi_mob_" NAMESUFFIX ".lua", "wt+");
	fp_map = fopen(DIRECTORYNAME PATHSEP_STR "navi_map_" NAMESUFFIX ".lua", "wt+");
	fp_link = fopen(DIRECTORYNAME PATHSEP_STR "navi_link_" NAMESUFFIX ".lua", "wt+");
	fp_npc = fopen(DIRECTORYNAME PATHSEP_STR "navi_npc_" NAMESUFFIX ".lua", "wt+");
	fp_npcdist = fopen(DIRECTORYNAME PATHSEP_STR "navi_npcdistance_" NAMESUFFIX ".lua", "wt+");
	fp_linkdist = fopen(DIRECTORYNAME PATHSEP_STR "navi_linkdistance_" NAMESUFFIX ".lua", "wt+");

	if( !fp_mob || !fp_map || !fp_link || !fp_npc || !fp_npcdist || !fp_linkdist ) {
		ShowError("do_navigationlua: Unable to open output file.\n");
		return false;
	}

	map_npcdata = (struct s_map_npcdata *)aCalloc(sizeof(struct s_map_npcdata), map->count);

	ShowStatus("Stage 1: creating maps and objects list...\n");

	writeheader(fp_map, "Navi_Map");
	writeheader(fp_mob, "Navi_Mob");
	writeheader(fp_npc, "Navi_Npc");
	writeheader(fp_link, "Navi_Link");
	writeheader(fp_npcdist, "Navi_NpcDistance");
	writeheader(fp_linkdist, "Navi_Distance");

	for( m=0; m < map->count; m++ ) {
		//int nmapnpc=0;

		atcommand_createnavigationlua_sub_map(fp_map, m);

		// Warps/NPCs
		for( npcidx = 0; npcidx < map->list[m].npc_num; npcidx++ ) {
			TBL_NPC *nd = map->list[m].npc[npcidx];
			struct npc_data_append *nda;

			if( !nd )
				continue;

			if( !(nda = getFromNPCD(nd, 0)) ) {
				CREATE(nda,struct npc_data_append,1);
				addToNPCD(nd, nda, 0, true);
			}

			if( nd->subtype == WARP ) {
				int mnext = map->mapindex2mapid(nd->u.warp.mapindex);
				if( mnext < 0 )
					continue;
				nda->npcid = 13350 + nlink;

				atcommand_createnavigationlua_sub_warp(fp_link, nd, mnext, nlink);

				map_npcdata[mnext].inner_warps[map_npcdata[mnext].ninner_warps++] = nd;
				map_npcdata[m].outer_warps[map_npcdata[m].nouter_warps++] = nd;

				nlink++;
			} else {
				if( nd->class_ == -1 || nd->class_ == INVISIBLE_CLASS || nd->class_ == HIDDEN_WARP_CLASS || nd->class_ == FLAG_CLASS )
					continue;

				nda->npcid = 11984 + nnpc;

				atcommand_createnavigationlua_sub_npc(fp_npc, nd, nnpc);

				map_npcdata[m].npcs[map_npcdata[m].nnpcs] = nd;
				map_npcdata[m].nnpcs++;

				nnpc++;
			}
		}

		// Mobs
		for( mobidx=0; mobidx < MAX_MOB_LIST_PER_MAP; mobidx++ ) {
			struct mob_db *mobinfo;

			if( !map->list[m].moblist[mobidx] )
				continue;

			mobinfo = mob->db(map->list[m].moblist[mobidx]->class_);
			if( mobinfo == mob->dummy )
				continue;

			atcommand_createnavigationlua_sub_mob(fp_mob, m, mobinfo, map->list[m].moblist[mobidx]->num, global_mob_idx+n);

			n++;
		}
		ShowStatus("Created %s objects list (%d/%d)\n", map->list[m].name, m+1, map->count);
	}