67
68
if (WulforUtil::isHubURL(arg))
68
69
args->urls.push_back(arg);
69
70
else if (WulforUtil::isMagnet(arg))
70
args->magnets.push_back(arg);
71
args->addmagnets.push_back(arg);
74
75
bool parseArguments(int *argc, char **argv[], CommandlineArgs* args)
76
gchar **magnet = NULL, **address = NULL;
77
gchar **searchmagnet = NULL, **address = NULL, **addmagnet = NULL;
77
78
gboolean show = FALSE, refresh = FALSE, version = FALSE, existing = FALSE;
79
80
GOptionEntry entries[] = {
80
81
{ "connect", 'c', 0, G_OPTION_ARG_STRING_ARRAY, &address, N_("Connect to the given hub"), N_("URI") },
81
82
{ "existing", 'e', 0, G_OPTION_ARG_NONE, &existing, N_("Send commands to the existing instance (if applicable)"), NULL },
82
{ "magnet", 'm', 0, G_OPTION_ARG_STRING_ARRAY, &magnet, N_("Search for the given magnet link"), N_("URI") },
83
{ "search-magnet", 'm', 0, G_OPTION_ARG_STRING_ARRAY, &searchmagnet, N_("Search for the given magnet link"), N_("URI") },
84
{ "add-magnet", 'a', 0, G_OPTION_ARG_STRING_ARRAY, &addmagnet, N_("Try to add given magnet directly to download queue"), N_("URI") },
83
85
{ "refresh", 'r', 0, G_OPTION_ARG_NONE, &refresh, N_("Initiate filelist refresh"), NULL },
84
86
{ "show", 's', 0, G_OPTION_ARG_NONE, &show, N_("Show the running instance (default action)"), NULL },
85
87
{ "version", 'v', 0, G_OPTION_ARG_NONE, &version, N_("Show version information and exit"), NULL },
109
111
args->version = TRUE;
111
113
args->existing = TRUE;
115
for (gchar* it = magnet[0]; it != NULL; it = magnet[++i])
116
args->magnets.push_back(std::string(it));
117
for (gchar* it = searchmagnet[0]; it != NULL; it = searchmagnet[++i])
118
args->searchmagnets.push_back(std::string(it));
119
g_strfreev(searchmagnet);
124
for (gchar* it = addmagnet[0]; it != NULL; it = addmagnet[++i])
125
args->addmagnets.push_back(std::string(it));
126
g_strfreev(addmagnet);
139
148
if (args.refresh)
140
149
retval = WulforUtil::writeIPCCommand("refresh");
141
for (std::vector<std::string>::const_iterator it = args.magnets.begin();
142
retval > 0 && it != args.magnets.end(); ++it)
144
retval = WulforUtil::writeIPCCommand(std::string("magnet ") + *it);
150
for (std::vector<std::string>::const_iterator it = args.searchmagnets.begin();
151
retval > 0 && it != args.searchmagnets.end(); ++it)
153
retval = WulforUtil::writeIPCCommand(std::string("search-magnet ") + *it);
155
for (std::vector<std::string>::const_iterator it = args.addmagnets.begin();
156
retval > 0 && it != args.addmagnets.end(); ++it)
158
retval = WulforUtil::writeIPCCommand(std::string("add-magnet ") + *it);
146
160
for (std::vector<std::string>::const_iterator it = args.urls.begin();
147
161
retval > 0 && it != args.urls.end(); ++it)