]> cygwin.com Git - cygwin-apps/setup.git/blob - fromcwd.cc
2002-02-19 Robert Collins <rbtcollins@hotmail.com>
[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 #include "cygpackage.h"
59 # if 0
60 static int
61 is_test_version (char *v)
62 {
63 int i;
64 for (i = 0; v[i] && isdigit (v[i]); i++);
65 return (i >= 6) ? 1 : 0;
66 }
67 #endif
68
69 static void
70 found_file (char *path, unsigned int fsize)
71 {
72 fileparse f;
73
74 if (!parse_filename (path, f))
75 return;
76
77 if (f.what.size() != 0)
78 return;
79
80 packagedb db;
81 packagemeta &p = db.packages.registerbykey (f.pkg);
82 packageversion *pv = new cygpackage (f.pkg);
83 ((cygpackage *)pv)->set_canonical_version (f.ver);
84 if (!f.what.size())
85 pv->bin.set_cached (String ("file://") + path);
86 else
87 // patch or src, assume src until someone complains
88 pv->src.set_cached (String ("file://") + path);
89
90 // check for a duplciate version FIXME make this a method or friend
91
92
93 int merged = 0;
94 for (size_t n = 1; !merged && n <= p.versions.number (); n++)
95 if (!p.versions[n]->Canonical_version().casecompare (pv->Canonical_version()))
96 {
97 /* Copy the binary mirror across if this site claims to have an install */
98 if (pv->bin.sites.number ())
99 p.versions[n]->bin.sites.registerbykey (pv->bin.sites[1]->key);
100 /* Ditto for src */
101 if (pv->src.sites.number ())
102 p.versions[n]->src.sites.registerbykey (pv->src.sites[1]->key);
103 /* Copy the descriptions across */
104 if (pv->SDesc ().size() && !p.versions[n]->SDesc ().size())
105 p.versions[n]->set_sdesc (pv->SDesc ());
106 if (pv->LDesc ().size() && !p.versions[n]->LDesc ().size())
107 p.versions[n]->set_ldesc (pv->LDesc ());
108 pv = p.versions[n];
109 merged = 1;
110 }
111 if (!merged)
112 p.add_version (*pv);
113
114 #if 0
115 // This is handled by the scan2 - there is no need for duplication - or is there?
116
117 int trust = is_test_version (f.ver) ? TRUST_TEST : TRUST_CURR;
118
119 /* See if this version is older than what we have */
120 if (p->info[trust].version)
121 {
122 char *ov = canonicalize_version (p->info[trust].version);
123 char *nv = canonicalize_version (f.ver);
124 if (strcmp (ov, nv) > 0)
125 return;
126 }
127
128 if (p->info[trust].version)
129 free (p->info[trust].version);
130 p->info[trust].version = _strdup (f.ver);
131
132 if (p->info[trust].install)
133 free (p->info[trust].install);
134 p->info[trust].install = _strdup (path);
135
136 p->info[trust].install_size = fsize;
137 #endif
138 }
139
140 static bool found_ini;
141
142 static void
143 check_ini (char *path, unsigned int fsize)
144 {
145 if (fsize && strstr (path, "setup.ini"))
146 found_ini = true;
147 }
148
149 void
150 do_fromcwd (HINSTANCE h, HWND owner)
151 {
152 // Assume we won't find the INI file.
153 found_ini = false;
154 find (".", check_ini);
155 if (found_ini)
156 {
157 // Found INI, load it.
158 next_dialog = IDD_S_LOAD_INI;
159 return;
160 }
161
162 next_dialog = IDD_CHOOSER;
163
164 find (".", found_file);
165
166 #if 0
167 // Reinstate this FIXME: Replace obsolete structures first
168 // Now see about source tarballs
169 int i, t;
170 packagemeta *p;
171 char srcpath[_MAX_PATH];
172 for (i = 0; i < npackages; i++)
173 {
174 p = package + i;
175 /* For each version with a binary after running find */
176 for (t = TRUST_PREV; t <= TRUST_TEST; t++)
177 if (p->info[t].install)
178 {
179 /* Is there a -src file too? */
180 int n = find_tar_ext (p->info[t].install);
181 strcpy (srcpath, p->info[t].install);
182 strcpy (srcpath + n, "-src.tar.gz");
183 msg ("looking for %s", srcpath);
184
185 WIN32_FIND_DATA wfd;
186 HANDLE h = FindFirstFile (srcpath, &wfd);
187 if (h == INVALID_HANDLE_VALUE)
188 {
189 strcpy (srcpath + n, "-src.tar.bz2");
190 h = FindFirstFile (srcpath, &wfd);
191 }
192 if (h != INVALID_HANDLE_VALUE)
193 {
194 msg ("-- got it");
195 FindClose (h);
196 p->info[t].source = _strdup (srcpath);
197 p->info[t].source_size = wfd.nFileSizeLow;
198 }
199 }
200 }
201 #endif
202 return;
203 }
This page took 0.047428 seconds and 5 git commands to generate.