Beispiel #1
0
void wm_autosave_location(char *filepath)
{
	const int pid = abs(getpid());
	char path[1024];
#ifdef WIN32
	const char *savedir;
#endif

	if (G.main && G.relbase_valid) {
		const char *basename = BLI_path_basename(G.main->name);
		int len = strlen(basename) - 6;
		BLI_snprintf(path, sizeof(path), "%.*s.blend", len, basename);
	}
	else {
		BLI_snprintf(path, sizeof(path), "%d.blend", pid);
	}

#ifdef WIN32
	/* XXX Need to investigate how to handle default location of '/tmp/'
	 * This is a relative directory on Windows, and it may be
	 * found. Example:
	 * Blender installed on D:\ drive, D:\ drive has D:\tmp\
	 * Now, BLI_exists() will find '/tmp/' exists, but
	 * BLI_make_file_string will create string that has it most likely on C:\
	 * through get_default_root().
	 * If there is no C:\tmp autosave fails. */
	if (!BLI_exists(BKE_tempdir_base())) {
		savedir = BKE_appdir_folder_id_create(BLENDER_USER_AUTOSAVE, NULL);
		BLI_make_file_string("/", filepath, savedir, path);
		return;
	}
#endif

	BLI_make_file_string("/", filepath, BKE_tempdir_base(), path);
}
static void write_history(void)
{
	struct RecentFile *recent, *next_recent;
	char name[FILE_MAX];
	const char *user_config_dir;
	FILE *fp;
	int i;

	/* no write history for recovered startup files */
	if (G.main->name[0] == 0)
		return;
	
	/* will be NULL in background mode */
	user_config_dir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL);
	if (!user_config_dir)
		return;

	BLI_make_file_string("/", name, user_config_dir, BLENDER_HISTORY_FILE);

	recent = G.recent_files.first;
	/* refresh recent-files.txt of recent opened files, when current file was changed */
	if (!(recent) || (BLI_path_cmp(recent->filepath, G.main->name) != 0)) {
		fp = BLI_fopen(name, "w");
		if (fp) {
			/* add current file to the beginning of list */
			recent = (RecentFile *)MEM_mallocN(sizeof(RecentFile), "RecentFile");
			recent->filepath = BLI_strdup(G.main->name);
			BLI_addhead(&(G.recent_files), recent);
			/* write current file to recent-files.txt */
			fprintf(fp, "%s\n", recent->filepath);
			recent = recent->next;
			i = 1;
			/* write rest of recent opened files to recent-files.txt */
			while ((i < U.recent_files) && (recent)) {
				/* this prevents to have duplicities in list */
				if (BLI_path_cmp(recent->filepath, G.main->name) != 0) {
					fprintf(fp, "%s\n", recent->filepath);
					recent = recent->next;
				}
				else {
					next_recent = recent->next;
					MEM_freeN(recent->filepath);
					BLI_freelinkN(&(G.recent_files), recent);
					recent = next_recent;
				}
				i++;
			}
			fclose(fp);
		}

		/* also update most recent files on System */
		GHOST_addToSystemRecentFiles(G.main->name);
	}
}
Beispiel #3
0
/* Only save the prefs block. operator entry */
int wm_userpref_write_exec(bContext *C, wmOperator *op)
{
	wmWindowManager *wm = CTX_wm_manager(C);
	char filepath[FILE_MAX];
	
	/* update keymaps in user preferences */
	WM_keyconfig_update(wm);
	
	BLI_make_file_string("/", filepath, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_USERPREF_FILE);
	printf("trying to save userpref at %s ", filepath);
	
	if (BKE_write_file_userdef(filepath, op->reports) == 0) {
		printf("fail\n");
		return OPERATOR_CANCELLED;
	}
	
	printf("ok\n");
	
	return OPERATOR_FINISHED;
}
Beispiel #4
0
/**
 * Write #BLENDER_HISTORY_FILE as-is, without checking the environment
 * (thats handled by #wm_history_file_update).
 */
static void wm_history_file_write(void)
{
	const char *user_config_dir;
	char name[FILE_MAX];
	FILE *fp;

	/* will be NULL in background mode */
	user_config_dir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL);
	if (!user_config_dir)
		return;

	BLI_make_file_string("/", name, user_config_dir, BLENDER_HISTORY_FILE);

	fp = BLI_fopen(name, "w");
	if (fp) {
		struct RecentFile *recent;
		for (recent = G.recent_files.first; recent; recent = recent->next) {
			fprintf(fp, "%s\n", recent->filepath);
		}
		fclose(fp);
	}
}
Beispiel #5
0
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
static void mat_livedb_draw_mat_preview(uiBlock *block, Scene *scene, ARegion *ar, SpaceLDB *slivedb, ListBase *lb)
{
    LiveDbTreeElement   *te;
    char                *file_path = (char*)BKE_appdir_folder_id_create(BLENDER_USER_DATAFILES, 0);

    strcat(file_path, "/livedb/");
    strcat(file_path, slivedb->server_address);
    strcat(file_path, "/previews/");
    BLI_path_native_slash(file_path);
    BLI_dir_create_recursive(file_path);

    for (te = lb->first; te; te = te->next) {
        if (TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_MATERIAL && te->ys + 2 * MAT_LIVEDB_UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
            unsigned int width, height;
            char* buf = mat_livedb_get_mat_preview(slivedb->server_address, te->item->mat_item.id, &width, &height, file_path);

            if(buf) {
                if(width && height) {
                    glEnable(GL_BLEND);
                    glColor4f(0.0, 0.0, 0.0, 0.0);

                    if (width != UI_UNIT_X || height != (MAT_LIVEDB_UI_UNIT_Y - 2)) {
                        float facx = (float)(MAT_LIVEDB_UI_UNIT_Y - 2) / (float)width;
                        float facy =  (float)(MAT_LIVEDB_UI_UNIT_Y - 2) / (float)height;
                        glPixelZoom(facx, facy);
                    }
                    glaDrawPixelsAuto((float)(ar->v2d.cur.xmax - MAT_LIVEDB_UI_UNIT_Y - 1),
                                      (float)te->ys + 1, width, height, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, buf);

                    glPixelZoom(1.0f, 1.0f);
                    glDisable(GL_BLEND);
                }
                MEM_freeN(buf);
            }
        }
        else if (MAT_LIVEDB_ELEM_OPEN(te, slivedb)) mat_livedb_draw_mat_preview(block, scene, ar, slivedb, &te->subtree);
    }
} /* mat_livedb_draw_mat_preview() */
Beispiel #6
0
/**
 * \see #wm_file_write wraps #BLO_write_file in a similar way.
 */
int wm_homefile_write_exec(bContext *C, wmOperator *op)
{
	wmWindowManager *wm = CTX_wm_manager(C);
	wmWindow *win = CTX_wm_window(C);
	char filepath[FILE_MAX];
	int fileflags;

	BLI_callback_exec(G.main, NULL, BLI_CB_EVT_SAVE_PRE);

	/* check current window and close it if temp */
	if (win && win->screen->temp)
		wm_window_close(C, wm, win);
	
	/* update keymaps in user preferences */
	WM_keyconfig_update(wm);
	
	BLI_make_file_string("/", filepath, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_STARTUP_FILE);
	printf("trying to save homefile at %s ", filepath);
	
	ED_editors_flush_edits(C, false);

	/*  force save as regular blend file */
	fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_AUTOPLAY | G_FILE_HISTORY);

	if (BLO_write_file(CTX_data_main(C), filepath, fileflags | G_FILE_USERPREFS, op->reports, NULL) == 0) {
		printf("fail\n");
		return OPERATOR_CANCELLED;
	}
	
	printf("ok\n");

	G.save_over = 0;

	BLI_callback_exec(G.main, NULL, BLI_CB_EVT_SAVE_POST);

	return OPERATOR_FINISHED;
}
Beispiel #7
0
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
static void get_material_startjob(void *customdata, short *stop, short *do_update, float *progress)
{
    Main            *bmain;
    bContext        *C;
    bNodeTree       *ntree;
    MatItem         *items;
    uint32_t        buf_size;
    GetMaterialJob  *mj = customdata;

    mj->stop        = stop;
    mj->do_update   = do_update;
    mj->progress    = progress;

    ntree   = mj->ntree;
    bmain   = mj->bmain;
    C       = mj->C;

    *progress = 0.1f;

    items = mat_livedb_get_material(mj->address, mj->mat_id, &buf_size);

    *progress = 0.9f;

    if(items) {
        bNode       *node, *next;
        MatItem     *cur_item = items;
        bNode       *node_to;
        bNodeSocket *sock_to;
        char        file_path[FILE_MAX];
        float       cur_y_pos = 0;

        /* Remove all existing nodes */
        ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
        for (node = ntree->nodes.first; node; node = next) {
            next = node->next;
            /* check id user here, nodeFreeNode is called for free dbase too */
            if (node->id) node->id->us--;
            nodeFreeNode(ntree, node);
        }
        ntreeUpdateTree(bmain, ntree);

        node_to = nodeAddNode(C, ntree, "ShaderNodeOutputMaterial");
        node_to->locx = 0;
        node_to->locy = 0;

        for (sock_to = node_to->inputs.first; sock_to; sock_to = sock_to->next) {
            if(!sock_to || strcmp(sock_to->name, "Surface")) continue;
            break;
        }

        /* create file path */
        if(!strlen(G.main->name)) {
            char *cur_path = (char*)BKE_appdir_folder_id_create(BLENDER_USER_DATAFILES, 0);
            strcpy(file_path, cur_path);
            strcat(file_path, "/livedb/");
        }
        else {
            BLI_strncpy(file_path, "//livedb/", sizeof(file_path));
            BLI_path_abs(file_path, G.main->name);
        }
        strcat(file_path, mj->address);
        strcat(file_path, "/textures/");
        BLI_path_native_slash(file_path);
        BLI_dir_create_recursive(file_path);

        mat_livedb_add_mat_element(bmain, C, ntree, node_to, sock_to, &cur_item, file_path, 0, &cur_y_pos);

        ED_node_tree_update(C);
        ED_node_tag_update_nodetree(bmain, ntree, 0);

        MEM_freeN(items);
    }

    *do_update  = 1;
    *stop       = 0;
    *progress   = 1.0f;

    return;
} /* get_material_job() */