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 // on Windows we have a hard time showing stuff printed to stdout/stderr to the user.
49 // because of that we write it to a log file.
50 char datetime[DT_DATETIME_EXIF_LENGTH];
52
53 // make sure to not redirect output when the output is already being redirected, either to a file or a pipe.
54 int out_type = GetFileType(GetStdHandle(STD_OUTPUT_HANDLE));
55 int err_type = GetFileType(GetStdHandle(STD_ERROR_HANDLE));
56 gboolean redirect_output = ((out_type != FILE_TYPE_DISK && out_type != FILE_TYPE_PIPE) &&
57 (err_type != FILE_TYPE_DISK && err_type != FILE_TYPE_PIPE));
58
59 for(int k = 1; k < argc; k++)
60 {
61 // For simple arguments do not redirect stdout
62 if(!strcmp(argv[k], "--help") || !strcmp(argv[k], "-h") || !strcmp(argv[k], "/?") || !strcmp(argv[k], "--version")
63 || !strcmp(argv[k], "-d") || !strcmp(argv[k], "--debug"))
64 {
65 redirect_output = FALSE;
66 break;
67 }
68 }
69
70 if(redirect_output)
71 {
72 // something like C:\Users\username\AppData\Local\Microsoft\Windows\Temporary Internet Files\ansel\ansel-log.txt
73 char *logdir = g_build_filename(g_get_user_cache_dir(), "ansel", NULL);
74 char *logfile = g_build_filename(logdir, "ansel-log.txt", NULL);
75
76 g_mkdir_with_parents(logdir, 0700);
77
78 g_freopen(logfile, "a", stdout);
79 dup2(fileno(stdout), fileno(stderr));
80
81 // We don't need the console window anymore, free it
82 // This ensures that only darktable's main window will be visible
83 FreeConsole();
84
85 dt_free(logdir);
86 dt_free(logfile);
87
88 // don't buffer stdout/stderr. we have basically two options: unbuffered or line buffered.
89 // unbuffered keeps the order in which things are printed but concurrent threads printing can lead to intermangled output. ugly.
90 // line buffered should keep lines together but in my tests the order of things no longer matches. ugly and potentially confusing.
91 // thus we are doing the thing that is just ugly (in rare cases) but at least not confusing.
92 setvbuf(stdout, NULL, _IONBF, 0);
93 setvbuf(stderr, NULL, _IONBF, 0);
94
95 printf("========================================\n");
96 printf("version: %s\n", darktable_package_string);
97 printf("start: %s\n", datetime);
98 printf("\n");
99 }
100
101 // make sure GTK client side decoration is disabled, otherwise windows resizing issues can be observed
102 g_setenv("GTK_CSD", "0", TRUE);
103#endif
104
105 if(dt_init(argc, argv, TRUE, TRUE)) exit(1);
107
108#ifdef _WIN32
109 if(redirect_output)
110 {
111 printf("\n");
112 printf("end: %s\n", datetime);
113 printf("========================================\n");
114 printf("\n");
115 }
116#endif
117
118 exit(0);
119}
120
121// clang-format off
122// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
123// vim: shiftwidth=2 expandtab tabstop=2 cindent
124// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
125// 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:181
int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load_data)
Definition darktable.c:451
#define dt_free(ptr)
Definition darktable.h:456
void dt_datetime_now_to_exif(char *exif)
Definition datetime.c:204
#define DT_DATETIME_EXIF_LENGTH
Definition datetime.h:38
void dt_gui_gtk_run(dt_gui_gtk_t *gui)
Definition gtk.c:1290
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:775