Menu-FN: Bring back the updater functionality, as improvements to the engine's package manager have been done

This commit is contained in:
Marco Cawthorne 2022-04-01 12:17:36 -07:00
parent 6802d907f7
commit bd63874118
Signed by: eukara
GPG key ID: C196CD8BA993248A
5 changed files with 187 additions and 1 deletions

View file

@ -136,7 +136,7 @@ menu_configuration_init(void)
cf_btnUpdate = spawn(CMainButton);
cf_btnUpdate.SetImage(BTN_UPDATE);
//cf_btnUpdate.SetExecute(cf_btnupdates_start);
cf_btnUpdate.SetExecute(cf_btnupdates_start);
cf_btnUpdate.SetPos(50,268);
Widget_Add(fn_configuration, cf_btnUpdate);

View file

@ -29,6 +29,51 @@ CMainButton customgame_btnRefresh;
CMainButton customgame_btnDeactivate;
CMainButton customgame_btnDone;
int g_iModInstallCache;
string g_strModInstallCache;
#if 1
/* get installing id */
void
game_getinstallcache(void)
{
int ret;
filestream fs_cache;
ret = 0;
fs_cache = fopen("mcache.dat", FILE_READ);
if (fs_cache >= 0) {
g_iModInstallCache = (int)stof(fgets(fs_cache));
g_strModInstallCache = fgets(fs_cache);
fclose(fs_cache);
} else {
g_iModInstallCache = -1;
g_strModInstallCache = "";
}
print(sprintf("id: %i, name: %s\n", ret, g_strModInstallCache));
}
/* write installing id */
void
game_writeinstallcache(int id, string gamedir)
{
filestream fs_cache;
fs_cache = fopen("mcache.dat", FILE_WRITE);
g_iModInstallCache = id;
g_strModInstallCache = gamedir;
if (fs_cache >= 0) {
fputs(fs_cache, sprintf("%i\n",id));
fputs(fs_cache, gamedir);
fclose(fs_cache);
}
}
#endif
int
game_getpackageid(string pkgname)
{
@ -492,12 +537,123 @@ customgame_btnactivate_start(void)
localcmd("menu_musicstart\n");
}
#if 1
void
customgame_installstart(int gameid)
{
int count;
count = tokenize(games[gameid].pkgname);
for (int i = 0; i < count; i++) {
int pkgid = game_getpackageid(argv(i));
localcmd(sprintf("pkg add %s\n", argv(i)));
print(sprintf("Marking package %s for install.\n",
argv(i)));
}
game_writeinstallcache(gameid, games[gameid].gamedir);
localcmd("pkg apply\n");
print("Starting installation of custom game packages\n");
}
void
customgame_installend(void)
{
int gid = g_iModInstallCache;
print("install-end!\n");
localcmd(sprintf("fs_changegame %s http://www.frag-net.com/mods/%s.fmf\n", g_strModInstallCache, g_strModInstallCache));
game_writeinstallcache(-1, g_strModInstallCache);
}
void
customgame_installframe(void)
{
int id;
float perc;
float c;
int loading;
/* graphical frame */
customgame_dlgWait.Draw();
WField_Static(162, 180, "Installing mod data...", 320, 260,
col_prompt_text, 1.0f, 2, font_label_p);
/* download percentage */
perc = 0.0f;
loading = FALSE;
/* a game can have multiple packages associated */
id = g_iModInstallCache;
c = tokenize(games[id].pkgname);
/* go through all invididual packages */
for (float i = 0; i < c; i++) {
string st;
int pkgid;
/* package query */
pkgid = game_getpackageid(argv(i));
st = getpackagemanagerinfo(pkgid, GPMI_INSTALLED);
/* filter out statuses so we can calculate percentage */
switch (st) {
case "":
case "pending":
case "enabled":
case "present":
case "corrupt":
break;
default:
perc += stof(st);
}
/* all packages need to be 'enabled', else fail to end */
if (st != "enabled")
loading = TRUE;
}
/* display download percentage we calculated */
perc = perc / c;
WField_Static(162, 220, sprintf("%d%%", perc), 320, 260,
[1,1,1], 1.0f, 2, font_label_p);
WField_Static(162, 260, "Service provided by frag-net.com through archive.org", 320, 260,
[1,1,1], 1.0f, 2, font_label);
/* not everything has been downloaded */
if (loading == TRUE)
return;
customgame_installend();
}
#endif
/* download the .fmf and switch games immediately */
void
customgame_btninstall_start(void)
{
#if 1
int id = customgame_lbMods.GetSelected();
string st;
st = getpackagemanagerinfo(games[id].pkgid, GPMI_INSTALLED);
print(st);
print("\n");
if (st != "enabled") {
customgame_installstart(id);
return;
}
game_writeinstallcache(id, games[id].gamedir);
customgame_installend();
#else
int nextgame = customgame_lbMods.GetSelected();
localcmd(sprintf("fs_changegame %s http://www.frag-net.com/mods/%s.fmf\n", games[nextgame].gamedir, games[nextgame].gamedir));
#endif
}
void
@ -795,6 +951,13 @@ menu_customgame_draw(void)
col_prompt_text, 1.0f, 2, font_label_p);
}
#if 1
if (g_iModInstallCache >= 0) {
customgame_installframe();
}
#endif
customgame_sbMods.SetMax(gameinfo_count-1); /* don't show our current game */
#endif
}

View file

@ -115,6 +115,10 @@ up_lbupdates_changed(void)
string newpic;
pkgid = up_lbUpdates.GetSelected();
if (!pkgid)
return;
newpic = sprintf(FN_UPDATE_IMGURL, updates[pkgid].name);
g_updates_previewpic = newpic;
precache_pic(g_updates_previewpic);
@ -278,6 +282,7 @@ menu_updates_init(void)
/* Drawing */
int g_pkgname_updating;
void
menu_updates_draw(void)
{
@ -289,6 +294,19 @@ menu_updates_draw(void)
if (!g_updates_initialized) {
int pkg_ready = 0;
/* we have no hard-coded list of supported packages, so query frag-net.com */
if (!games[gameinfo_current].pkgname && !g_pkgname_updating) {
string gamedir = games[gameinfo_current].gamedir;
print(sprintf("Querying package names for %s\n", gamedir));
uri_get(sprintf("http://www.frag-net.com/dl/packages_%s", uri_escape(gamedir)), MODSERVER_REQ_PKGNAMES);
g_pkgname_updating = 1;
}
/* don't query packages YET until we get a response */
if (g_pkgname_updating == 1) {
return;
}
/* query until 1 package is ready */
for (int i = 0; (getpackagemanagerinfo(i, GPMI_NAME)); i++) {
string installed = getpackagemanagerinfo(i, GPMI_INSTALLED);

View file

@ -17,6 +17,7 @@
#ifndef WEBMENU
#define MODSERVER_REQ_LIST 100
#define MODSERVER_REQ_ITEM 101
#define MODSERVER_REQ_PKGNAMES 102
#define ModServer_URI_Callback URI_Get_Callback

View file

@ -201,6 +201,10 @@ ModServer_URI_Callback(float id, float code, string data, int resourcebytes)
case MODSERVER_REQ_ITEM:
ModServer_ParseItem(data);
break;
case MODSERVER_REQ_PKGNAMES:
games[gameinfo_current].pkgname = data;
g_pkgname_updating = 0;
break;
default:
print(sprintf("^1ModServer_URI_Callback^7: Unknown request id %d with code %d\n", id, code));
}