Skip to content

Commit

Permalink
A more or less complete set of hacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jun 2, 2004
1 parent 2ba6710 commit dd20774
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -25,7 +25,7 @@ PLATFORMDEF := -DPLATFORM_UNIX
PLATFORMSRCS := platform_unix.c ui_stdio.c
endif

CFLAGS := $(PLATFORMDEF) -Wall -g -fsigned-char -fno-omit-frame-pointer -O0
CFLAGS := $(PLATFORMDEF) -Wall -g -fsigned-char -fno-omit-frame-pointer -Os

ifeq ($(strip $(use_zlib)),true)
CFLAGS += -DUSE_ZLIB
Expand Down
Binary file modified MojoPatch.app/Contents/Resources/mojopatch.icns
Binary file not shown.
55 changes: 38 additions & 17 deletions build-patchfile.sh
Expand Up @@ -3,35 +3,56 @@
# Just die if anything fails.
set -e

rm -f ~/Desktop/nwn.mojopatch
# revert everything to a sane state.
make
strip -S ./bin/mojopatch
mv ./bin/mojopatch ./MojoPatch.app/Contents/MacOS/
rm -rf ./MojoPatch.app/default.mojopatch
rm -rf "/Users/icculus/Desktop/Shadows of Undrentide Installer.app"
rm -rf "/Users/icculus/Desktop/Hordes of the Underdark Installer.app"

./MojoPatch.app/Contents/MacOS/mojopatch --create --alwaysadd --zliblevel 1 \
--product "Neverwinter Nights Dedicated Server" --identifier "nwserver.icns" \
--version "0.0.1d1" --newversion "1.62" --replace --append --quietonsuccess \
--titlebar "Neverwinter Nights Dedicated Server 1.62 patch" \
"/Users/icculus/Desktop/nwn.mojopatch" \
"/Users/icculus/Desktop/Neverwinter Nights orig/Dedicated Server.app" \
"/Users/icculus/Desktop/nwn162/Dedicated Server.app"
# Just a blank dir, so everything in the patch dir is added in the patch...
mkdir -p tmp

# Put the 1.62 patch together...
./MojoPatch.app/Contents/MacOS/mojopatch --create --alwaysadd --zliblevel 1 \
--product "Neverwinter Nights Main Game Icon" --identifier "nwmain.icns" \
--product "Neverwinter Nights" \
--identifier "nwmain.icns" \
--version "0.0.1d1" --newversion "1.62" --replace --append --quietonsuccess \
--titlebar "Neverwinter Nights 1.62 patch" \
"/Users/icculus/Desktop/nwn.mojopatch" \
"/Users/icculus/Desktop/Neverwinter Nights orig/Neverwinter Nights.app" \
"/Users/icculus/Desktop/nwn162/Neverwinter Nights.app"
"./MojoPatch.app/default.mojopatch" \
"./tmp" \
"/Users/icculus/Desktop/nwn162"

# Just a blank dir, so everything in the patch dir is added in the patch...
mkdir -p tmp
# Copy initial patchfile to seperate expansion pack installers...
echo "copying initial patch to SoU branch..."
cp -R MojoPatch.app "/Users/icculus/Desktop/Shadows of Undrentide Installer.app"
rm -f "/Users/icculus/Desktop/Shadows of Undrentide Installer.app/Contents/MacOS/xdelta"

echo "copying initial patch to HotU branch..."
cp -R MojoPatch.app "/Users/icculus/Desktop/Hordes of the Underdark Installer.app"
rm -f "/Users/icculus/Desktop/Hordes of the Underdark Installer.app/Contents/MacOS/xdelta"

# Add XP1 data to patchfile...
./MojoPatch.app/Contents/MacOS/mojopatch --create --alwaysadd --zliblevel 1 \
--product "Neverwinter Nights base folder" \
--version "Neverwinter Nights.app" --replace --append \
--product "Neverwinter Nights" \
--identifier "SoU" \
--version "a" --newversion "b" --replace --append --quietonsuccess \
--titlebar "NWN Shadows of Undrentide Expansion Pack" \
"/Users/icculus/Desktop/nwn.mojopatch" \
"/Users/icculus/Desktop/Shadows of Undrentide Installer.app/default.mojopatch" \
"./tmp" \
"/Users/icculus/Desktop/XP1/XP1-1.62.8047e"

# Add XP2 data to the other patchfile...
./MojoPatch.app/Contents/MacOS/mojopatch --create --alwaysadd --zliblevel 1 \
--product "Neverwinter Nights" \
--identifier "HotU" \
--version "a" --newversion "b" --replace --append \
--titlebar "NWN Hordes of the Underdark Expansion Pack" \
"/Users/icculus/Desktop/Hordes of the Underdark Installer.app/default.mojopatch" \
"./tmp" \
"/Users/icculus/Desktop/XP2/XP2-1.62.8047e"

rmdir tmp

exit 0;
Expand Down
108 changes: 67 additions & 41 deletions mojopatch.c
@@ -1,7 +1,7 @@
/*
*----------------------------------------------------------------------------
*
* mojopatch
* mojopatch : nwn expansion pack branch
* Copyright (C) 2003 Ryan C. Gordon.
*
*----------------------------------------------------------------------------
Expand Down Expand Up @@ -43,7 +43,7 @@
#define VER_EXT_ZLIB " (w/zlib)"
#endif

#define VERSION "0.0.5" VER_EXT_ZLIB
#define VERSION "0.0.5nwnxp" VER_EXT_ZLIB

#define DEFAULT_PATCHFILENAME "default.mojopatch"

Expand Down Expand Up @@ -165,9 +165,6 @@ typedef enum
ZLIB_UNCOMPRESS
} ZlibOptions;

/* This is a hack. */
static int must_prompt_for_location = 1;

static int debug = 0;
static int interactive = 0;
static int replace = 0;
Expand Down Expand Up @@ -577,25 +574,7 @@ static void _current_operation(const char *fmt, ...)
/* don't taunt this function. */
int version_ok(const char *ver, const char *allowed_ver)
{
char *ptr;
char *buf;

if (*allowed_ver == '\0')
return 1; /* No specified version? Anything is okay, then. */

buf = (char *) alloca(strlen(allowed_ver) + 1);
strcpy(buf, allowed_ver);

while ((ptr = strstr(buf, " or ")) != NULL)
{
*ptr = '\0';
if (strcmp(ver, buf) == 0)
return(1);

buf = ptr + 4;
} /* while */

return(strcmp(ver, buf) == 0);
return(strcmp(ver, "0.0.1d1") == 0);
} /* version_ok */


Expand Down Expand Up @@ -1118,8 +1097,7 @@ static int put_add(SerialArchive *ar, const char *fname)
struct stat statbuf;
int retval = PATCHERROR;

_current_operation("%s %s", (replace) ? "ADDORREPLACE" : "ADD",
final_path_element(fname));
_current_operation("Installing file %s ...", final_path_element(fname));
_log("%s %s", (replace) ? "ADDORREPLACE" : "ADD", fname);

if (!confirm())
Expand Down Expand Up @@ -1175,8 +1153,7 @@ static int handle_add_op(SerialArchive *ar, OperationType op, void *d)
FILE *io = NULL;
int rc;

_current_operation("%s %s", (replace_ok) ? "ADDORREPLACE" : "ADD",
final_path_element(add->fname));
_current_operation("Installing file %s ...", final_path_element(add->fname));
_log("%s %s", (replace_ok) ? "ADDORREPLACE" : "ADD", add->fname);

if ( (info_only()) || (!confirm()) || (in_ignore_list(add->fname)) )
Expand Down Expand Up @@ -1206,7 +1183,7 @@ static int handle_add_op(SerialArchive *ar, OperationType op, void *d)
} /* if */

_log("[%s] already exists...looking at md5sum...", add->fname);
_current_operation("VERIFY %s", final_path_element(add->fname));
_current_operation("Verifying %s ...", final_path_element(add->fname));
io = fopen(add->fname, "rb");
if (io == NULL)
{
Expand Down Expand Up @@ -1249,7 +1226,7 @@ static int handle_add_op(SerialArchive *ar, OperationType op, void *d)

chmod(add->fname, add->mode); /* !!! FIXME: Should this be an error condition? */

_current_operation("VERIFY %s", final_path_element(add->fname));
_current_operation("Verifying %s ...", final_path_element(add->fname));
io = fopen(add->fname, "rb");
if (io == NULL)
{
Expand Down Expand Up @@ -2005,7 +1982,8 @@ static int process_patch_header(SerialArchive *ar, PatchHeader *h)

ui_title(h->titlebar);

if ( (!info_only()) && (must_prompt_for_location) )
#if 0
if ( (!info_only()) )
{
int rc = chdir_by_identifier(h->product, h->identifier,
h->version, h->newversion);
Expand All @@ -2014,6 +1992,7 @@ static int process_patch_header(SerialArchive *ar, PatchHeader *h)
else if (rc == -1)
skip_patch = 1;
} /* if */
#endif

if (*h->readmefname)
{
Expand All @@ -2027,6 +2006,55 @@ static int process_patch_header(SerialArchive *ar, PatchHeader *h)
return(retval);
} /* process_patch_header */

int manually_locate_product(const char *name, char *buf, size_t bufsize);
int parse_info_dot_plist(const char *ident,
const char *version,
const char *newversion);

static char nwnbase[MAXPATHLEN];

static int nwn_patch_start(void)
{
int rc = 0;
ui_msgbox("Welcome to the Neverwinter Nights expansion pack installer!"
" Before installing the expansion pack, we need to make sure"
" the game is patched up to an acceptable version.");

while (1)
{
if (!manually_locate_product("Neverwinter Nights", nwnbase, sizeof (nwnbase)))
{
_fatal("We can't patch the product if we can't find it!");
return(0);
} /* if */

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

if (file_exists("./Neverwinter Nights.app"))
break;

ui_msgbox("This doesn't appear to be the right directory!");
} /* while */

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

rc = parse_info_dot_plist("nwmain.icns", "0.0.1d1", "1.62");
if (!rc)
return(0);
else if (rc == -1)
skip_patch = 1;

return(1);
} /* nwn_patch_start */


static int do_patching(void)
{
Expand All @@ -2045,11 +2073,8 @@ static int do_patching(void)
if (file_size == 0)
do_progress = 0; /* prevent a division by zero. */

ui_msgbox("Welcome to the Neverwinter Nights expansion pack installer!"
" Before installing the expansion pack, we need to make sure"
" the game is patched up to an acceptable version. You may be"
" prompted to show us where some icons in your original game "
" installation reside.");
if (!nwn_patch_start())
return(PATCHERROR);

while (1)
{
Expand All @@ -2060,18 +2085,19 @@ static int do_patching(void)
if (legitEOF) /* actually end of file, so bail. */
break;

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

/* if there's no identifier, then we're past the game patches. */
if (*header.identifier == '\0')
{
ui_msgbox("Now we're ready to install the expansion pack.\n"
" This will take around 5 to 10 minutes.");

chdir(".."); /* presumably, this is the base of the install. */
if (file_exists("./nwn.ini"))
must_prompt_for_location = 0;
} /* if */


if (process_patch_header(&ar, &header) == PATCHERROR)
goto do_patching_done;

Expand Down
29 changes: 16 additions & 13 deletions platform_unix.c
Expand Up @@ -293,9 +293,9 @@ static char *find_info_plist_bundle_id(char *ptr)
} /* find_info_plist_version */


static int parse_info_dot_plist(const char *ident,
const char *version,
const char *newversion)
int parse_info_dot_plist(const char *ident,
const char *version,
const char *newversion)
{
const char *fname = "Contents/Info.plist"; /* already chdir'd for this. */
char *mem = NULL;
Expand Down Expand Up @@ -337,17 +337,17 @@ static int parse_info_dot_plist(const char *ident,
retval = 1;
else
{
if (strcmp(ptr, newversion) == 0)
{
_fatal("You seem to be all patched up already!");
// if (strcmp(ptr, newversion) == 0)
// {
_fatal("You seem to have the required %s patch already!", newversion);
retval = -1;
} /* if */
else
{
_fatal("This patch applies to version '%s', but you have '%s'.",
version, ptr);
retval = 0;
} /* else */
// } /* if */
// else
// {
// _fatal("This patch applies to version '%s', but you have '%s'.",
// version, ptr);
// retval = 0;
// } /* else */
} /* else */
} /* if */

Expand All @@ -363,6 +363,8 @@ static int parse_info_dot_plist(const char *ident,

int update_version(const char *ver)
{
return 1;
#if 0
const char *fname = "Contents/Info.plist"; /* already chdir'd for this. */
char *mem = NULL;
char *ptr;
Expand Down Expand Up @@ -400,6 +402,7 @@ int update_version(const char *ver)

if (!retval) _fatal("Can't update product's installed version.");
return(retval);
#endif
} /* update_version */


Expand Down
2 changes: 1 addition & 1 deletion ui_carbon.c
Expand Up @@ -176,7 +176,7 @@ int manually_locate_product(const char *name, char *buf, size_t bufsize)
OSStatus rc;
int retval = 0;
int yn;
const char *promptfmt = "We can't find your \"%s\" installation."
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);

Expand Down

0 comments on commit dd20774

Please sign in to comment.