about summary refs log tree commit diff stats
path: root/src/files.c
blob: bb339ad81cc6db927707221f540ff671fdc6ccd0 (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
152
153
/*
 * files.c
 *
 * Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
 *
 * This file is part of Profanity.
 *
 * Profanity is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Profanity is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Profanity.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>

#include <glib.h>

#include "common.h"

static void _files_create_config_directory(void);
static void _files_create_data_directory(void);
static void _files_create_chatlog_directory(void);
static void _files_create_log_directory(void);
static void _files_create_themes_directory(void);

void
files_create_directories(void)
{
    _files_create_config_directory();
    _files_create_data_directory();
    _files_create_chatlog_directory();
    _files_create_log_directory();
    _files_create_themes_directory();
}

gchar *
files_get_preferences_file(void)
{
    gchar *xdg_config = xdg_get_config_home();
    GString *prefs_file = g_string_new(xdg_config);
    g_string_append(prefs_file, "/profanity/profrc");
    gchar *result = strdup(prefs_file->str);
    g_free(xdg_config);
    g_string_free(prefs_file, TRUE);

    return result;
}

gchar *
files_get_log_file(void)
{
    gchar *xdg_data = xdg_get_data_home();
    GString *logfile = g_string_new(xdg_data);
    g_string_append(logfile, "/profanity/logs/profanity.log");
    gchar *result = strdup(logfile->str);
    g_free(xdg_data);
    g_string_free(logfile, TRUE);

    return result;
}

gchar *
files_get_accounts_file(void)
{
    gchar *xdg_data = xdg_get_data_home();
    GString *logfile = g_string_new(xdg_data);
    g_string_append(logfile, "/profanity/accounts");
    gchar *result = strdup(logfile->str);
    g_free(xdg_data);
    g_string_free(logfile, TRUE);

    return result;
}

gchar *
files_get_themes_dir(void)
{
    gchar *xdg_config = xdg_get_config_home();
    GString *themes_dir = g_string_new(xdg_config);
    g_string_append(themes_dir, "/profanity/themes");
    gchar *result = strdup(themes_dir->str);
    g_free(xdg_config);
    g_string_free(themes_dir, TRUE);

    return result;
}

static void
_files_create_config_directory(void)
{
    gchar *xdg_config = xdg_get_config_home();
    GString *prof_conf_dir = g_string_new(xdg_config);
    g_string_append(prof_conf_dir, "/profanity");
    mkdir_recursive(prof_conf_dir->str);
    g_free(xdg_config);
    g_string_free(prof_conf_dir, TRUE);
}

static void
_files_create_data_directory(void)
{
    gchar *xdg_data = xdg_get_data_home();
    GString *prof_data_dir = g_string_new(xdg_data);
    g_string_append(prof_data_dir, "/profanity");
    mkdir_recursive(prof_data_dir->str);
    g_free(xdg_data);
    g_string_free(prof_data_dir, TRUE);
}

static void
_files_create_chatlog_directory(void)
{
    gchar *xdg_data = xdg_get_data_home();
    GString *chatlogs_dir = g_string_new(xdg_data);
    g_string_append(chatlogs_dir, "/profanity/chatlogs");
    mkdir_recursive(chatlogs_dir->str);
    g_free(xdg_data);
    g_string_free(chatlogs_dir, TRUE);
}

static void
_files_create_log_directory(void)
{
    gchar *xdg_data = xdg_get_data_home();
    GString *chatlogs_dir = g_string_new(xdg_data);
    g_string_append(chatlogs_dir, "/profanity/logs");
    mkdir_recursive(chatlogs_dir->str);
    g_free(xdg_data);
    g_string_free(chatlogs_dir, TRUE);
}

static void
_files_create_themes_directory(void)
{
    gchar *xdg_config = xdg_get_config_home();
    GString *themes_dir = g_string_new(xdg_config);
    g_string_append(themes_dir, "/profanity/themes");
    mkdir_recursive(themes_dir->str);
    g_free(xdg_config);
    g_string_free(themes_dir, TRUE);
}