Skip to content

Commit

Permalink
Revert "Introduce App Directory Path (#572)"
Browse files Browse the repository at this point in the history
This reverts commit 7710d91.
  • Loading branch information
briaguya-ai authored Jul 14, 2022
1 parent a91ad6f commit b84d742
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 186 deletions.
5 changes: 2 additions & 3 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ make setup -j8 DEBUG=0
# Compile the code (watch the -j parameter as above)
make -j8 DEBUG=0
# Create macOS app bundle
make appbundle
make filledappbundle
```
9. Copy your OTR file to ~/Library/Application\ Support/com.shipofharkinian.soh
10. Launch soh app in the soh folder!
9. Launch soh app in the soh folder!

# Compatible Roms
```
Expand Down
2 changes: 1 addition & 1 deletion ZAPDTR/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ LDFLAGS := -lm -ldl \
-L../StormLib/build -L../libultraship -lbz2 -pthread -lultraship -lstorm

ifeq ($(UNAME), Darwin)
LDFLAGS += $(shell pkg-config --libs glew libpng zlib) $(shell sdl2-config --libs) -framework OpenGL -framework Foundation
LDFLAGS += $(shell pkg-config --libs glew libpng zlib) $(shell sdl2-config --libs) -framework OpenGL
INC += $(shell pkg-config --cflags libpng)
else
LDFLAGS += -lpng -lGL -lGLEW -lX11 -lz -lSDL2 -lpulse
Expand Down
37 changes: 7 additions & 30 deletions libultraship/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

CXX ?= g++
CC ?= gcc
AR := ar
AR := ar
FORMAT := clang-format-11
UNAME := $(shell uname)

Expand All @@ -11,15 +11,6 @@ DEBUG ?= 1
OPTFLAGS ?= -O0
LTO ?= 0

# flag to save whether the compiler being used is clang or gcc by checking CXX --version
CXX_IS_CLANG ?= $(shell $(CXX) --version | grep -c clang)
ifeq ($(CXX_IS_CLANG),1)
MXX := $(CXX)
else
MXX ?= clang++
endif


WARN := -Wall -Wextra -Werror \
-Wno-unused-variable \
-Wno-unused-parameter \
Expand All @@ -38,7 +29,8 @@ WARN := -Wall -Wextra -Werror \
CWARN :=
CXXWARN := -Wno-deprecated-enum-enum-conversion -Wno-deprecated-copy

ifneq ($(CXX_IS_CLANG),1)
COMPILER_VERSION := $(shell $(CXX) --version)
ifneq '' '$(findstring g++,$(COMPILER_VERSION))'
WARN += -Wno-error=stringop-overflow
CXXWARN += -Wno-error=maybe-uninitialized
endif
Expand All @@ -47,17 +39,12 @@ CXXFLAGS := $(WARN) $(CXXWARN) -std=c++20 -D_GNU_SOURCE -DENABLE_OPENGL -DSPDLOG
CFLAGS := $(WARN) $(CWARN) -std=c99 -D_GNU_SOURCE -DENABLE_OPENGL -DSPDLOG_ACTIVE_LEVEL=0
CPPFLAGS := -MMD

MMFLAGS := -Wno-deprecated-declarations -ObjC++ -fobjc-weak -fobjc-arc

# if not using clang, ask clang to use gcc standard library
ifneq ($(CXX_IS_CLANG),1)
STD_ISYSTEM=$(shell ${CXX} -xc++ -E -v - < /dev/null 2>&1 | grep "> search starts here" -A2 | tail -n 2 | head -n 1)
CXX_ISYSTEM=$(shell ${CXX} -xc++ -E -v - < /dev/null 2>&1 | grep "> search starts here" -A2 | tail -n 2 | tail -n 1)
MMFLAGS += -stdlib++-isystem ${STD_ISYSTEM} -cxx-isystem ${CXX_ISYSTEM}
ifeq ($(UNAME), Darwin) #APPLE
CPPFLAGS += $(shell pkg-config --cflags sdl2 glew) -framework OpenGL
endif

ifeq ($(UNAME), Darwin) #APPLE
CPPFLAGS += $(shell pkg-config --cflags sdl2 glew) -framework OpenGL -framework Foundation
ifeq ($(UNAME), Linux)
WARN += -Wno-error=stringop-overflow # This is required with clang on Linux.
endif

ifneq ($(DEBUG),0)
Expand Down Expand Up @@ -91,19 +78,12 @@ C_FILES := \
libultraship/mixer.c \
libultraship/Lib/stb/stb_impl.c

MM_FILES := \
libultraship/OSXFolderManager.mm

FMT_FILES := $(shell find libultraship/ -type f \( -name "*.cpp" -o -name "*.h" \) -a -not -path "libultraship/Lib/*")

O_FILES := \
$(CXX_FILES:%.cpp=build/%.o) \
$(C_FILES:%.c=build/%.o)

ifeq ($(UNAME), Darwin) #APPLE
O_FILES += $(MM_FILES:%.mm=build/%.o)
endif

D_FILES := $(O_FILES:%.o=%.d)

LIB := libultraship.a
Expand Down Expand Up @@ -137,9 +117,6 @@ build/%.o: %.cpp
build/%.o: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(OPTFLAGS) $(INC_DIRS) -c $< -o $@

build/%.o: %.mm
$(MXX) $(MMFLAGS) $(CXXFLAGS) $(OPTFLAGS) $(INC_DIRS) -c $< -o $@

$(LIB): $(O_FILES)
$(AR) rcs $@ $^

Expand Down
4 changes: 2 additions & 2 deletions libultraship/libultraship/ConfigFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ namespace Ship {
}

bool ConfigFile::CreateDefaultConfig() {
(*this)["ARCHIVE"]["Main Archive"] = "";
(*this)["ARCHIVE"]["Main Archive"] = "oot.otr";
(*this)["ARCHIVE"]["Patches Directory"] = "";

(*this)["SAVE"]["Save Filename"] = "";
(*this)["SAVE"]["Save Filename"] = "oot_save.sav";

(*this)["CONTROLLERS"]["CONTROLLER 1"] = "Auto";
(*this)["CONTROLLERS"]["CONTROLLER 2"] = "Unplugged";
Expand Down
30 changes: 4 additions & 26 deletions libultraship/libultraship/GlobalCtx2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/sohconsole_sink.h"
#include "ModManager.h"
#ifdef __APPLE__
#include "OSXFolderManager.h"
#endif

namespace Ship {
std::weak_ptr<GlobalCtx2> GlobalCtx2::Context;
ModManager* INSTANCE;

std::shared_ptr<GlobalCtx2> GlobalCtx2::GetInstance() {
return Context.lock();
}
Expand All @@ -33,22 +29,6 @@ namespace Ship {
return GetInstance();
}

std::string GlobalCtx2::GetAppDirectoryPath() {
#ifdef __APPLE__
FolderManager folderManager;
std::string fpath = std::string(folderManager.pathForDirectory(NSApplicationSupportDirectory, NSUserDomainMask));
fpath.append("/com.shipofharkinian.soh");
return fpath;
#endif

return ".";

}

std::string GlobalCtx2::GetPathRelativeToAppDirectory(const char* path) {
return GlobalCtx2::GetAppDirectoryPath() + "/" + path;
}

GlobalCtx2::GlobalCtx2(const std::string& Name) : Name(Name), MainPath(""), PatchesPath("") {

}
Expand All @@ -60,14 +40,14 @@ namespace Ship {

void GlobalCtx2::InitWindow() {
InitLogging();
Config = std::make_shared<ConfigFile>(GlobalCtx2::GetInstance(), GetPathRelativeToAppDirectory("shipofharkinian.ini"));
Config = std::make_shared<ConfigFile>(GlobalCtx2::GetInstance(), "shipofharkinian.ini");
MainPath = (*Config)["ARCHIVE"]["Main Archive"];
if (MainPath.empty()) {
MainPath = GetPathRelativeToAppDirectory("oot.otr");
MainPath = "oot.otr";
}
PatchesPath = (*Config)["ARCHIVE"]["Patches Directory"];
if (PatchesPath.empty()) {
PatchesPath = GetAppDirectoryPath() + "/";
PatchesPath = "./";
}
ResMan = std::make_shared<ResourceMgr>(GlobalCtx2::GetInstance(), MainPath, PatchesPath);
Win = std::make_shared<Window>(GlobalCtx2::GetInstance());
Expand All @@ -87,13 +67,11 @@ namespace Ship {

void GlobalCtx2::InitLogging() {
try {
auto logPath = GetPathRelativeToAppDirectory(("logs/" + GetName() + ".log").c_str());

// Setup Logging
spdlog::init_thread_pool(8192, 1);
auto SohConsoleSink = std::make_shared<spdlog::sinks::soh_sink_mt>();
auto ConsoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
auto FileSink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(logPath, 1024 * 1024 * 10, 10);
auto FileSink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>("logs/" + GetName() + ".log", 1024 * 1024 * 10, 10);
SohConsoleSink->set_level(spdlog::level::trace);
ConsoleSink->set_level(spdlog::level::trace);
FileSink->set_level(spdlog::level::trace);
Expand Down
3 changes: 0 additions & 3 deletions libultraship/libultraship/GlobalCtx2.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ namespace Ship {
std::shared_ptr<spdlog::logger> GetLogger() { return Logger; }
std::shared_ptr<ConfigFile> GetConfig() { return Config; }

static std::string GetAppDirectoryPath();
static std::string GetPathRelativeToAppDirectory(const char* path);

void WriteSaveFile(std::filesystem::path savePath, uintptr_t addr, void* dramAddr, size_t size);
void ReadSaveFile(std::filesystem::path savePath, uintptr_t addr, void* dramAddr, size_t size);

Expand Down
5 changes: 0 additions & 5 deletions libultraship/libultraship/ImGuiImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,6 @@ namespace SohImGui {
SohImGui::overlay->TextDrawNotification(30.0f, true, "Press F1 to access enhancements menu");
}

auto imguiIniPath = Ship::GlobalCtx2::GetPathRelativeToAppDirectory("imgui.ini");
auto imguiLogPath = Ship::GlobalCtx2::GetPathRelativeToAppDirectory("imgui_log.txt");
io->IniFilename = strcpy(new char[imguiIniPath.length() + 1], imguiIniPath.c_str());
io->LogFilename = strcpy(new char[imguiLogPath.length() + 1], imguiLogPath.c_str());

if (UseViewports()) {
io->ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
}
Expand Down
60 changes: 0 additions & 60 deletions libultraship/libultraship/OSXFolderManager.h

This file was deleted.

37 changes: 0 additions & 37 deletions libultraship/libultraship/OSXFolderManager.mm

This file was deleted.

8 changes: 7 additions & 1 deletion soh/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ ifeq ($(UNAME), Darwin) #APPLE
LDLIBS += \
$(addprefix -framework , \
OpenGL \
Foundation \
) \
$(shell sdl2-config --libs) $(shell pkg-config --libs glew)
endif
Expand Down Expand Up @@ -225,6 +224,9 @@ appbundle: macosx/$(APPNAME).icns
cp macosx/PkgInfo $(APPBUNDLECONTENTS)/
cp macosx/$(APPNAME).icns $(APPBUNDLEICON)/
cp $(TARGET) $(APPBUNDLEEXE)/soh
cp macosx/launcher.sh $(APPBUNDLEEXE)/launcher.sh
clang -ObjC macosx/appsupport.m -arch arm64 -arch x86_64 -framework Foundation -o macosx/appsupport
cp macosx/appsupport $(APPBUNDLEEXE)/appsupport
otool -l $(TARGET) | grep -A 2 LC_RPATH | tail -n 1 | awk '{print $2}' | dylibbundler -od -b -x $(APPBUNDLEEXE)/soh -d $(APPBUNDLECONTENTS)/libs

macosx/$(APPNAME).icns: macosx/$(APPNAME)Icon.png
Expand All @@ -242,3 +244,7 @@ macosx/$(APPNAME).icns: macosx/$(APPNAME)Icon.png
cp macosx/$(APPNAME)Icon.png macosx/$(APPNAME).iconset/icon_512x512@2x.png
iconutil -c icns -o macosx/$(APPNAME).icns macosx/$(APPNAME).iconset
rm -r macosx/$(APPNAME).iconset

filledappbundle: appbundle
cp ./oot.otr $(APPBUNDLEEXE)/oot.otr

2 changes: 1 addition & 1 deletion soh/macosx/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleName</key>
<string>Ship of Harkinian</string>
<key>CFBundleExecutable</key>
<string>soh</string>
<string>launcher.sh</string>
<key>CFBundleGetInfoString</key>
<string>2.0.0</string>
<key>CFBundleIconFile</key>
Expand Down
26 changes: 26 additions & 0 deletions soh/macosx/appsupport.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#import <Foundation/Foundation.h>
int main(void) {
NSString *appSupportDir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject];
//If there isn't an App Support Directory yet ...
if (![[NSFileManager defaultManager] fileExistsAtPath:appSupportDir isDirectory:NULL]) {
NSError *error = nil;
//Create one
if (![[NSFileManager defaultManager] createDirectoryAtPath:appSupportDir withIntermediateDirectories:YES attributes:nil error:&error]) {
NSLog(@"%@", error.localizedDescription);
}
else {
// *** OPTIONAL *** Mark the directory as excluded from iCloud backups
NSURL *url = [NSURL fileURLWithPath:appSupportDir];
if (![url setResourceValue:@YES
forKey:NSURLIsExcludedFromBackupKey
error:&error])
{
NSLog(@"Error excluding %@ from backup %@", url.lastPathComponent, error.localizedDescription);
}
else {
NSLog(@"Yay");
}
}
}
printf("%s\n", [appSupportDir UTF8String]);
}
9 changes: 9 additions & 0 deletions soh/macosx/launcher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
APPPATH="${0%/*}"
cd "${APPPATH}"
APPPATH=$(pwd)
APPSUPPORT=$(./appsupport)
mkdir -p "${APPSUPPORT}/com.shipofharkinian.soh"
cd "${APPSUPPORT}/com.shipofharkinian.soh"
cp "${APPPATH}/oot.otr" .
${APPPATH}/soh
Loading

0 comments on commit b84d742

Please sign in to comment.