]> cygwin.com Git - cygwin-apps/setup.git/blob - cygpackage.cc
2002-07-15 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / cygpackage.cc
1 /*
2 * Copyright (c) 2001, Robert Collins.
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 Robert Collins <rbtcollins@hotmail.com>
13 *
14 */
15
16 /* this is the parent class for all package operations.
17 */
18
19 #if 0
20 static const char *cvsid =
21 "\n%%% $Id$\n";
22 #endif
23
24 #include "cygpackage.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include "String++.h"
29
30 #include "io_stream.h"
31 #include "compress.h"
32
33 #include "package_version.h"
34 #include "cygpackage.h"
35
36 /* this constructor creates an invalid package - further details MUST be provided */
37 cygpackage::cygpackage ():
38 name (),
39 vendor (),
40 packagev (),
41 canonical (),
42 fn (),
43 sdesc (),
44 ldesc (),
45 status (package_installed),
46 type (package_binary),
47 listdata (),
48 listfile ()
49 {
50 memset( getfilenamebuffer, '\0', _MAX_PATH);
51
52 /* FIXME: query the install database for the currently installed
53 * version details
54 */
55 }
56
57 packageversion
58 cygpackage::createInstance (String const &pkgname)
59 {
60 cygpackage *temp = new cygpackage;
61 temp->name = pkgname;
62 return packageversion(temp);
63 }
64
65 packageversion
66 cygpackage::createInstance (String const &pkgname, String const &filename,
67 size_t const fs, String const &version,
68 package_status_t const newstatus,
69 package_type_t const newtype)
70 {
71 cygpackage *temp = new cygpackage;
72 temp->name = pkgname;
73 temp->fn = filename;
74 temp->status = newstatus;
75 temp->type = newtype;
76 temp->filesize = fs;
77 temp->setCanonicalVersion (version);
78 return packageversion(temp);
79 }
80
81 /* tell the version */
82 void
83 cygpackage::setCanonicalVersion (String const &version)
84 {
85 canonical = version;
86 char *start = strchr (canonical.cstr_oneuse(), '-');
87 char*curr=start;
88 if (curr)
89 {
90 char *next;
91 while ((next = strchr (curr + 1, '-')))
92 curr = next;
93 /* curr = last - in the version string */
94 packagev = curr + 1;
95 char tvendor [version.size() +1];
96 strcpy (tvendor, version.cstr_oneuse());
97 tvendor[curr - start] = '\0';
98 vendor=tvendor;
99 }
100 else
101 {
102 packagev = 0;
103 vendor = version;
104 }
105 }
106
107 cygpackage::~cygpackage ()
108 {
109 destroy ();
110 }
111
112 /* helper functions */
113
114 void
115 cygpackage::destroy ()
116 {
117 }
118
119 String const
120 cygpackage::getfirstfile ()
121 {
122 if (listdata)
123 delete listdata;
124 listfile =
125 io_stream::open (String ("cygfile:///etc/setup/") + name + ".lst.gz", "rb");
126 listdata = compress::decompress (listfile);
127 if (!listdata)
128 return String();
129 return listdata->gets (getfilenamebuffer, sizeof (getfilenamebuffer));
130 }
131
132 String const
133 cygpackage::getnextfile ()
134 {
135 if (listdata)
136 return listdata->gets (getfilenamebuffer, sizeof (getfilenamebuffer));
137 return String();
138 }
139
140 void
141 cygpackage::uninstall ()
142 {
143 if (listdata)
144 delete listdata;
145 listdata = 0;
146 io_stream::remove (String("cygfile:///etc/setup/") + name + ".lst.gz");
147 }
148
149 String const
150 cygpackage::Name ()
151 {
152 return name;
153 }
154
155 String const
156 cygpackage::Vendor_version ()
157 {
158 return vendor;
159 }
160
161 String const
162 cygpackage::Package_version ()
163 {
164 return packagev;
165 }
166
167 String const
168 cygpackage::Canonical_version ()
169 {
170 return canonical;
171 }
172
173 void
174 cygpackage::set_sdesc (String const &desc)
175 {
176 sdesc = desc;
177 }
178
179 void
180 cygpackage::set_ldesc (String const &desc)
181 {
182 ldesc = desc;
183 }
184
185 #if 0
186 package_stability_t cygpackage::Stability ()
187 {
188 return stability;
189 }
190 #endif
This page took 0.042634 seconds and 5 git commands to generate.