Skip to content

Commit

Permalink
Did a lot of ripping things up.
Browse files Browse the repository at this point in the history
Now all the UI drivers are compiled for all platforms (and nonsense ones, like
 ui_carbon.c on, say, Windows, will be one-fuction stubs), and the appropriate
 one is chosen at startup. This lets us pick a GUI one by default, but fall
 back to stdio if there's an initialization issue or the let the user pick
 stdio because he's ssh'd to a headless server, etc). It also lets us plug
 in a Qt and GTK and blahblahblah UI on linux and let everything coexist in
 one binary.

Also, a lot of the bad abstraction breakage in platform_unix.c that got wedged
 in there when this was a Mac Thing Done In A Hurry has been cleaned up into
 general application code in mojopatch.c, platform stuff in platform_*,
 and UI stuff in the UI drivers.

Over all, this was a lot of good cleanup that'll make sane Linux and Windows
 ports much easier.
  • Loading branch information
icculus committed Apr 22, 2005
1 parent 4dc78ee commit a9bd86a
Show file tree
Hide file tree
Showing 9 changed files with 512 additions and 297 deletions.
14 changes: 7 additions & 7 deletions Makefile
Expand Up @@ -20,19 +20,19 @@ use_pthread := false
# you probably shouldn't touch anything below this line.

ifeq ($(strip $(platform)),macosx)
PLATFORMDEF := -DPLATFORM_UNIX -DPLATFORM_MACOSX
PLATFORMSRCS := platform_unix.c ui_carbon.c
PLATFORMDEF := -DPLATFORM_UNIX=1 -DPLATFORM_MACOSX=1
PLATFORMSRCS := platform_unix.c
LDFLAGS := -framework Carbon
endif

ifeq ($(strip $(platform)),win32)
PLATFORMDEF := -DPLATFORM_WIN32
PLATFORMSRCS := platform_win32.c ui_stdio.c
PLATFORMDEF := -DPLATFORM_WIN32=1
PLATFORMSRCS := platform_win32.c
endif

ifeq ($(strip $(platform)),unix)
PLATFORMDEF := -DPLATFORM_UNIX
PLATFORMSRCS := platform_unix.c ui_stdio.c
PLATFORMDEF := -DPLATFORM_UNIX=1
PLATFORMSRCS := platform_unix.c
endif

#CFLAGS := $(PLATFORMDEF) -Wall -g -fsigned-char -fno-omit-frame-pointer -O0 -DDEBUG=1 -D_DEBUG=1
Expand All @@ -54,7 +54,7 @@ ifeq ($(strip $(use_pthread)),true)
endif
endif

MOJOPATCHSRCS := mojopatch.c md5.c $(PLATFORMSRCS)
MOJOPATCHSRCS := mojopatch.c md5.c ui.c ui_carbon.c ui_stdio.c $(PLATFORMSRCS)
OBJS1 := $(MOJOPATCHSRCS:.c=.o)
OBJS2 := $(OBJS1:.cpp=.o)
OBJS3 := $(OBJS2:.asm=.o)
Expand Down
1 change: 0 additions & 1 deletion TODO
Expand Up @@ -10,7 +10,6 @@
- Get other platforms besides Mac updated and building again.
- Look for FIXMEs...
- "_fatal" isn't really appropriate anymore, since it might not be fatal.
- chdir_by_identifier() has way too many unwritten responsibilities.
- We md5sum to compare files. A byte-by-byte compare that halts as soon as
there's a difference would be much faster when creating the initial patch
files.
Expand Down
108 changes: 103 additions & 5 deletions mojopatch.c
Expand Up @@ -2022,6 +2022,80 @@ static inline void header_log(const char *str, const char *val)
} /* header_log */


static int show_and_install_readme(const char *fname, const char *text)
{
FILE *io = fopen(fname, "wb");
if (io == NULL)
{
_fatal("Failed to open [%s] for writing.", fname);
return(0);
} /* if */

/* !!! FIXME: "text" may be binary data, not an asciz string... */
fputs(text, io); /* !!! FIXME: error checking! */
fclose(io);
return(ui_show_readme(fname, text));
} /* show_and_install_readme */


static int manually_locate_product(const char *name, char *buf, size_t bufsize)
{
const char *promptfmt = "We can't find your \"%s\" installation."
" Would you like to show us where it is?";
char *promptstr = alloca(strlen(name) + strlen(promptfmt) + 1);

if (promptstr == NULL)
{
_fatal("Out of memory.");
return(0);
} /* if */
sprintf(promptstr, promptfmt, name);

if (!ui_prompt_yn(promptstr))
{
_log("User chose not to manually locate installation");
return(0);
} /* if */

return(ui_file_picker(buf, bufsize));
} /* manually_locate_product */


static int chdir_by_identifier(const char *name, const char *str,
const char *version, const char *newversion)
{
char buf[MAXPATHLEN];
int hasident = ((str != NULL) && (*str));
int found = 0;

if (hasident)
{
found = locate_product_by_identifier(str, buf, sizeof (buf));
if (!found)
_log("Couldn't find product. Perhaps it isn't installed?");
} /* if */

if (!found) /* No identifier, or platform layer couldn't find it. */
{
if (!manually_locate_product(name, buf, sizeof (buf)))
{
_fatal("We can't patch the product if we can't find it!");
return(0);
} /* if */
} /* if */

_log("I think the product is installed at [%s].", buf);

if (chdir(buf) != 0)
{
_fatal("Failed to change to product's installation directory.");
return(0);
} /* if */

return(check_product_version(str, version, newversion));
} /* chdir_by_identifier */


static int process_patch_header(SerialArchive *ar, PatchHeader *h)
{
int retval = PATCHSUCCESS;
Expand Down Expand Up @@ -2255,6 +2329,8 @@ static int parse_cmdline(int argc, char **argv)
make_static_string(header.renamedir, argv[++i]);
else if (strcmp(argv[i], "--titlebar") == 0)
make_static_string(header.titlebar, argv[++i]);
else if (strcmp(argv[i], "--ui") == 0)
i++; /* (really handled elsewhere.) Just skip ui driver name. */
else if (strcmp(argv[i], "--zliblevel") == 0)
{
zliblevel = atoi(argv[++i]);
Expand Down Expand Up @@ -2339,6 +2415,31 @@ static int parse_cmdline(int argc, char **argv)

/* !!! FIXME: signal_cleanup */

static int kickoff_ui(int argc, char **argv)
{
int seen_ui = 0;
int i;

for (i = 1; i < argc; i++)
{
if (strcmp(argv[i], "--ui") == 0)
{
seen_ui = 1;
if (ui_init(argv[++i]))
return(1);
} /* if */
} /* for */

if (!seen_ui)
{
if (ui_init(NULL))
return(1);
} /* if */

fprintf(stderr, "MojoPatch: ui_init() failed!"); /* oh well. */
return(0);
} /* kickoff_ui */


int mojopatch_main(int argc, char **argv)
{
Expand All @@ -2347,11 +2448,8 @@ int mojopatch_main(int argc, char **argv)

memset(&header, '\0', sizeof (header));

if (!ui_init())
{
_fatal("MojoPatch: ui_init() failed!"); /* oh well. */
return(PATCHERROR);
} /* if */
if (!kickoff_ui(argc, argv))
return(PATCHERROR); /* oh well. */

_log("MojoPatch %s starting up.", VERSION);

Expand Down
6 changes: 3 additions & 3 deletions platform.h
Expand Up @@ -49,6 +49,7 @@ void _log(const char *fmt, ...);
/* Call this for logging (debug info). */
void _dlog(const char *fmt, ...);

/* Does a given version match the requirements? */
int version_ok(const char *ver, const char *allowed, const char *newver);

/* platform-specific stuff you implement. */
Expand All @@ -62,9 +63,8 @@ char *get_realpath(const char *path);
int spawn_xdelta(const char *cmdline);
int update_version(const char *ver);
int calc_tmp_filenames(char **tmp1, char **tmp2);
int show_and_install_readme(const char *fname, const char *text);
int chdir_by_identifier(const char *name, const char *str,
const char *ver, const char *newver);
int locate_product_by_identifier(const char *str, char *buf, size_t bufsize);
int check_product_version(const char *ident, const char *version, const char *newversion);

#ifdef __cplusplus
}
Expand Down

0 comments on commit a9bd86a

Please sign in to comment.