Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
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 "common/darktable.h"
30#include "gui/gtk.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#endif
41
42int main(int argc, char *argv[])
43{
44#ifdef __APPLE__
46#endif
47#ifdef _WIN32
48 // Opening any native shell dialog (GtkFileChooserNative -> IFileDialog) loads every
49 // installed shell extension into our process; extensions shipping Intel's OpenMP
50 // runtime (libiomp5md.dll) then collide with our libomp and the Intel runtime aborts
51 // the app with OMP error #15. We never run their OpenMP code and they never run ours,
52 // so the duplicate-runtime detection is a false positive here: silence it, as the
53 // runtime's own message advises.
54 g_setenv("KMP_DUPLICATE_LIB_OK", "TRUE", TRUE);
55
56 // on Windows we have a hard time showing stuff printed to stdout/stderr to the user.
57 // because of that we write it to a log file.
58 char datetime[DT_DATETIME_EXIF_LENGTH];
60
61 // make sure to not redirect output when the output is already being redirected, either to a file or a pipe.
62 int out_type = GetFileType(GetStdHandle(STD_OUTPUT_HANDLE));
63 int err_type = GetFileType(GetStdHandle(STD_ERROR_HANDLE));
64 gboolean redirect_output = ((out_type != FILE_TYPE_DISK && out_type != FILE_TYPE_PIPE) &&
65 (err_type != FILE_TYPE_DISK && err_type != FILE_TYPE_PIPE));
66
67 for(int k = 1; k < argc; k++)
68 {
69 // For simple arguments do not redirect stdout
70 if(!strcmp(argv[k], "--help") || !strcmp(argv[k], "-h") || !strcmp(argv[k], "/?") || !strcmp(argv[k], "--version")
71 || !strcmp(argv[k], "-d") || !strcmp(argv[k], "--debug"))
72 {
73 redirect_output = FALSE;
74 break;
75 }
76 }
77
78 if(redirect_output)
79 {
80 // something like C:\Users\username\AppData\Local\Microsoft\Windows\Temporary Internet Files\ansel\ansel-log.txt
81 char *logdir = g_build_filename(g_get_user_cache_dir(), "ansel", NULL);
82 char *logfile = g_build_filename(logdir, "ansel-log.txt", NULL);
83
84 g_mkdir_with_parents(logdir, 0700);
85
86 g_freopen(logfile, "a", stdout);
87 dup2(fileno(stdout), fileno(stderr));
88
89 // We don't need the console window anymore, free it
90 // This ensures that only darktable's main window will be visible
91 FreeConsole();
92
93 dt_free(logdir);
94 dt_free(logfile);
95
96 // don't buffer stdout/stderr. we have basically two options: unbuffered or line buffered.
97 // unbuffered keeps the order in which things are printed but concurrent threads printing can lead to intermangled output. ugly.
98 // line buffered should keep lines together but in my tests the order of things no longer matches. ugly and potentially confusing.
99 // thus we are doing the thing that is just ugly (in rare cases) but at least not confusing.
100 setvbuf(stdout, NULL, _IONBF, 0);
101 setvbuf(stderr, NULL, _IONBF, 0);
102
103 printf("========================================\n");
104 printf("version: %s\n", darktable_package_string);
105 printf("start: %s\n", datetime);
106 printf("\n");
107 }
108
109 // make sure GTK client side decoration is disabled, otherwise windows resizing issues can be observed
110 g_setenv("GTK_CSD", "0", TRUE);
111#endif
112
113 if(dt_init(argc, argv, TRUE, TRUE)) exit(1);
115
116#ifdef _WIN32
117 if(redirect_output)
118 {
119 printf("\n");
120 printf("end: %s\n", datetime);
121 printf("========================================\n");
122 printf("\n");
123 }
124#endif
125
126 exit(0);
127}
128
129// clang-format off
130// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
131// vim: shiftwidth=2 expandtab tabstop=2 cindent
132// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
133// clang-format on
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
const char darktable_package_string[]
darktable_t darktable
Definition darktable.c:183
int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load_data)
Definition darktable.c:489
#define dt_free(ptr)
Definition darktable.h:478
void dt_datetime_now_to_exif(char *exif)
Definition datetime.c:211
#define DT_DATETIME_EXIF_LENGTH
Definition datetime.h:38
void dt_gui_gtk_run(dt_gui_gtk_t *gui)
Definition gtk.c:1371
float *const restrict const size_t k
void dt_osx_prepare_environment()
Definition osx.mm:212
int main()
Definition prova.c:47
struct dt_gui_gtk_t * gui
Definition darktable.h:803