2001-05-21 02:37:07 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_DIRENT_H
|
|
|
|
#include <dirent.h>
|
|
|
|
#endif
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <process.h> /* For _getpid() */
|
2001-05-26 06:04:21 +08:00
|
|
|
#include <io.h> /* for _unlink() */
|
2001-05-21 02:37:07 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "base-types.h"
|
|
|
|
|
|
|
|
#include "base.h"
|
|
|
|
#include "base-config.h"
|
2001-07-14 03:25:34 +08:00
|
|
|
#include "detect-mmx.h"
|
2001-05-21 02:37:07 +08:00
|
|
|
#include "temp-buf.h"
|
|
|
|
#include "tile-swap.h"
|
|
|
|
|
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void toast_old_temp_files (void);
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
base_init (void)
|
|
|
|
{
|
2001-10-24 23:56:33 +08:00
|
|
|
gchar *swapfile;
|
2001-05-21 02:37:07 +08:00
|
|
|
gchar *path;
|
|
|
|
|
2001-07-14 03:25:34 +08:00
|
|
|
#ifdef HAVE_ASM_MMX
|
|
|
|
use_mmx = (intel_cpu_features() & (1 << 23)) ? 1 : 0;
|
|
|
|
g_print ("using MMX: %s\n", use_mmx ? "yes" : "no");
|
|
|
|
#endif
|
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
toast_old_temp_files ();
|
|
|
|
|
2001-05-21 02:37:07 +08:00
|
|
|
/* Add the swap file */
|
|
|
|
if (base_config->swap_path == NULL)
|
2001-08-01 07:28:56 +08:00
|
|
|
base_config->swap_path = g_strdup (g_get_tmp_dir ());
|
2001-05-21 02:37:07 +08:00
|
|
|
|
2001-10-24 23:56:33 +08:00
|
|
|
swapfile = g_strdup_printf ("gimpswap.%lu", (unsigned long) getpid ());
|
|
|
|
|
|
|
|
path = g_build_filename (base_config->swap_path, swapfile, NULL);
|
|
|
|
|
|
|
|
g_free (swapfile);
|
|
|
|
|
2001-05-21 02:37:07 +08:00
|
|
|
tile_swap_add (path, NULL, NULL);
|
2001-10-24 23:56:33 +08:00
|
|
|
|
2001-05-21 02:37:07 +08:00
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
paint_funcs_setup ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
base_exit (void)
|
|
|
|
{
|
|
|
|
swapping_free ();
|
|
|
|
paint_funcs_free ();
|
|
|
|
tile_swap_exit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
toast_old_temp_files (void)
|
|
|
|
{
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *entry;
|
|
|
|
|
|
|
|
dir = opendir (base_config->swap_path);
|
|
|
|
|
|
|
|
if (!dir)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while ((entry = readdir (dir)) != NULL)
|
2001-10-24 23:56:33 +08:00
|
|
|
if (! strncmp (entry->d_name, "gimpswap.", 9))
|
2001-05-21 02:37:07 +08:00
|
|
|
{
|
|
|
|
/* don't try to kill swap files of running processes
|
|
|
|
* yes, I know they might not all be gimp processes, and when you
|
|
|
|
* unlink, it's refcounted, but lets not confuse the user by
|
|
|
|
* "where did my disk space go?" cause the filename is gone
|
|
|
|
* if the kill succeeds, and there running process isn't gimp
|
|
|
|
* we'll probably get it the next time around
|
|
|
|
*/
|
|
|
|
|
|
|
|
gint pid = atoi (entry->d_name + 9);
|
2001-10-24 23:56:33 +08:00
|
|
|
|
|
|
|
/* On Windows, you can't remove open files anyhow,
|
|
|
|
* so no harm trying.
|
|
|
|
*/
|
2001-05-21 02:37:07 +08:00
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
if (kill (pid, 0))
|
|
|
|
#endif
|
|
|
|
{
|
2001-10-24 23:56:33 +08:00
|
|
|
gchar *filename;
|
|
|
|
|
|
|
|
filename = g_build_filename (base_config->swap_path, entry->d_name,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
unlink (filename);
|
|
|
|
|
|
|
|
g_free (filename);
|
2001-05-21 02:37:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir (dir);
|
|
|
|
}
|