Пример #1
0
static int test_tigroup()
{
	TigContent *content = NULL;
	TigEntry te = { NULL, 0, { NULL } };
	int ret = -1;

	// SVN can't handle file like 'pépé'. You will have to rename it from pepe to pépé and
	// uncomment line below and another line.
	//char *name = g_filename_from_utf8("tig/p\xC3\xA9p\xC3\xA9.tig", -1, NULL, NULL, NULL);

	char *array[2];
	char files[2][1024];

	printf("--> Testing TiGroup support (r/w)...\n");
	tifiles_file_display_tigroup(PATH("tig/test.tig"));

	content = tifiles_content_create_tigroup(CALC_NONE, 0);
	if (content != NULL)
	{
		ret = tifiles_file_read_tigroup(PATH("tig/test2.tig"), content);
		if (!ret)
		{
			ret = tifiles_file_write_tigroup(PATH("tig/test2_.tig"), content);
		}
		tifiles_content_delete_tigroup(content);
	}

	if (!ret)
	{
		content = tifiles_content_create_tigroup(CALC_NONE, 0);
		if (content != NULL)
		{
			ret = tifiles_file_read_tigroup(PATH("tig/test.tig"), content);
			if (!ret)
			{
				ret = tifiles_file_write_tigroup(PATH("tig/test_.tig"), content);
				if (!ret)
				{
					ret = compare_files(PATH("tig/test.tig"), PATH2("tig/test_.tig"));
				}
			}
			tifiles_content_delete_tigroup(content);
		}
	}

	if (!ret)
	{
		printf("--> Testing add/del from TiGroup support (r/w)...\n");
		ret = tifiles_tigroup_add_file(PATH("tig/C.8Xn"), PATH2("tig/test2.tig"));
		if (!ret)
		{
			ret = tifiles_tigroup_add_file(PATH("tig/D.8Xn"), PATH2("tig/test2.tig"));
			if (!ret)
			{
				te.filename = strdup("C.8Xn");
				ret = tifiles_tigroup_del_file(&te, PATH("tig/test2.tig"));
				if (!ret)
				{
					te.filename = strdup("D.8Xn");
					ret = tifiles_tigroup_del_file(&te, PATH("tig/test2.tig"));
					if (!ret)
					{
						tifiles_file_display_tigroup(PATH("tig/test2.tig"));
						ret = compare_files(PATH("tig/test.tig"), PATH2("tig/test2.tig"));
					}
				}
			}
		}
	}

	if (!ret)
	{
		printf("--> Testing TiGroup support (group/ungroup)...\n");

		strncpy(files[0], PATH("tig/str.89s"), 1023);
		files[0][1023] = 0;
		strncpy(files[1], PATH("tig/ticabfra.89k"), 1023);
		files[1][1023] = 0;
		array[0] = files[0];
		array[1] = files[1];
		ret = tifiles_tigroup_files(array, PATH("tig/test_.tig"));
		if (!ret)
		{
			tifiles_file_display(PATH("tig/test_.tig"));
			ret = tifiles_untigroup_file(PATH("tig/test.tig"), NULL);
			if (!ret)
			{
				move_file("A.8Xn", "tig/AA.8Xn");
				move_file("B.8Xn", "tig/BB.8Xn");
				ret = compare_files(PATH("tig/A.8Xn"), PATH2("tig/AA.8Xn"));
				if (!ret)
				{
					ret = compare_files(PATH("tig/B.8Xn"), PATH2("tig/BB.8Xn"));
				}
			}
		}
	}

	return ret;
}
Пример #2
0
int gfm_tifiles_ungroup(const char *filename, int type)
{
	gchar *dirname = g_path_get_dirname(filename);
	gchar *basename = g_path_get_basename(filename);
	
	gchar *src_file;
	gchar *dst_file;
	
	gchar *folder, *tmp;
	gchar *input;	
	gchar *e;
	int err = 0;

	// Ask for folder
	folder = g_strdup(basename);
	e = strrchr(folder, '.');
	if(e) *e = '\0';

	input = msgbox_input(_("Create new directory"), folder, _("Directory where files will be ungrouped: "));
	g_free(folder);
	if (input == NULL)
		return -1;

	tmp = g_filename_from_utf8(input, -1, NULL, NULL, NULL);
	g_free(input);

	folder = g_strconcat(dirname, G_DIR_SEPARATOR_S, tmp, NULL);
	g_free(tmp);

	// Check for folder existence
	if(!strcmp(dirname, ".") || !strcmp(dirname, ""))
	{
		msgbox_one(MSGBOX_ERROR, _("You can't ungroup in this folder."));
		g_free(basename);
		g_free(dirname);
		return -1;
	}
   
	// Create folder
	if(file_mkdir(folder))
	{
		g_free(basename);
		g_free(dirname);
		return -1;
	}
	file_chdir(folder);

	// Copy file to target
	src_file = g_strdup(filename);	
	dst_file = g_strconcat(folder, G_DIR_SEPARATOR_S, basename, NULL);
	file_copy(src_file, dst_file);
	
	// Ungroup
	if(type == TIFILE_GROUP)
		err = tifiles_ungroup_file(dst_file, NULL);
	else if(type == TIFILE_TIGROUP)
		err = tifiles_untigroup_file(dst_file, NULL);
	if(err)
	{
		gchar *str;

		tifiles_error_get(err, &str);
		msgbox_one(MSGBOX_ERROR, str);
		g_free(str);
	}
	file_chdir("..");

	// And release
	g_free(basename);
	g_free(dirname);
	g_free(src_file);
	g_free(dst_file);

	return 0;
}