Эх сурвалжийг харах

Merge branch 'bug1' of xry111/tx01-data into master

Fixes #1.
xry111 5 жил өмнө
parent
commit
374832f091
3 өөрчлөгдсөн 55 нэмэгдсэн , 1 устгасан
  1. 4 1
      config.cc
  2. 42 0
      executable.cc
  3. 9 0
      executable.hpp

+ 4 - 1
config.cc

@@ -2,6 +2,7 @@
 #include <boost/property_tree/ini_parser.hpp>
 
 #include "config.hpp"
+#include "executable.hpp"
 
 double conf_aggr_ts;
 double conf_aggr_tav;
@@ -14,7 +15,9 @@ public:
 	_config_()
 	{
 		boost::property_tree::ptree pt;
-		boost::property_tree::ini_parser::read_ini("config.ini", pt);
+		boost::filesystem::path path = get_executable_directory();
+		path /= "config.ini";
+		boost::property_tree::ini_parser::read_ini(path.string(), pt);
 		conf_aggr_ts = pt.get<double>("aggregation.ts");
 		conf_aggr_tav = pt.get<double>("aggregation.tav");
 		conf_debug_dump_flight_data = pt.get<bool>("debug.dump_flight_data");

+ 42 - 0
executable.cc

@@ -0,0 +1,42 @@
+#include "executable.hpp"
+
+#ifdef __linux__
+
+#define _EXEC_PATH_IMPL_ 1
+
+#include <unistd.h>
+#include <string>
+#include <climits>
+
+boost::filesystem::path get_executable_path()
+{
+	static char buf[PATH_MAX];
+	readlink("/proc/self/exe", buf, PATH_MAX);
+	return buf;
+}
+
+#endif
+
+#ifdef __WINNT__
+
+#define _EXEC_PATH_IMPL_ 1
+
+#include <windows.h>
+
+boost::filesystem::path get_executable_path()
+{
+	static char buf[MAX_PATH];
+	GetModuleFileNameA(NULL, buf, MAX_PATH);
+	return buf;
+}
+
+#endif
+
+#ifndef _EXEC_PATH_IMPL_
+#error "don't know how to get executable path"
+#endif
+
+boost::filesystem::path get_executable_directory()
+{
+	return get_executable_path().parent_path();
+}

+ 9 - 0
executable.hpp

@@ -0,0 +1,9 @@
+#ifndef _EXECUTABLE_HPP_
+#define _EXECUTABLE_HPP_
+
+#include <boost/filesystem.hpp>
+
+extern boost::filesystem::path get_executable_path(void);
+extern boost::filesystem::path get_executable_directory(void);
+
+#endif