Skip to content
This repository was archived by the owner on Mar 2, 2025. It is now read-only.

Commit 95b446e

Browse files
author
Humdinger
committed
Don't accept folders for uploading
Put a note into the clipboard that UploadIt only works with files, if the user tries to send a folder. Update catkeys.
1 parent 8eca070 commit 95b446e

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

locales/de.catkeys

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
1 English application/x-vnd.humdinger-UploadIt 1837252867
1+
1 German application/x-vnd.humdinger-UploadIt 496113555
22
UploadIt can only be used as a Tracker add-on.\n Add-On UploadIt can nur als Tracker Add-on benutzt werden.\n
33
Online upload service not available Add-On Online Upload-Dienst nicht verfügbar
4+
UploadIt only works on a single file, no folders Add-On UploadIt verarbeitet nur eine einzelne Datei, keine Ordner

locales/en.catkeys

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
1 English application/x-vnd.humdinger-UploadIt 1837252867
1+
1 English application/x-vnd.humdinger-UploadIt 496113555
22
UploadIt can only be used as a Tracker add-on.\n Add-On UploadIt can only be used as a Tracker add-on.\n
33
Online upload service not available Add-On Online upload service not available
4+
UploadIt only works on a single file, no folders Add-On UploadIt only works on a single file, no folders

main.cpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,39 @@ process_refs(entry_ref directoryRef, BMessage* msg, void*)
2727
{
2828
BPath path;
2929
entry_ref file_ref;
30+
3031
if (msg->FindRef("refs", &file_ref) == B_NO_ERROR) {
31-
BEntry(&file_ref).GetPath(&path);
32-
BString command(
33-
"stat=$(curl -m 2 -s -I http://google.com | grep HTTP/1 | awk {'print $2'}) ; "
34-
"if [ -z \"$stat\" ] ; then " // network up in general?
35-
"clipboard -c \"%ERROR%\" ; "
36-
"else "
37-
"curl -F'file=@'\"%FILENAME%\" https://0x0.st | clipboard -i ; "
38-
"fi ; "
39-
"exit");
40-
command.ReplaceAll("%ERROR%",
41-
B_TRANSLATE("Online upload service not available"));
42-
command.ReplaceAll("%FILENAME%", path.Path());
43-
system(command.String());
32+
BEntry entry(&file_ref);
33+
if (entry.IsDirectory()) {
34+
BString text(B_TRANSLATE(
35+
"UploadIt only works on a single file, no folders"));
36+
ssize_t textLen = text.Length();
37+
BMessage* message = (BMessage *)NULL;
38+
39+
if (be_clipboard->Lock()) {
40+
be_clipboard->Clear();
41+
if ((message = be_clipboard->Data())) {
42+
message->AddData("text/plain", B_MIME_TYPE, text.String(),
43+
textLen);
44+
be_clipboard->Commit();
45+
}
46+
be_clipboard->Unlock();
47+
}
48+
} else {
49+
entry.GetPath(&path);
50+
BString command(
51+
"stat=$(curl -m 2 -s -I http://google.com | grep HTTP/1 | awk {'print $2'}) ; "
52+
"if [ -z \"$stat\" ] ; then " // network up in general?
53+
"clipboard -c \"%ERROR%\" ; "
54+
"else "
55+
"curl -F'file=@'\"%FILENAME%\" https://0x0.st | clipboard -i ; "
56+
"fi ; "
57+
"exit");
58+
command.ReplaceAll("%ERROR%",
59+
B_TRANSLATE("Online upload service not available"));
60+
command.ReplaceAll("%FILENAME%", path.Path());
61+
system(command.String());
62+
}
4463
}
4564
}
4665

0 commit comments

Comments
 (0)