Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mbsim-env/mbsim
Browse files Browse the repository at this point in the history
  • Loading branch information
foerg committed Feb 25, 2025
2 parents 4b6bd9f + 5f17b06 commit 96b3946
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
6 changes: 3 additions & 3 deletions mbsimgui/mbsimgui/freedesktop.org/desktopIntegration.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
shutil.copyfile(F, f"{DATAHOME}/icons/hicolor/scalable/apps/mbsim-env.{os.path.basename(F)}")

# mimeapps
os.makedirs(f"{HOME}/.config", exist_ok=True)
os.makedirs(CONFIG, exist_ok=True)
cp=configparser.ConfigParser(delimiters=('='), comment_prefixes=('#'), strict=False, interpolation=None)
cp.optionxform=str
cp.read([f"{HOME}/.config/mimeapps.list"]+glob.glob(f"{FREEDESKTOPORGDIR}/mimeapps-*.list"))
with open(f"{HOME}/.config/mimeapps.list", "wt") as ff:
cp.read([f"{CONFIG}/mimeapps.list"]+glob.glob(f"{FREEDESKTOPORGDIR}/mimeapps-*.list"))
with open(f"{CONFIG}/mimeapps.list", "wt") as ff:
cp.write(ff, space_around_delimiters=False)

# apps
Expand Down
32 changes: 28 additions & 4 deletions mbsimgui/mbsimgui/mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
#include "dialogs.h"
#include "wizards.h"
#include <evaluator/evaluator.h>
#ifndef _WIN32
#include <sys/vfs.h>
#include <linux/magic.h>
#endif

using namespace std;
using namespace MBXMLUtils;
Expand Down Expand Up @@ -114,15 +118,35 @@ namespace MBSimGUI {

#if _WIN32
uniqueTempDir=bfs::unique_path(bfs::temp_directory_path()/"mbsimgui_%%%%-%%%%-%%%%-%%%%");

configPath = qgetenv("APPDATA")+"/mbsim-env/";
#else
if(bfs::is_directory("/dev/shm"))
uniqueTempDir=bfs::unique_path("/dev/shm/mbsimgui_%%%%-%%%%-%%%%-%%%%");
auto checkTMPFS=[](const bfs::path &dir) {
struct statfs buf;
if(statfs(dir.string().c_str(), &buf)!=0)
return false;
return buf.f_type==TMPFS_MAGIC;
};
const char *XDG_RUNTIME_DIR=getenv("XDG_RUNTIME_DIR");
bfs::path tmpDir;
if(XDG_RUNTIME_DIR && checkTMPFS(XDG_RUNTIME_DIR))
tmpDir=XDG_RUNTIME_DIR;
if(tmpDir.empty() && checkTMPFS("/dev/shm"))
tmpDir="/dev/shm";
if(tmpDir.empty() && XDG_RUNTIME_DIR)
tmpDir=XDG_RUNTIME_DIR;
if(tmpDir.empty())
tmpDir=bfs::temp_directory_path();
uniqueTempDir=bfs::unique_path(tmpDir/"mbsimgui_%%%%-%%%%-%%%%-%%%%");

configPath = qgetenv("XDG_CONFIG_HOME");
if(!configPath.isEmpty())
configPath += "/mbsim-env/";
else
uniqueTempDir=bfs::unique_path(bfs::temp_directory_path()/"mbsimgui_%%%%-%%%%-%%%%-%%%%");
configPath = qgetenv("HOME")+"/.config/mbsim-env/";
configPath = qgetenv("HOME")+"/.config/mbsim-env/";
#endif
bfs::create_directories(uniqueTempDir);
bfs::permissions(uniqueTempDir, bfs::owner_read|bfs::owner_write|bfs::owner_exe);

QString program = QString::fromStdString((boost::dll::program_location().parent_path().parent_path()/"bin"/"mbsimxml").string());
QStringList arguments;
Expand Down
6 changes: 3 additions & 3 deletions mbsimxml/mbsimxml/freedesktop.org/desktopIntegration.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
shutil.copyfile(F, f"{DATAHOME}/icons/hicolor/scalable/apps/mbsim-env.{os.path.basename(F)}")

# mimeapps
os.makedirs(f"{HOME}/.config", exist_ok=True)
os.makedirs(CONFIG, exist_ok=True)
cp=configparser.ConfigParser(delimiters=('='), comment_prefixes=('#'), strict=False, interpolation=None)
cp.optionxform=str
cp.read([f"{HOME}/.config/mimeapps.list"]+glob.glob(f"{FREEDESKTOPORGDIR}/mimeapps-*.list"))
with open(f"{HOME}/.config/mimeapps.list", "wt") as ff:
cp.read([f"{CONFIG}/mimeapps.list"]+glob.glob(f"{FREEDESKTOPORGDIR}/mimeapps-*.list"))
with open(f"{CONFIG}/mimeapps.list", "wt") as ff:
cp.write(ff, space_around_delimiters=False)

# apps
Expand Down
9 changes: 6 additions & 3 deletions mbsimxml/mbsimxml/mbsimflatxml.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ set<boost::filesystem::path> MBSimXML::loadModules(const set<boost::filesystem::
boost::filesystem::path modulePathConfigFile(
boost::filesystem::path(getenv("APPDATA")?getenv("APPDATA"):"")/"mbsim-env"/"mbsimxml.modulepath");
#else
boost::filesystem::path modulePathConfigFile(
boost::filesystem::path(getenv("HOME")?getenv("HOME"):"")/".config"/"mbsim-env"/"mbsimxml.modulepath");
boost::filesystem::path modulePathConfigFile;
if(getenv("XDG_CONFIG_HOME")!=nullptr)
modulePathConfigFile=boost::filesystem::path(getenv("XDG_CONFIG_HOME"))/"mbsim-env"/"mbsimxml.modulepath";
else
modulePathConfigFile=boost::filesystem::path(getenv("HOME"))/".config"/"mbsim-env"/"mbsimxml.modulepath";
#endif
if(boost::filesystem::exists(modulePathConfigFile)) {
boost::filesystem::ifstream modulePathConfig(modulePathConfigFile);
Expand Down Expand Up @@ -187,7 +190,7 @@ int MBSimXML::preInit(list<string> args, unique_ptr<DynamicSystemSolver>& dss, u
cout<<"--modulePath <dir> Add <dir> to MBSim module serach path. The central MBSim installation"<<endl;
cout<<" module dir and the current dir is always included."<<endl;
cout<<" Also added are all directories listed in the file"<<endl;
cout<<" Linux: $HOME/.config/mbsim-env/mbsimxml.modulepath"<<endl;
cout<<" Linux: $XDG_CONFIG_HOME/mbsim-env/mbsimxml.modulepath"<<endl;
cout<<" Windows: %APPDATA%\\mbsim-env\\mbsimxml.modulepath"<<endl;
cout<<" This file contains one directory per line."<<endl;
cout<<"--stdout <msg> Print on stdout messages of type <msg>."<<endl;
Expand Down
7 changes: 5 additions & 2 deletions mbsimxml/mbsimxml/mbsimxml.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ shared_ptr<DOMDocument> getMBSimXMLCatalog(const set<bfs::path> &searchDirs) {
boost::filesystem::path modulePathConfigFile(
boost::filesystem::path(getenv("APPDATA")?getenv("APPDATA"):"")/"mbsim-env"/"mbsimxml.modulepath");
#else
boost::filesystem::path modulePathConfigFile(
boost::filesystem::path(getenv("HOME")?getenv("HOME"):"")/".config"/"mbsim-env"/"mbsimxml.modulepath");
boost::filesystem::path modulePathConfigFile;
if(getenv("XDG_CONFIG_HOME")!=nullptr)
modulePathConfigFile=boost::filesystem::path(getenv("XDG_CONFIG_HOME"))/"mbsim-env"/"mbsimxml.modulepath";
else
modulePathConfigFile=boost::filesystem::path(getenv("HOME"))/".config"/"mbsim-env"/"mbsimxml.modulepath";
#endif
if(boost::filesystem::exists(modulePathConfigFile)) {
boost::filesystem::ifstream modulePathConfig(modulePathConfigFile);
Expand Down

0 comments on commit 96b3946

Please sign in to comment.