Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
dtwin.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2016-2018 Peter Budai.
4 Copyright (C) 2020 Pascal Obry.
5 Copyright (C) 2020 U-GAMERTRON-3000\zack.
6 Copyright (C) 2022 Martin Bařinka.
7 Copyright (C) 2022 Miloš Komarčević.
8
9 darktable is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 darktable is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with darktable. If not, see <http://www.gnu.org/licenses/>.
21*/
22#include "common/darktable.h"
23#include "dtwin.h"
24#include <setjmp.h>
25#include <windows.h>
26
27// Required by (at least) clang 10.0 as packaged by MSYS2 MinGW64.
28// This platform combination is needed for dt appveyor build.
29#ifdef __clang__
30#ifdef __MINGW32__ // 64-bit subsystem also sets this symbol
31#include <errno.h>
32#endif
33#endif
34
35const wchar_t *dtwin_get_locale()
36{
37 wchar_t *posix = NULL;
38 LCID lcid;
39
40 lcid = GetUserDefaultLCID();
41 int lang_id = PRIMARYLANGID(lcid);
42 int sub_id = SUBLANGID(lcid);
43
44 switch(lang_id)
45 {
46 case LANG_AFRIKAANS:
47 posix = L"af";
48 break;
49 case LANG_ARABIC:
50 posix = L"ar";
51 break;
52 case LANG_AZERI:
53 posix = L"az";
54 break;
55 case LANG_BENGALI:
56 posix = L"bn";
57 break;
58 case LANG_BULGARIAN:
59 posix = L"bg";
60 break;
61 case LANG_CATALAN:
62 posix = L"ca";
63 break;
64 case LANG_CZECH:
65 posix = L"cs";
66 break;
67 case LANG_DANISH:
68 posix = L"da";
69 break;
70 case LANG_ESTONIAN:
71 posix = L"et";
72 break;
73 case LANG_PERSIAN:
74 posix = L"fa";
75 break;
76 case LANG_GERMAN:
77 posix = L"de";
78 break;
79 case LANG_GREEK:
80 posix = L"el";
81 break;
82 case LANG_ENGLISH:
83 switch(sub_id)
84 {
85 case SUBLANG_ENGLISH_UK:
86 posix = L"en_GB";
87 break;
88 case SUBLANG_ENGLISH_AUS:
89 posix = L"en_AU";
90 break;
91 case SUBLANG_ENGLISH_CAN:
92 posix = L"en_CA";
93 break;
94 default:
95 posix = L"en";
96 break;
97 }
98 break;
99 case LANG_SPANISH:
100 posix = L"es";
101 break;
102 case LANG_BASQUE:
103 posix = L"eu";
104 break;
105 case LANG_FINNISH:
106 posix = L"fi";
107 break;
108 case LANG_FRENCH:
109 posix = L"fr";
110 break;
111 case LANG_GALICIAN:
112 posix = L"gl";
113 break;
114 case LANG_GUJARATI:
115 posix = L"gu";
116 break;
117 case LANG_HEBREW:
118 posix = L"he";
119 break;
120 case LANG_HINDI:
121 posix = L"hi";
122 break;
123 case LANG_HUNGARIAN:
124 posix = L"hu";
125 break;
126 case LANG_ICELANDIC:
127 break;
128 case LANG_INDONESIAN:
129 posix = L"id";
130 break;
131 case LANG_ITALIAN:
132 posix = L"it";
133 break;
134 case LANG_JAPANESE:
135 posix = L"ja";
136 break;
137 case LANG_GEORGIAN:
138 posix = L"ka";
139 break;
140 case LANG_KANNADA:
141 posix = L"kn";
142 break;
143 case LANG_KOREAN:
144 posix = L"ko";
145 break;
146 case LANG_LITHUANIAN:
147 posix = L"lt";
148 break;
149 case LANG_MACEDONIAN:
150 posix = L"mk";
151 break;
152 case LANG_DUTCH:
153 posix = L"nl";
154 break;
155 case LANG_NEPALI:
156 posix = L"ne";
157 break;
158 case LANG_NORWEGIAN:
159 switch(sub_id)
160 {
161 case SUBLANG_NORWEGIAN_BOKMAL:
162 posix = L"nb";
163 break;
164 case SUBLANG_NORWEGIAN_NYNORSK:
165 posix = L"nn";
166 break;
167 }
168 break;
169 case LANG_PUNJABI:
170 posix = L"pa";
171 break;
172 case LANG_POLISH:
173 posix = L"pl";
174 break;
175 case LANG_PASHTO:
176 posix = L"ps";
177 break;
178 case LANG_PORTUGUESE:
179 switch(sub_id)
180 {
181 case SUBLANG_PORTUGUESE_BRAZILIAN:
182 posix = L"pt_BR";
183 break;
184 default:
185 posix = L"pt";
186 break;
187 }
188 break;
189 case LANG_ROMANIAN:
190 posix = L"ro";
191 break;
192 case LANG_RUSSIAN:
193 posix = L"ru";
194 break;
195 case LANG_SLOVAK:
196 posix = L"sk";
197 break;
198 case LANG_SLOVENIAN:
199 posix = L"sl";
200 break;
201 case LANG_ALBANIAN:
202 posix = L"sq";
203 break;
204 /* LANG_CROATIAN == LANG_SERBIAN == LANG_BOSNIAN */
205 case LANG_SERBIAN:
206 switch(sub_id)
207 {
208 case SUBLANG_SERBIAN_LATIN:
209 posix = L"sr@Latn";
210 break;
211 case SUBLANG_SERBIAN_CYRILLIC:
212 posix = L"sr";
213 break;
214 case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC:
215 case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN:
216 posix = L"bs";
217 break;
218 case SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN:
219 posix = L"hr";
220 break;
221 }
222 break;
223 case LANG_SWEDISH:
224 posix = L"sv";
225 break;
226 case LANG_TAMIL:
227 posix = L"ta";
228 break;
229 case LANG_TELUGU:
230 posix = L"te";
231 break;
232 case LANG_THAI:
233 posix = L"th";
234 break;
235 case LANG_TURKISH:
236 posix = L"tr";
237 break;
238 case LANG_UKRAINIAN:
239 posix = L"uk";
240 break;
241 case LANG_VIETNAMESE:
242 posix = L"vi";
243 break;
244 case LANG_XHOSA:
245 posix = L"xh";
246 break;
247 case LANG_CHINESE:
248 switch(sub_id)
249 {
250 case SUBLANG_CHINESE_SIMPLIFIED:
251 posix = L"zh_CN";
252 break;
253 case SUBLANG_CHINESE_TRADITIONAL:
254 posix = L"zh_TW";
255 break;
256 default:
257 posix = L"zh";
258 break;
259 }
260 break;
261 case LANG_URDU:
262 break;
263 case LANG_BELARUSIAN:
264 break;
265 case LANG_LATVIAN:
266 break;
267 case LANG_ARMENIAN:
268 break;
269 case LANG_FAEROESE:
270 break;
271 case LANG_MALAY:
272 break;
273 case LANG_KAZAK:
274 break;
275 case LANG_KYRGYZ:
276 break;
277 case LANG_SWAHILI:
278 break;
279 case LANG_UZBEK:
280 break;
281 case LANG_TATAR:
282 break;
283 case LANG_ORIYA:
284 break;
285 case LANG_MALAYALAM:
286 break;
287 case LANG_ASSAMESE:
288 break;
289 case LANG_MARATHI:
290 break;
291 case LANG_SANSKRIT:
292 break;
293 case LANG_MONGOLIAN:
294 break;
295 case LANG_KONKANI:
296 break;
297 case LANG_MANIPURI:
298 break;
299 case LANG_SINDHI:
300 break;
301 case LANG_SYRIAC:
302 break;
303 case LANG_KASHMIRI:
304 break;
305 case LANG_DIVEHI:
306 break;
307 }
308
309 /* Deal with exceptions */
310 if(IS_NULL_PTR(posix))
311 {
312 switch(lcid)
313 {
314 case 0x0455:
315 posix = L"my_MM";
316 break; /* Myanmar (Burmese) */
317 case 9999:
318 posix = L"ku";
319 break; /* Kurdish (from NSIS) */
320 default:
321 posix = L"en";
322 }
323 }
324
325 return posix;
326}
327
328typedef struct tagTHREADNAME_INFO
329{
330 DWORD dwType; // must be 0x1000
331 LPCSTR szName; // pointer to name (in user addr space)
332 DWORD dwThreadID; // thread ID (-1=caller thread)
333 DWORD dwFlags; // reserved for future use, must be zero
335
336const DWORD MS_VC_EXCEPTION = 0x406D1388;
337
338void dtwin_set_thread_name(DWORD dwThreadID, const char *threadName)
339{
340 THREADNAME_INFO info;
341 info.dwType = 0x1000;
342 info.szName = threadName;
343 info.dwThreadID = dwThreadID;
344 info.dwFlags = 0;
345
346 // Yes, don't get heart attack, naming of thread is done by raising a special exception on Windows
347 // https://msdn.microsoft.com/en-us/library/xcb2z8hs(v=vs.71).aspx
348 RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(DWORD), (const ULONG_PTR *)&info);
349}
350
351// This is taken from: https://git.gnome.org/browse/glib/tree/gio/glocalfile.c#n2269
352// The glib version of this function unfortunately shows always confirmation dialog boxes
353// This version does thrashing silently, without dialog boxes: FOF_SILENT | FOF_NOCONFIRMATION
354// When glib version on Windows will do silent trashing we can remove this function
355boolean dt_win_file_trash(GFile *file, GCancellable *cancellable, GError **error)
356{
357 SHFILEOPSTRUCTW op = { 0 };
358 gboolean success;
359 wchar_t *wfilename;
360 long len;
361
362 wfilename = g_utf8_to_utf16(g_file_get_parse_name(file), -1, NULL, &len, NULL);
363 /* SHFILEOPSTRUCT.pFrom is double-zero-terminated */
364 wfilename = g_renew(wchar_t, wfilename, len + 2);
365 wfilename[len + 1] = 0;
366
367 op.wFunc = FO_DELETE;
368 op.pFrom = wfilename;
369 op.fFlags = FOF_ALLOWUNDO | FOF_SILENT | FOF_NOCONFIRMATION;
370
371 success = SHFileOperationW(&op) == 0;
372
373 if(success && op.fAnyOperationsAborted)
374 {
375 if(cancellable && !g_cancellable_is_cancelled(cancellable)) g_cancellable_cancel(cancellable);
376 g_set_error(error, G_IO_ERROR, g_io_error_from_errno(ECANCELED), "Unable to trash file %s: %s",
377 g_file_get_parse_name(file), g_strerror(ECANCELED));
378 success = FALSE;
379 }
380 else if(!success)
381 g_set_error(error, G_IO_ERROR, g_io_error_from_errno(0), "Unable to trash file %s",
382 g_file_get_parse_name(file));
383
384 dt_free(wfilename);
385 return success;
386}
387// clang-format off
388// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
389// vim: shiftwidth=2 expandtab tabstop=2 cindent
390// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
391// clang-format on
392
static void error(char *msg)
Definition ashift_lsd.c:202
#define FALSE
Definition ashift_lsd.c:158
#define dt_free(ptr)
Definition darktable.h:456
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition darktable.h:281
boolean dt_win_file_trash(GFile *file, GCancellable *cancellable, GError **error)
Definition dtwin.c:355
const DWORD MS_VC_EXCEPTION
Definition dtwin.c:336
struct tagTHREADNAME_INFO THREADNAME_INFO
void dtwin_set_thread_name(DWORD dwThreadID, const char *threadName)
Definition dtwin.c:338
const wchar_t * dtwin_get_locale()
Definition dtwin.c:35