mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:57:46 +00:00
most apps now begin in the correct directory
This commit is contained in:
parent
e3f81bce49
commit
50154a23cb
7 changed files with 34 additions and 14 deletions
|
@ -1,5 +1,6 @@
|
|||
#include <LibCore/CConfigFile.h>
|
||||
#include <LibCore/CFile.h>
|
||||
#include <LibCore/CUserInfo.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
|
@ -7,15 +8,8 @@
|
|||
|
||||
Retained<CConfigFile> CConfigFile::get_for_app(const String& app_name)
|
||||
{
|
||||
String home_path;
|
||||
if (auto* home_env = getenv("HOME")) {
|
||||
home_path = home_env;
|
||||
} else {
|
||||
uid_t uid = getuid();
|
||||
if (auto* pwd = getpwuid(uid))
|
||||
home_path = pwd->pw_dir;
|
||||
}
|
||||
if (home_path.is_empty())
|
||||
String home_path = get_current_user_home_path();
|
||||
if (home_path == "/")
|
||||
home_path = String::format("/tmp");
|
||||
auto path = String::format("%s/%s.ini", home_path.characters(), app_name.characters());
|
||||
return adopt(*new CConfigFile(path));
|
||||
|
|
17
LibCore/CUserInfo.cpp
Normal file
17
LibCore/CUserInfo.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "CUserInfo.h"
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
|
||||
const char *get_current_user_home_path() {
|
||||
if (auto* home_env = getenv("HOME")) {
|
||||
return home_env;
|
||||
} else {
|
||||
auto d = "/";
|
||||
uid_t uid = getuid();
|
||||
if (auto* pwd = getpwuid(uid))
|
||||
return pwd->pw_dir;
|
||||
else
|
||||
return d;
|
||||
}
|
||||
}
|
1
LibCore/CUserInfo.h
Normal file
1
LibCore/CUserInfo.h
Normal file
|
@ -0,0 +1 @@
|
|||
const char *get_current_user_home_path();
|
|
@ -19,7 +19,8 @@ OBJS = \
|
|||
CConfigFile.o \
|
||||
CEvent.o \
|
||||
CProcessStatisticsReader.o \
|
||||
CDirIterator.o
|
||||
CDirIterator.o \
|
||||
CUserInfo.o
|
||||
|
||||
LIBRARY = libcore.a
|
||||
DEFINES += -DUSERLAND
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue