]> FriiDump Source - friidump.git/blobdiff - src/redump_dat.c
Record A102 and B101 live profile evidence
[friidump.git] / src / redump_dat.c
index 028aa1362938c89f25c67aed0b951b2e0b46bca0..d2aba7c2ca7a1619052a343ba0bd5f0939c2b500 100644 (file)
@@ -51,6 +51,7 @@ int redump_resolve_dat_path(
     char *out_path,
     size_t out_path_size
 ) {
     char *out_path,
     size_t out_path_size
 ) {
+    const char *environment_dir;
     char candidate[1024];
 
     if (!basename || !basename[0] || !out_path || out_path_size == 0)
     char candidate[1024];
 
     if (!basename || !basename[0] || !out_path || out_path_size == 0)
@@ -58,6 +59,9 @@ int redump_resolve_dat_path(
 
     out_path[0] = '\0';
 
 
     out_path[0] = '\0';
 
+    /* An explicit CLI directory is authoritative.  Do not silently fall back
+     * when the operator supplied a path, because that would make evidence
+     * provenance ambiguous. */
     if (explicit_dir && explicit_dir[0]) {
         if (!redump_join_path(explicit_dir, NULL, basename,
                               out_path, out_path_size))
     if (explicit_dir && explicit_dir[0]) {
         if (!redump_join_path(explicit_dir, NULL, basename,
                               out_path, out_path_size))
@@ -65,6 +69,17 @@ int redump_resolve_dat_path(
         return redump_path_exists(out_path);
     }
 
         return redump_path_exists(out_path);
     }
 
+    /* Environment override is useful for packaged and read-only installs.
+     * Like the CLI override, it is authoritative when set. */
+    environment_dir = getenv("FRIIDUMP_REDUMP_DAT_DIR");
+    if (environment_dir && environment_dir[0]) {
+        if (!redump_join_path(environment_dir, NULL, basename,
+                              out_path, out_path_size))
+            return 0;
+        return redump_path_exists(out_path);
+    }
+
+    /* Portable/source-build layout: DAT directory beside the executable. */
     if (executable_dir && executable_dir[0] &&
         redump_join_path(executable_dir, "redump_dat", basename,
                          candidate, sizeof(candidate))) {
     if (executable_dir && executable_dir[0] &&
         redump_join_path(executable_dir, "redump_dat", basename,
                          candidate, sizeof(candidate))) {
@@ -72,19 +87,27 @@ int redump_resolve_dat_path(
             snprintf(out_path, out_path_size, "%s", candidate);
             return 1;
         }
             snprintf(out_path, out_path_size, "%s", candidate);
             return 1;
         }
-
-        /* Retain the executable-relative path as the preferred diagnostic
-         * candidate if neither automatic location exists. */
         snprintf(out_path, out_path_size, "%s", candidate);
     }
 
         snprintf(out_path, out_path_size, "%s", candidate);
     }
 
+    /* Installed Unix layout: <prefix>/bin/friidump with data under
+     * <prefix>/share/friidump/redump_dat. */
+    if (executable_dir && executable_dir[0] &&
+        redump_join_path(executable_dir, "../share/friidump/redump_dat",
+                         basename, candidate, sizeof(candidate))) {
+        if (redump_path_exists(candidate)) {
+            snprintf(out_path, out_path_size, "%s", candidate);
+            return 1;
+        }
+    }
+
+    /* Development convenience for direct source-tree execution. */
     if (redump_join_path(".", "redump_dat", basename,
                          candidate, sizeof(candidate))) {
         if (redump_path_exists(candidate)) {
             snprintf(out_path, out_path_size, "%s", candidate);
             return 1;
         }
     if (redump_join_path(".", "redump_dat", basename,
                          candidate, sizeof(candidate))) {
         if (redump_path_exists(candidate)) {
             snprintf(out_path, out_path_size, "%s", candidate);
             return 1;
         }
-
         if (!out_path[0])
             snprintf(out_path, out_path_size, "%s", candidate);
     }
         if (!out_path[0])
             snprintf(out_path, out_path_size, "%s", candidate);
     }