]>
Commit | Line | Data |
---|---|---|
23c9e63c DD |
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 | ||
ca83c665 | 28 | #if 0 |
b24c88b3 RC |
29 | static const char *cvsid = |
30 | "\n%%% $Id$\n"; | |
ca83c665 | 31 | #endif |
8507f105 | 32 | |
23c9e63c DD |
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 | ||
23c9e63c | 41 | #include "resource.h" |
23c9e63c DD |
42 | #include "state.h" |
43 | #include "dialog.h" | |
44 | #include "msg.h" | |
45 | #include "find.h" | |
fb087b80 | 46 | #include "filemanip.h" |
13d27274 | 47 | #include "version.h" |
de6a1a64 RC |
48 | #include "site.h" |
49 | #include "rfc1738.h" | |
23c9e63c DD |
50 | |
51 | #include "port.h" | |
52 | ||
bb849dbd RC |
53 | #include "package_db.h" |
54 | #include "package_meta.h" | |
55 | #include "package_version.h" | |
21f325d7 | 56 | #include "cygpackage.h" |
bb849dbd | 57 | # if 0 |
23c9e63c DD |
58 | static int |
59 | is_test_version (char *v) | |
60 | { | |
61 | int i; | |
b24c88b3 | 62 | for (i = 0; v[i] && isdigit (v[i]); i++); |
23c9e63c DD |
63 | return (i >= 6) ? 1 : 0; |
64 | } | |
bb849dbd | 65 | #endif |
23c9e63c DD |
66 | |
67 | static void | |
68 | found_file (char *path, unsigned int fsize) | |
69 | { | |
85b43844 | 70 | fileparse f; |
23c9e63c | 71 | |
85b43844 | 72 | if (!parse_filename (path, f)) |
23c9e63c | 73 | return; |
fb087b80 | 74 | |
3c054baf | 75 | if (f.what.size() != 0) |
23c9e63c | 76 | return; |
23c9e63c | 77 | |
bb849dbd | 78 | packagedb db; |
21f325d7 RC |
79 | packagemeta &p = db.packages.registerbykey (f.pkg); |
80 | packageversion *pv = new cygpackage (f.pkg); | |
81 | ((cygpackage *)pv)->set_canonical_version (f.ver); | |
3c054baf RC |
82 | if (!f.what.size()) |
83 | pv->bin.set_cached (String ("file://") + path); | |
21f325d7 RC |
84 | else |
85 | // patch or src, assume src until someone complains | |
3c054baf | 86 | pv->src.set_cached (String ("file://") + path); |
21f325d7 RC |
87 | |
88 | // check for a duplciate version FIXME make this a method or friend | |
89 | ||
90 | ||
91 | int merged = 0; | |
92 | for (size_t n = 1; !merged && n <= p.versions.number (); n++) | |
3c054baf | 93 | if (!p.versions[n]->Canonical_version().casecompare (pv->Canonical_version())) |
21f325d7 RC |
94 | { |
95 | /* Copy the binary mirror across if this site claims to have an install */ | |
96 | if (pv->bin.sites.number ()) | |
97 | p.versions[n]->bin.sites.registerbykey (pv->bin.sites[1]->key); | |
98 | /* Ditto for src */ | |
99 | if (pv->src.sites.number ()) | |
100 | p.versions[n]->src.sites.registerbykey (pv->src.sites[1]->key); | |
101 | /* Copy the descriptions across */ | |
3c054baf | 102 | if (pv->SDesc ().size() && !p.versions[n]->SDesc ().size()) |
21f325d7 | 103 | p.versions[n]->set_sdesc (pv->SDesc ()); |
3c054baf | 104 | if (pv->LDesc ().size() && !p.versions[n]->LDesc ().size()) |
21f325d7 RC |
105 | p.versions[n]->set_ldesc (pv->LDesc ()); |
106 | pv = p.versions[n]; | |
107 | merged = 1; | |
108 | } | |
109 | if (!merged) | |
110 | p.add_version (*pv); | |
bb849dbd RC |
111 | |
112 | #if 0 | |
113 | // This is handled by the scan2 - there is no need for duplication - or is there? | |
23c9e63c | 114 | |
85b43844 | 115 | int trust = is_test_version (f.ver) ? TRUST_TEST : TRUST_CURR; |
23c9e63c DD |
116 | |
117 | /* See if this version is older than what we have */ | |
118 | if (p->info[trust].version) | |
5f48f258 DD |
119 | { |
120 | char *ov = canonicalize_version (p->info[trust].version); | |
85b43844 | 121 | char *nv = canonicalize_version (f.ver); |
5f48f258 DD |
122 | if (strcmp (ov, nv) > 0) |
123 | return; | |
124 | } | |
23c9e63c | 125 | |
94525fd9 | 126 | if (p->info[trust].version) |
b24c88b3 | 127 | free (p->info[trust].version); |
85b43844 | 128 | p->info[trust].version = _strdup (f.ver); |
94525fd9 RC |
129 | |
130 | if (p->info[trust].install) | |
b24c88b3 | 131 | free (p->info[trust].install); |
23c9e63c | 132 | p->info[trust].install = _strdup (path); |
94525fd9 | 133 | |
23c9e63c | 134 | p->info[trust].install_size = fsize; |
bb849dbd | 135 | #endif |
23c9e63c DD |
136 | } |
137 | ||
de6a1a64 RC |
138 | static bool found_ini; |
139 | ||
140 | static void | |
141 | check_ini (char *path, unsigned int fsize) | |
142 | { | |
143 | if (fsize && strstr (path, "setup.ini")) | |
144 | found_ini = true; | |
145 | } | |
146 | ||
23c9e63c | 147 | void |
ab57ceaa | 148 | do_fromcwd (HINSTANCE h, HWND owner) |
23c9e63c | 149 | { |
ab57ceaa RC |
150 | // Assume we won't find the INI file. |
151 | found_ini = false; | |
de6a1a64 RC |
152 | find (".", check_ini); |
153 | if (found_ini) | |
858f100d RC |
154 | { |
155 | // Found INI, load it. | |
156 | next_dialog = IDD_S_LOAD_INI; | |
23c9e63c | 157 | return; |
858f100d | 158 | } |
23c9e63c | 159 | |
858f100d | 160 | next_dialog = IDD_CHOOSER; |
23c9e63c DD |
161 | |
162 | find (".", found_file); | |
163 | ||
bb849dbd | 164 | #if 0 |
9835fb4a | 165 | // Reinstate this FIXME: Replace obsolete structures first |
3b9077d4 DD |
166 | // Now see about source tarballs |
167 | int i, t; | |
bb849dbd | 168 | packagemeta *p; |
3b9077d4 | 169 | char srcpath[_MAX_PATH]; |
fb087b80 | 170 | for (i = 0; i < npackages; i++) |
3b9077d4 | 171 | { |
b24c88b3 | 172 | p = package + i; |
bb849dbd | 173 | /* For each version with a binary after running find */ |
fb087b80 | 174 | for (t = TRUST_PREV; t <= TRUST_TEST; t++) |
3b9077d4 DD |
175 | if (p->info[t].install) |
176 | { | |
bb849dbd | 177 | /* Is there a -src file too? */ |
fb087b80 | 178 | int n = find_tar_ext (p->info[t].install); |
3b9077d4 | 179 | strcpy (srcpath, p->info[t].install); |
fb087b80 | 180 | strcpy (srcpath + n, "-src.tar.gz"); |
3b9077d4 DD |
181 | msg ("looking for %s", srcpath); |
182 | ||
183 | WIN32_FIND_DATA wfd; | |
184 | HANDLE h = FindFirstFile (srcpath, &wfd); | |
fb087b80 CF |
185 | if (h == INVALID_HANDLE_VALUE) |
186 | { | |
187 | strcpy (srcpath + n, "-src.tar.bz2"); | |
188 | h = FindFirstFile (srcpath, &wfd); | |
189 | } | |
3b9077d4 DD |
190 | if (h != INVALID_HANDLE_VALUE) |
191 | { | |
b24c88b3 | 192 | msg ("-- got it"); |
3b9077d4 DD |
193 | FindClose (h); |
194 | p->info[t].source = _strdup (srcpath); | |
195 | p->info[t].source_size = wfd.nFileSizeLow; | |
196 | } | |
197 | } | |
198 | } | |
bb849dbd | 199 | #endif |
23c9e63c DD |
200 | return; |
201 | } |