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