static void render_result_exr_file_cache_path(Scene *sce, const char *root, char *r_path)
{
	char filename_full[FILE_MAX + MAX_ID_NAME + 100], filename[FILE_MAXFILE], dirname[FILE_MAXDIR];
	char path_digest[16] = {0};
	char path_hexdigest[33];

	/* If root is relative, use either current .blend file dir, or temp one if not saved. */
	if (G.main->name[0]) {
		BLI_split_dirfile(G.main->name, dirname, filename, sizeof(dirname), sizeof(filename));
		BLI_replace_extension(filename, sizeof(filename), "");  /* strip '.blend' */
		BLI_hash_md5_buffer(G.main->name, strlen(G.main->name), path_digest);
	}
	else {
		BLI_strncpy(dirname, BKE_tempdir_base(), sizeof(dirname));
		BLI_strncpy(filename, "UNSAVED", sizeof(filename));
	}
	BLI_hash_md5_to_hexdigest(path_digest, path_hexdigest);

	/* Default to *non-volatile* tmp dir. */
	if (*root == '\0') {
		root = BKE_tempdir_base();
	}

	BLI_snprintf(filename_full, sizeof(filename_full), "cached_RR_%s_%s_%s.exr",
	             filename, sce->id.name + 2, path_hexdigest);
	BLI_make_file_string(dirname, r_path, root, filename_full);
}
Example #2
0
static int wm_alembic_export_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
	RNA_boolean_set(op->ptr, "init_scene_frame_range", true);

	if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
		Main *bmain = CTX_data_main(C);
		char filepath[FILE_MAX];

		if (bmain->name[0] == '\0') {
			BLI_strncpy(filepath, "untitled", sizeof(filepath));
		}
		else {
			BLI_strncpy(filepath, bmain->name, sizeof(filepath));
		}

		BLI_replace_extension(filepath, sizeof(filepath), ".abc");
		RNA_string_set(op->ptr, "filepath", filepath);
	}

	WM_event_add_fileselect(C, op);

	return OPERATOR_RUNNING_MODAL;

	UNUSED_VARS(event);
}
Example #3
0
static void imb_cache_filename(char *filename, const char *name, int flags)
{
	/* read .tx instead if it exists and is not older */
	if (flags & IB_tilecache) {
		BLI_strncpy(filename, name, IB_FILENAME_SIZE);
		if (!BLI_replace_extension(filename, IB_FILENAME_SIZE, ".tx"))
			return;

		if (BLI_file_older(name, filename))
			return;
	}

	BLI_strncpy(filename, name, IB_FILENAME_SIZE);
}
Example #4
0
/* easy access from gdb */
bool write_crash_blend(void)
{
	char path[FILE_MAX];
	int fileflags = G.fileflags & ~(G_FILE_HISTORY); /* don't do file history on crash file */

	BLI_strncpy(path, G.main->name, sizeof(path));
	BLI_replace_extension(path, sizeof(path), "_crash.blend");
	if (BLO_write_file(G.main, path, fileflags, NULL, NULL)) {
		printf("written: %s\n", path);
		return 1;
	}
	else {
		printf("failed: %s\n", path);
		return 0;
	}
}
Example #5
0
static int wm_collada_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
    if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
        char filepath[FILE_MAX];

        if (G.main->name[0] == 0)
            BLI_strncpy(filepath, "untitled", sizeof(filepath));
        else
            BLI_strncpy(filepath, G.main->name, sizeof(filepath));

        BLI_replace_extension(filepath, sizeof(filepath), ".dae");
        RNA_string_set(op->ptr, "filepath", filepath);
    }

    WM_event_add_fileselect(C, op);

    return OPERATOR_RUNNING_MODAL;
}
Example #6
0
static void blender_crash_handler(int signum)
{

#if 0
	{
		char fname[FILE_MAX];

		if (!G.main->name[0]) {
			BLI_make_file_string("/", fname, BLI_temporary_dir(), "crash.blend");
		}
		else {
			BLI_strncpy(fname, G.main->name, sizeof(fname));
			BLI_replace_extension(fname, sizeof(fname), ".crash.blend");
		}

		printf("Writing: %s\n", fname);
		fflush(stdout);

		BKE_undo_save_file(fname);
	}
#endif

	FILE *fp;
	char header[512];
	wmWindowManager *wm = G.main->wm.first;

	char fname[FILE_MAX];

	if (!G.main->name[0]) {
		BLI_join_dirfile(fname, sizeof(fname), BLI_temporary_dir(), "blender.crash.txt");
	}
	else {
		BLI_join_dirfile(fname, sizeof(fname), BLI_temporary_dir(), BLI_path_basename(G.main->name));
		BLI_replace_extension(fname, sizeof(fname), ".crash.txt");
	}

	printf("Writing: %s\n", fname);
	fflush(stdout);

	BLI_snprintf(header, sizeof(header), "# " BLEND_VERSION_FMT ", Revision: %s\n", BLEND_VERSION_ARG,
#ifdef BUILD_DATE
	             build_rev
#else
	             "Unknown"
#endif
	             );

	/* open the crash log */
	errno = 0;
	fp = BLI_fopen(fname, "wb");
	if (fp == NULL) {
		fprintf(stderr, "Unable to save '%s': %s\n",
		        fname, errno ? strerror(errno) : "Unknown error opening file");
	}
	else {
		if (wm) {
			BKE_report_write_file_fp(fp, &wm->reports, header);
		}

		blender_crash_handler_backtrace(fp);

		fclose(fp);
	}


	/* really crash */
	signal(signum, SIG_DFL);
#ifndef WIN32
	kill(getpid(), signum);
#else
	TerminateProcess(GetCurrentProcess(), signum);
#endif
}
Example #7
0
static int fluid_init_filepaths(Object *fsDomain, char *targetDir, char *targetFile, char *debugStrBuffer)
{
	FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(fsDomain, eModifierType_Fluidsim);
	FluidsimSettings *domainSettings= fluidmd->fss;
	FILE *fileCfg;
	int dirExist = 0;
	char newSurfdataPath[FILE_MAX]; /* modified output settings */
	const char *suffixConfigTmp = FLUID_SUFFIX_CONFIG_TMP;
	int outStringsChanged = 0;

	/* prepare names... */
	const char *relbase= modifier_path_relbase(fsDomain);

	BLI_strncpy(targetDir, domainSettings->surfdataPath, FILE_MAXDIR);
	BLI_strncpy(newSurfdataPath, domainSettings->surfdataPath, FILE_MAXDIR); /* if 0'd out below, this value is never used! */
	BLI_path_abs(targetDir, relbase); /* fixed #frame-no */

	/* .tmp: don't overwrite/delete original file */
	BLI_join_dirfile(targetFile, FILE_MAX, targetDir, suffixConfigTmp);

	// make sure all directories exist
	// as the bobjs use the same dir, this only needs to be checked
	// for the cfg output
	BLI_make_existing_file(targetFile);
	
	// check selected directory
	// simply try to open cfg file for writing to test validity of settings
	fileCfg = BLI_fopen(targetFile, "w");
	if (fileCfg) {
		dirExist = 1; fclose(fileCfg); 
		// remove cfg dummy from  directory test
		BLI_delete(targetFile, false, false);
	}
	
	if (targetDir[0] == '\0' || (!dirExist)) {
		char blendFile[FILE_MAX];
		
		// invalid dir, reset to current/previous
		BLI_split_file_part(G.main->name, blendFile, sizeof(blendFile));
		BLI_replace_extension(blendFile, FILE_MAX, ""); /* strip .blend */
		BLI_snprintf(newSurfdataPath, FILE_MAX, "//fluidsimdata/%s_%s_", blendFile, fsDomain->id.name);
		
		BLI_snprintf(debugStrBuffer, 256, "fluidsimBake::error - warning resetting output dir to '%s'\n", newSurfdataPath);
		elbeemDebugOut(debugStrBuffer);
		outStringsChanged=1;
	}
	
	/* check if modified output dir is ok */
#if 0
	if (outStringsChanged) {
		char dispmsg[FILE_MAX+256];
		int  selection=0;
		BLI_strncpy(dispmsg, "Output settings set to: '", sizeof(dispmsg));
		strcat(dispmsg, newSurfdataPath);
		strcat(dispmsg, "'%t|Continue with changed settings %x1|Discard and abort %x0");
		
		/* ask user if thats what he/she wants... */
		selection = pupmenu(dispmsg);
		if (selection < 1) return 0; /* 0 from menu, or -1 aborted */
		BLI_strncpy(targetDir, newSurfdataPath, sizeof(targetDir));
		strncpy(domainSettings->surfdataPath, newSurfdataPath, FILE_MAXDIR);
		BLI_path_abs(targetDir, G.main->name); /* fixed #frame-no */
	}
#endif
	return outStringsChanged;
}
Example #8
0
int WM_write_file(bContext *C, const char *target, int fileflags, ReportList *reports, int copy)
{
	Library *li;
	int len;
	char filepath[FILE_MAX];

	int *thumb = NULL;
	ImBuf *ibuf_thumb = NULL;

	len = strlen(target);
	
	if (len == 0) {
		BKE_report(reports, RPT_ERROR, "Path is empty, cannot save");
		return -1;
	}

	if (len >= FILE_MAX) {
		BKE_report(reports, RPT_ERROR, "Path too long, cannot save");
		return -1;
	}
 
	BLI_strncpy(filepath, target, FILE_MAX);
	BLI_replace_extension(filepath, FILE_MAX, ".blend");
	/* don't use 'target' anymore */
	
	/* send the OnSave event */
	for (li = G.main->library.first; li; li = li->id.next) {
		if (BLI_path_cmp(li->filepath, filepath) == 0) {
			BKE_reportf(reports, RPT_ERROR, "Can't overwrite used library '%.240s'", filepath);
			return -1;
		}
	}

	/* blend file thumbnail */
	/* save before exit_editmode, otherwise derivedmeshes for shared data corrupt #27765) */
	if (U.flag & USER_SAVE_PREVIEWS) {
		ibuf_thumb = blend_file_thumb(CTX_data_scene(C), CTX_wm_screen(C), &thumb);
	}

	BLI_exec_cb(G.main, NULL, BLI_CB_EVT_SAVE_PRE);

	/* operator now handles overwrite checks */

	if (G.fileflags & G_AUTOPACK) {
		packAll(G.main, reports);
	}
	
	ED_object_exit_editmode(C, EM_DO_UNDO);
	ED_sculpt_force_update(C);

	/* don't forget not to return without! */
	WM_cursor_wait(1);
	
	fileflags |= G_FILE_HISTORY; /* write file history */

	if (BLO_write_file(CTX_data_main(C), filepath, fileflags, reports, thumb)) {
		if (!copy) {
			G.relbase_valid = 1;
			BLI_strncpy(G.main->name, filepath, sizeof(G.main->name));  /* is guaranteed current file */
	
			G.save_over = 1; /* disable untitled.blend convention */
		}

		if (fileflags & G_FILE_COMPRESS) G.fileflags |= G_FILE_COMPRESS;
		else G.fileflags &= ~G_FILE_COMPRESS;
		
		if (fileflags & G_FILE_AUTOPLAY) G.fileflags |= G_FILE_AUTOPLAY;
		else G.fileflags &= ~G_FILE_AUTOPLAY;

		/* prevent background mode scripts from clobbering history */
		if (!G.background) {
			write_history();
		}

		BLI_exec_cb(G.main, NULL, BLI_CB_EVT_SAVE_POST);

		/* run this function after because the file cant be written before the blend is */
		if (ibuf_thumb) {
			IMB_thumb_delete(filepath, THB_FAIL); /* without this a failed thumb overrides */
			ibuf_thumb = IMB_thumb_create(filepath, THB_NORMAL, THB_SOURCE_BLEND, ibuf_thumb);
			IMB_freeImBuf(ibuf_thumb);
		}

		if (thumb) MEM_freeN(thumb);
	}
	else {
		if (ibuf_thumb) IMB_freeImBuf(ibuf_thumb);
		if (thumb) MEM_freeN(thumb);
		
		WM_cursor_wait(0);
		return -1;
	}

	WM_cursor_wait(0);
	
	return 0;
}