Add HomeDir function
This commit is contained in:
parent
4ae938ada9
commit
4f1b3206c5
6 changed files with 92 additions and 21 deletions
|
@ -6,8 +6,9 @@ void android_main(struct android_app *app) {
|
|||
androidMain(app);
|
||||
}
|
||||
|
||||
void init_asset_manager(void *state) {
|
||||
void android_init(void *state) {
|
||||
struct android_app *app;
|
||||
app = (struct android_app *)state;
|
||||
asset_manager = app->activity->assetManager;
|
||||
internal_storage_path = app->activity->internalDataPath;
|
||||
}
|
||||
|
|
|
@ -8,9 +8,10 @@ package raylib
|
|||
#include <android_native_app_glue.h>
|
||||
|
||||
extern void android_main(struct android_app *app);
|
||||
extern void android_init(void *state);
|
||||
|
||||
AAssetManager* asset_manager;
|
||||
extern void init_asset_manager(void *state);
|
||||
const char* internal_storage_path;
|
||||
*/
|
||||
import "C"
|
||||
|
||||
|
@ -31,7 +32,7 @@ func InitWindow(width int32, height int32, t interface{}) {
|
|||
app, ok := t.(unsafe.Pointer)
|
||||
if ok {
|
||||
C.InitWindow(cwidth, cheight, app)
|
||||
C.init_asset_manager(app)
|
||||
C.android_init(app)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// +build !android
|
||||
// +build !android,!windows
|
||||
|
||||
package raylib
|
||||
|
||||
|
@ -38,3 +38,8 @@ func TraceLog(msgType int, text string, v ...interface{}) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HomeDir returns user home directory
|
||||
func HomeDir() string {
|
||||
return os.Getenv("HOME")
|
||||
}
|
||||
|
|
24
raylib/utils_android.c
Normal file
24
raylib/utils_android.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
// +build android
|
||||
|
||||
#include "_cgo_export.h"
|
||||
#include <android/log.h>
|
||||
|
||||
void log_info(const char *msg) {
|
||||
__android_log_print(ANDROID_LOG_INFO, "raylib", msg);
|
||||
}
|
||||
|
||||
void log_warn(const char *msg) {
|
||||
__android_log_print(ANDROID_LOG_WARN, "raylib", msg);
|
||||
}
|
||||
|
||||
void log_error(const char *msg) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "raylib", msg);
|
||||
}
|
||||
|
||||
void log_debug(const char *msg) {
|
||||
__android_log_print(ANDROID_LOG_DEBUG, "raylib", msg);
|
||||
}
|
||||
|
||||
const char* get_internal_storage_path() {
|
||||
return internal_storage_path;
|
||||
}
|
|
@ -3,29 +3,14 @@
|
|||
package raylib
|
||||
|
||||
/*
|
||||
#include <android/log.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void log_info(const char *msg) {
|
||||
__android_log_print(ANDROID_LOG_INFO, "raylib", msg);
|
||||
}
|
||||
|
||||
void log_warn(const char *msg) {
|
||||
__android_log_print(ANDROID_LOG_WARN, "raylib", msg);
|
||||
}
|
||||
|
||||
void log_error(const char *msg) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "raylib", msg);
|
||||
}
|
||||
|
||||
void log_debug(const char *msg) {
|
||||
__android_log_print(ANDROID_LOG_DEBUG, "raylib", msg);
|
||||
}
|
||||
|
||||
void log_info(const char *msg);
|
||||
void log_warn(const char *msg);
|
||||
void log_error(const char *msg);
|
||||
void log_debug(const char *msg);
|
||||
|
||||
extern char* get_internal_storage_path();
|
||||
*/
|
||||
import "C"
|
||||
|
||||
|
@ -74,3 +59,9 @@ func TraceLog(msgType int, text string, v ...interface{}) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HomeDir returns user home directory
|
||||
// NOTE: On Android this returns internal data path and must be called after InitWindow
|
||||
func HomeDir() string {
|
||||
return C.GoString(C.get_internal_storage_path())
|
||||
}
|
||||
|
|
49
raylib/utils_windows.go
Normal file
49
raylib/utils_windows.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
// +build windows
|
||||
|
||||
package raylib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Log message types
|
||||
const (
|
||||
LogInfo = iota
|
||||
LogError
|
||||
LogWarning
|
||||
LogDebug
|
||||
)
|
||||
|
||||
var traceDebugMsgs = false
|
||||
|
||||
// Set debug messages
|
||||
func SetDebug(enabled bool) {
|
||||
traceDebugMsgs = enabled
|
||||
}
|
||||
|
||||
// Trace log
|
||||
func TraceLog(msgType int, text string, v ...interface{}) {
|
||||
switch msgType {
|
||||
case LogInfo:
|
||||
fmt.Printf("INFO: "+text+"\n", v...)
|
||||
case LogError:
|
||||
fmt.Printf("ERROR: "+text+"\n", v...)
|
||||
os.Exit(1)
|
||||
case LogWarning:
|
||||
fmt.Printf("WARNING: "+text+"\n", v...)
|
||||
case LogDebug:
|
||||
if traceDebugMsgs {
|
||||
fmt.Printf("DEBUG: "+text+"\n", v...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HomeDir returns user home directory
|
||||
func HomeDir() string {
|
||||
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
|
||||
if home == "" {
|
||||
home = os.Getenv("USERPROFILE")
|
||||
}
|
||||
return home
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue