]>
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 | ||
8507f105 DD |
28 | static char *cvsid = "\n%%% $Id$\n"; |
29 | ||
23c9e63c DD |
30 | #include "win32.h" |
31 | ||
32 | #include <stdio.h> | |
33 | #include <stdlib.h> | |
34 | #include <io.h> | |
35 | #include <unistd.h> | |
36 | #include <ctype.h> | |
37 | ||
38 | #include "ini.h" | |
39 | #include "resource.h" | |
40 | #include "concat.h" | |
41 | #include "state.h" | |
42 | #include "dialog.h" | |
43 | #include "msg.h" | |
44 | #include "find.h" | |
fb087b80 | 45 | #include "filemanip.h" |
13d27274 | 46 | #include "version.h" |
23c9e63c DD |
47 | |
48 | #include "port.h" | |
49 | ||
50 | static int | |
51 | is_test_version (char *v) | |
52 | { | |
53 | int i; | |
54 | for (i=0; v[i] && isdigit (v[i]); i++) ; | |
55 | return (i >= 6) ? 1 : 0; | |
56 | } | |
57 | ||
13d27274 DD |
58 | char * |
59 | canonicalize_version (char *v) | |
23c9e63c | 60 | { |
50f64a4b DD |
61 | static char nv[3][100]; |
62 | static int idx = 0; | |
63 | char *np, *dp, *ov = v; | |
23c9e63c DD |
64 | int i; |
65 | ||
50f64a4b DD |
66 | idx = (idx+1) % 3; |
67 | np = nv[idx]; | |
68 | ||
23c9e63c DD |
69 | while (*v) |
70 | { | |
71 | if (isdigit (*v)) | |
72 | { | |
73 | for (dp=v; *dp && isdigit (*dp); dp++) ; | |
74 | for (i=dp-v; i<12; i++) | |
75 | *np++ = '0'; | |
76 | while (v < dp) | |
77 | *np++ = *v++; | |
78 | } | |
79 | else | |
80 | *np++ = *v++; | |
81 | } | |
82 | *np++ = 0; | |
50f64a4b | 83 | return nv[idx]; |
23c9e63c DD |
84 | } |
85 | ||
86 | static void | |
87 | found_file (char *path, unsigned int fsize) | |
88 | { | |
85b43844 CF |
89 | fileparse f; |
90 | char base[_MAX_PATH]; | |
23c9e63c | 91 | |
85b43844 | 92 | if (!parse_filename (path, f)) |
23c9e63c | 93 | return; |
fb087b80 | 94 | |
85b43844 | 95 | if (f.what[0] != '\0') |
23c9e63c | 96 | return; |
23c9e63c | 97 | |
85b43844 CF |
98 | Package *p = NULL; |
99 | for (int i = 0; i < npackages; i++) | |
100 | if (strcmp (package[i].name, f.pkg) == 0) | |
23c9e63c DD |
101 | { |
102 | p = package + i; | |
103 | break; | |
104 | } | |
85b43844 CF |
105 | |
106 | if (p == NULL) | |
23c9e63c DD |
107 | p = new_package (strdup (base)); |
108 | ||
85b43844 | 109 | int trust = is_test_version (f.ver) ? TRUST_TEST : TRUST_CURR; |
23c9e63c DD |
110 | |
111 | /* See if this version is older than what we have */ | |
112 | if (p->info[trust].version) | |
5f48f258 DD |
113 | { |
114 | char *ov = canonicalize_version (p->info[trust].version); | |
85b43844 | 115 | char *nv = canonicalize_version (f.ver); |
5f48f258 DD |
116 | if (strcmp (ov, nv) > 0) |
117 | return; | |
118 | } | |
23c9e63c | 119 | |
85b43844 | 120 | p->info[trust].version = _strdup (f.ver); |
23c9e63c DD |
121 | p->info[trust].install = _strdup (path); |
122 | p->info[trust].install_size = fsize; | |
123 | } | |
124 | ||
125 | void | |
126 | do_fromcwd (HINSTANCE h) | |
127 | { | |
128 | if (_access ("./setup.ini", 0) == 0) | |
129 | { | |
130 | mirror_site = "."; | |
131 | next_dialog = IDD_S_LOAD_INI; | |
132 | return; | |
133 | } | |
134 | ||
713bbe5f | 135 | next_dialog = IDD_CHOOSE; |
23c9e63c DD |
136 | |
137 | find (".", found_file); | |
138 | ||
3b9077d4 DD |
139 | // Now see about source tarballs |
140 | int i, t; | |
141 | Package *p; | |
142 | char srcpath[_MAX_PATH]; | |
fb087b80 | 143 | for (i = 0; i < npackages; i++) |
3b9077d4 DD |
144 | { |
145 | p = package+i; | |
fb087b80 | 146 | for (t = TRUST_PREV; t <= TRUST_TEST; t++) |
3b9077d4 DD |
147 | if (p->info[t].install) |
148 | { | |
fb087b80 | 149 | int n = find_tar_ext (p->info[t].install); |
3b9077d4 | 150 | strcpy (srcpath, p->info[t].install); |
fb087b80 | 151 | strcpy (srcpath + n, "-src.tar.gz"); |
3b9077d4 DD |
152 | msg ("looking for %s", srcpath); |
153 | ||
154 | WIN32_FIND_DATA wfd; | |
155 | HANDLE h = FindFirstFile (srcpath, &wfd); | |
fb087b80 CF |
156 | if (h == INVALID_HANDLE_VALUE) |
157 | { | |
158 | strcpy (srcpath + n, "-src.tar.bz2"); | |
159 | h = FindFirstFile (srcpath, &wfd); | |
160 | } | |
3b9077d4 DD |
161 | if (h != INVALID_HANDLE_VALUE) |
162 | { | |
163 | msg("-- got it"); | |
164 | FindClose (h); | |
165 | p->info[t].source = _strdup (srcpath); | |
166 | p->info[t].source_size = wfd.nFileSizeLow; | |
167 | } | |
168 | } | |
169 | } | |
170 | ||
23c9e63c DD |
171 | return; |
172 | } |