Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
filepath.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2009-2011 johannes hanika.
4 Copyright (C) 2012 Richard Wonka.
5 Copyright (C) 2016 Roman Lebedev.
6 Copyright (C) 2016, 2019 Tobias Ellinghaus.
7 Copyright (C) 2019 Edgardo Hoszowski.
8 Copyright (C) 2020 GrahamByrnes.
9 Copyright (C) 2020 Marco.
10 Copyright (C) 2020 Pascal Obry.
11 Copyright (C) 2022 Martin Baƙinka.
12
13 darktable is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 darktable is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with darktable. If not, see <http://www.gnu.org/licenses/>.
25*/
26
27#include "common/darktable.h"
28#include "dtwin.h"
29
30GList* win_image_find_duplicates(const char* filename)
31{
32 // find all duplicates of an image
33 gchar pattern[PATH_MAX] = { 0 };
34 GList* files = NULL;
35 gchar *imgpath = g_path_get_dirname(filename);
36 // Windows only accepts generic wildcards for filename
37 static const gchar *glob_patterns[] = { "", "_????", NULL };
38 const gchar *c3 = filename + strlen(filename);
39 while(*c3 != '\\' && c3 > filename) c3--;
40 if(*c3 == '\\') c3++;
41 const gchar **glob_pattern = glob_patterns;
42 files = NULL;
43 while(*glob_pattern)
44 {
45 g_strlcpy(pattern, filename, sizeof(pattern));
46 gchar *c1 = pattern + strlen(pattern);
47 while(*c1 != '.' && c1 > pattern) c1--;
48 g_strlcpy(c1, *glob_pattern, pattern + sizeof(pattern) - c1);
49 const gchar *c2 = filename + strlen(filename);
50 while(*c2 != '.' && c2 > filename) c2--;
51 snprintf(c1 + strlen(*glob_pattern), pattern + sizeof(pattern) - c1 - strlen(*glob_pattern), "%s.xmp", c2);
52 wchar_t *wpattern = g_utf8_to_utf16(pattern, -1, NULL, NULL, NULL);
53 WIN32_FIND_DATAW data;
54 HANDLE handle = FindFirstFileW(wpattern, &data);
55 dt_free(wpattern);
56 gchar *imgfile_without_path=g_strndup(c3,c2-c3); /*Need to remove path from front of filename*/
57 if(handle != INVALID_HANDLE_VALUE)
58 {
59 do
60 {
61 gchar *file = g_utf16_to_utf8(data.cFileName, -1, NULL, NULL, NULL);
62 gchar *short_file_name = g_strndup(file, strlen(file) - 4 + c2 - filename - strlen(filename));
63 gboolean valid_xmp_name = FALSE;
64 if(!(valid_xmp_name = (strlen(short_file_name) == strlen(imgfile_without_path))))
65 {
66 // if not the same length, make sure the extra char are 2-4 digits preceded by '_'
67 gchar *c4 = short_file_name + strlen(short_file_name);
68 int i=0;
69 do
70 {
71 c4--;
72 i++;
73 }
74 while(g_ascii_isdigit(*c4) && c4 > short_file_name && i <= 4);
75 valid_xmp_name = (*c4 == '_' && strlen(short_file_name) == strlen(imgfile_without_path) + i);
76 }
77
78 if(valid_xmp_name)
79 files = g_list_append(files, g_build_filename(imgpath, file, NULL));
80
81 dt_free(short_file_name);
82 dt_free(file);
83 }
84 while(FindNextFileW(handle, &data));
85
86 }
87
88 dt_free(imgfile_without_path);
89 FindClose(handle);
90 glob_pattern++;
91 }
92
93 dt_free(imgpath);
94 return files;
95}
96
97// clang-format off
98// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
99// vim: shiftwidth=2 expandtab tabstop=2 cindent
100// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
101// clang-format on
102
#define FALSE
Definition ashift_lsd.c:158
#define dt_free(ptr)
Definition darktable.h:456
#define PATH_MAX
Definition darktable.h:1062
GList * win_image_find_duplicates(const char *filename)
Definition filepath.c:30