1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
#include <sys/types.h>
29
#include <glib-object.h>
32
#include <process.h> /* for _getpid() */
33
#include <io.h> /* for _unlink() */
36
#include "base-types.h"
38
#include "config/gimpbaseconfig.h"
39
#include "config/gimpconfig-path.h"
41
#include "paint-funcs/paint-funcs.h"
42
#include "composite/gimp-composite.h"
46
#include "tile-cache.h"
47
#include "tile-swap.h"
50
GimpBaseConfig *base_config = NULL;
53
static void base_toast_old_temp_files (GimpBaseConfig *config);
54
static void base_tile_cache_size_notify (GObject *config,
55
GParamSpec *param_spec,
59
/* public functions */
62
base_init (GimpBaseConfig *config,
64
gboolean use_cpu_accel)
71
g_return_val_if_fail (GIMP_IS_BASE_CONFIG (config), FALSE);
72
g_return_val_if_fail (base_config == NULL, FALSE);
74
base_config = g_object_ref (config);
76
tile_cache_init (config->tile_cache_size);
78
g_signal_connect (config, "notify::tile-cache-size",
79
G_CALLBACK (base_tile_cache_size_notify),
82
base_toast_old_temp_files (config);
84
/* Add the swap file */
85
if (! config->swap_path)
86
g_object_set (config, "swap_path", "${gimp_dir}", NULL);
88
swapdir = gimp_config_path_expand (config->swap_path, TRUE, NULL);
89
swapfile = g_strdup_printf ("gimpswap.%lu", (unsigned long) getpid ());
91
path = g_build_filename (swapdir, swapfile, NULL);
96
tile_swap_add (path, NULL, NULL);
100
swap_is_ok = tile_swap_test ();
102
gimp_composite_init (be_verbose, use_cpu_accel);
104
paint_funcs_setup ();
112
g_return_if_fail (base_config != NULL);
119
g_signal_handlers_disconnect_by_func (base_config,
120
base_tile_cache_size_notify,
123
g_object_unref (base_config);
128
/* private functions */
131
base_toast_old_temp_files (GimpBaseConfig *config)
137
if (!config->swap_path)
140
dirname = gimp_config_path_expand (config->swap_path, TRUE, NULL);
144
dir = g_dir_open (dirname, 0, NULL);
152
while ((entry = g_dir_read_name (dir)) != NULL)
153
if (! strncmp (entry, "gimpswap.", 9))
155
/* don't try to kill swap files of running processes
156
* yes, I know they might not all be gimp processes, and when you
157
* unlink, it's refcounted, but lets not confuse the user by
158
* "where did my disk space go?" cause the filename is gone
159
* if the kill succeeds, and there running process isn't gimp
160
* we'll probably get it the next time around
163
gint pid = atoi (entry + 9);
165
/* On Windows, you can't remove open files anyhow,
174
filename = g_build_filename (dirname, entry, NULL);
186
base_tile_cache_size_notify (GObject *config,
187
GParamSpec *param_spec,
190
tile_cache_set_size (GIMP_BASE_CONFIG (config)->tile_cache_size);