1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Bryan Childs
11 * Copyright (c) 2007 Alexander Levin
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
23 #include "shortcuts.h"
28 bool append_entry_to_file(sc_file_t
*file
, char *path
, bool is_dir
)
32 unsigned int required_len
= rb
->strlen(path
);
34 required_len
+= PATH_SEPARATOR_LEN
; /* Add 1 for the trailing / */
36 if (required_len
>= sizeof(entry
.path
)) {
37 /* no attempt to print it: it will also be so too long for the splash */
38 rb
->splash(HZ
*2, "Can't append shortcut, it's too long");
41 entry
.explicit_disp
= false;
42 rb
->strcpy(entry
.path
, path
);
44 rb
->strcat(entry
.path
, PATH_SEPARATOR
);
46 if (!append_entry(file
, &entry
)) {
47 rb
->splash(HZ
*2, "Too many entries!");
54 enum plugin_status
plugin_start(const void* void_parameter
)
59 /* This is a viewer, so a parameter must have been specified */
60 if (void_parameter
== NULL
) {
61 rb
->splash(HZ
*2, "No parameter specified!");
64 char *parameter
= (char*)void_parameter
;
65 DEBUGF("Trying to append '%s' to the default link file '%s'...\n",
66 parameter
, SHORTCUTS_FILENAME
);
68 allocate_memory(&memory_buf
, &memory_bufsize
);
70 /* Determine if it's a file or a directory. First check
71 * if it's a dir and then file (not vice versa) since
72 * open() can also open a dir */
74 if (rb
->dir_exists(parameter
)) {
76 } else if (rb
->file_exists(parameter
)) {
81 /* now we know if it's a file or a directory
82 * (or something went wrong) */
85 /* Something's gone properly pear shaped -
86 * we couldn't even find the entry */
87 rb
->splashf(HZ
*2, "File/Dir not found: %s", parameter
);
91 DEBUGF("'%s' is a %s\n", parameter
, (its_a_dir
? "dir" : "file"));
93 if (!load_sc_file(&sc_file
, SHORTCUTS_FILENAME
, false,
94 memory_buf
, memory_bufsize
)) {
95 DEBUGF("Couldn't load '%s'\n", SHORTCUTS_FILENAME
);
99 if (!append_entry_to_file(&sc_file
, parameter
, its_a_dir
)) {
100 DEBUGF("Couldn't append entry (too many entries?)\n");
104 if (!dump_sc_file(&sc_file
, SHORTCUTS_FILENAME
)) {
105 DEBUGF("Couldn't write shortcuts to '%s'\n", SHORTCUTS_FILENAME
);