Explorar o código

most apps now begin in the correct directory

Christopher Dumas %!s(int64=6) %!d(string=hai) anos
pai
achega
50154a23cb

+ 1 - 0
Applications/FileManager/main.cpp

@@ -14,6 +14,7 @@
 #include <LibGUI/GTreeView.h>
 #include <LibGUI/GFileSystemModel.h>
 #include <LibGUI/GSplitter.h>
+#include <LibCore/CUserInfo.h>
 #include <AK/FileSystemPath.h>
 #include <unistd.h>
 #include <signal.h>

+ 2 - 0
Applications/Launcher/main.cpp

@@ -10,6 +10,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <errno.h>
+#include <LibCore/CUserInfo.h>
 
 static GWindow* make_launcher_window();
 
@@ -23,6 +24,7 @@ void handle_sigchld(int)
 
 int main(int argc, char** argv)
 {
+    chdir(get_current_user_home_path());
     GApplication app(argc, argv);
 
     signal(SIGCHLD, handle_sigchld);

+ 8 - 4
Applications/Terminal/main.cpp

@@ -7,6 +7,7 @@
 #include <assert.h>
 #include <sys/ioctl.h>
 #include <sys/select.h>
+#include <pwd.h>
 #include "Terminal.h"
 #include <Kernel/KeyCode.h>
 #include <LibGUI/GApplication.h>
@@ -16,6 +17,7 @@
 #include <LibGUI/GAction.h>
 #include <LibGUI/GFontDatabase.h>
 #include <LibGUI/GSlider.h>
+#include <LibCore/CUserInfo.h>
 
 static void make_shell(int ptm_fd)
 {
@@ -80,6 +82,8 @@ int main(int argc, char** argv)
 {
     GApplication app(argc, argv);
 
+    chdir(get_current_user_home_path());
+
     int ptm_fd = open("/dev/ptmx", O_RDWR);
     if (ptm_fd < 0) {
         perror("open(ptmx)");
@@ -112,7 +116,7 @@ int main(int argc, char** argv)
     slider->set_fill_with_background_color(true);
     slider->set_background_color(Color::LightGray);
 
-    slider->on_value_changed = [&terminal] (int value) {
+    slider->on_value_changed = [&terminal, &config] (int value) {
         float opacity = value / 100.0;
         terminal.set_opacity(opacity);
     };
@@ -138,11 +142,11 @@ int main(int argc, char** argv)
 
     auto font_menu = make<GMenu>("Font");
     GFontDatabase::the().for_each_fixed_width_font([&] (const String& font_name) {
-        font_menu->add_action(GAction::create(font_name, [&terminal] (const GAction& action) {
+                                                       font_menu->add_action(GAction::create(font_name, [&terminal, &config] (const GAction& action) {
             terminal.set_font(GFontDatabase::the().get_by_name(action.text()));
             auto metadata = GFontDatabase::the().get_metadata_by_name(action.text());
-            terminal.config()->write_entry("Text", "Font", metadata.path);
-            terminal.config()->sync();
+            config->write_entry("Text", "Font", metadata.path);
+            config->sync();
             terminal.force_repaint();
         }));
     });

+ 3 - 9
LibCore/CConfigFile.cpp

@@ -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 - 0
LibCore/CUserInfo.cpp

@@ -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 - 0
LibCore/CUserInfo.h

@@ -0,0 +1 @@
+const char *get_current_user_home_path();

+ 2 - 1
LibCore/Makefile

@@ -19,7 +19,8 @@ OBJS = \
     CConfigFile.o \
     CEvent.o \
     CProcessStatisticsReader.o \
-    CDirIterator.o
+    CDirIterator.o \
+    CUserInfo.o
 
 LIBRARY = libcore.a
 DEFINES += -DUSERLAND