Skip to content

Commit

Permalink
Bunch of untested work on downloads and install progress...reworkings…
Browse files Browse the repository at this point in the history
… of GUI

 and MojoInput_toPhysicalFile() to support it. Other fixes.
  • Loading branch information
icculus committed May 7, 2007
1 parent b637dbf commit 67fa111
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 204 deletions.
68 changes: 37 additions & 31 deletions fileio.c
Expand Up @@ -78,9 +78,11 @@ void MojoArchive_resetEntry(MojoArchiveEntry *info)
boolean MojoInput_toPhysicalFile(MojoInput *in, const char *fname, uint16 perms,
MojoInput_FileCopyCallback cb, void *data)
{
boolean retval = false;
uint32 start = MojoPlatform_ticks();
FILE *out = NULL;
boolean iofailure = false;
int32 br = 0;
int64 br = 0;
int64 flen = 0;
int64 bw = 0;

Expand All @@ -92,46 +94,50 @@ boolean MojoInput_toPhysicalFile(MojoInput *in, const char *fname, uint16 perms,
STUBBED("fopen?");
MojoPlatform_unlink(fname);
out = fopen(fname, "wb");
if (out == NULL)
return false;

while (!iofailure)
if (out != NULL)
{
br = (int32) in->read(in, scratchbuf_128k, sizeof (scratchbuf_128k));
if (br == 0) // we're done!
break;
else if (br < 0)
iofailure = true;
else
while (!iofailure)
{
if (fwrite(scratchbuf_128k, br, 1, out) != 1)
iofailure = true;
else
// !!! FIXME: to be written
// if (!in->ready(in))
// MojoPlatform_sleep(100);
// else
{
bw += br;
if (cb != NULL)
br = in->read(in, scratchbuf_128k, sizeof (scratchbuf_128k));
if (br == 0) // we're done!
break;
else if (br < 0)
iofailure = true;
else
{
int pct = -1;
if (flen > 0)
pct = (int) ((((double)bw) / ((double)flen)) * 100.0);
if (!cb(pct, data))
if (fwrite(scratchbuf_128k, br, 1, out) != 1)
iofailure = true;
} // if
else
bw += br;
} // else
} // else
} // else
} // while

if (fclose(out) != 0)
iofailure = true;
if (cb != NULL)
{
if (!cb(MojoPlatform_ticks() - start, bw, flen, data))
iofailure = true;
} // if
} // while

if (iofailure)
{
MojoPlatform_unlink(fname);
return false;
if (fclose(out) != 0)
iofailure = true;

if (iofailure)
MojoPlatform_unlink(fname);
else
{
MojoPlatform_chmod(fname, perms);
retval = true;
} // else
} // if

MojoPlatform_chmod(fname, perms);
return true;
in->close(in);
return retval;
} // MojoInput_toPhysicalFile


Expand Down
3 changes: 2 additions & 1 deletion fileio.h
Expand Up @@ -87,7 +87,8 @@ extern MojoArchive *GBaseArchive;
MojoArchive *MojoArchive_initBaseArchive(void);
void MojoArchive_deinitBaseArchive(void);

typedef boolean (*MojoInput_FileCopyCallback)(int percent, void *data);
typedef boolean (*MojoInput_FileCopyCallback)(uint32 ticks, int64 bw,
int64 total, void *data);
boolean MojoInput_toPhysicalFile(MojoInput *in, const char *fname, uint16 perms,
MojoInput_FileCopyCallback cb, void *data);

Expand Down
23 changes: 5 additions & 18 deletions gui.h
Expand Up @@ -58,12 +58,8 @@ struct MojoGui
char * (*destination)(const char **recommendations, int reccount,
boolean can_go_back, boolean can_go_forward);
boolean (*insertmedia)(const char *medianame);
void (*startdownload)(void);
void (*pumpdownload)(void);
void (*enddownload)(void);
void (*startinstall)(void);
void (*pumpinstall)(void);
void (*endinstall)(void);
boolean (*progress)(const char *type, const char *component,
int percent, const char *item);
};

typedef const MojoGui* (*MojoGuiEntryPoint)(int revision,
Expand Down Expand Up @@ -101,12 +97,8 @@ static boolean MojoGui_##module##_options(MojoGuiSetupOptions *opts, \
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); \
static void MojoGui_##module##_startdownload(void); \
static void MojoGui_##module##_pumpdownload(void); \
static void MojoGui_##module##_enddownload(void); \
static void MojoGui_##module##_startinstall(void); \
static void MojoGui_##module##_pumpinstall(void); \
static void MojoGui_##module##_endinstall(void); \
static boolean MojoGui_##module##_progress(const char *typ, const char *comp, \
int percent, const char *item); \
const MojoGui *MojoGuiPlugin_##module(int rev, const MojoSetupEntryPoints *e) \
{ \
if (rev == MOJOGUI_INTERFACE_REVISION) { \
Expand All @@ -123,12 +115,7 @@ const MojoGui *MojoGuiPlugin_##module(int rev, const MojoSetupEntryPoints *e) \
MojoGui_##module##_options, \
MojoGui_##module##_destination, \
MojoGui_##module##_insertmedia, \
MojoGui_##module##_startdownload, \
MojoGui_##module##_pumpdownload, \
MojoGui_##module##_enddownload, \
MojoGui_##module##_startinstall, \
MojoGui_##module##_pumpinstall, \
MojoGui_##module##_endinstall, \
MojoGui_##module##_progress, \
}; \
entry = e; \
return &retval; \
Expand Down
33 changes: 4 additions & 29 deletions gui/gui_macosx.c
Expand Up @@ -169,38 +169,13 @@ static boolean MojoGui_macosx_insertmedia(const char *medianame)
entry->_("OK"), entry->_("Cancel"));
} // MojoGui_macosx_insertmedia


static void MojoGui_macosx_startdownload(void)
{
// !!! FIXME: write me.
STUBBED(__FUNCTION__)
} // MojoGui_macosx_startdownload
static void MojoGui_macosx_pumpdownload(void)
{
// !!! FIXME: write me.
STUBBED(__FUNCTION__)
} // MojoGui_macosx_pumpdownload
static void MojoGui_macosx_enddownload(void)
{
// !!! FIXME: write me.
STUBBED(__FUNCTION__)
} // MojoGui_macosx_enddownload

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

// end of gui_macosx.c ...

73 changes: 44 additions & 29 deletions gui/gui_stdio.c
Expand Up @@ -13,6 +13,11 @@ CREATE_MOJOGUI_ENTRY_POINT(stdio)

#include <ctype.h>

static char *lastType = NULL;
static char *lastComponent = NULL;
static int lastPercent = -1;
static uint32 percentTicks = 0;

static int read_stdin(char *buf, int len)
{
if (fgets(buf, len, stdin) == NULL)
Expand Down Expand Up @@ -70,6 +75,12 @@ static uint8 MojoGui_stdio_priority(void)

static boolean MojoGui_stdio_init(void)
{
free(lastType);
lastType = NULL;
free(lastComponent);
lastComponent = NULL;
lastPercent = -1;
percentTicks = 0;
return true; // always succeeds.
} // MojoGui_stdio_init

Expand Down Expand Up @@ -116,6 +127,7 @@ static boolean MojoGui_stdio_promptyn(const char *title, const char *text)
return retval;
} // MojoGui_stdio_promptyn


static boolean MojoGui_stdio_start(const char *title, const char *splash)
{
printf("%s\n", title);
Expand Down Expand Up @@ -317,38 +329,41 @@ static boolean MojoGui_stdio_insertmedia(const char *medianame)
} // MojoGui_stdio_insertmedia


static void MojoGui_stdio_startdownload(void)
{
// !!! FIXME: write me.
STUBBED(__FUNCTION__)
} // MojoGui_stdio_startdownload
static void MojoGui_stdio_pumpdownload(void)
static boolean MojoGui_stdio_progress(const char *type, const char *component,
int percent, const char *item)
{
// !!! FIXME: write me.
STUBBED(__FUNCTION__)
} // MojoGui_stdio_pumpdownload
static void MojoGui_stdio_enddownload(void)
{
// !!! FIXME: write me.
STUBBED(__FUNCTION__)
} // MojoGui_stdio_enddownload
const uint32 now = entry->ticks();
if ((lastType == NULL) || (strcmp(lastType, type) == 0))
{
percentTicks = 0;
lastPercent = -1;
free(lastType);
lastType = entry->xstrdup(type);
printf("%s\n", type);
} // if

static void MojoGui_stdio_startinstall(void)
{
// !!! FIXME: write me.
STUBBED(__FUNCTION__)
} // MojoGui_stdio_startinstall
static void MojoGui_stdio_pumpinstall(void)
{
// !!! FIXME: write me.
STUBBED(__FUNCTION__)
} // MojoGui_stdio_pumpinstall
static void MojoGui_stdio_endinstall(void)
{
// !!! FIXME: write me.
STUBBED(__FUNCTION__)
} // MojoGui_stdio_endinstall
if ((lastComponent == NULL) || (strcmp(lastComponent, component) == 0))
{
percentTicks = 0;
free(lastComponent);
lastComponent = entry->xstrdup(component);
printf("%s\n", component);
} // if

// limit update spam... will only write every two seconds, tops.
if (percentTicks <= now)
{
percentTicks = now + 2000;
if (percent != lastPercent)
{
lastPercent = percent;
// !!! FIXME: localization.
printf(entry->_("%s (total %d%%)\n"), item, percent);
} // if
} // if

return true;
} // MojoGui_stdio_progress

// end of gui_stdio.c ...

0 comments on commit 67fa111

Please sign in to comment.