summaryrefslogtreecommitdiff
path: root/src/import.c
blob: cd1f2b3ea82613acd64d84ee8f0dc09f7ed33922 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/***************************************************************************
 *            import.c
 *
 *  Copyright  2005  Ian McIntosh
 *  ian_mcintosh@linuxadvocate.org
 ****************************************************************************/

/*
 *  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 Library 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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>

#include "main.h"
#include "import.h"
#include "importwindow.h"
#include "import_tiger.h"
#include "db.h"

#ifdef USE_GNOME_VFS
#include <gnome-vfs-2.0/libgnomevfs/gnome-vfs.h>
#endif

#if ROADSTER_DEAD_CODE
static void import_progress_pulse(void)
{
	importwindow_progress_pulse();
}
#endif /* ROADSTER_DEAD_CODE */

gboolean import_from_uri(const gchar* pszURI)
{
#ifdef USE_GNOME_VFS
	gboolean bResult = FALSE;

	GnomeVFSFileInfo info;
	if(GNOME_VFS_OK != gnome_vfs_get_file_info(pszURI, &info, GNOME_VFS_FILE_INFO_DEFAULT)) {
		importwindow_log_append("Couldn't read %s\n", pszURI);
		return FALSE;
	}

//	func_progress_callback(0.0, pCallbackData);

	gchar* pszFileBaseName = info.name;

	g_return_val_if_fail(pszFileBaseName != NULL, FALSE);
	// does it look like a tgr file name (tgr00000.zip) ?
	if(strlen(pszFileBaseName) == 12 && g_str_has_prefix(pszFileBaseName, "TGR") && g_str_has_suffix(pszFileBaseName, ".ZIP")) {
		importwindow_log_append("Importing TIGER file %s", info.name);	// NOTE: no "\n" so we can add ...
		gchar buf[6];
		memcpy(buf, &pszFileBaseName[3], 5);
		buf[5] = '\0';

		gint nTigerSetNumber = atoi(buf);
		// just assume it's a TIGER file for now since it's all we support

		//	db_disable_keys();
		bResult = import_tiger_from_uri(pszURI, nTigerSetNumber);
		//	db_enable_keys();

		if(bResult) {
			importwindow_log_append("success.\n\n");
		}
		else {
			importwindow_log_append("\n** Failed.\n\n");
		}
	}
//	g_free(pszFileBaseName);

	// free file info
	gnome_vfs_file_info_unref(&info);

//	func_progress_callback(1.0, pCallbackData);
	return bResult;
#endif
}