mirror of
https://github.com/weechat/weechat.git
synced 2026-07-04 00:33:13 +02:00
Using new default value for DCC download dir (created at startup), fixed logs dir creation
This commit is contained in:
+14
-9
@@ -107,15 +107,20 @@ void
|
||||
log_start (t_gui_buffer *buffer)
|
||||
{
|
||||
int length;
|
||||
char *ptr_home, *log_path, *log_path2, *ptr_path;
|
||||
char *log_path, *log_path2;
|
||||
|
||||
ptr_home = getenv ("HOME");
|
||||
log_path = weechat_strreplace (cfg_log_path, "~", ptr_home);
|
||||
log_path2 = weechat_strreplace ((log_path) ?
|
||||
log_path : cfg_log_path,
|
||||
"%h", weechat_home);
|
||||
ptr_path = (log_path2) ? log_path2 : ((log_path) ? log_path : cfg_log_path);
|
||||
length = strlen (ptr_path) + 64;
|
||||
log_path = weechat_strreplace (cfg_log_path, "~", getenv ("HOME"));
|
||||
log_path2 = weechat_strreplace (log_path, "%h", weechat_home);
|
||||
if (!log_path || !log_path2)
|
||||
{
|
||||
weechat_log_printf (_("Not enough memory to write log file for a buffer\n"));
|
||||
if (log_path)
|
||||
free (log_path);
|
||||
if (log_path2)
|
||||
free (log_path2);
|
||||
return;
|
||||
}
|
||||
length = strlen (log_path2) + 64;
|
||||
if (SERVER(buffer))
|
||||
length += strlen (SERVER(buffer)->name);
|
||||
if (CHANNEL(buffer))
|
||||
@@ -132,7 +137,7 @@ log_start (t_gui_buffer *buffer)
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy (buffer->log_filename, ptr_path);
|
||||
strcpy (buffer->log_filename, log_path2);
|
||||
if (log_path)
|
||||
free (log_path);
|
||||
if (log_path2)
|
||||
|
||||
+39
-14
@@ -273,6 +273,9 @@ weechat_strreplace (char *string, char *search, char *replace)
|
||||
char *pos, *new_string;
|
||||
int length1, length2, length_new, count;
|
||||
|
||||
if (!string || !search || !replace)
|
||||
return NULL;
|
||||
|
||||
length1 = strlen (search);
|
||||
length2 = strlen (replace);
|
||||
|
||||
@@ -694,13 +697,13 @@ weechat_create_dir (char *directory)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_create_home_dirs: create WeeChat directories (if not found)
|
||||
* weechat_create_home_dirs: create WeeChat directories
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_create_home_dirs ()
|
||||
{
|
||||
char *ptr_home, *dir_name;
|
||||
char *ptr_home;
|
||||
int dir_length;
|
||||
|
||||
if (!weechat_home)
|
||||
@@ -732,21 +735,42 @@ weechat_create_home_dirs ()
|
||||
WEECHAT_ERROR, weechat_home);
|
||||
weechat_shutdown (EXIT_FAILURE, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_create_config_dirs: create config directories (read from config file)
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_create_config_dirs ()
|
||||
{
|
||||
char *dir1, *dir2;
|
||||
|
||||
dir_length = strlen (weechat_home) + 64;
|
||||
dir_name = (char *) malloc (dir_length * sizeof (char));
|
||||
|
||||
/* create "<weechat_home>/logs" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
|
||||
"logs");
|
||||
if (!weechat_create_dir (dir_name))
|
||||
{
|
||||
/* create logs directory" */
|
||||
dir1 = weechat_strreplace (cfg_log_path, "~", getenv ("HOME"));
|
||||
dir2 = weechat_strreplace (dir1, "%h", weechat_home);
|
||||
if (weechat_create_dir (dir2))
|
||||
chmod (dir2, 0700);
|
||||
else
|
||||
fprintf (stderr, _("%s unable to create \"%s\" directory\n"),
|
||||
WEECHAT_WARNING, dir_name);
|
||||
}
|
||||
chmod (dir_name, 0700);
|
||||
WEECHAT_WARNING, dir2);
|
||||
if (dir1)
|
||||
free (dir1);
|
||||
if (dir2)
|
||||
free (dir2);
|
||||
|
||||
free (dir_name);
|
||||
/* create DCC download directory */
|
||||
dir1 = weechat_strreplace (cfg_dcc_download_path, "~", getenv ("HOME"));
|
||||
dir2 = weechat_strreplace (dir1, "%h", weechat_home);
|
||||
if (weechat_create_dir (dir2))
|
||||
chmod (dir2, 0700);
|
||||
else
|
||||
fprintf (stderr, _("%s unable to create \"%s\" directory\n"),
|
||||
WEECHAT_WARNING, dir2);
|
||||
if (dir1)
|
||||
free (dir1);
|
||||
if (dir2)
|
||||
free (dir2);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1040,6 +1064,7 @@ main (int argc, char *argv[])
|
||||
weechat_init_log (); /* init log file */
|
||||
command_index_build (); /* build cmd index for completion */
|
||||
weechat_config_read (); /* read configuration */
|
||||
weechat_create_config_dirs (); /* create config directories */
|
||||
utf8_init (); /* init UTF-8 in WeeChat */
|
||||
gui_init (); /* init WeeChat interface */
|
||||
fifo_create (); /* FIFO pipe for remote control */
|
||||
|
||||
@@ -791,7 +791,7 @@ t_config_option weechat_options_dcc[] =
|
||||
{ "dcc_download_path", N_("path for incoming files with dcc"),
|
||||
N_("path for writing incoming files with dcc (default: user home)"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
"~", NULL, NULL, &cfg_dcc_download_path, &config_change_noop },
|
||||
"%h/dcc", NULL, NULL, &cfg_dcc_download_path, &config_change_noop },
|
||||
{ "dcc_upload_path", N_("default path for sending files with dcc"),
|
||||
N_("path for reading files when sending thru dcc (when no path is specified)"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0, "~",
|
||||
|
||||
+36
-28
@@ -146,34 +146,39 @@ dcc_file_is_resumable (t_irc_dcc *ptr_dcc, char *filename)
|
||||
void
|
||||
dcc_find_filename (t_irc_dcc *ptr_dcc)
|
||||
{
|
||||
char *ptr_home, *filename2;
|
||||
char *dir1, *dir2, *filename2;
|
||||
|
||||
if (!DCC_IS_FILE(ptr_dcc->type))
|
||||
return;
|
||||
|
||||
ptr_home = getenv ("HOME");
|
||||
ptr_dcc->local_filename = (char *) malloc (strlen (cfg_dcc_download_path) +
|
||||
dir1 = weechat_strreplace (cfg_dcc_download_path, "~", getenv ("HOME"));
|
||||
if (!dir1)
|
||||
return;
|
||||
dir2 = weechat_strreplace (dir1, "%h", weechat_home);
|
||||
if (!dir2)
|
||||
{
|
||||
free (dir1);
|
||||
return;
|
||||
}
|
||||
|
||||
ptr_dcc->local_filename = (char *) malloc (strlen (dir2) +
|
||||
strlen (ptr_dcc->nick) +
|
||||
strlen (ptr_dcc->filename) +
|
||||
((cfg_dcc_download_path[0] == '~') ?
|
||||
strlen (ptr_home) : 0) +
|
||||
4);
|
||||
strlen (ptr_dcc->filename) + 4);
|
||||
if (!ptr_dcc->local_filename)
|
||||
return;
|
||||
|
||||
if (cfg_dcc_download_path[0] == '~')
|
||||
{
|
||||
strcpy (ptr_dcc->local_filename, ptr_home);
|
||||
strcat (ptr_dcc->local_filename, cfg_dcc_download_path + 1);
|
||||
}
|
||||
else
|
||||
strcpy (ptr_dcc->local_filename, cfg_dcc_download_path);
|
||||
strcpy (ptr_dcc->local_filename, dir2);
|
||||
if (ptr_dcc->local_filename[strlen (ptr_dcc->local_filename) - 1] != DIR_SEPARATOR_CHAR)
|
||||
strcat (ptr_dcc->local_filename, DIR_SEPARATOR);
|
||||
strcat (ptr_dcc->local_filename, ptr_dcc->nick);
|
||||
strcat (ptr_dcc->local_filename, ".");
|
||||
strcat (ptr_dcc->local_filename, ptr_dcc->filename);
|
||||
|
||||
if (dir1)
|
||||
free (dir1);
|
||||
if (dir2 )
|
||||
free (dir2);
|
||||
|
||||
/* file already exists? */
|
||||
if (access (ptr_dcc->local_filename, F_OK) == 0)
|
||||
{
|
||||
@@ -847,7 +852,7 @@ dcc_add (t_irc_server *server, int type, unsigned long addr, int port, char *nic
|
||||
void
|
||||
dcc_send_request (t_irc_server *server, int type, char *nick, char *filename)
|
||||
{
|
||||
char *ptr_home, *filename2, *short_filename, *pos;
|
||||
char *dir1, *dir2, *filename2, *short_filename, *pos;
|
||||
int spaces, args, port_start, port_end;
|
||||
struct stat st;
|
||||
int sock, port;
|
||||
@@ -872,12 +877,17 @@ dcc_send_request (t_irc_server *server, int type, char *nick, char *filename)
|
||||
filename2 = strdup (filename);
|
||||
else
|
||||
{
|
||||
ptr_home = getenv ("HOME");
|
||||
filename2 = (char *) malloc (strlen (cfg_dcc_upload_path) +
|
||||
strlen (filename) +
|
||||
((cfg_dcc_upload_path[0] == '~') ?
|
||||
strlen (ptr_home) : 0) +
|
||||
4);
|
||||
dir1 = weechat_strreplace (cfg_dcc_upload_path, "~", getenv ("HOME"));
|
||||
if (!dir1)
|
||||
return;
|
||||
dir2 = weechat_strreplace (dir1, "%h", weechat_home);
|
||||
if (!dir2)
|
||||
{
|
||||
free (dir1);
|
||||
return;
|
||||
}
|
||||
filename2 = (char *) malloc (strlen (dir2) +
|
||||
strlen (filename) + 4);
|
||||
if (!filename2)
|
||||
{
|
||||
irc_display_prefix (server, server->buffer, PREFIX_ERROR);
|
||||
@@ -886,16 +896,14 @@ dcc_send_request (t_irc_server *server, int type, char *nick, char *filename)
|
||||
WEECHAT_ERROR);
|
||||
return;
|
||||
}
|
||||
if (cfg_dcc_upload_path[0] == '~')
|
||||
{
|
||||
strcpy (filename2, ptr_home);
|
||||
strcat (filename2, cfg_dcc_upload_path + 1);
|
||||
}
|
||||
else
|
||||
strcpy (filename2, cfg_dcc_upload_path);
|
||||
strcpy (filename2, dir2);
|
||||
if (filename2[strlen (filename2) - 1] != DIR_SEPARATOR_CHAR)
|
||||
strcat (filename2, DIR_SEPARATOR);
|
||||
strcat (filename2, filename);
|
||||
if (dir1)
|
||||
free (dir1);
|
||||
if (dir2)
|
||||
free (dir2);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user