]> git.jsancho.org Git - dungeon-master.git/commitdiff
Search paths for mods and games
authorJavier Sancho <jsf@jsancho.org>
Fri, 3 May 2019 18:33:00 +0000 (20:33 +0200)
committerJavier Sancho <jsf@jsancho.org>
Fri, 3 May 2019 18:33:00 +0000 (20:33 +0200)
src/Makefile.am
src/mods.cpp
src/paths.cpp [new file with mode: 0644]
src/paths.h [new file with mode: 0644]

index a15f108dde95d18a91a8b85396038ee55dc726ca..e11bd0d47550850299750fc4fee31e2fde802e12 100644 (file)
@@ -1,4 +1,4 @@
 bin_PROGRAMS = $(top_builddir)/DungeonMaster
-__top_builddir__DungeonMaster_SOURCES = main.cpp mods.cpp
+__top_builddir__DungeonMaster_SOURCES = main.cpp mods.cpp paths.cpp
 __top_builddir__DungeonMaster_CPPFLAGS = @GUILE_CFLAGS@
 __top_builddir__DungeonMaster_LDFLAGS = @GUILE_LIBS@
index a1dccfa74b437863e2d9e34b08e6e70acfa1eb93..bbbd6c46818095814f8cfa6e7ab525ef282ba774 100644 (file)
@@ -1,5 +1,7 @@
+#include <iostream>
 #include <libguile.h>
 #include "mods.h"
+#include "paths.h"
 
 SCM register_generator(SCM name, SCM proc)
 {
@@ -21,6 +23,11 @@ void scm_init_dungeon_master_module()
 
 void load_mods()
 {
+  std::set<std::string> paths = get_dm_paths();
+  for (const std::string &path : paths) {
+    std::cout << path << std::endl;
+  }
+
   scm_init_guile();
   scm_init_dungeon_master_module();
   scm_primitive_load(scm_from_locale_string("mods/default/main.scm"));
diff --git a/src/paths.cpp b/src/paths.cpp
new file mode 100644 (file)
index 0000000..ae05f3b
--- /dev/null
@@ -0,0 +1,28 @@
+#include <unistd.h>
+#include "paths.h"
+
+std::string get_exec_path()
+{
+  char pBuf[256];
+  size_t len = sizeof(pBuf);
+  char szTmp[32];
+
+  sprintf(szTmp, "/proc/%d/exe", getpid());
+  int bytes = readlink(szTmp, pBuf, len);
+  if (bytes > len - 1)
+    bytes = len - 1;
+  if (bytes >= 0)
+    pBuf[bytes] = '\0';
+
+  std::string exec_path = pBuf;
+  return exec_path.substr(0, exec_path.rfind(DIR_DELIM) + 1);
+}
+
+
+std::set<std::string> get_dm_paths() {
+  std::set<std::string> paths;
+
+  paths.insert(get_exec_path());
+
+  return paths;
+}
diff --git a/src/paths.h b/src/paths.h
new file mode 100644 (file)
index 0000000..c8ecc8e
--- /dev/null
@@ -0,0 +1,7 @@
+#include <set>
+#include <iostream>
+
+#define DIR_DELIM "/"
+
+std::string get_exec_path();
+std::set<std::string> get_dm_paths();