summaryrefslogtreecommitdiffstats
path: root/examples/c4add.c
blob: df5384605c142bdcfdbe676a12868dcdb05a9e79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "cc4group.h"

int main(int argc, char* argv[])
{
	if(argc != 3 && argc != 4)
	{
		fprintf(stderr, "USAGE: %s <group> <file|directory> [target path]\n", argv[0]);
		return EXIT_FAILURE;
	}

	CC4Group* group = cc4group.new();
	bool success = cc4group.openExisting(group, argv[1]);
	if(!success)
	{
		fprintf(stderr, "ERROR: Can not open group file \"%s\": %s\n", argv[1], cc4group.getErrorMessage(group));
	}
	else
	{
		success = cc4group.addFromDisk(group, argv[2], argc == 4 ? argv[3] : argv[2], cc4group.AllowedEntryTypes.All);

		if(!success)
		{
			fprintf(stderr, "ERROR: Can not add file/directory \"%s\" from disk: %s\n", argv[2], cc4group.getErrorMessage(group));
		}
		else
		{
			success = cc4group.saveParent(group);

			if(!success)
			{
				fprintf(stderr, "ERROR: Can not save group file \"%s\": %s\n", argv[1], cc4group.getErrorMessage(group));
			}
		}
	}
	cc4group.delete(group);

	return success ? EXIT_SUCCESS : EXIT_FAILURE;
}