diff options
Diffstat (limited to 'src/mimehooks.c')
-rw-r--r-- | src/mimehooks.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/mimehooks.c b/src/mimehooks.c index 8bb838ef..fd535643 100644 --- a/src/mimehooks.c +++ b/src/mimehooks.c | |||
@@ -1,6 +1,8 @@ | |||
1 | #include "mimehooks.h" | 1 | #include "mimehooks.h" |
2 | #include "app.h" | ||
2 | 3 | ||
3 | #include <the_Foundation/file.h> | 4 | #include <the_Foundation/file.h> |
5 | #include <the_Foundation/fileinfo.h> | ||
4 | #include <the_Foundation/path.h> | 6 | #include <the_Foundation/path.h> |
5 | #include <the_Foundation/process.h> | 7 | #include <the_Foundation/process.h> |
6 | #include <the_Foundation/stringlist.h> | 8 | #include <the_Foundation/stringlist.h> |
@@ -23,6 +25,7 @@ void deinit_FilterHook(iFilterHook *d) { | |||
23 | 25 | ||
24 | void setMimePattern_FilterHook(iFilterHook *d, const iString *pattern) { | 26 | void setMimePattern_FilterHook(iFilterHook *d, const iString *pattern) { |
25 | iReleasePtr(&d->mimeRegex); | 27 | iReleasePtr(&d->mimeRegex); |
28 | set_String(&d->mimePattern, pattern); | ||
26 | d->mimeRegex = new_RegExp(cstr_String(pattern), caseInsensitive_RegExpOption); | 29 | d->mimeRegex = new_RegExp(cstr_String(pattern), caseInsensitive_RegExpOption); |
27 | } | 30 | } |
28 | 31 | ||
@@ -105,6 +108,7 @@ iBlock *tryFilter_MimeHooks(const iMimeHooks *d, const iString *mime, const iBlo | |||
105 | static const char *mimeHooksFilename_MimeHooks_ = "mimehooks.txt"; | 108 | static const char *mimeHooksFilename_MimeHooks_ = "mimehooks.txt"; |
106 | 109 | ||
107 | void load_MimeHooks(iMimeHooks *d, const char *saveDir) { | 110 | void load_MimeHooks(iMimeHooks *d, const char *saveDir) { |
111 | iBool reportError = iFalse; | ||
108 | iFile *f = newCStr_File(concatPath_CStr(saveDir, mimeHooksFilename_MimeHooks_)); | 112 | iFile *f = newCStr_File(concatPath_CStr(saveDir, mimeHooksFilename_MimeHooks_)); |
109 | if (open_File(f, read_FileMode | text_FileMode)) { | 113 | if (open_File(f, read_FileMode | text_FileMode)) { |
110 | iBlock * src = readAll_File(f); | 114 | iBlock * src = readAll_File(f); |
@@ -124,6 +128,15 @@ void load_MimeHooks(iMimeHooks *d, const char *saveDir) { | |||
124 | setRange_String(&hook->label, lines[0]); | 128 | setRange_String(&hook->label, lines[0]); |
125 | setMimePattern_FilterHook(hook, collect_String(newRange_String(lines[1]))); | 129 | setMimePattern_FilterHook(hook, collect_String(newRange_String(lines[1]))); |
126 | setCommand_FilterHook(hook, collect_String(newRange_String(lines[2]))); | 130 | setCommand_FilterHook(hook, collect_String(newRange_String(lines[2]))); |
131 | /* Check if commmand is valid. */ { | ||
132 | iRangecc seg = iNullRange; | ||
133 | while (nextSplit_Rangecc(range_String(&hook->command), ";", &seg)) { | ||
134 | if (!fileExistsCStr_FileInfo(cstr_Rangecc(seg))) { | ||
135 | reportError = iTrue; | ||
136 | } | ||
137 | break; | ||
138 | } | ||
139 | } | ||
127 | pushBack_PtrArray(&d->filters, hook); | 140 | pushBack_PtrArray(&d->filters, hook); |
128 | pos = 0; | 141 | pos = 0; |
129 | } | 142 | } |
@@ -131,9 +144,37 @@ void load_MimeHooks(iMimeHooks *d, const char *saveDir) { | |||
131 | delete_Block(src); | 144 | delete_Block(src); |
132 | } | 145 | } |
133 | iRelease(f); | 146 | iRelease(f); |
147 | if (reportError) { | ||
148 | postCommand_App("~config.error where:mimehooks.txt"); | ||
149 | } | ||
134 | } | 150 | } |
135 | 151 | ||
136 | void save_MimeHooks(const iMimeHooks *d) { | 152 | void save_MimeHooks(const iMimeHooks *d) { |
137 | iUnused(d); | 153 | iUnused(d); |
138 | } | 154 | } |
139 | 155 | ||
156 | const iString *debugInfo_MimeHooks(const iMimeHooks *d) { | ||
157 | iString *str = collectNew_String(); | ||
158 | size_t index = 0; | ||
159 | iConstForEach(PtrArray, i, &d->filters) { | ||
160 | const iFilterHook *filter = i.ptr; | ||
161 | appendFormat_String(str, "### %d: %s\n", index, cstr_String(&filter->label)); | ||
162 | appendFormat_String(str, "MIME regex:\n```\n%s\n```\n", cstr_String(&filter->mimePattern)); | ||
163 | iStringList *args = iClob(split_String(&filter->command, ";")); | ||
164 | if (isEmpty_StringList(args)) { | ||
165 | appendFormat_String(str, "\u26a0 Command not specified!\n"); | ||
166 | continue; | ||
167 | } | ||
168 | const iString *exec = constAt_StringList(args, 0); | ||
169 | if (isEmpty_String(exec)) { | ||
170 | appendFormat_String(str, "\u26a0 Command not specified!\n"); | ||
171 | } | ||
172 | else { | ||
173 | appendFormat_String(str, "Executable: %s\n```\n%s\n```\n", | ||
174 | fileExists_FileInfo(exec) ? "" : "\u26a0 FILE NOT FOUND", | ||
175 | cstr_String(exec)); | ||
176 | } | ||
177 | index++; | ||
178 | } | ||
179 | return str; | ||
180 | } | ||