(svn r970) Added 2nd data path for all non-windows OSes
authorbjarni
Tue, 07 Dec 2004 17:16:57 +0000
changeset 561 9a0c469a251c
parent 560 60e198893a41
child 562 66cddf7eeb5f
(svn r970) Added 2nd data path for all non-windows OSes
added completely customizable lang path (all non-Windows OSes)
Makefile
fileio.c
makefiledir/Makefile.config_writer
ttd.c
unix.c
variables.h
--- a/Makefile	Mon Dec 06 00:03:26 2004 +0000
+++ b/Makefile	Tue Dec 07 17:16:57 2004 +0000
@@ -89,6 +89,10 @@
 #		stored. You cannot use ~ here, define USE_HOMEDIR for that.
 # USE_HOMEDIR:	If this variable is set, PERSONAL_DIR will be prefixed with
 #		~/ at runtime (the user's homedir)
+# SECOND_DATA_PATH  Use this data dir if a file is not found in the data dir in the data path
+# CUSTOM_LANG_PATH  If this is set, it will use the path given to search for lng files 
+#		instead of the lang dir in the data path
+#   NOTE: both SECOND_DATA_PATH and CUSTOM_LANG_PATH uses paths relative to where OTTD is opened
 #
 # DEST_DIR:	make install will use this directory instead of the filesystem
 # 		root to install its files. This should normally not be used by
@@ -113,7 +117,7 @@
 
 # Makefile version tag
 # it checks if the version tag in makefile.config is the same and force update outdated config files
-MAKEFILE_VERSION:=4
+MAKEFILE_VERSION:=5
 
 # CONFIG_WRITER have to be found even for manual configuration
 CONFIG_WRITER=makefiledir/Makefile.config_writer
@@ -444,6 +448,12 @@
 ifndef MIDI
 MIDI:=$(OSXAPP)/contents/macos/track_starter
 endif
+ifndef SECOND_DATA_PATH
+SECOND_DATA_PATH:="$(OSXAPP)/contents/data/"
+endif
+ifndef CUSTOM_LANG_DIR
+CUSTOM_LANG_DIR:="$(OSXAPP)/contents/lang/"
+endif
 endif
 
 ifdef MIDI
@@ -469,6 +479,15 @@
 endif
 endif
 
+
+ifdef SECOND_DATA_PATH
+CDEFS += -DSECOND_DATA_DIR=\"$(SECOND_DATA_PATH)/\"
+endif
+
+ifdef CUSTOM_LANG_DIR
+CDEFS += -DCUSTOM_LANG_DIR=\"$(CUSTOM_LANG_DIR)/\"
+endif
+
 ifdef WITH_DIRECTMUSIC
 CDEFS += -DWIN32_ENABLE_DIRECTMUSIC_SUPPORT
 endif
@@ -604,8 +623,11 @@
  		$(C_LINK) $@ $(TTDLDFLAGS) $(ttd_OBJS) $(LIBS) $(VERBOSE_FILTER)
 
 $(OSX):
+	@rm -fr $(OSXAPP)
 	@mkdir -p $(OSXAPP)/Contents/MacOS
 	@mkdir -p $(OSXAPP)/Contents/Resources
+	@mkdir -p $(OSXAPP)/Contents/Data
+	@mkdir -p $(OSXAPP)/Contents/Lang
 	@echo "APPL????" > $(OSXAPP)/Contents/PkgInfo
 	@cp os/macos/ttd.icns $(OSXAPP)/Contents/Resources/openttd.icns
 	@os/macos/plistgen.sh $(OSXAPP) $(REV)
@@ -613,7 +635,11 @@
 	@ls os/macos | grep -q "\.class" || \
 	javac os/macos/OpenTTDMidi.java
 	@cp os/macos/OpenTTDMidi.class $(OSXAPP)/contents/macos
+	@cp data/* $(OSXAPP)/Contents/data/
+	@cp lang/*.lng $(OSXAPP)/Contents/lang/
 	@cp $(TTD) $(OSXAPP)/Contents/MacOS/$(TTD)
+	
+	
 
 $(endwarnings): $(64_bit_warnings)
 
--- a/fileio.c	Mon Dec 06 00:03:26 2004 +0000
+++ b/fileio.c	Tue Dec 07 17:16:57 2004 +0000
@@ -110,6 +110,16 @@
 		for(s=buf + strlen(_path.data_dir) - 1; *s != 0; s++)
 			*s = tolower(*s);
 		f = fopen(buf, "rb");
+		
+#if defined SECOND_DATA_DIR
+	// tries in the 2nd data directory
+		if (f == NULL) {
+			sprintf(buf, "%s%s", _path.second_data_dir, filename);
+			for(s=buf + strlen(_path.second_data_dir) - 1; *s != 0; s++)
+			*s = tolower(*s);
+		f = fopen(buf, "rb");
+		}
+#endif
 	}
 #endif
 
--- a/makefiledir/Makefile.config_writer	Mon Dec 06 00:03:26 2004 +0000
+++ b/makefiledir/Makefile.config_writer	Tue Dec 07 17:16:57 2004 +0000
@@ -39,6 +39,8 @@
 	$(call CONFIG_LINE,DATA_DIR:=$(DATA_DIR))
 	$(call CONFIG_LINE,USE_HOMEDIR:=$(USE_HOMEDIR))
 	$(call CONFIG_LINE,PERSONAL_DIR:=$(PERSONAL_DIR))
+	$(call CONFIG_LINE,SECOND_DATA_PATH:=$(SECOND_DATA_PATH))
+	$(call CONFIG_LINE,CUSTOM_LANG_PATH:=$(CUSTOM_LANG_PATH))
 	$(call CONFIG_LINE,)
 	
 	$(call CONFIG_LINE,\# Experimental)
--- a/ttd.c	Mon Dec 06 00:03:26 2004 +0000
+++ b/ttd.c	Tue Dec 07 17:16:57 2004 +0000
@@ -496,8 +496,15 @@
 	// Generate a world.
 	sprintf(filename, "%sopntitle.dat",  _path.data_dir);
 	if (SaveOrLoad(filename, SL_LOAD) != SL_OK)
-		GenerateWorld(1); // if failed loading, make empty world.
-
+#if defined SECOND_DATA_DIR
+		{
+		sprintf(filename, "%sopntitle.dat",  _path.second_data_dir);
+		if (SaveOrLoad(filename, SL_LOAD) != SL_OK)
+#endif
+			GenerateWorld(1); // if failed loading, make empty world.
+#if defined SECOND_DATA_DIR
+		}
+#endif
 	_opt.currency = _new_opt.currency;
 
 	_pause = 0;
--- a/unix.c	Mon Dec 06 00:03:26 2004 +0000
+++ b/unix.c	Tue Dec 07 17:16:57 2004 +0000
@@ -424,7 +424,7 @@
 	// this creates an error in the console and then opens the console.
 	// Colourcodes are not used in the console, so they are skipped here
 	fprintf(stderr, "Error: %s", buf);
-	system("/Applications/Utilities/Console.app/Contents/MacOS/Console");
+	system("/Applications/Utilities/Console.app/Contents/MacOS/Console &");
 #else
 	// all systems, but OSX
 	fprintf(stderr, "\033[1;31mError: %s\033[0;39m\n", buf);
@@ -452,7 +452,11 @@
 	char *s;
 
 	_path.game_data_dir = malloc( MAX_PATH );
-	strcpy(_path.game_data_dir, GAME_DATA_DIR);
+	ttd_strlcpy(_path.game_data_dir, GAME_DATA_DIR, MAX_PATH);
+	#if defined SECOND_DATA_DIR
+	_path.second_data_dir = malloc( MAX_PATH );
+	ttd_strlcpy( _path.second_data_dir, SECOND_DATA_DIR, MAX_PATH);
+	#endif
 
 #if defined(USE_HOMEDIR)
 	{
@@ -470,7 +474,7 @@
 #else /* not defined(USE_HOMEDIR) */
 
 	_path.personal_dir = malloc( MAX_PATH );
-	strcpy(_path.personal_dir, PERSONAL_DIR);
+	ttd_strlcpy(_path.personal_dir, PERSONAL_DIR, MAX_PATH);
 
 	// check if absolute or relative path
 	s = strchr(_path.personal_dir, '/');
@@ -480,7 +484,7 @@
 		getcwd(_path.personal_dir, MAX_PATH);
 		s = strchr(_path.personal_dir, 0);
 		*s++ = '/';
-		strcpy(s, PERSONAL_DIR);
+		ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH);
 	}
 
 #endif /* defined(USE_HOMEDIR) */
@@ -495,9 +499,15 @@
 	_path.scenario_dir = str_fmt("%sscenario", _path.personal_dir);
 	_path.gm_dir = str_fmt("%sgm/", _path.game_data_dir);
 	_path.data_dir = str_fmt("%sdata/", _path.game_data_dir);
+	_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir);
+	
+#if defined CUSTOM_LANG_DIR
+	// sets the search path for lng files to the custom one
+	_path.lang_dir = malloc( MAX_PATH );
+	ttd_strlcpy( _path.lang_dir, CUSTOM_LANG_DIR, MAX_PATH);
+#else
 	_path.lang_dir = str_fmt("%slang/", _path.game_data_dir);
-
-	_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir);
+#endif
 
 	// create necessary folders
 	mkdir(_path.personal_dir, 0755);
--- a/variables.h	Mon Dec 06 00:03:26 2004 +0000
+++ b/variables.h	Tue Dec 07 17:16:57 2004 +0000
@@ -199,6 +199,7 @@
 	char *save_dir;
 	char *autosave_dir;
 	char *scenario_dir;
+	char *second_data_dir;
 } Paths;
 
 VARDEF Paths _path;