Serenity Operating System
at master 52 lines 1.6 kB view raw
1/* 2 * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#define AK_DONT_REPLACE_STD 8 9#include "Utilities.h" 10#include <AK/LexicalPath.h> 11#include <AK/Platform.h> 12#include <LibCore/DeprecatedFile.h> 13#include <QCoreApplication> 14 15DeprecatedString s_serenity_resource_root; 16 17AK::DeprecatedString ak_deprecated_string_from_qstring(QString const& qstring) 18{ 19 return AK::DeprecatedString(qstring.toUtf8().data()); 20} 21 22ErrorOr<String> ak_string_from_qstring(QString const& qstring) 23{ 24 return String::from_utf8(StringView(qstring.toUtf8().data(), qstring.size())); 25} 26 27QString qstring_from_ak_deprecated_string(AK::DeprecatedString const& ak_deprecated_string) 28{ 29 return QString::fromUtf8(ak_deprecated_string.characters(), ak_deprecated_string.length()); 30} 31 32void platform_init() 33{ 34#ifdef AK_OS_ANDROID 35 extern void android_platform_init(); 36 android_platform_init(); 37#else 38 s_serenity_resource_root = [] { 39 auto const* source_dir = getenv("SERENITY_SOURCE_DIR"); 40 if (source_dir) { 41 return DeprecatedString::formatted("{}/Base", source_dir); 42 } 43 auto* home = getenv("XDG_CONFIG_HOME") ?: getenv("HOME"); 44 VERIFY(home); 45 auto home_lagom = DeprecatedString::formatted("{}/.lagom", home); 46 if (Core::DeprecatedFile::is_directory(home_lagom)) 47 return home_lagom; 48 auto app_dir = ak_deprecated_string_from_qstring(QCoreApplication::applicationDirPath()); 49 return LexicalPath(app_dir).parent().append("share"sv).string(); 50 }(); 51#endif 52}