Skip to content

Commit

Permalink
Install stages now specify a number, not a boolean...so you can go back,
Browse files Browse the repository at this point in the history
 forward, or cancel.
  • Loading branch information
icculus committed May 10, 2007
1 parent 0eafecf commit 4a92264
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 50 deletions.
20 changes: 10 additions & 10 deletions gui.h
Expand Up @@ -51,12 +51,12 @@ struct MojoGui
boolean (*promptyn)(const char *title, const char *text);
boolean (*start)(const char *title, const char *splash);
void (*stop)(void);
boolean (*readme)(const char *name, const uint8 *data, size_t len,
boolean can_go_back, boolean can_go_forward);
boolean (*options)(MojoGuiSetupOptions *opts,
boolean can_go_back, boolean can_go_forward);
int (*readme)(const char *name, const uint8 *data, size_t len,
boolean can_go_back, boolean can_go_forward);
int (*options)(MojoGuiSetupOptions *opts,
boolean can_go_back, boolean can_go_forward);
char * (*destination)(const char **recommendations, int reccount,
boolean can_go_back, boolean can_go_forward);
boolean can_go_back, boolean can_go_forward);
boolean (*insertmedia)(const char *medianame);
boolean (*progress)(const char *type, const char *component,
int percent, const char *item);
Expand Down Expand Up @@ -89,11 +89,11 @@ static void MojoGui_##module##_msgbox(const char *title, const char *text); \
static boolean MojoGui_##module##_promptyn(const char *t1, const char *t2); \
static boolean MojoGui_##module##_start(const char *t, const char *s); \
static void MojoGui_##module##_stop(void); \
static boolean MojoGui_##module##_readme(const char *name, const uint8 *data, \
size_t len, boolean can_go_back, \
boolean can_go_forward); \
static boolean MojoGui_##module##_options(MojoGuiSetupOptions *opts, \
boolean can_go_back, boolean can_go_forward); \
static int MojoGui_##module##_readme(const char *name, const uint8 *data, \
size_t len, boolean can_go_back, \
boolean can_go_forward); \
static int MojoGui_##module##_options(MojoGuiSetupOptions *opts, \
boolean can_go_back, boolean can_go_forward); \
static char *MojoGui_##module##_destination(const char **r, int reccount, \
boolean can_go_back, boolean can_go_forward); \
static boolean MojoGui_##module##_insertmedia(const char *medianame); \
Expand Down
14 changes: 7 additions & 7 deletions gui_macosx.c
Expand Up @@ -135,25 +135,25 @@ static void MojoGui_macosx_stop(void)
} // MojoGui_macosx_stop


static boolean MojoGui_macosx_readme(const char *name, const uint8 *data,
static int MojoGui_macosx_readme(const char *name, const uint8 *data,
size_t len, boolean can_go_back,
boolean can_go_forward)
{
STUBBED("macosx readme");
return true;
return 1;
} // MojoGui_macosx_readme


static boolean MojoGui_macosx_options(MojoGuiSetupOptions *opts,
static int MojoGui_macosx_options(MojoGuiSetupOptions *opts,
boolean can_go_back, boolean can_go_forward)
{
// !!! FIXME: write me.
STUBBED("macosx options");
return true;
return 1;
} // MojoGui_macosx_options

static char *MojoGui_macosx_destination(const char **recommends, int reccount,
boolean can_go_back, boolean can_go_fwd)
boolean can_go_back, boolean can_go_fwd)
{
// !!! FIXME: write me.
STUBBED("macosx destination");
Expand All @@ -169,12 +169,12 @@ static boolean MojoGui_macosx_insertmedia(const char *medianame)
entry->_("OK"), entry->_("Cancel"));
} // MojoGui_macosx_insertmedia

static boolean MojoGui_macosx_progress(const char *type, const char *component,
static int MojoGui_macosx_progress(const char *type, const char *component,
int percent, const char *item)
{
// !!! FIXME: write me.
STUBBED(__FUNCTION__)
return true;
return 1;
} // MojoGui_macosx_progress

// end of gui_macosx.c ...
Expand Down
20 changes: 13 additions & 7 deletions gui_stdio.c
Expand Up @@ -136,12 +136,12 @@ static void MojoGui_stdio_stop(void)
} // MojoGui_stdio_stop


static boolean MojoGui_stdio_readme(const char *name, const uint8 *data,
static int MojoGui_stdio_readme(const char *name, const uint8 *data,
size_t datalen, boolean can_go_back,
boolean can_go_forward)
{
boolean getout = false;
boolean retval = false;
int retval = -1;
int len = 0;
char buf[128];

Expand All @@ -151,7 +151,10 @@ static boolean MojoGui_stdio_readme(const char *name, const uint8 *data,
if ((len = readstr(NULL, buf, sizeof (buf), can_go_back, true)) < 0)
getout = true;
else if (len == 0)
getout = retval = true;
{
getout = true;
retval = 1;
} // else if
} // while

return retval;
Expand Down Expand Up @@ -227,12 +230,12 @@ static void print_options(MojoGuiSetupOptions *opts, int *line, int level)
} // print_options


static boolean MojoGui_stdio_options(MojoGuiSetupOptions *opts,
boolean can_go_back, boolean can_go_forward)
static int MojoGui_stdio_options(MojoGuiSetupOptions *opts,
boolean can_go_back, boolean can_go_forward)
{
const char *prompt = entry->xstrdup(entry->_("Choose number to change."));
const char *inst_opts_str = entry->xstrdup(entry->_("Install options:"));
boolean retval = false;
int retval = -1;
boolean getout = false;
char buf[128];
int len = 0;
Expand All @@ -250,7 +253,10 @@ static boolean MojoGui_stdio_options(MojoGuiSetupOptions *opts,
if ((len = readstr(prompt, buf, sizeof (buf), can_go_back, true)) < 0)
getout = true;
else if (len == 0)
retval = getout = true;
{
getout = true;
retval = 1;
} // else if
else
{
char *endptr = NULL;
Expand Down
6 changes: 3 additions & 3 deletions lua_glue.c
Expand Up @@ -854,7 +854,7 @@ static int luahook_gui_readme(lua_State *L)
if (data == NULL)
fatal(_("failed to load file '%s'"), fname);

lua_pushboolean(L, GGui->readme(name, data, len, can_go_back, can_go_fwd));
lua_pushnumber(L, GGui->readme(name, data, len, can_go_back, can_go_fwd));
free((void *) data);
return 1;
} // luahook_gui_readme
Expand Down Expand Up @@ -1061,7 +1061,7 @@ static int luahook_gui_options(lua_State *L)
const int maxstage = luaL_checkint(L, 3);
const boolean can_go_back = canGoBack(thisstage);
const boolean can_go_fwd = canGoForward(thisstage, maxstage);
boolean rc = true;
int rc = 0;
GuiOptions *opts = NULL;

assert(lua_gettop(L) == 3);
Expand All @@ -1080,7 +1080,7 @@ static int luahook_gui_options(lua_State *L)
done_gui_options(L, opts); // free C structs, update Lua tables...
lua_pop(L, 1); // pop table we created.

return retvalBoolean(L, rc);
return retvalNumber(L, rc);
} // luahook_gui_options


Expand Down
55 changes: 32 additions & 23 deletions scripts/mojosetup_mainline.lua
Expand Up @@ -426,6 +426,10 @@ local function do_install(install)
-- !!! FIXME: I would like everything possible to fail here instead of
-- !!! FIXME: when a user happens to pick an option no one tested...

if install.options ~= nil and install.optiongroups ~= nil then
MojoSetup.fatal(_("Config bug: no options"))
end

-- This is to save us the trouble of a loop every time we have to
-- find media by id...
MojoSetup.media = {}
Expand Down Expand Up @@ -454,6 +458,7 @@ local function do_install(install)
if errstr ~= nil then
MojoSetup.fatal(errstr)
end
return 1
end
end

Expand All @@ -466,20 +471,20 @@ local function do_install(install)

-- (desc) and (fname) become an upvalues in this function.
stages[#stages+1] = function (thisstage, maxstage)
if not MojoSetup.gui.readme(desc, fname, thisstage, maxstage) then
return false
end

if not MojoSetup.promptyn(desc, _("Accept this license?")) then
MojoSetup.fatal(_("You must accept the license before you may install"))
local retval = MojoSetup.gui.readme(desc,fname,thisstage,maxstage)
if retval == 1 then
if not MojoSetup.promptyn(desc, _("Accept this license?")) then
MojoSetup.fatal(_("You must accept the license before you may install"))
end
end
return true
return retval
end
end

-- Next stage: show any READMEs.
for k,readme in pairs(install.readmes) do
local desc = readme.description
-- !!! FIXME: pull from archive?
local fname = "data/" .. readme.source
-- (desc) and (fname) become upvalues in this function.
stages[#stages+1] = function(thisstage, maxstage)
Expand All @@ -498,11 +503,12 @@ local function do_install(install)
-- (recommend) becomes an upvalue in this function.
stages[#stages+1] = function(thisstage, maxstage)
local x = MojoSetup.gui.destination(recommend, thisstage, maxstage)
-- !!! FIXME: need back/forward/cancel.
if x == nil then
return false -- go back
return -1 -- go back
end
set_destination(x)
return true
return 1 -- go forward
end
end

Expand Down Expand Up @@ -591,7 +597,7 @@ local function do_install(install)
-- so it only spits out crap if debug-level logging is enabled.
MojoSetup.dumptable("MojoSetup.files", MojoSetup.files)

return true -- always go forward from non-GUI stage.
return 1 -- always go forward from non-GUI stage.
end

-- Next stage: Download external packages.
Expand Down Expand Up @@ -627,7 +633,7 @@ local function do_install(install)
MojoSetup.downloads[#MojoSetup.downloads+1] = f
end
end
return true
return 1
end

-- Next stage: actual installation.
Expand All @@ -653,7 +659,7 @@ local function do_install(install)
local basepath = MojoSetup.findmedia(media.uniquefile)
while basepath == nil do
if not MojoSetup.gui.insertmedia(media.description) then
MojoSetup.fatal(_("User cancelled.")) -- !!! FIXME: don't like this.
return 0 -- user cancelled.
end
basepath = MojoSetup.findmedia(media.uniquefile)
end
Expand Down Expand Up @@ -693,11 +699,10 @@ local function do_install(install)
end
end

return true -- go to next stage.
return 1 -- go to next stage.
end

-- Next stage: show results gui
-- On failure, back out changes (make this part of fatal()).
-- Next stage: show results gui (!!! FIXME: write me.)

-- Now make all this happen.
if not MojoSetup.gui.start(install.description, install.splash) then
Expand All @@ -714,22 +719,25 @@ local function do_install(install)
local i = 1
while MojoSetup.stages[i] ~= nil do
local stage = MojoSetup.stages[i]
local go_forward = stage(i, #MojoSetup.stages)
local rc = stage(i, #MojoSetup.stages)

-- Too many times I forgot to return something. :)
if go_forward == nil then
MojoSetup.fatal("Bug in the installer: stage returned nil.")
if type(rc) ~= "number" then
MojoSetup.fatal(_("BUG: stage returned wrong type."))
end

if go_forward then
i = i + 1
else
if rc == 1 then
i = i + 1 -- next stage.
elseif rc == -1 then
if i == 1 then
MojoSetup.logwarning("Stepped back over start of stages")
MojoSetup.fatal(_("Internal error"))
MojoSetup.fatal(_("BUG: stepped back over start of stages"))
else
i = i - 1
end
elseif rc == 0 then
MojoSetup.fatal(_("User cancelled installation."))
else
MojoSetup.fatal(_("BUG: stage returned wrong value."))
end
end

Expand All @@ -748,6 +756,7 @@ local function do_install(install)
MojoSetup.gui.stop()

-- Done with these things. Make them eligible for garbage collection.
stages = nil
MojoSetup.destination = nil
MojoSetup.scratchdir = nil
MojoSetup.rollbackdir = nil
Expand Down

0 comments on commit 4a92264

Please sign in to comment.