]> cygwin.com Git - cygwin-apps/setup.git/blob - fromcwd.cc
2002-01-07 Gary R. Van Sickle <g.r.vansickle@worldnet.att.net>
[cygwin-apps/setup.git] / fromcwd.cc
1 /*
2 * Copyright (c) 2000, Red Hat, Inc.
3 *
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.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
13 *
14 */
15
16 /* The purpose of this file is to handle the case where we're
17 installing from files that already exist in the current directory.
18 If a setup.ini file is present, we set the mirror site to "." and
19 pretend we're installing from the `internet' ;-) else we have to
20 find all the .tar.gz files, deduce their versions, and try to
21 compare versions in the case where the current directory contains
22 multiple versions of any given package. We do *not* try to compare
23 versions with already installed packages; we always choose a
24 package in the current directory over one that's already installed
25 (otherwise, why would you have asked to install it?). Note
26 that we search recursively. */
27
28 #if 0
29 static const char *cvsid =
30 "\n%%% $Id$\n";
31 #endif
32
33 #include "win32.h"
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <io.h>
38 #include <unistd.h>
39 #include <ctype.h>
40
41 #include "ini.h"
42 #include "resource.h"
43 #include "concat.h"
44 #include "state.h"
45 #include "dialog.h"
46 #include "msg.h"
47 #include "find.h"
48 #include "filemanip.h"
49 #include "version.h"
50 #include "site.h"
51 #include "rfc1738.h"
52
53 #include "port.h"
54
55 #include "package_db.h"
56 #include "package_meta.h"
57 #include "package_version.h"
58 # if 0
59 static int
60 is_test_version (char *v)
61 {
62 int i;
63 for (i = 0; v[i] && isdigit (v[i]); i++);
64 return (i >= 6) ? 1 : 0;
65 }
66 #endif
67
68 static void
69 found_file (char *path, unsigned int fsize)
70 {
71 fileparse f;
72
73 if (!parse_filename (path, f))
74 return;
75
76 if (f.what[0] != '\0')
77 return;
78
79 packagemeta *p = NULL;
80 packagedb db;
81 p = db.packages.getbykey (f.pkg);
82 if (p == NULL)
83 p = new packagemeta (f.pkg, path);
84
85 #if 0
86 // This is handled by the scan2 - there is no need for duplication - or is there?
87
88 int trust = is_test_version (f.ver) ? TRUST_TEST : TRUST_CURR;
89
90 /* See if this version is older than what we have */
91 if (p->info[trust].version)
92 {
93 char *ov = canonicalize_version (p->info[trust].version);
94 char *nv = canonicalize_version (f.ver);
95 if (strcmp (ov, nv) > 0)
96 return;
97 }
98
99 if (p->info[trust].version)
100 free (p->info[trust].version);
101 p->info[trust].version = _strdup (f.ver);
102
103 if (p->info[trust].install)
104 free (p->info[trust].install);
105 p->info[trust].install = _strdup (path);
106
107 p->info[trust].install_size = fsize;
108 #endif
109 }
110
111 static bool found_ini;
112
113 static void
114 check_ini (char *path, unsigned int fsize)
115 {
116 if (fsize && strstr (path, "setup.ini"))
117 found_ini = true;
118 }
119
120 void
121 do_fromcwd (HINSTANCE h, HWND owner)
122 {
123 // Assume we won't find the INI file.
124 found_ini = false;
125 find (".", check_ini);
126 if (found_ini)
127 {
128 // Found INI, load it.
129 next_dialog = IDD_S_LOAD_INI;
130 return;
131 }
132
133 next_dialog = IDD_CHOOSER;
134
135 find (".", found_file);
136
137 #if 0
138 // Reinstate this FIXME:
139 // Now see about source tarballs
140 int i, t;
141 packagemeta *p;
142 char srcpath[_MAX_PATH];
143 for (i = 0; i < npackages; i++)
144 {
145 p = package + i;
146 /* For each version with a binary after running find */
147 for (t = TRUST_PREV; t <= TRUST_TEST; t++)
148 if (p->info[t].install)
149 {
150 /* Is there a -src file too? */
151 int n = find_tar_ext (p->info[t].install);
152 strcpy (srcpath, p->info[t].install);
153 strcpy (srcpath + n, "-src.tar.gz");
154 msg ("looking for %s", srcpath);
155
156 WIN32_FIND_DATA wfd;
157 HANDLE h = FindFirstFile (srcpath, &wfd);
158 if (h == INVALID_HANDLE_VALUE)
159 {
160 strcpy (srcpath + n, "-src.tar.bz2");
161 h = FindFirstFile (srcpath, &wfd);
162 }
163 if (h != INVALID_HANDLE_VALUE)
164 {
165 msg ("-- got it");
166 FindClose (h);
167 p->info[t].source = _strdup (srcpath);
168 p->info[t].source_size = wfd.nFileSizeLow;
169 }
170 }
171 }
172 #endif
173 return;
174 }
This page took 0.046831 seconds and 6 git commands to generate.