root/branches/3.00/src/cygpackage.cc

Revision 644, 3.8 kB (checked in by fujii, 3 years ago)

Add new netinstall source.

Line 
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: cygpackage.cc,v 2.12 2002/07/01 20:58:46 rbcollins Exp $\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 #ifdef MEADOW_NETINSTALL
126     io_stream::open (String ("cygfile:///packages/setup/") + name + ".lst.gz", "rb");
127 #else
128     io_stream::open (String ("cygfile:///etc/setup/") + name + ".lst.gz", "rb");
129 #endif
130   listdata = compress::decompress (listfile);
131   if (!listdata)
132     return String();
133   return listdata->gets (getfilenamebuffer, sizeof (getfilenamebuffer));
134 }
135
136 String const
137 cygpackage::getnextfile ()
138 {
139   if (listdata)
140     return listdata->gets (getfilenamebuffer, sizeof (getfilenamebuffer));
141   return String();
142 }
143
144 void
145 cygpackage::uninstall ()
146 {
147   if (listdata)
148     delete listdata;
149   listdata = 0;
150 #ifdef MEADOW_NETINSTALL
151   io_stream::remove (String("cygfile:///packages/setup/") + name + ".lst.gz");
152 #else
153   io_stream::remove (String("cygfile:///etc/setup/") + name + ".lst.gz");
154 #endif
155 }
156
157 String const
158 cygpackage::Name ()
159 {
160   return name;
161 }
162
163 String const
164 cygpackage::Vendor_version ()
165 {
166   return vendor;
167 }
168
169 String const
170 cygpackage::Package_version ()
171 {
172   return packagev;
173 }
174
175 String  const
176 cygpackage::Canonical_version ()
177 {
178   return canonical;
179 }
180
181 void
182 cygpackage::set_sdesc (String const &desc)
183 {
184   sdesc = desc;
185 }
186
187 void
188 cygpackage::set_ldesc (String const &desc)
189 {
190   ldesc = desc;
191 }
192
193 #if 0
194 package_stability_t cygpackage::Stability ()
195 {
196   return stability;
197 }
198 #endif
Note: See TracBrowser for help on using the browser.