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);
}
Beispiel #2
0
PyObject *bpy_text_reimport(PyObject *module, int *found)
{
	Text *text;
	const char *name;
	char *filepath;
	char *buf = NULL;
//XXX	Main *maggie = bpy_import_main ? bpy_import_main:G.main;
	Main *maggie = bpy_import_main;
	
	if (!maggie) {
		printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n");
		return NULL;
	}
	
	*found = 0;
	
	/* get name, filename from the module itself */
	if ((name = PyModule_GetName(module)) == NULL)
		return NULL;

	if ((filepath = (char *)PyModule_GetFilename(module)) == NULL)
		return NULL;

	/* look up the text object */
	text = BLI_findstring(&maggie->text, BLI_path_basename(filepath), offsetof(ID, name) + 2);

	/* uh-oh.... didn't find it */
	if (!text)
		return NULL;
	else
		*found = 1;

	/* if previously compiled, free the object */
	/* (can't see how could be NULL, but check just in case) */ 
	if (text->compiled) {
		Py_DECREF((PyObject *)text->compiled);
	}

	/* compile the buffer */
	buf = txt_to_buf(text);
	text->compiled = Py_CompileString(buf, text->id.name + 2, Py_file_input);
	MEM_freeN(buf);

	/* if compile failed.... return this error */
	if (PyErr_Occurred()) {
		PyErr_Print();
		PyErr_Clear();
		PySys_SetObject("last_traceback", NULL);
		free_compiled_text(text);
		return NULL;
	}

	/* make into a module */
	return PyImport_ExecCodeModule((char *)name, text->compiled);
}
Beispiel #3
0
PyObject *bpy_text_reimport(PyObject *module, int *found)
{
	Text *text;
	const char *name;
	const char *filepath;
//XXX	Main *maggie = bpy_import_main ? bpy_import_main:G.main;
	Main *maggie = bpy_import_main;
	
	if (!maggie) {
		printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n");
		return NULL;
	}
	
	*found = 0;
	
	/* get name, filename from the module itself */
	if ((name = PyModule_GetName(module)) == NULL)
		return NULL;

	{
		PyObject *module_file = PyModule_GetFilenameObject(module);
		if (module_file == NULL) {
			return NULL;
		}
		filepath = _PyUnicode_AsString(module_file);
		Py_DECREF(module_file);
		if (filepath == NULL) {
			return NULL;
		}
	}

	/* look up the text object */
	text = BLI_findstring(&maggie->text, BLI_path_basename(filepath), offsetof(ID, name) + 2);

	/* uh-oh.... didn't find it */
	if (!text)
		return NULL;
	else
		*found = 1;

	if (bpy_text_compile(text) == false) {
		return NULL;
	}

	/* make into a module */
	return PyImport_ExecCodeModule(name, text->compiled);
}
/* path to temporary exr file */
void render_result_exr_file_path(Scene *scene, const char *layname, int sample, char *filepath)
{
	char name[FILE_MAXFILE + MAX_ID_NAME + MAX_ID_NAME + 100];
	const char *fi = BLI_path_basename(G.main->name);
	
	if (sample == 0) {
		BLI_snprintf(name, sizeof(name), "%s_%s_%s.exr", fi, scene->id.name + 2, layname);
	}
	else {
		BLI_snprintf(name, sizeof(name), "%s_%s_%s%d.exr", fi, scene->id.name + 2, layname, sample);
	}

	/* Make name safe for paths, see T43275. */
	BLI_filename_make_safe(name);

	BLI_make_file_string("/", filepath, BKE_tempdir_session(), name);
}
Beispiel #5
0
bSound *BKE_sound_new_file(struct Main *bmain, const char *filepath)
{
	bSound *sound;
	const char *path;
	char str[FILE_MAX];

	BLI_strncpy(str, filepath, sizeof(str));

	path = /*bmain ? bmain->name :*/ G.main->name;

	BLI_path_abs(str, path);

	sound = BKE_libblock_alloc(bmain, ID_SO, BLI_path_basename(filepath));
	BLI_strncpy(sound->name, filepath, FILE_MAX);
	/* sound->type = SOUND_TYPE_FILE; */ /* XXX unused currently */

	BKE_sound_load(bmain, sound);

	return sound;
}
Beispiel #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
}
Beispiel #7
0
static int get_sequence_len(char *filename, int *ofs)
{
	int frame;
	int numdigit;

	if (!BLI_path_frame_get(filename, &frame, &numdigit)) {
		return 1;
	}

	char path[FILE_MAX];
	BLI_path_abs(filename, G.main->name);
	BLI_split_dir_part(filename, path, FILE_MAX);

	if (path[0] == '\0') {
		/* The filename had no path, so just use the blend file path. */
		BLI_split_dir_part(G.main->name, path, FILE_MAX);
	}

	DIR *dir = opendir(path);
	if (dir == NULL) {
		fprintf(stderr, "Error opening directory '%s': %s\n",
		        path, errno ? strerror(errno) : "unknown error");
		return -1;
	}

	const char *ext = ".abc";
	const char *basename = BLI_path_basename(filename);
	const int len = strlen(basename) - (numdigit + strlen(ext));

	ListBase frames;
	BLI_listbase_clear(&frames);

	struct dirent *fname;
	while ((fname = readdir(dir)) != NULL) {
		/* do we have the right extension? */
		if (!strstr(fname->d_name, ext)) {
			continue;
		}

		if (!STREQLEN(basename, fname->d_name, len)) {
			continue;
		}

		CacheFrame *cache_frame = MEM_callocN(sizeof(CacheFrame), "abc_frame");

		BLI_path_frame_get(fname->d_name, &cache_frame->framenr, &numdigit);

		BLI_addtail(&frames, cache_frame);
	}

	closedir(dir);

	BLI_listbase_sort(&frames, cmp_frame);

	CacheFrame *cache_frame = frames.first;

	if (cache_frame) {
		int frame_curr = cache_frame->framenr;
		(*ofs) = frame_curr;

		while (cache_frame && (cache_frame->framenr == frame_curr)) {
			++frame_curr;
			cache_frame = cache_frame->next;
		}

		BLI_freelistN(&frames);

		return frame_curr - (*ofs);
	}

	return 1;
}
Beispiel #8
0
static int get_sequence_len(char *filename, int *ofs)
{
	int frame;
	int numdigit;

	if (!BLI_path_frame_get(filename, &frame, &numdigit)) {
		return 1;
	}

	char path[FILE_MAX];
	BLI_split_dir_part(filename, path, FILE_MAX);

	DIR *dir = opendir(path);

	const char *ext = ".abc";
	const char *basename = BLI_path_basename(filename);
	const int len = strlen(basename) - (numdigit + strlen(ext));

	ListBase frames;
	BLI_listbase_clear(&frames);

	struct dirent *fname;
	while ((fname = readdir(dir)) != NULL) {
		/* do we have the right extension? */
		if (!strstr(fname->d_name, ext)) {
			continue;
		}

		if (!STREQLEN(basename, fname->d_name, len)) {
			continue;
		}

		CacheFrame *cache_frame = MEM_callocN(sizeof(CacheFrame), "abc_frame");

		BLI_path_frame_get(fname->d_name, &cache_frame->framenr, &numdigit);

		BLI_addtail(&frames, cache_frame);
	}

	closedir(dir);

	BLI_listbase_sort(&frames, cmp_frame);

	CacheFrame *cache_frame = frames.first;

	if (cache_frame) {
		int frame_curr = cache_frame->framenr;
		(*ofs) = frame_curr;

		while (cache_frame && (cache_frame->framenr == frame_curr)) {
			++frame_curr;
			cache_frame = cache_frame->next;
		}

		BLI_freelistN(&frames);

		return frame_curr - (*ofs);
	}

	return 1;
}