summaryrefslogtreecommitdiff
path: root/src/configpaths.cpp
blob: ea48ddd8f5529fd9b8b32f6c57e4937759079d3e (plain) (blame)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "configpaths.h"

#include <cstring>
#include <fstream>
#include <iostream>
#include <pwd.h>
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include "config.h"
#include "globals.h"
#include "ruststring.h"
#include "strprintf.h"

extern "C" {
	void* create_rs_configpaths();

	void destroy_rs_configpaths(void* rs_configpaths);

	bool rs_configpaths_initialized(void* rs_configpaths);

	char* rs_configpaths_error_message(void* rs_configpaths);

	void rs_configpaths_process_args(void* rs_configpaths, void* rs_cliargsparser);

	bool rs_configpaths_try_migrate_from_newsbeuter(void* rs_configpaths);

	bool rs_configpaths_create_dirs(void* rs_configpaths);

	char* rs_configpaths_url_file(void* rs_configpaths);

	char* rs_configpaths_cache_file(void* rs_configpaths);

	void rs_configpaths_set_cache_file(void* rs_configpaths, const char*);

	char* rs_configpaths_config_file(void* rs_configpaths);

	char* rs_configpaths_lock_file(void* rs_configpaths);

	char* rs_configpaths_queue_file(void* rs_configpaths);

	char* rs_configpaths_search_file(void* rs_configpaths);

	char* rs_configpaths_cmdline_file(void* rs_configpaths);
}

#define SIMPLY_RUN(NAME) \
	if (rs_configpaths) { \
		rs_configpaths_ ## NAME (rs_configpaths); \
	}

#define GET_VALUE(NAME, DEFAULT) \
	if (rs_configpaths) { \
		return rs_configpaths_ ## NAME (rs_configpaths); \
	} else { \
		return DEFAULT; \
	}

#define GET_STRING(NAME) \
	if (rs_configpaths) { \
		return RustString(rs_configpaths_ ## NAME (rs_configpaths)); \
	} else { \
		return {}; \
	}

namespace newsboat {

ConfigPaths::ConfigPaths()
{
	rs_configpaths = create_rs_configpaths();
}

ConfigPaths::~ConfigPaths()
{
	if (rs_configpaths) {
		destroy_rs_configpaths(rs_configpaths);
	}
}

bool ConfigPaths::initialized() const
{
	GET_VALUE(initialized, false);
}

std::string ConfigPaths::error_message() const
{
	GET_STRING(error_message);
}

void ConfigPaths::process_args(const CliArgsParser& args)
{
	if (rs_configpaths) {
		rs_configpaths_process_args(rs_configpaths, args.get_rust_pointer());
	}
}

bool ConfigPaths::try_migrate_from_newsbeuter()
{
	GET_VALUE(try_migrate_from_newsbeuter, false);
}

bool ConfigPaths::create_dirs() const
{
	GET_VALUE(create_dirs, false);
}

void ConfigPaths::set_cache_file(const std::string& new_cachefile)
{
	if (rs_configpaths) {
		rs_configpaths_set_cache_file(rs_configpaths, new_cachefile.c_str());
	}
}

std::string ConfigPaths::url_file() const
{
	GET_STRING(url_file);
}

std::string ConfigPaths::cache_file() const
{
	GET_STRING(cache_file);
}

std::string ConfigPaths::config_file() const
{
	GET_STRING(config_file);
}

std::string ConfigPaths::lock_file() const
{
	GET_STRING(lock_file);
}

std::string ConfigPaths::queue_file() const
{
	GET_STRING(queue_file);
}

std::string ConfigPaths::search_file() const
{
	GET_STRING(search_file);
}

std::string ConfigPaths::cmdline_file() const
{
	GET_STRING(cmdline_file);
}

} // namespace newsboat