annotate src/modplug/archive/arch_gzip.cxx @ 1150:3506c611a802 trunk

[svn] - fix registration of lastfm session ID
author nenolod
date Mon, 28 May 2007 23:29:02 -0700
parents 9549fea94794
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1 /* Modplug XMMS Plugin
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
2 * Authors: Kenton Varda <temporal@gauge3d.org>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
3 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
4 * This source code is public domain.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
5 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
6
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
7 //open()
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
8 #include <sys/types.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
9 #include <sys/stat.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
10 #include <fcntl.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
11 #include <unistd.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
12 #include <stdio.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
13
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
14 #include "arch_gzip.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
15
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
16
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
17 arch_Gzip::arch_Gzip(const string& aFileName)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
18 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
19 //check if file exists
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
20 int lFileDesc = open(aFileName.c_str(), O_RDONLY);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
21
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
22 if(lFileDesc == -1)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
23 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
24 mSize = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
25 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
26 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
27 close(lFileDesc);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
28
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
29 // file exists.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
30 string lCommand = "gunzip -l \"" + aFileName + '\"'; //get info
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
31 FILE *f = popen(lCommand.c_str(), "r");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
32
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
33 if (f <= 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
34 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
35 mSize = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
36 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
37 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
38
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
39 char line[81];
963
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
40 if(!fgets(line, 80, f)){ // ignore a line.
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
41 mSize = 0;
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
42 pclose(f);
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
43 return;
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
44 }
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
45 if(fscanf(f, "%u", &mSize) != 1){ // ignore first number.
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
46 mSize = 0;
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
47 pclose(f);
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
48 return;
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
49 }
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
50
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
51 if (fscanf(f, "%u", &mSize) != 1){; // keep second number.
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
52 mSize = 0;
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
53 pclose(f);
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
54 return;
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
55 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
56
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
57 pclose(f);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
58
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
59 mMap = new char[mSize];
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
60 if(mMap == NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
61 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
62 mSize = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
63 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
64 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
65
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
66 lCommand = "gunzip -c \"" + aFileName + '\"'; //decompress to stdout
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
67 f = popen(lCommand.c_str(), "r");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
68
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
69 if (f <= 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
70 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
71 mSize = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
72 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
73 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
74
963
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
75 if(fread((char *)mMap, sizeof(char), mSize, f) != mSize)
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
76 mSize = 0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
77
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
78 pclose(f);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
79
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
80 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
81
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
82 arch_Gzip::~arch_Gzip()
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
83 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
84 if(mSize != 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
85 delete [] (char*)mMap;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
86 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
87
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
88 bool arch_Gzip::ContainsMod(const string& aFileName)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
89 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
90 string lName;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
91 int lFileDesc = open(aFileName.c_str(), O_RDONLY);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
92 uint32 num;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
93 float fnum;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
94
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
95 if(lFileDesc == -1)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
96 return false;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
97
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
98 close(lFileDesc);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
99
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
100 // file exists.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
101 string lCommand = "gunzip -l \"" + aFileName + '\"'; //get info
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
102 FILE *f = popen(lCommand.c_str(),"r");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
103
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
104 if (f <= 0) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
105 pclose(f);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
106 return false;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
107 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
108
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
109 char line[300];
963
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
110 if(!fgets(line, 80, f)){ // ignore a line.
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
111 pclose(f);
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
112 return false;
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
113 }
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
114 if(fscanf(f, "%i", &num) != 1){ // ignore first number
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
115 pclose(f);
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
116 return false;
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
117 }
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
118 if(fscanf(f, "%i", &num) != 1){ // ignore second number
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
119 pclose(f);
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
120 return false;
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
121 }
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
122 if(fscanf(f, "%f%%", &fnum) != 1){ // ignore ratio
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
123 pclose(f);
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
124 return false;
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
125 }
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
126 if(!fgets(line, 300, f)){ // read in correct line safely.
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
127 pclose(f);
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
128 return false;
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 12
diff changeset
129 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
130 if (strlen(line) > 1)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
131 line[strlen(line)-1] = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
132 lName = line;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
133
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
134 pclose(f);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
135
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
136 return IsOurFile(lName);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
137 }