Skip to content

Commit

Permalink
Lots of FIXME removals, clenaups, and tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jan 14, 2008
1 parent 36464bb commit 963aff1
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 44 deletions.
3 changes: 0 additions & 3 deletions gui_gtkplus2.c
Expand Up @@ -97,7 +97,6 @@ static int wait_event(void)
gtk_main_iteration();
if (click_value == CLICK_CANCEL)
{
// !!! FIXME: language.
char *title = entry->xstrdup(entry->_("Cancel installation"));
char *text = entry->xstrdup(entry->_("Are you sure you want to cancel installation?"));
if (!MojoGui_gtkplus2_promptyn(title, text, false))
Expand Down Expand Up @@ -280,7 +279,6 @@ static void MojoGui_gtkplus2_msgbox(const char *title, const char *text)
static boolean MojoGui_gtkplus2_promptyn(const char *title, const char *text,
boolean defval)
{
// !!! FIXME: support defval.
gint rc = do_msgbox(title, text, GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO,
defval ? GTK_RESPONSE_YES : GTK_RESPONSE_NO,
Expand Down Expand Up @@ -310,7 +308,6 @@ static MojoGuiYNAN MojoGui_gtkplus2_promptynan(const char *title,
const char *text,
boolean defval)
{
// !!! FIXME: support defval.
const gint rc = do_msgbox(title, text, GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
defval ? GTK_RESPONSE_YES : GTK_RESPONSE_NO,
Expand Down
1 change: 0 additions & 1 deletion gui_stdio.c
Expand Up @@ -621,7 +621,6 @@ static boolean MojoGui_stdio_progress(const char *type, const char *component,
char *fmt = NULL;
char *msg = NULL;
percentTicks = now + 1000;
// !!! FIXME: localization.
if (percent < 0)
printf("%s\n", item);
else
Expand Down
19 changes: 11 additions & 8 deletions lua_glue.c
Expand Up @@ -988,7 +988,7 @@ static int luahook_stringtofile(lua_State *L)
size_t len = 0;
int retval = 0;
boolean rc = false;
uint16 perms = 0600; // !!! FIXME
uint16 perms = MojoPlatform_defaultFilePerms();
MojoChecksums sums;

str = lua_tolstring(L, 1, &len);
Expand Down Expand Up @@ -1365,28 +1365,31 @@ static int luahook_gui_destination(lua_State *L)
size_t reccount = 0;
char *rc = NULL;
int command = 0;
size_t i = 0;

if (lua_istable(L, 1))
{
size_t i;

reccount = lua_objlen(L, 1);
recommend = (char **) alloca(reccount * sizeof (char *));
recommend = (char **) xmalloc(reccount * sizeof (char *));
for (i = 0; i < reccount; i++)
{
const char *str = NULL;
lua_pushinteger(L, i+1);
lua_gettable(L, 1);
str = lua_tostring(L, -1); // !!! FIXME: alloca in a loop...
recommend[i] = (char *) alloca(strlen(str) + 1);
strcpy(recommend[i], str);
recommend[i] = xstrdup(lua_tostring(L, -1));
lua_pop(L, 1);
} // for
} // if

rc = GGui->destination((const char **) recommend, reccount,
&command, can_go_back, can_go_fwd);

if (recommend != NULL)
{
for (i = 0; i < reccount; i++)
free(recommend[i]);
free(recommend);
} // if

retvalNumber(L, command);
retvalString(L, rc); // may push nil.
free(rc);
Expand Down
5 changes: 3 additions & 2 deletions mojosetup.c
Expand Up @@ -455,8 +455,9 @@ void MojoLog_initLogging(void)
else // Unknown string gets everything...that'll teach you.
MojoLog_logLevel = MOJOSETUP_LOG_EVERYTHING;

// !!! FIXME: allow logging to stdout on Unix.
if (fname != NULL)
if ((fname != NULL) && (strcmp(fname, "-") == 0))
logFile = MojoPlatform_stdout();
else if (fname != NULL)
{
const uint32 flags = MOJOFILE_WRITE|MOJOFILE_CREATE|MOJOFILE_TRUNCATE;
const uint16 mode = MojoPlatform_defaultFilePerms();
Expand Down
6 changes: 6 additions & 0 deletions platform.h
Expand Up @@ -147,6 +147,12 @@ typedef enum
// handle with MojoPlatform_close() when done with it.
void *MojoPlatform_open(const char *fname, uint32 flags, uint16 mode);

// Return a handle that's compatible with MojoPlatform_open()'s return values
// that represents stdout. May return NULL for platforms that don't support
// this concept. You need to make sure that stdout itself doesn't really
// close in MojoPlatform_close(), at least for now.
void *MojoPlatform_stdout(void);

// Read (bytes) bytes from (fd) into (buf). This wraps the Unix read() syscall.
// Returns number of bytes read, -1 on error.
int64 MojoPlatform_read(void *fd, void *buf, uint32 bytes);
Expand Down
19 changes: 18 additions & 1 deletion platform_unix.c
Expand Up @@ -591,6 +591,14 @@ boolean MojoPlatform_isfile(const char *dir)
} // MojoPlatform_isfile


void *MojoPlatform_stdout(void)
{
int *retval = (int *) xmalloc(sizeof (int));
*retval = 1; // stdout.
return retval;
} // MojoPlatform_stdout


void *MojoPlatform_open(const char *fname, uint32 flags, uint16 mode)
{
void *retval = NULL;
Expand Down Expand Up @@ -678,7 +686,16 @@ boolean MojoPlatform_flush(void *fd)
boolean MojoPlatform_close(void *fd)
{
boolean retval = false;
if (close(*((int *) fd)) == 0)
int handle = *((int *) fd);

// don't close stdin, stdout, or stderr.
if ((handle == 0) || (handle == 1) || (handle == 2))
{
free(fd);
return true;
} // if

if (close(handle) == 0)
free(fd);
return retval;
} // MojoPlatform_close
Expand Down
6 changes: 6 additions & 0 deletions platform_windows.c
Expand Up @@ -1132,6 +1132,12 @@ boolean MojoPlatform_isfile(const char *dir)
} // MojoPlatform_isfile


void *MojoPlatform_stdout(void)
{
return NULL; // unsupported on Windows.
} // MojoPlatform_stdout


void *MojoPlatform_open(const char *fname, uint32 flags, uint16 mode)
{
HANDLE *retval = NULL;
Expand Down
17 changes: 12 additions & 5 deletions scripts/localization.lua
Expand Up @@ -126,6 +126,10 @@ MojoSetup.localization = {
["NOTICE: %0\n[hit enter]"] = {
};

-- That's meant to be the name of an item (%0) and the percent done (%1).
["%0: %1%%"] = {
};

["%0 (total progress: %1%%)\n"] = {
};

Expand Down Expand Up @@ -180,10 +184,10 @@ MojoSetup.localization = {
["Cancel installation"] = {
};

["cannot open archive."] = {
["Can't enumerate archive"] = {
};

["Can't enumerate archive"] = {
["Can't open archive."] = {
};

["Choose install destination by number (hit enter for #1), or enter your own."] = {
Expand Down Expand Up @@ -238,7 +242,10 @@ MojoSetup.localization = {
["File creation failed!"] = {
};

["file download failed!"] = {
["File download failed!"] = {
};

["File '$0' already exists! Replace?"] = {
};

["Finish"] = {
Expand Down Expand Up @@ -272,7 +279,7 @@ MojoSetup.localization = {
["Media change"] = {
};

["mkdir failed"] = {
["Directory creation failed"] = {
};

["need dictionary"] = {
Expand Down Expand Up @@ -322,7 +329,7 @@ MojoSetup.localization = {
["(stalled)"] = {
};

["symlink creation failed!"] = {
["Symlink creation failed!"] = {
};

["The installer has been stopped by the system."] = {
Expand Down
38 changes: 14 additions & 24 deletions scripts/mojosetup_mainline.lua
Expand Up @@ -35,7 +35,6 @@ local function delete_files(filelist, callback, error_is_fatal)
for i = max,1,-1 do
local fname = filelist[i]
if not do_delete(fname) and error_is_fatal then
-- !!! FIXME: formatting
MojoSetup.fatal(_("Deletion failed!"))
end

Expand Down Expand Up @@ -77,7 +76,6 @@ local function do_rollbacks()
local dest = MojoSetup.rollbacks[id]
if not MojoSetup.movefile(src, dest) then
-- we're already in fatal(), so we can only throw up a msgbox...
-- !!! FIXME: formatting
MojoSetup.msgbox(_("Serious problem"),
_("Couldn't restore some files. Your existing installation is likely damaged."))
end
Expand Down Expand Up @@ -110,7 +108,6 @@ end

-- This gets called by fatal()...must be a global function.
function MojoSetup.revertinstall()
-- !!! FIXME: language.
if MojoSetup.gui_started then
MojoSetup.gui.final(_("Incomplete installation. We will revert any changes we made."))
end
Expand Down Expand Up @@ -219,7 +216,7 @@ end
-- This code's a little nasty...
local function drill_for_archive(archive, path, arclist)
if not MojoSetup.archive.enumerate(archive) then
MojoSetup.fatal(_("Couldn't enumerate archive.")) -- !!! FIXME: error message
MojoSetup.fatal(_("Couldn't enumerate archive."))
end

local pathtab = split_path(path)
Expand All @@ -237,7 +234,7 @@ local function drill_for_archive(archive, path, arclist)
-- open it as an archive and keep drilling...
local arc = MojoSetup.archive.fromentry(archive)
if arc == nil then
MojoSetup.fatal(_("Couldn't open archive.")) -- !!! FIXME: error message.
MojoSetup.fatal(_("Couldn't open archive."))
end
arclist[#arclist+1] = arc
if pathtab[i] == nil then
Expand All @@ -249,14 +246,14 @@ local function drill_for_archive(archive, path, arclist)
ent = MojoSetup.archive.enumnext(archive)
end

MojoSetup.fatal(_("Archive not found.")) -- !!! FIXME: error message.
MojoSetup.fatal(_("Archive not found."))
end


local function install_file(dest, perms, writefn, desc, manifestkey)
-- Upvalued so we don't look these up each time...
local fname = string.gsub(dest, "^.*/", "", 1) -- chop the dirs off...
local ptype = _("Installing") -- !!! FIXME: localization.
local ptype = _("Installing")
local component = desc
local keepgoing = true
local callback = function(ticks, justwrote, bw, total)
Expand All @@ -265,7 +262,7 @@ local function install_file(dest, perms, writefn, desc, manifestkey)
if total >= 0 then
MojoSetup.written = MojoSetup.written + justwrote
percent = calc_percent(MojoSetup.written, MojoSetup.totalwrite)
item = fname .. ": " .. calc_percent(bw, total) .. "%" -- !!! FIXME: localization
item = MojoSetup.format(_("%0: %1%%"), fname, calc_percent(bw, total))
end
keepgoing = MojoSetup.gui.progress(ptype, component, percent, item)
return keepgoing
Expand All @@ -288,7 +285,6 @@ local function install_file(dest, perms, writefn, desc, manifestkey)

local written, sums = writefn(callback)
if not written then
-- !!! FIXME: formatting!
if not keepgoing then
MojoSetup.logerror("User cancelled install during file write.")
MojoSetup.fatal()
Expand Down Expand Up @@ -324,9 +320,8 @@ end
-- !!! FIXME: thousands of symlinks in a row or something.
local function install_symlink(dest, lndest, manifestkey)
if not MojoSetup.platform.symlink(dest, lndest) then
-- !!! FIXME: formatting!
MojoSetup.logerror("Failed to create symlink '" .. dest .. "'")
MojoSetup.fatal(_("symlink creation failed!"))
MojoSetup.fatal(_("Symlink creation failed!"))
end

if manifestkey ~= nil then
Expand All @@ -350,9 +345,8 @@ end
-- !!! FIXME: thousands of dirs in a row or something.
local function install_directory(dest, perms, manifestkey)
if not MojoSetup.platform.mkdir(dest, perms) then
-- !!! FIXME: formatting
MojoSetup.logerror("Failed to create dir '" .. dest .. "'")
MojoSetup.fatal(_("mkdir failed"))
MojoSetup.fatal(_("Directory creation failed"))
end

if manifestkey ~= nil then
Expand Down Expand Up @@ -404,7 +398,8 @@ local function permit_write(dest, entinfo, file)
if not allowoverwrite then
-- !!! FIXME: language and formatting.
MojoSetup.loginfo("File '" .. dest .. "' already exists.")
local ynan = MojoSetup.promptynan(_("Conflict!"), _("File already exists! Replace?"), true)
local text = MojoSetup.format(_("File '$0' already exists! Replace?"), dest);
local ynan = MojoSetup.promptynan(_("Conflict!"), text, true)
if ynan == "always" then
MojoSetup.forceoverwrite = true
allowoverwrite = true
Expand All @@ -427,7 +422,6 @@ local function permit_write(dest, entinfo, file)
install_parent_dirs(f, nil)
MojoSetup.rollbacks[id] = dest
if not MojoSetup.movefile(dest, f) then
-- !!! FIXME: formatting
MojoSetup.fatal(_("Couldn't backup file for rollback"))
end
MojoSetup.loginfo("Moved rollback #" .. id .. ": '" .. dest .. "' -> '" .. f .. "'")
Expand Down Expand Up @@ -472,7 +466,6 @@ local function install_archive_entry(archive, ent, file, option)
elseif ent.type == "symlink" then
install_symlink(dest, ent.linkdest, option)
else -- !!! FIXME: device nodes, etc...
-- !!! FIXME: formatting!
-- !!! FIXME: should this be fatal?
MojoSetup.fatal(_("Unknown file type in archive"))
end
Expand All @@ -483,7 +476,6 @@ end

local function install_archive(archive, file, option)
if not MojoSetup.archive.enumerate(archive) then
-- !!! FIXME: need formatting function.
MojoSetup.fatal(_("Can't enumerate archive"))
end

Expand Down Expand Up @@ -562,8 +554,8 @@ local function install_basepath(basepath, file, option)
local archive = MojoSetup.archive.fromdir(path)
if archive == nil then
archive = MojoSetup.archive.fromfile(path)
if archive == nil then -- !!! FIXME: error message.
MojoSetup.fatal(_("cannot open archive."))
if archive == nil then
MojoSetup.fatal(_("Can't open archive."))
end
end
return archive
Expand All @@ -583,7 +575,7 @@ local function install_basepath(basepath, file, option)
local knowngood = path
path = path .. "/" .. v
if not MojoSetup.platform.exists(path) then
if knowngood == "" then -- !!! FIXME: error message.
if knowngood == "" then
MojoSetup.fatal(_("Archive not found"))
end
local archive = create_basepath_archive(knowngood)
Expand Down Expand Up @@ -1093,7 +1085,7 @@ local function do_install(install)
-- Upvalued so we don't look these up each time...
local url = file.source
local fname = string.gsub(url, "^.*/", "", 1) -- chop the dirs off...
local ptype = _("Downloading") -- !!! FIXME: localization.
local ptype = _("Downloading")
local component = option.description
local bps = 0
local bpsticks = 0
Expand Down Expand Up @@ -1123,8 +1115,7 @@ local function do_install(install)
MojoSetup.loginfo("Download '" .. url .. "' to '" .. f .. "'")
local downloaded, sums = MojoSetup.download(url, f, callback)
if not downloaded then
-- !!! FIXME: formatting!
MojoSetup.fatal(_("file download failed!"))
MojoSetup.fatal(_("File download failed!"))
end
MojoSetup.downloads[#MojoSetup.downloads+1] = f
end
Expand Down Expand Up @@ -1206,7 +1197,6 @@ local function do_install(install)

-- Next stage: show results gui
stages[#stages+1] = function(thisstage, maxstage)
-- !!! FIXME: language.
MojoSetup.gui.final(_("Installation was successful."))
return 1 -- go forward.
end
Expand Down

0 comments on commit 963aff1

Please sign in to comment.