Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion libaegisub/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ libaegisub_src = [
if host_machine.system() == 'darwin'
libaegisub_src += [
'osx/dispatch.mm',
'osx/path.mm',
'osx/spellchecker.mm',
'osx/util.mm',
]
Expand All @@ -76,9 +77,12 @@ else
'unix/access.cpp',
'unix/fs.cpp',
'unix/log.cpp',
'unix/path.cpp',
'unix/util.cpp',
]

if host_machine.system() != 'darwin'
libaegisub_src += 'unix/path.cpp'
endif
endif

libaegisub_cpp_pch = ['include/lagi_pre.h']
Expand Down
31 changes: 31 additions & 0 deletions libaegisub/osx/path.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2013, Thomas Goyne <plorkyeran@aegisub.org>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// Aegisub Project http://www.aegisub.org/

#include <libaegisub/path.h>
#include <libaegisub/util_osx.h>

namespace sfs = std::filesystem;

namespace agi {
void Path::FillPlatformSpecificPaths() {
agi::fs::path user_dir = agi::fs::path(sfs::path(agi::util::GetApplicationSupportDirectory()))/"Aegisub";
SetToken("?user", user_dir);
SetToken("?local", user_dir);
SetToken("?data", agi::util::GetBundleSharedSupportDirectory());
SetToken("?dictionary", Decode("?data/dictionaries"));
SetToken("?temp", agi::fs::path(sfs::temp_directory_path()));
}
}
65 changes: 21 additions & 44 deletions libaegisub/unix/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,82 +15,59 @@
// Aegisub Project http://www.aegisub.org/

#include <libaegisub/path.h>

#include <libaegisub/exception.h>
#include <libaegisub/util_osx.h>

#include <pwd.h>

#ifndef __APPLE__
#include <fstream>
#include <stdlib.h>
#include <libgen.h>
#endif

namespace sfs = std::filesystem;

namespace {
#ifndef __APPLE__
std::string home_dir() {
agi::fs::path home_dir() {
const char *env = getenv("HOME");
if (env) return env;
if (env) return agi::fs::path(sfs::path(env));

if ((env = getenv("USER")) || (env = getenv("LOGNAME"))) {
if (passwd *user_info = getpwnam(env))
return user_info->pw_dir;
return agi::fs::path(sfs::path(user_info->pw_dir));
}

throw agi::EnvironmentError("Could not get home directory. Make sure HOME is set.");
}

#ifdef APPIMAGE_BUILD
std::string exe_dir() {
char *exe, *dir;
std::string data = "";

#ifdef __FreeBSD__
exe = realpath("/proc/self/file", NULL);
#else
exe = realpath("/proc/self/exe", NULL);
#endif

agi::fs::path data_dir() {
char *exe = realpath("/proc/self/exe", NULL);
if (!exe) return "";

if ((dir = dirname(exe)) && strlen(dir) > 0) {
data = dir;
}

sfs::path p = sfs::path(exe).parent_path();
free(exe);

return data;
if (p.filename() == "bin") {
// assume unix prefix layout
return agi::fs::path(p.parent_path()/"share");
}

return agi::fs::path(p);
}
#endif /* APPIMAGE_BUILD */
#endif /* !__APPLE__ */
#endif
}

namespace agi {
void Path::FillPlatformSpecificPaths() {
#ifndef __APPLE__
agi::fs::path home = home_dir();
SetToken("?user", home/".aegisub");
SetToken("?local", home/".aegisub");
agi::fs::path dotdir = home_dir()/".aegisub";
SetToken("?user", dotdir);
SetToken("?local", dotdir);

#ifdef APPIMAGE_BUILD
agi::fs::path data = exe_dir();
if (data == "") data = home/".aegisub";
SetToken("?data", data);
agi::fs::path data = data_dir();
SetToken("?data", (data == "") ? dotdir : data);
SetToken("?dictionary", Decode("?data/dictionaries"));
#else
SetToken("?data", P_DATA);
SetToken("?dictionary", "/usr/share/hunspell");
#endif

#else
agi::fs::path app_support = agi::util::GetApplicationSupportDirectory();
SetToken("?user", app_support/"Aegisub");
SetToken("?local", app_support/"Aegisub");
SetToken("?data", agi::util::GetBundleSharedSupportDirectory());
SetToken("?dictionary", Decode("?data/dictionaries"));
#endif
SetToken("?temp", agi::fs::path(std::filesystem::temp_directory_path()));
SetToken("?temp", agi::fs::path(sfs::temp_directory_path()));
}

}
Loading