Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Location of game_data.ini on GNU/Linux #30

Closed
anders-larsson opened this issue Jul 26, 2014 · 11 comments
Closed

Location of game_data.ini on GNU/Linux #30

anders-larsson opened this issue Jul 26, 2014 · 11 comments

Comments

@anders-larsson
Copy link

Hi,

I'm attempting to create a Dwarf Therapist ebuild (used by the package manager in Gentoo). However i stumbled upon this weird behaviour of game_data.ini. When Dwarf Therapist is installed it looks for game_data.ini in $HOME/etc instead of the installed location of game_data.ini (/usr/share/dwarftherapist/etc/game_data.ini).

Actual home directory replaced by $HOME.

getcwd("$HOME", 4096)             = 12
lstat("$HOME/etc/game_data.ini", 0x7fff42ccb380) = -1 ENOENT (No such file or directory)
open("$HOME/etc/game_data.ini", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("$HOME/etc/game_data.ini", 0x7fff42ccb3e0) = -1 ENOENT (No such file or directory)
stat("$HOME/etc/game_data.ini", 0x7fff42ccb3a0) = -1 ENOENT (No such file or directory)

After $HOME/etc was created and game_data.ini copied into that directory it worked.

Uncertain if I had done something wrong in the ebuild I compiled and built Dwarf Therapist from source manually and followed the supplied instructions (qmake, make, make install).
Interestingly enough it when I started Dwarf-Therapist (from /usr/bin/Dwarf-Therapist) it worked. However further investigation showed that it found game_data.ini in my build directory and not in /usr/share/dwarftherapist/etc).

lstat("$HOME/temp/dwarftherapist/etc/game_data.ini", {st_mode=S_IFREG|0644, st_size=187006, ...}) = 0
open("$HOME/temp/dwarftherapist/etc/game_data.ini", O_RDONLY|O_CLOEXEC) = 11
stat("$HOME/temp/dwarftherapist/etc/game_data.ini", {st_mode=S_IFREG|0644, st_size=187006, ...}) = 0

When $HOME/temp/dwarftherapist was moved it stopped working since it was unable to find game_data.ini.

Dwarf Therapist does not seem to look for game_data.ini in the correct location or am I missing something?

@anders-larsson
Copy link
Author

Looking through the source code I found what is causing the error. It's looking for both game_data.ini and memory_layouts using relative paths instead of absolute paths. I guess this is why it worked previously when I ran it directly in the build directory.

The following modification fixes the issue. However it will no longer be possible to run Dwarf Therapist from the build directory.

diff --git a/src/dfinstance.cpp b/src/dfinstance.cpp
index b05a272..55b6214 100644
--- a/src/dfinstance.cpp
+++ b/src/dfinstance.cpp
@@ -102,7 +102,7 @@ DFInstance::DFInstance(QObject* parent)
     search_paths << working_dir.path();

     QString subdir = LAYOUT_SUBDIR;
-    search_paths << QString("etc/memory_layouts/%1").arg(subdir);
+    search_paths << QString("/usr/share/dwarftherapist/etc/memory_layouts/%1").arg(subdir);

     TRACE << "Searching for MemoryLayout ini files in the following directories";
     foreach(QString path, search_paths) {
diff --git a/src/gamedatareader.cpp b/src/gamedatareader.cpp
index 56ebe72..3660bde 100644
--- a/src/gamedatareader.cpp
+++ b/src/gamedatareader.cpp
@@ -44,7 +44,7 @@ GameDataReader::GameDataReader(QObject *parent)
     : QObject(parent)
 {
     QDir working_dir = QDir::current();
-    QString filename = working_dir.absoluteFilePath("etc/game_data.ini");
+    QString filename = working_dir.absoluteFilePath("/usr/share/dwarftherapist/etc/game_data.ini");
     m_data_settings = new QSettings(filename, QSettings::IniFormat);

     build_calendar();

Perhaps there's a better way to solve it? Which allows the user to use Dwarf Therapist in the build directory as well and for other operating systems?

@splintermind
Copy link
Owner

I'll have to move things around a bit to allow multiple, different search paths for the files for each operating system. The code above will break osx and windows since it's hard-coding linux file paths in the base dfinstance object.

Any other linux paths that should be checked by default?

@anders-larsson
Copy link
Author

Yes I'm aware that it would mess up other operating systems. That's why I didn't create an actual pull request for the modification. Just wanted to inform you what's causing the issue.

After applying the changes above it works correctly. Can't find any other issues.

Thank you for your time!

@anders-larsson
Copy link
Author

Actually I've a thought regarding directory structure.

It would be neat if Dwarf Therapist would search "$HOME/.config/UDP\ Software/memory_layouts (user specific), /etc/dwarftherapist/ (system specific) and finally /usr/share/dwarftherapist/etc for memory_layouts as default. This would make it simpler to add new memory_layouts for a user in case an official one hasn't been released yet.

I don't know if game_data.ini would be edited by users. Perhaps same logic should be applied to this file in that case.

User settings for DT seems to be saved in $HOME/.config/UDP\ Software. That's why this directory was chosen for user-specific settings.

@splintermind
Copy link
Owner

That sounds like a plan. Normally users shouldn't mess around with the file, since it's normally overwritten when updating.

@Hello71
Copy link
Contributor

Hello71 commented Jul 27, 2014

Hello71 added a commit to Hello71/Dwarf-Therapist that referenced this issue Aug 5, 2014
Hello71 added a commit to Hello71/Dwarf-Therapist that referenced this issue Aug 13, 2014
Hello71 added a commit to Hello71/Dwarf-Therapist that referenced this issue Aug 15, 2014
Hello71 added a commit to Hello71/Dwarf-Therapist that referenced this issue Aug 16, 2014
Hello71 added a commit to Hello71/Dwarf-Therapist that referenced this issue Aug 18, 2014
Hello71 added a commit to Hello71/Dwarf-Therapist that referenced this issue Aug 19, 2014
Also build outside of bin.

Conflicts:
	dwarftherapist.pro
Hello71 added a commit to Hello71/Dwarf-Therapist that referenced this issue Aug 19, 2014
Also build outside of bin.

Conflicts:
	dwarftherapist.pro
Hello71 added a commit to Hello71/Dwarf-Therapist that referenced this issue Aug 21, 2014
Also build outside of bin.

Conflicts:
	dwarftherapist.pro
Hello71 added a commit to Hello71/Dwarf-Therapist that referenced this issue Aug 26, 2014
Hello71 added a commit to Hello71/Dwarf-Therapist that referenced this issue Aug 26, 2014
Hello71 added a commit to Hello71/Dwarf-Therapist that referenced this issue Aug 26, 2014
Hello71 added a commit to Hello71/Dwarf-Therapist that referenced this issue Aug 26, 2014
@wRAR
Copy link
Contributor

wRAR commented Sep 1, 2014

In case anyone is concerned: I'm going to hardcode /etc/dwarftherapist for Debian. Some cross-platform solution leading to the same paths on Linux would be great but I'm fine with maintaining a Debian-specific patch. As a worst case you can add platform-specific ifdefs in those parts of the code.

@splintermind
Copy link
Owner

Have you had a look, or tried #150? Once it's validated for OSX I do plan to merge it into the DF2014 man branch.

@wRAR
Copy link
Contributor

wRAR commented Sep 1, 2014

I think it is a good idea to allow users to provide newer .ini files without updating the software itself and this requires support for reading those files from /etc or the home dir.

@Hello71
Copy link
Contributor

Hello71 commented Sep 1, 2014

conjecture: it would be a good idea to peruse the contents of said ini file before making generalizations.

@wRAR
Copy link
Contributor

wRAR commented Sep 1, 2014

I know that memory layout files are not user-writable configs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants