Downloading works. Still to come: cancelling downloads and extraction.
This commit is contained in:
committed by
Chris Forbes
parent
5991ecdcf5
commit
2e309b46e8
@@ -12,14 +12,16 @@
|
||||
#include <glib.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
int util_get_mod_list (GChildWatchFunc callback)
|
||||
int util_do_command_async(char * command, GChildWatchFunc callback)
|
||||
{
|
||||
GPid child_pid;
|
||||
gint * out_fd = (gint *)malloc(sizeof(gint));
|
||||
char * spawn_args[] = { "mono", "OpenRA.Utility.exe", "-l", NULL };
|
||||
gboolean result = g_spawn_async_with_pipes(NULL, spawn_args, NULL,
|
||||
G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
|
||||
NULL, NULL, &child_pid, NULL, out_fd, NULL, NULL);
|
||||
char * spawn_args[] = { "mono", "OpenRA.Utility.exe", command, NULL };
|
||||
gboolean result;
|
||||
|
||||
result = g_spawn_async_with_pipes(NULL, spawn_args, NULL,
|
||||
G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
|
||||
NULL, NULL, &child_pid, NULL, out_fd, NULL, NULL);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
@@ -31,6 +33,11 @@ int util_get_mod_list (GChildWatchFunc callback)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int util_get_mod_list (GChildWatchFunc callback)
|
||||
{
|
||||
return util_do_command_async("-l", callback);
|
||||
}
|
||||
|
||||
int util_do_command_blocking(char * command, GChildWatchFunc callback)
|
||||
{
|
||||
GPid child_pid;
|
||||
@@ -58,16 +65,50 @@ int util_do_command_blocking(char * command, GChildWatchFunc callback)
|
||||
|
||||
int util_get_mod_metadata(char const * mod, GChildWatchFunc callback)
|
||||
{
|
||||
char util_args[32];
|
||||
char * util_args;
|
||||
int return_val;
|
||||
|
||||
util_args = (char *)malloc(strlen(mod) + strlen("-i=") + 1);
|
||||
sprintf(util_args, "-i=%s", mod);
|
||||
return util_do_command_blocking(util_args, callback);
|
||||
return_val = util_do_command_blocking(util_args, callback);
|
||||
free(util_args);
|
||||
return return_val;
|
||||
}
|
||||
|
||||
int util_get_setting(const char * setting, GChildWatchFunc callback)
|
||||
{
|
||||
char command[64];
|
||||
char * command;
|
||||
int return_val;
|
||||
|
||||
command = (char *)malloc(strlen(setting) + strlen("--settings-value=~/.openra,") + 1);
|
||||
sprintf(command, "--settings-value=~/.openra,%s", setting);
|
||||
return util_do_command_blocking(command, callback);
|
||||
return_val = util_do_command_blocking(command, callback);
|
||||
free(command);
|
||||
return return_val;
|
||||
}
|
||||
|
||||
int util_do_download(const char * url, const char * dest, GPid * pid)
|
||||
{
|
||||
char * command;
|
||||
int out_fd;
|
||||
gboolean result;
|
||||
|
||||
char * launch_args[] = { "mono", "OpenRA.Utility.exe", NULL, NULL };
|
||||
|
||||
command = (char *)malloc(strlen(url) + strlen(dest) + strlen("--download-url=") + 2);
|
||||
sprintf(command, "--download-url=%s,%s", url, dest);
|
||||
|
||||
launch_args[2] = command;
|
||||
|
||||
result = g_spawn_async_with_pipes(NULL, launch_args, NULL, G_SPAWN_SEARCH_PATH,
|
||||
NULL, NULL, pid, NULL, &out_fd, NULL, NULL);
|
||||
free(command);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return out_fd;
|
||||
}
|
||||
|
||||
char * util_get_output(int fd, int * output_len)
|
||||
|
||||
Reference in New Issue
Block a user