mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 18:03:56 -04:00
use ~/Library/Caches/Panda3D on Mac, ~/Panda3D on Linux
This commit is contained in:
parent
8987a19ba2
commit
54e34d4672
@ -33,6 +33,7 @@
|
|||||||
#define SOURCES \
|
#define SOURCES \
|
||||||
fileSpec.cxx fileSpec.h fileSpec.I \
|
fileSpec.cxx fileSpec.h fileSpec.I \
|
||||||
find_root_dir.cxx find_root_dir.h \
|
find_root_dir.cxx find_root_dir.h \
|
||||||
|
$[if $[IS_OSX],find_root_dir_assist.mm] \
|
||||||
get_tinyxml.h \
|
get_tinyxml.h \
|
||||||
binaryXml.cxx binaryXml.h \
|
binaryXml.cxx binaryXml.h \
|
||||||
fhandle.h \
|
fhandle.h \
|
||||||
@ -149,6 +150,7 @@
|
|||||||
load_plugin.cxx load_plugin.h \
|
load_plugin.cxx load_plugin.h \
|
||||||
fileSpec.cxx fileSpec.h fileSpec.I \
|
fileSpec.cxx fileSpec.h fileSpec.I \
|
||||||
find_root_dir.cxx find_root_dir.h \
|
find_root_dir.cxx find_root_dir.h \
|
||||||
|
$[if $[IS_OSX],find_root_dir_assist.mm] \
|
||||||
is_pathsep.h is_pathsep.I \
|
is_pathsep.h is_pathsep.I \
|
||||||
mkdir_complete.cxx mkdir_complete.h
|
mkdir_complete.cxx mkdir_complete.h
|
||||||
|
|
||||||
|
@ -241,8 +241,15 @@ find_root_dir() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
// e.g., /Users/<username>/Library/Caches/Panda3D
|
||||||
|
string root = find_osx_root_dir();
|
||||||
|
if (!root.empty()) {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
#else // _WIN32
|
#else // _WIN32
|
||||||
// e.g., /home/<username>/.panda3d
|
// e.g., /home/<username>/Panda3D
|
||||||
|
|
||||||
string root;
|
string root;
|
||||||
const char *uname = getlogin();
|
const char *uname = getlogin();
|
||||||
@ -255,7 +262,7 @@ find_root_dir() {
|
|||||||
root = pwdata->pw_dir;
|
root = pwdata->pw_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
root += "/.panda3d";
|
root += "/Panda3D";
|
||||||
if (mkdir(root.c_str(), 0700) == 0 || errno == EEXIST) {
|
if (mkdir(root.c_str(), 0700) == 0 || errno == EEXIST) {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
@ -21,4 +21,8 @@ using namespace std;
|
|||||||
|
|
||||||
string find_root_dir();
|
string find_root_dir();
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
string find_osx_root_dir();
|
||||||
|
#endif // __APPLE__
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
92
direct/src/plugin/find_root_dir_assist.mm
Normal file
92
direct/src/plugin/find_root_dir_assist.mm
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// Filename: filename_assist.mm
|
||||||
|
// Created by: drose (13Apr09)
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PANDA 3D SOFTWARE
|
||||||
|
// Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||||
|
//
|
||||||
|
// All use of this software is subject to the terms of the revised BSD
|
||||||
|
// license. You should have received a copy of this license along
|
||||||
|
// with this source code in a file named "LICENSE."
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "find_root_dir.h"
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
|
||||||
|
#include <Foundation/Foundation.h>
|
||||||
|
#include <AppKit/AppKit.h>
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: NSString_to_cpp_string
|
||||||
|
// Description: Copy the Objective-C string to a C++ string.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
static string
|
||||||
|
NSString_to_cpp_string(NSString *str) {
|
||||||
|
size_t length = [str length];
|
||||||
|
string result;
|
||||||
|
for (size_t i = 0; i < length; ++i) {
|
||||||
|
result += (char)[str characterAtIndex: i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: call_NSSearchPathForDirectories
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
static string
|
||||||
|
call_NSSearchPathForDirectories(NSSearchPathDirectory dirkey, NSSearchPathDomainMask domain) {
|
||||||
|
// Ensure that Carbon has been initialized, and that we have an
|
||||||
|
// auto-release pool.
|
||||||
|
NSApplicationLoad();
|
||||||
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(dirkey, domain, YES);
|
||||||
|
string result;
|
||||||
|
if ([paths count] != 0) {
|
||||||
|
result = NSString_to_cpp_string([paths objectAtIndex:0]);
|
||||||
|
}
|
||||||
|
[pool release];
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: get_osx_home_directory
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
static string
|
||||||
|
get_osx_home_directory() {
|
||||||
|
NSApplicationLoad();
|
||||||
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
|
NSString *dir = NSHomeDirectory();
|
||||||
|
string result = NSString_to_cpp_string(dir);
|
||||||
|
[pool release];
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: find_osx_root_dir
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
string
|
||||||
|
find_osx_root_dir() {
|
||||||
|
string result = call_NSSearchPathForDirectories(NSCachesDirectory, NSUserDomainMask);
|
||||||
|
if (!result.empty()) {
|
||||||
|
return result + "/Panda3D";
|
||||||
|
}
|
||||||
|
result = get_osx_home_directory();
|
||||||
|
if (!result.empty()) {
|
||||||
|
return result + "/Panda3D";
|
||||||
|
}
|
||||||
|
|
||||||
|
return string();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // __APPLE__
|
Loading…
x
Reference in New Issue
Block a user