Mercurial > audlegacy-plugins
comparison src/modplug/archive/arch_gzip.cxx @ 12:3da1b8942b8b trunk
[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author | nenolod |
---|---|
date | Mon, 18 Sep 2006 03:14:20 -0700 |
parents | src/Input/modplug/archive/arch_gzip.cxx@13389e613d67 |
children | 9549fea94794 |
comparison
equal
deleted
inserted
replaced
11:cff1d04026ae | 12:3da1b8942b8b |
---|---|
1 /* Modplug XMMS Plugin | |
2 * Authors: Kenton Varda <temporal@gauge3d.org> | |
3 * | |
4 * This source code is public domain. | |
5 */ | |
6 | |
7 //open() | |
8 #include <sys/types.h> | |
9 #include <sys/stat.h> | |
10 #include <fcntl.h> | |
11 #include <unistd.h> | |
12 #include <stdio.h> | |
13 | |
14 #include "arch_gzip.h" | |
15 | |
16 | |
17 arch_Gzip::arch_Gzip(const string& aFileName) | |
18 { | |
19 //check if file exists | |
20 int lFileDesc = open(aFileName.c_str(), O_RDONLY); | |
21 | |
22 if(lFileDesc == -1) | |
23 { | |
24 mSize = 0; | |
25 return; | |
26 } | |
27 close(lFileDesc); | |
28 | |
29 // file exists. | |
30 string lCommand = "gunzip -l \"" + aFileName + '\"'; //get info | |
31 FILE *f = popen(lCommand.c_str(), "r"); | |
32 | |
33 if (f <= 0) | |
34 { | |
35 mSize = 0; | |
36 return; | |
37 } | |
38 | |
39 char line[81]; | |
40 fgets(line, 80, f); // ignore a line. | |
41 fscanf(f, "%u", &mSize); // ignore first number. | |
42 fscanf(f, "%u", &mSize); // keep second number. | |
43 | |
44 pclose(f); | |
45 | |
46 mMap = new char[mSize]; | |
47 if(mMap == NULL) | |
48 { | |
49 mSize = 0; | |
50 return; | |
51 } | |
52 | |
53 lCommand = "gunzip -c \"" + aFileName + '\"'; //decompress to stdout | |
54 f = popen(lCommand.c_str(), "r"); | |
55 | |
56 if (f <= 0) | |
57 { | |
58 mSize = 0; | |
59 return; | |
60 } | |
61 | |
62 fread((char *)mMap, sizeof(char), mSize, f); | |
63 | |
64 pclose(f); | |
65 | |
66 } | |
67 | |
68 arch_Gzip::~arch_Gzip() | |
69 { | |
70 if(mSize != 0) | |
71 delete [] (char*)mMap; | |
72 } | |
73 | |
74 bool arch_Gzip::ContainsMod(const string& aFileName) | |
75 { | |
76 string lName; | |
77 int lFileDesc = open(aFileName.c_str(), O_RDONLY); | |
78 uint32 num; | |
79 float fnum; | |
80 | |
81 if(lFileDesc == -1) | |
82 return false; | |
83 | |
84 close(lFileDesc); | |
85 | |
86 // file exists. | |
87 string lCommand = "gunzip -l \"" + aFileName + '\"'; //get info | |
88 FILE *f = popen(lCommand.c_str(),"r"); | |
89 | |
90 if (f <= 0) { | |
91 pclose(f); | |
92 return false; | |
93 } | |
94 | |
95 char line[300]; | |
96 fgets(line, 80, f); // ignore a line. | |
97 fscanf(f, "%i", &num); // ignore first number | |
98 fscanf(f, "%i", &num); // ignore second number | |
99 fscanf(f, "%f%%", &fnum); // ignore ratio | |
100 fgets(line, 300, f); // read in correct line safely. | |
101 if (strlen(line) > 1) | |
102 line[strlen(line)-1] = 0; | |
103 lName = line; | |
104 | |
105 pclose(f); | |
106 | |
107 return IsOurFile(lName); | |
108 } |