-
Notifications
You must be signed in to change notification settings - Fork 32
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
use XDG_CONFIG_HOME standard #137
Conversation
This breaks the continuous build at the step that validates the build of debian package: You should be able to fix it by modifying this file similarly to cap32.cfg: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Globally I agree this is an improvement. Few remarks and questions.
doc/man6/cap32.6
Outdated
.br | ||
- \fBcap32.cfg\fR file in the location pointed to by the XDG_CONFIG_HOME environment variable. If XDG_CONFIG_HOME is undefined, it will look at $HOME/.config/ as default XDG_CONFIG_HOME directory. | ||
.br | ||
- \fB$HOME/cap32.cfg\fR for compatibility. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be $HOME/.cap32.cfg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also mention $HOME/.config/cap32.cfg as it is also in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redondant with "it will look at $HOME/.config/ as default XDG_CONFIG_HOME directory."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, but it's inaccurate. If XDG_CONFIG_HOME is defined, it will still look at $HOME/.config/cap32.cfg
since i could fix it and let travis test it, i can fix the debian package. Globally, we don't need to patch anymore. |
// If not found, look for .cap32.cfg in the XDG_CONFIG_HOME of current user | ||
// If not found, look for .cap32.cfg in the default XDG_CONFIG_HOME of current user | ||
std::string defaultConfig = ( getenv("XDG_CONFIG_HOME") != nullptr ) ? \ | ||
std::string(getenv("XDG_CONFIG_HOME")) : (std::string(getenv("HOME")) + "/.config") + "/cap32.cfg"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we can rely on HOME always being defined (typically on windows, but not only).
I realize previous code did, I suppose it was OK because it was always finding it locally.
I tried to think of multiple options, maybe the simplest would be something like that:
std::vector<std::pair<char*, std::string>> configPaths = {
{ "", args.cfgFilePath},
{ chAppPath, "/cap32.cfg" },
{ getenv("XDG_CONFIG_HOME"), "/cap32.cfg" },
...
}
for(const auto& p: configFilename){
// Skip paths using getenv if it returned NULL (i.e environment variable not defined)
if (!p.first) continue;
std::string s = std::string(p.first) + p.second;
if (access(s.c_str(), mode) == 0)
 std::cout << "Using configuration file" << (forWrite ? " to save" : "") << ": " << s << std::endl;
return s;
}
}
And for the default, just hardcode "cap32.cfg" or "/etc/cap32.cfg", logging something to stdout or stderr as this should never be used ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry but i read a bit about such issue (multiplateform default config file) before i wrote this PR and i can tell that's not small code like our that solves every cases. People want better ? they fix it. I've no much time to spend on this. I solve my bugs for nixos and Magick2cpc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm reading http://koshmaar.linuxpl.info/sdl_config/news.php
available here too https://github.com/Koshmaar/SDL_Config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, solving every cases is one thing. Here we're talking about making Caprice32 segfault systematically at startup on windows. Unless I miss something, previous code was working because it was never executing the getenv when running on windows because it takes the config file from the current directory before. But here it will execute the getenv no matter what resulting in a segfault.
Unfortunately, the windows CI on appveyor doesn't execute any e2e test. I should work on integrating it. But I suspect this would fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could have #ifdef for different plateform default path settings. btw i'd like your feedback on sdl_config, if you're not against, i will try something, since it has substitution that was missing for my second part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
benefits : reduce code coverage, share code with other produts on configuration issue, add substitution etc. if you're not ready to increase your dependancies, you're not living in my world (no cost for a git module) yes ,last update is 2008 seems dead, but github was upload 8 months ago (people from SF) and i've already made an issue to see activity. As i did here .. answere here ? 6 days, so i'll look sdl-config that way. I first do a small contribution or legitimate question, then i wait. You still doesn't have merge my contribution, let's see , perharps sdl-config has not a lot of public interesting but i could make things there, i'm not worried. Free software died because of bad dictatorship not knowing on how deal with new contributor. I've plenty of non commenting PR on project, i know now their people are not able to manage a project (navit case). My PR merged i 'll do a new improvement, no news, i do nothing. My rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configuration parsing/generation is 150 lines of code (.h and .cpp), didn't change much since its inception and never caused any issue so I'm not sure it's worth the overhead. A module that handles finding the configuration file too would be another story, but just parsing I'd advise against putting any effort into it.
As for the merging of the PR, I'm currently working on making the e2e tests run on appveyor so that I can verify whether this crashes systematically under windows, but I really think it does. I clearly can't merge a PR that would make the application crash systematically at startup for many users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plus this not so great ones functions from cap32.cpp :
saveConfiguration() 67l
loadConfiguration() 114l
and variables substitutions in configuration would be great... btw, if you're not interessting by, no matter. Let write your test and i'll fix after failure. That way, we ensure a bit your test and my fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those methods would remain if you were to use SDL_Config, just replacing (set|get).*Value with the SDL_Config equivalent. If not, then I'm missing something.
Appveyor build is updated to run the e2e_test too so you can sync your repository to see what it says.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do a git pull and update your pull request to see what this gives on appveyor?
@@ -0,0 +1,5 @@ | |||
with import <nixpkgs> {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a component describing what this is.
Something like this I suppose:
# Package description for Nix (http://nixos.org)
Any news on this? I'm interested by the change so if you don't want to finish it, I can take it over. |
yes, very sorry to not reply. I'll have a look very soon. |
Replaced by #139 |
Make a new tagged version release, for bignaux to finish the nixpkgs integration with this modification. |
I created a v4.6.0 (release on-going). |
It can now find the file but it won't create it for the moment, so user has still to cp /nix/store/4zwhyybwb73barllbll964dk2db6zmlw-caprice32-4.6.0/etc/cap32.cfg ~/.config/ to make cap32 look for it. Would be nicer to enable creation of the file, but that would be another task. For the moment i've no time for this, i just try to close the different topic i started month ago before my disease. Thanks, i did my duty for nixos NixOS/nixpkgs#82586 |
Sorry, i try again, that doesn't write the file even with save. |
Sorry, didn't see your comment so far. |
I just tried on a file without write permissions and indeed, there's no error but the config is not saved. |
Now Caprice will display an error in the GUI and in the console when failing to save to a file (e.g non-writable). |
APP_PATH flag is to solve a problem on nixos where the path changed every update :
/nix/store/vzklpxmzhgm8wrnl4m6blrad2jw925il-caprice32-4.5.0
so it breaks user configuration for rom_path and resources_path. Btw, it makes debian patch unecessary too ;). They just have to add APP_PATH=/usr/share/caprice32 at make call.