diff --git a/src/dcp.c b/src/dcp.c index 61a11d7..ea545de 100644 --- a/src/dcp.c +++ b/src/dcp.c @@ -7,34 +7,27 @@ #include #include #include +#ifndef SYSCONFDIR +#include "config.h" +#endif bool find_calibration_by_model(char *conffile, char *model, const char *sensor) { - // Check config/%model,%sensor.dcp in the current working directory - sprintf(conffile, "config/%s,%s.dcp", model, sensor); - if (access(conffile, F_OK) != -1) { - printf("Found calibration file at %s\n", conffile); - return true; + static const char *paths[] = { + "config/%s,%s.dcp", + SYSCONFDIR "/megapixels/config/%s,%s.dcp", + DATADIR "/megapixels/config/%s,%s.dcp", + NULL + }; + for (const char *fmt = paths[0]; fmt; fmt++) { + sprintf(conffile, fmt, model, sensor); + if (access(conffile, F_OK) != -1) { + printf("Found calibration file at %s\n", conffile); + return true; + } } - // Check user overridden /etc/megapixels/config/%model,%sensor.dcp - sprintf(conffile, "%s/megapixels/config/%s,%s.dcp", "/etc", model, sensor); - if (access(conffile, F_OK) != -1) { - printf("Found calibration file at %s\n", conffile); - return true; - } - - // Check packaged /usr/share/megapixels/config/%model,%sensor.ini - sprintf(conffile, - "%s/megapixels/config/%s,%s.dcp", - "/usr/share", - model, - sensor); - if (access(conffile, F_OK) != -1) { - printf("Found calibration file at %s\n", conffile); - return true; - } printf("No calibration found for %s,%s\n", model, sensor); return false; }