git @ Cat's Eye Technologies linapple / 842441d
Load bmp files and Master.dsk from "proper" dir It's customary on Windows to load asset files from the same directory as the executable, but this is not normal for an installed Linux program. We now try to load the asset files from ${PREFIX}/share/linapple/ first and fall back on SDL_GetBasePath() if that doesn't work. The former can be overridden by changing ASSET_DIR when compiling. For now both ASSET_DIR at compile time and SDL_GetBasePath at runtime have fallbacks on ./ if they're not provided. When we autoconf this mess, the fallback for failure to define ASSET_DIR may go away. Currently none of these allow SDL_GetPrefPath() to override them. They all could. Do we want that? At this point the only file still handled by existing code is the registry file. I need some help with deciding how we should handle that. Mostly it's complicated by the fact that the registry file includes its own documentation. If it were a simple ini file with documentation in a text document or manpage or something, it'd be real easy: All values would have defaults, the file we put in /etc would list all of those default values and allow the sysadmin to override the defaults, and we'd allow a user registry file to override those. Not so easy with the docs in the monolithic file not set up for override. T. Joseph Carter 3 years ago
4 changed file(s) with 81 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
44
55 # Where does this get installed
66 PREFIX := /usr/local
7 ASSET_DIR := $(PREFIX)/share/$(PACKAGE)
78
89 #Compiler and Linker
910 CC := g++
2122 DEPEXT := d
2223 OBJEXT := o
2324
25 # FIXME: Make this go away!
2426 INSTDIR := $(PREFIX)/lib/$(PACKAGE)
2527
2628 #Flags, Libraries and Includes
3941 #DEBUGGING
4042 #CFLAGS := -Wall -O0 -ggdb -ansi -c -finstrument-functions
4143 #OPTIMIZED
42 CFLAGS := -Wall -O3 -ansi -c
44 CFLAGS := -Wall -O3 -ansi -c -DASSET_DIR=\"$(ASSET_DIR)\"
4345 CFLAGS += $(SDL_CFLAGS)
4446 CFLAGS += $(CURL_CFLAGS)
4547
9496 @echo
9597 @echo "`tput bold`o Copying binary to install directory '$(INSTDIR)'`tput sgr0`"
9698 # This should be able to live in $(PREFIX)/bin directly, symlink for now
97 install -m 755 -o root -g root "$(TARGETDIR)/$(TARGET)" "$(INSTDIR)"
99 install -m 755 -o root -g root "$(TARGETDIR)/$(TARGET)" "$(INSTDIR)/$(TARGET)"
98100 # We'll use a symlink until then
99101 if [ -L "$(PREFIX)/bin/$(TARGET)" ]; then \
100102 rm -f "$(PREFIX)/bin/$(TARGET)" ;\
102104 ln -s $(INSTDIR)/$(TARGET) $(PREFIX)/bin/$(TARGET)
103105
104106 @echo
105 @echo "`tput bold`o Copying assets to install directory '$(INSTDIR)'`tput sgr0`"
106 # These properly belong in $(PREFIX)/share…
107 @echo "`tput bold`o Copying assets to '$(ASSET_DIR)'`tput sgr0`"
108 install -d -m 755 -o root -g root "$(ASSET_DIR)"
107109 for file in $(INSTASSETS); do \
108 install -m 644 -o root -g root "$(RESDIR)/$$file" "$(INSTDIR)" ;\
110 install -m 644 -o root -g root "$(RESDIR)/$$file" "$(ASSET_DIR)/$$file" ;\
109111 done
110112
111113 @echo
112114 @echo "`tput bold`o Copying docs to install directory '$(INSTDIR)'`tput sgr0`"
113115 # This belongs in $(PREFIX)/etc or /etc
114116 for file in $(CONFFILES); do \
115 install -m 644 -o root -g root "$(RESDIR)/$$file" "$(INSTDIR)" ;\
117 install -m 644 -o root -g root "$(RESDIR)/$$file" "$(INSTDIR)/$$file" ;\
116118 done
117119
118120 uninstall:
121123 for file in $(TARGET) $(INSTASSETS) $(CONFFILES); do \
122124 rm -f "$(INSTDIR)/$$file" ;\
123125 done
124 # It's okay if this fails (examine $(INSTDIR) yourself)
126 for file in $(INSTASSETS); do \
127 rm -f "$(ASSET_DIR)/$$file" ;\
128 done
129 # It's okay if these fail (examine the directories yourself)
125130 rmdir $(INSTDIR) 2>/dev/null || true
131 rmdir $(ASSET_DIR) 2>/dev/null || true
126132 # Don't forget the linapple symlink in $(PREFIX)/bin
127133 rm -f "$(PREFIX)/bin/$(TARGET)"
128134
2020 #define __asset_h
2121
2222 typedef struct {
23 char *basepath;
2423 SDL_Surface *icon;
2524 SDL_Surface *font;
2625 SDL_Surface *charset40;
3130
3231 bool Asset_Init(void);
3332 void Asset_Quit(void);
33 int Asset_InsertMasterDisk(void);
3434
3535 #endif // __asset_h
552552 SetDiskImageDirectory(szDiskImage1, 1);
553553 }
554554 else {
555 #define MASTER_DISK "Master.dsk"
556 static char szMasterDisk[] = MASTER_DISK;
557 DoDiskInsert(0, szMasterDisk);
555 Asset_InsertMasterDisk();
558556 }
559557
560558 // Load hard disk images and insert it automatically in slot 7
2121 #include <SDL.h>
2222
2323 #include "asset.h"
24 #include "stdafx.h" // for Disk.h DiskInsert()
2425 #include "shim.h" // SDL_GetBasePath()
2526
2627 #define ASSET_ICON_BMP "icon.bmp"
2728 #define ASSET_SPLASH_BMP "splash.bmp"
2829 #define ASSET_CHARSET40_BMP "charset40.bmp"
2930 #define ASSET_FONT_BMP "font.bmp"
31 #define ASSET_MASTER_DSK "Master.dsk"
3032
3133 assets_t *assets = NULL;
3234
35 #ifdef ASSET_DIR
36 static char system_assets[] = ASSET_DIR "/";
37 #else
38 static char system_assets[] = "./"
39 #endif
40 static char *system_exedir = NULL;
41
42 SDL_Surface *Asset_LoadBMP(const char *filename)
43 {
44 SDL_Surface *surf;
45 char *path = (char *)SDL_malloc(sizeof(char[PATH_MAX]));
46 if (NULL == path) {
47 fprintf(stderr, "Asset_Init: Allocating path: %s\n", SDL_GetError());
48 return NULL;
49 }
50
51 snprintf(path, PATH_MAX, "%s%s", system_assets, filename);
52 surf = SDL_LoadBMP(path);
53 if (NULL == surf) {
54 snprintf(path, PATH_MAX, "%s%s", system_exedir, filename);
55 surf = SDL_LoadBMP(path);
56 if (NULL == surf) {
57 fprintf(stderr, "Asset_LoadBMP: Couldn't load %s in either %s or %s!\n",
58 filename, system_assets, system_exedir);
59 }
60 }
61
62 SDL_free(path);
63 return surf;
64 }
65
3366 bool Asset_Init(void)
3467 {
68 system_exedir = SDL_GetBasePath();
69 if (NULL == system_exedir) {
70 fprintf(stderr, "Asset_Init: Warning: SDL_GetBasePath() returned NULL, using \"./\"\n");
71 system_exedir = SDL_strdup("./");
72 }
73
3574 assets = (assets_t *)SDL_calloc(1, sizeof(assets_t));
3675 if (NULL == assets) {
3776 fprintf(stderr, "Asset_Init: Allocating assets: %s\n", SDL_GetError());
3877 return false;
3978 }
4079
41 char *path = (char *)SDL_malloc(sizeof(char[PATH_MAX]));
42 if (NULL == path) {
43 fprintf(stderr, "Asset_Init: Allocating path: %s\n", SDL_GetError());
80 assets->icon = Asset_LoadBMP(ASSET_ICON_BMP);
81 if (NULL == assets->icon) {
4482 return false;
4583 }
4684
47 assets->basepath = SDL_GetBasePath();
48 if (NULL == assets->basepath) {
49 fprintf(stderr, "Asset_Init: Warning: SDL_GetBasePath() returned NULL, using \"./\"\n");
50 assets->basepath = SDL_strdup("./");
51 }
52
53 snprintf(path, PATH_MAX, "%s%s", assets->basepath, ASSET_ICON_BMP);
54 assets->icon = SDL_LoadBMP(path);
55 if (NULL == assets->icon) {
56 fprintf(stderr, "Error loading required asset: %s\n", SDL_GetError());
85 assets->font = Asset_LoadBMP(ASSET_FONT_BMP);
86 if (NULL == assets->font) {
5787 return false;
5888 }
5989
60 snprintf(path, PATH_MAX, "%s%s", assets->basepath, ASSET_FONT_BMP);
61 assets->font = SDL_LoadBMP(path);
62 if (NULL == assets->font) {
63 fprintf(stderr, "Error loading required asset: %s\n", SDL_GetError());
90 assets->charset40 = Asset_LoadBMP(ASSET_CHARSET40_BMP);
91 if (NULL == assets->charset40) {
6492 return false;
6593 }
6694
67 snprintf(path, PATH_MAX, "%s%s", assets->basepath, ASSET_CHARSET40_BMP);
68 assets->charset40 = SDL_LoadBMP(path);
69 if (NULL == assets->charset40) {
70 fprintf(stderr, "Error loading required asset: %s\n", SDL_GetError());
95 assets->splash = Asset_LoadBMP(ASSET_SPLASH_BMP);
96 if (NULL == assets->splash) {
7197 return false;
7298 }
7399
74 snprintf(path, PATH_MAX, "%s%s", assets->basepath, ASSET_SPLASH_BMP);
75 assets->splash = SDL_LoadBMP(path);
76 if (NULL == assets->splash) {
77 fprintf(stderr, "Error loading required asset: %s\n", SDL_GetError());
78 return false;
79 }
80
81 free(path);
82100 return true;
83101 }
84102
105123 assets->splash = NULL;
106124 }
107125
108 if (NULL != assets->basepath) {
109 SDL_free(assets->basepath);
110 assets->basepath = NULL;
126 if (NULL != system_exedir) {
127 SDL_free(system_exedir);
128 system_exedir = NULL;
111129 }
112130
113131 SDL_free(assets);
114132 }
115133 }
134
135 // FIXME: How this is done is currently kinda screwed up. Refactor
136 int Asset_InsertMasterDisk(void)
137 {
138 int rc;
139 char *path = (char *)SDL_malloc(sizeof(char[PATH_MAX]));
140 snprintf(path, PATH_MAX, "%s%s", system_assets, ASSET_MASTER_DSK);
141 rc = DiskInsert(0, path, 0, 0);
142 if (IMAGE_ERROR_UNABLE_TO_OPEN == rc) {
143 snprintf(path, PATH_MAX, "%s%s", system_exedir, ASSET_MASTER_DSK);
144 rc = DiskInsert(0, path, 0, 0);
145 }
146
147 SDL_free(path);
148 return 0;
149 }