Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
ansel/main.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) 2014 Jérémy Rosen.
6 Copyright (C) 2014, 2016-2018 Tobias Ellinghaus.
7 Copyright (C) 2018 Peter Budai.
8 Copyright (C) 2019 Michael Baumgaertner.
9 Copyright (C) 2019 parafin.
10 Copyright (C) 2019-2020 Pascal Obry.
11 Copyright (C) 2022 Aurélien PIERRE.
12 Copyright (C) 2022 Martin Bařinka.
13 Copyright (C) 2022 Philippe Weyland.
14 Copyright (C) 2025 Guillaume Stutin.
15
16 darktable is free software: you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation, either version 3 of the License, or
19 (at your option) any later version.
20
21 darktable is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with darktable. If not, see <http://www.gnu.org/licenses/>.
28*/
29#include "darktable.h"
30#include "gui/application.h"
31#include <stdlib.h>
32
33#ifdef __APPLE__
34#include "osx/osx.h"
35#endif
36
37#ifdef _WIN32
38#include "win/main_wrapper.h"
39#include "common/datetime.h"
40// Placed unconditionally this is an unused include on every other platform, which
41// tools/check_unused_includes.sh rightly rejects.
42#include "common/file_location.h" // conditional-ok: dt_loc_default_user_cache_dir() is called only by the log redirection in this same #ifdef
43#endif
44
45int main(int argc, char *argv[])
46{
47#ifdef __APPLE__
49#endif
50#ifdef _WIN32
51 // Opening any native shell dialog (GtkFileChooserNative -> IFileDialog) loads every
52 // installed shell extension into our process; extensions shipping Intel's OpenMP
53 // runtime (libiomp5md.dll) then collide with our libomp and the Intel runtime aborts
54 // the app with OMP error #15. We never run their OpenMP code and they never run ours,
55 // so the duplicate-runtime detection is a false positive here: silence it, as the
56 // runtime's own message advises.
57 g_setenv("KMP_DUPLICATE_LIB_OK", "TRUE", TRUE);
58
59 // ansel.exe is linked as a GUI-subsystem binary, so it has no console of its own and
60 // anything printed to stdout/stderr would go nowhere. We write it to a log file
61 // instead -- unless the caller already arranged somewhere for it to go.
62 char datetime[DT_DATETIME_EXIF_LENGTH];
64
65 // make sure to not redirect output when the output is already being redirected, either to a file or a pipe.
66 int out_type = GetFileType(GetStdHandle(STD_OUTPUT_HANDLE));
67 int err_type = GetFileType(GetStdHandle(STD_ERROR_HANDLE));
68 gboolean redirect_output = ((out_type != FILE_TYPE_DISK && out_type != FILE_TYPE_PIPE) &&
69 (err_type != FILE_TYPE_DISK && err_type != FILE_TYPE_PIPE));
70
71 for(int k = 1; k < argc; k++)
72 {
73 // These print one thing and exit, so they want whatever the caller arranged, not a log file.
74 // `-d`/`--debug` used to be in this list and must NOT come back: this binary has no console of
75 // its own, so cancelling the redirection for the flags that PRODUCE output sent every debug
76 // channel nowhere at all, which is why Windows reports arrived with no log (#1472). A caller
77 // who does want the output on a handle of their own still gets it -- the test above declines to
78 // redirect as soon as stdout or stderr is a file or a pipe.
79 if(!strcmp(argv[k], "--help") || !strcmp(argv[k], "-h") || !strcmp(argv[k], "/?") || !strcmp(argv[k], "--version"))
80 {
81 redirect_output = FALSE;
82 break;
83 }
84 }
85
86 if(redirect_output)
87 {
88 // C:\Users<username>\AppData\Local\cache\ansel\ansel-log.txt. dt_loc_init() has not run
89 // yet, so this resolves the same default it will, without setting any global -- and without
90 // honouring --cachedir, which is not parsed yet either.
91 char *logdir = dt_loc_default_user_cache_dir();
92 char *logfile = g_build_filename(logdir, "ansel-log.txt", NULL);
93
94 g_mkdir_with_parents(logdir, 0700);
95
96 /* If this fails, freopen() has already closed stdout and fileno() answers -1; handing
97 * that to dup2() reaches the CRT's invalid-parameter handler, which ends the process
98 * before the first window is ever drawn. A log file we could not open is not worth
99 * dying for, so stop redirecting and carry on. */
100 redirect_output = (g_freopen(logfile, "a", stdout) != NULL);
101
102 if(redirect_output)
103 {
104 dup2(fileno(stdout), fileno(stderr));
105
106 // don't buffer stdout/stderr. we have basically two options: unbuffered or line buffered.
107 // unbuffered keeps the order in which things are printed but concurrent threads printing can lead to intermangled output. ugly.
108 // line buffered should keep lines together but in my tests the order of things no longer matches. ugly and potentially confusing.
109 // thus we are doing the thing that is just ugly (in rare cases) but at least not confusing.
110 setvbuf(stdout, NULL, _IONBF, 0);
111 setvbuf(stderr, NULL, _IONBF, 0);
112
113 printf("========================================\n");
114 printf("version: %s\n", darktable_package_string);
115 printf("start: %s\n", datetime);
116 printf("\n");
117 }
118
119 dt_free(logdir);
120 dt_free(logfile);
121 }
122
123 // make sure GTK client side decoration is disabled, otherwise windows resizing issues can be observed
124 g_setenv("GTK_CSD", "0", TRUE);
125#endif
126
127 if(dt_init(argc, argv, TRUE, TRUE)) exit(1);
129
130#ifdef _WIN32
131 if(redirect_output)
132 {
133 printf("\n");
134 printf("end: %s\n", datetime);
135 printf("========================================\n");
136 printf("\n");
137 }
138#endif
139
140 exit(0);
141}
142
143// clang-format off
144// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
145// vim: shiftwidth=2 expandtab tabstop=2 cindent
146// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
147// clang-format on
void dt_gui_gtk_run(dt_gui_gtk_t *gui)
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
const char darktable_package_string[]
int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load_data)
Definition darktable.c:888
struct dt_gui_gtk_t * dt_gui_get_global(void)
Definition darktable.c:526
void dt_datetime_now_to_exif(char *exif)
Definition datetime.c:225
#define DT_DATETIME_EXIF_LENGTH
Definition datetime.h:39
gchar * dt_loc_default_user_cache_dir(void)
Resolve the default user cache directory the way dt_loc_init_user_cache_dir() does,...
float *const restrict const size_t k
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
Definition mem_alloc.h:171
void dt_osx_prepare_environment()
Definition osx.mm:213
int main()
Definition prova.c:47