This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
50_DownloadsControl.c
146 lines (124 loc) · 3.37 KB
/
50_DownloadsControl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "c/ModioC.h"
bool finish = false;
void onModDownloaded(u32 response_code, u32 mod_id)
{
printf("Downloaded Mod response: %i\n", response_code);
if (response_code == 200)
{
printf("Mod %i downloaded successfully!\n", mod_id);
}
if (modioGetModDownloadQueueCount() == 0)
finish = true;
}
int main(void)
{
modioInit(MODIO_ENVIRONMENT_TEST, 7, (char *)"e91c01b8882f4affeddd56c96111977b", NULL);
bool prompt_menu = true;
// In this example we are going to queue two mods downloads.
u32 mod_id;
printf("Enter a mod id to download: \n");
scanf("%i", &mod_id);
modioDownloadMod(mod_id);
printf("Enter another mod id to download: \n");
scanf("%i", &mod_id);
modioDownloadMod(mod_id);
printf("Downloading mods...\n");
modioSetDownloadListener(&onModDownloaded);
while (!finish)
{
u32 queue_size = modioGetModDownloadQueueCount();
if (queue_size != 0)
{
// The download queue contains all the information about the current downloads
ModioQueuedModDownload *download_queue = malloc(queue_size * sizeof(*download_queue));
modioGetModDownloadQueue(download_queue);
printf("\n");
printf("Download queue:\n");
printf("===============\n");
for (u32 i = 0; i < queue_size; i++)
{
ModioQueuedModDownload *queued_mod_download = &(download_queue[i]);
printf("Name: %s\n", queued_mod_download->mod.name);
printf("Id: %d\n", queued_mod_download->mod.id);
double current_progress = queued_mod_download->current_progress;
double total_size = queued_mod_download->total_size;
printf("Download progress: %f%%\n", (current_progress / total_size) * 100.0);
printf("\n");
}
if (prompt_menu && queue_size > 0)
{
u32 option;
ModioQueuedModDownload *current_download = &(download_queue[0]);
// Depending on the current download state, there are multiple options that can be given to the user to control their downloads
switch (current_download->state)
{
case MODIO_MOD_STARTING_DOWNLOAD:
{
printf("Starting download. Please wait...\n");
break;
}
case MODIO_MOD_DOWNLOADING:
{
if (current_download->current_progress == 0)
{
printf("Download started. Please wait...");
}
else
{
printf("Menu:\n");
printf("=====\n");
printf("1. Continue\n");
printf("2. Pause\n");
printf("3. Stop asking\n");
printf("4. Prioritize download\n");
printf("5. Exit\n");
printf("Option: \n");
scanf("%i", &option);
if (option == 2)
modioPauseDownloads();
if (option == 3)
prompt_menu = false;
if (option == 4)
{
u32 mod_id;
printf("Enter the mod id to prioritize: \n");
scanf("%i", &mod_id);
modioPrioritizeModDownload(mod_id);
}
if (option == 5)
finish = true;
}
break;
}
case MODIO_MOD_PAUSING:
{
printf("Pausing. Please wait...\n");
break;
}
case MODIO_MOD_PAUSED:
{
printf("Menu:\n");
printf("=====\n");
printf("1. Continue\n");
printf("2. Resume\n");
printf("3. Exit\n");
printf("Option: \n");
scanf("%i", &option);
if (option == 2)
modioResumeDownloads();
if (option == 3)
finish = true;
break;
}
}
}
free(download_queue);
}
modioSleep(10);
modioProcess();
system("cls");
}
modioShutdown();
printf("Process finished\n");
return 0;
}