summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2011-01-27 20:38:07 -0600
committerDavid Athay <ko2fan@gmail.com>2011-01-27 20:38:07 -0600
commit66bd56ebec2bff48fb1484603b41643fd89bf4d6 (patch)
tree0136c1e0d1381d400897227d812cfa160e7d28b1
parente5ecfdfd67b806c76cbcc57f0df8e2ddda75ac2e (diff)
downloadmana-66bd56ebec2bff48fb1484603b41643fd89bf4d6.tar.gz
mana-66bd56ebec2bff48fb1484603b41643fd89bf4d6.tar.bz2
mana-66bd56ebec2bff48fb1484603b41643fd89bf4d6.tar.xz
mana-66bd56ebec2bff48fb1484603b41643fd89bf4d6.zip
Moved bundle resource path to Cocoa. Moved alert to Cocoa. Added changing dock icon at runtime.
-rw-r--r--src/bundle.h11
-rw-r--r--src/bundle.mm36
-rw-r--r--src/client.cpp59
-rw-r--r--src/log.cpp8
-rw-r--r--src/window.h10
-rw-r--r--src/window.mm26
6 files changed, 118 insertions, 32 deletions
diff --git a/src/bundle.h b/src/bundle.h
new file mode 100644
index 00000000..3231988c
--- /dev/null
+++ b/src/bundle.h
@@ -0,0 +1,11 @@
+//
+// bundle.h
+// themanaworld
+//
+// Created by David Athay on 1/27/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#include <string>
+
+std::string getBundleResourcesPath();
diff --git a/src/bundle.mm b/src/bundle.mm
new file mode 100644
index 00000000..424e35f8
--- /dev/null
+++ b/src/bundle.mm
@@ -0,0 +1,36 @@
+//
+// bundle.m
+// themanaworld
+//
+// Created by David Athay on 1/27/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "bundle.h"
+#import <Cocoa/Cocoa.h>
+
+std::string getBundleResourcesPath()
+{
+ std::string resPath;
+ NSBundle *mainBundle;
+
+ // Get the main bundle for the app.
+ mainBundle = [NSBundle mainBundle];
+
+ NSString *bundlePath = [mainBundle bundlePath];
+ NSArray *bundlePathArray = [[NSFileManager defaultManager] directoryContentsAtPath:bundlePath];
+ // check it contains the right directories
+ if ((nil != bundlePathArray) && ([bundlePathArray containsObject:@"Contents"]))
+ {
+ NSString *contentsPath = [bundlePath stringByAppendingPathComponent:@"Contents"];
+ NSArray *contentsPathArray = [[NSFileManager defaultManager] directoryContentsAtPath:contentsPath];
+ if ((nil != contentsPath) && ([contentsPathArray containsObject:@"MacOS"]) && ([contentsPathArray containsObject:@"Resources"]))
+ {
+ // get the final path of the resources
+ NSString *finalResourcesPath = [contentsPath stringByAppendingPathComponent:@"Resources"];
+ resPath = [finalResourcesPath UTF8String];
+ }
+ }
+
+ return resPath;
+} \ No newline at end of file
diff --git a/src/client.cpp b/src/client.cpp
index b57c3ae8..42a8465b 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -77,7 +77,8 @@
#include "utils/stringutils.h"
#ifdef __APPLE__
-#include <CoreFoundation/CFBundle.h>
+#include "window.h"
+#include "bundle.h"
#endif
#include <physfs.h>
@@ -211,16 +212,35 @@ Client::Client(const Options &options):
mInstance = this;
logger = new Logger;
+
+ ResourceManager *resman = ResourceManager::getInstance();
+
+#if defined __APPLE__
+ std::string path;
+ path = getBundleResourcesPath();
+ path.append("/data");
+ resman->addToSearchPath(path.c_str(), false);
+ mPackageDir = path;
+#else
+ resman->addToSearchPath(PKG_DATADIR "data", false);
+ mPackageDir = PKG_DATADIR "data";
+#endif
// Load branding information
if (!options.brandingPath.empty())
{
- branding.init(options.brandingPath);
+ branding.init(options.brandingPath, true);
}
-
+
initRootDir();
initHomeDir();
initConfiguration();
+
+ if (!resman->setWriteDir(mLocalDataDir))
+ {
+ logger->error(strprintf("%s couldn't be set as home directory! "
+ "Exiting.", mLocalDataDir.c_str()));
+ }
// Configure logger
logger->setLogFile(mLocalDataDir + std::string("/mana.log"));
@@ -245,34 +265,8 @@ Client::Client(const Options &options):
SDL_WM_SetCaption(branding.getValue("appName", "Mana").c_str(), NULL);
- ResourceManager *resman = ResourceManager::getInstance();
-
- if (!resman->setWriteDir(mLocalDataDir))
- {
- logger->error(strprintf("%s couldn't be set as home directory! "
- "Exiting.", mLocalDataDir.c_str()));
- }
-
Image::SDLsetEnableAlphaCache(config.getValue("alphaCache", true));
-#if defined __APPLE__
- CFBundleRef mainBundle = CFBundleGetMainBundle();
- CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
- char path[PATH_MAX];
- if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path,
- PATH_MAX))
- {
- fprintf(stderr, "Can't find Resources directory\n");
- }
- CFRelease(resourcesURL);
- strncat(path, "/data", PATH_MAX - 1);
- resman->addToSearchPath(path, false);
- mPackageDir = path;
-#else
- resman->addToSearchPath(PKG_DATADIR "data", false);
- mPackageDir = PKG_DATADIR "data";
-#endif
-
resman->addToSearchPath("data", false);
// Add branding/data to PhysFS search path
@@ -302,10 +296,15 @@ Client::Client(const Options &options):
std::string iconFile = branding.getValue("appIcon", "icons/mana");
#ifdef WIN32
iconFile += ".ico";
+#elif defined (__APPLE__)
+ // MacOSX expects just the filename without extension
+ iconFile = iconFile.substr(iconFile.find_last_of("/")+1);
#else
iconFile += ".png";
#endif
+#ifndef __APPLE__
iconFile = resman->getPath(iconFile);
+#endif
logger->log("Loading icon from file: %s", iconFile.c_str());
#ifdef WIN32
static SDL_SysWMinfo pInfo;
@@ -320,6 +319,8 @@ Client::Client(const Options &options):
if (icon)
SetClassLong(pInfo.window, GCL_HICON, (LONG) icon);
+#elif defined(__APPLE__)
+ setIcon(iconFile.c_str());
#else
mIcon = IMG_Load(iconFile.c_str());
if (mIcon)
diff --git a/src/log.cpp b/src/log.cpp
index 5880e108..acb9f67c 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -26,7 +26,8 @@
#ifdef WIN32
#include <windows.h>
#elif __APPLE__
-#include <Carbon/Carbon.h>
+//#include <Carbon/Carbon.h>
+#include "window.h"
#endif
#include <sys/time.h>
@@ -114,7 +115,7 @@ void Logger::error(const std::string &error_text)
#ifdef WIN32
MessageBox(NULL, error_text.c_str(), "Error", MB_ICONERROR | MB_OK);
#elif defined __APPLE__
- Str255 msg;
+ /*Str255 msg;
CFStringRef error;
error = CFStringCreateWithCString(NULL,
error_text.c_str(),
@@ -122,7 +123,8 @@ void Logger::error(const std::string &error_text)
CFStringGetPascalString(error, msg, 255, kCFStringEncodingMacRoman);
StandardAlert(kAlertStopAlert,
"\pError",
- (ConstStr255Param) msg, NULL, NULL);
+ (ConstStr255Param) msg, NULL, NULL);*/
+ windowAlert(error_text.c_str());
#elif defined __linux__ || __linux
std::cerr << "Error: " << error_text << std::endl;
std::string msg="xmessage \"" + error_text + "\"";
diff --git a/src/window.h b/src/window.h
new file mode 100644
index 00000000..482f65ee
--- /dev/null
+++ b/src/window.h
@@ -0,0 +1,10 @@
+//
+// window.h
+// themanaworld
+//
+// Created by David Athay on 1/27/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+void setIcon(const char *icon);
+void windowAlert(const char *msg); \ No newline at end of file
diff --git a/src/window.mm b/src/window.mm
new file mode 100644
index 00000000..f631f17d
--- /dev/null
+++ b/src/window.mm
@@ -0,0 +1,26 @@
+//
+// window.m
+// themanaworld
+//
+// Created by David Athay on 1/27/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "window.h"
+#import <Cocoa/Cocoa.h>
+
+void setIcon(const char *icon)
+{
+ NSString *path = [NSString stringWithCString:icon
+ encoding:[NSString defaultCStringEncoding]];
+ NSString *imageName = [[NSBundle mainBundle] pathForResource:path ofType:@"icns" inDirectory:@"data/icons"];
+ NSImage *iconImage = [[NSImage alloc] initWithContentsOfFile:imageName];
+ [NSApp setApplicationIconImage: iconImage];
+}
+
+void windowAlert(const char *msg)
+{
+ NSString *alertText = [NSString stringWithCString:msg
+ encoding:[NSString defaultCStringEncoding]];
+ NSRunAlertPanel(nil, alertText , @"OK", nil, nil);
+} \ No newline at end of file