summaryrefslogtreecommitdiff
path: root/Libraries/LibCore
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries/LibCore')
-rw-r--r--Libraries/LibCore/ConfigFile.cpp6
-rw-r--r--Libraries/LibCore/Makefile2
-rw-r--r--Libraries/LibCore/StandardPaths.cpp (renamed from Libraries/LibCore/UserInfo.cpp)30
-rw-r--r--Libraries/LibCore/StandardPaths.h (renamed from Libraries/LibCore/UserInfo.h)15
4 files changed, 40 insertions, 13 deletions
diff --git a/Libraries/LibCore/ConfigFile.cpp b/Libraries/LibCore/ConfigFile.cpp
index 08fdb130ff..15fdb8020d 100644
--- a/Libraries/LibCore/ConfigFile.cpp
+++ b/Libraries/LibCore/ConfigFile.cpp
@@ -27,7 +27,7 @@
#include <AK/StringBuilder.h>
#include <LibCore/ConfigFile.h>
#include <LibCore/File.h>
-#include <LibCore/UserInfo.h>
+#include <LibCore/StandardPaths.h>
#include <pwd.h>
#include <stdio.h>
#include <unistd.h>
@@ -36,9 +36,7 @@ namespace Core {
NonnullRefPtr<ConfigFile> ConfigFile::get_for_app(const String& app_name)
{
- String home_path = get_current_user_home_path();
- if (home_path == "/")
- home_path = String::format("/tmp");
+ String home_path = StandardPaths::home_directory();
auto path = String::format("%s/%s.ini", home_path.characters(), app_name.characters());
return adopt(*new ConfigFile(path));
}
diff --git a/Libraries/LibCore/Makefile b/Libraries/LibCore/Makefile
index 9948956218..90f00d7488 100644
--- a/Libraries/LibCore/Makefile
+++ b/Libraries/LibCore/Makefile
@@ -23,12 +23,12 @@ OBJS = \
ProcessStatisticsReader.o \
Socket.o \
SocketAddress.o \
+ StandardPaths.o \
TCPServer.o \
TCPSocket.o \
Timer.o \
UDPServer.o \
UDPSocket.o \
- UserInfo.o \
puff.o
LIBRARY = libcore.a
diff --git a/Libraries/LibCore/UserInfo.cpp b/Libraries/LibCore/StandardPaths.cpp
index 284272be4e..b46ab334b0 100644
--- a/Libraries/LibCore/UserInfo.cpp
+++ b/Libraries/LibCore/StandardPaths.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -24,18 +24,38 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <LibCore/UserInfo.h>
+#include <AK/FileSystemPath.h>
+#include <AK/String.h>
+#include <AK/StringBuilder.h>
+#include <LibCore/StandardPaths.h>
#include <pwd.h>
#include <stdlib.h>
#include <unistd.h>
-String get_current_user_home_path()
+namespace Core {
+
+String StandardPaths::home_directory()
{
if (auto* home_env = getenv("HOME"))
- return home_env;
+ return canonicalized_path(home_env);
auto* pwd = getpwuid(getuid());
String path = pwd ? pwd->pw_dir : "/";
endpwent();
- return path;
+ return canonicalized_path(path);
+}
+
+String StandardPaths::desktop_directory()
+{
+ StringBuilder builder;
+ builder.append(home_directory());
+ builder.append("/Desktop");
+ return canonicalized_path(builder.to_string());
+}
+
+String StandardPaths::tempfile_directory()
+{
+ return "/tmp";
+}
+
}
diff --git a/Libraries/LibCore/UserInfo.h b/Libraries/LibCore/StandardPaths.h
index d609cdbe59..53b3cca95e 100644
--- a/Libraries/LibCore/UserInfo.h
+++ b/Libraries/LibCore/StandardPaths.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -26,6 +26,15 @@
#pragma once
-#include <AK/String.h>
+#include <AK/Forward.h>
-String get_current_user_home_path();
+namespace Core {
+
+class StandardPaths {
+public:
+ static String home_directory();
+ static String desktop_directory();
+ static String tempfile_directory();
+};
+
+}