evecache 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,322 @@
1
+ // libevecache - EVE Cache File Reader Library
2
+ // Copyright (C) 2009-2010 StackFoundry LLC and Yann Ramin
3
+ //
4
+ // This library is free software; you can redistribute it and/or
5
+ // modify it under the terms of the GNU General Public
6
+ // License as published by the Free Software Foundation; either
7
+ // version 2 of the License, or (at your option) any later version.
8
+ //
9
+ // This library is distributed in the hope that it will be useful,
10
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ // General Public License for more details.
13
+ //
14
+ // You should have received a copy of the GNU General Public
15
+ // License along with this library; if not, write to the Free Software
16
+ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+ //
18
+ // http://dev.eve-central.com/libevecache/
19
+ // http://gitorious.org/libevecache
20
+
21
+ #include "evecache/reader.hpp"
22
+ #include "evecache/exceptions.hpp"
23
+
24
+ #include <fstream>
25
+ #include <iostream>
26
+ #include <cstring>
27
+ #include <assert.h>
28
+ #include <vector>
29
+
30
+ namespace EveCache {
31
+
32
+
33
+ #ifdef WIN32
34
+ CacheFile::CacheFile(const std::wstring &filename) : contents(0), length(0), valid(false),
35
+ wfilename(filename)
36
+ {
37
+
38
+ }
39
+
40
+ #else
41
+ CacheFile::CacheFile(const std::string &filename) : contents(0), length(0), valid(false),
42
+ filename(filename)
43
+ {
44
+
45
+ }
46
+
47
+ #endif
48
+
49
+ CacheFile::CacheFile(std::vector<unsigned char> &buf)
50
+ {
51
+ length = (int)buf.size()+16; // TODO: unugly padding
52
+ contents = new unsigned char[length];
53
+ unsigned char *cur = contents;
54
+ std::vector<unsigned char>::iterator i = buf.begin();
55
+ for (; i != buf.end(); ++i)
56
+ {
57
+ *cur = *i;
58
+ cur++;
59
+ }
60
+ while (cur < contents+length) { // TODO ... need "virtual" 0 at end of buffer?
61
+ *cur = 0;
62
+ cur++;
63
+ }
64
+
65
+ valid = true;
66
+ }
67
+
68
+ CacheFile::CacheFile(const CacheFile&rhs) : length(rhs.length), valid(rhs.valid),
69
+ filename(rhs.filename), wfilename(rhs.wfilename)
70
+ {
71
+ contents = new unsigned char[length];
72
+ memcpy(contents, rhs.contents, length);
73
+ }
74
+
75
+ CacheFile::~CacheFile()
76
+ {
77
+ if (contents != NULL)
78
+ delete [] contents;
79
+ }
80
+
81
+ bool CacheFile::readFile()
82
+ {
83
+ using namespace std;
84
+ #ifdef WIN32
85
+ ifstream file(wfilename, ios::in | ios::binary | ios::ate);
86
+ #endif
87
+ ifstream file(filename.c_str(), ios::in | ios::binary | ios::ate);
88
+ if (file.is_open())
89
+ {
90
+ ifstream::pos_type size;
91
+ size = file.tellg();
92
+ contents = new unsigned char [(int)size];
93
+ file.seekg(0, ios::beg);
94
+ file.read(reinterpret_cast<char*>(contents), size);
95
+ file.close();
96
+ valid = true;
97
+ length = static_cast<int>(size);
98
+ }
99
+ return valid;
100
+ }
101
+
102
+ int CacheFile::getLength() const
103
+ {
104
+ if (!valid)
105
+ return -1;
106
+ return length;
107
+ }
108
+
109
+ CacheFile_Iterator CacheFile::begin() const
110
+ {
111
+ return CacheFile_Iterator(this, 0, getLength());
112
+ }
113
+
114
+ CacheFile_Iterator CacheFile::end() const
115
+ {
116
+ return CacheFile_Iterator(this, length, getLength());
117
+ }
118
+
119
+ unsigned char CacheFile::byteAt(int pos) const
120
+ {
121
+ if (pos >= 0 && pos < length)
122
+ return contents[pos];
123
+ throw EndOfFileException();
124
+ }
125
+
126
+ void CacheFile::peekAt(unsigned char *data, int at, int len) const
127
+ {
128
+ // Broken for big endian...
129
+ memcpy(data, &contents[at], len);
130
+ }
131
+
132
+
133
+ /**
134
+ * Iterator
135
+ */
136
+
137
+ CacheFile_Iterator::CacheFile_Iterator(CacheFile const* cf, int position, int valid_length) :
138
+ cacheFile(cf), lastPeek(0), pos(position), _limit(valid_length)
139
+ {
140
+ }
141
+
142
+ CacheFile_Iterator::CacheFile_Iterator(const CacheFile_Iterator& rhs)
143
+ : cacheFile(rhs.cacheFile), lastPeek(rhs.lastPeek), pos(rhs.pos), _limit(rhs._limit)
144
+ {
145
+ }
146
+
147
+ CacheFile_Iterator::~CacheFile_Iterator()
148
+ {
149
+ }
150
+
151
+ CacheFile_Iterator& CacheFile_Iterator::operator=(const CacheFile_Iterator& rhs)
152
+ {
153
+ pos = rhs.pos;
154
+ _limit = rhs._limit;
155
+ cacheFile = rhs.cacheFile;
156
+ return *this;
157
+ }
158
+
159
+ bool CacheFile_Iterator::operator==(const CacheFile_Iterator& rhs) const
160
+ {
161
+ if (rhs.pos == pos && rhs.cacheFile == cacheFile)
162
+ return true;
163
+ return false;
164
+ }
165
+
166
+ bool CacheFile_Iterator::operator!=(const CacheFile_Iterator& rhs) const
167
+ {
168
+ return !((*this) == rhs);
169
+ }
170
+
171
+ bool CacheFile_Iterator::atEnd() const
172
+ {
173
+ if (pos <= _limit)
174
+ return false;
175
+ return true;
176
+ }
177
+
178
+ int CacheFile_Iterator::position() const
179
+ {
180
+ return pos;
181
+ }
182
+
183
+ int CacheFile_Iterator::limit() const
184
+ {
185
+ return _limit - pos;
186
+ }
187
+
188
+ int CacheFile_Iterator::peekInt() const
189
+ {
190
+ int i = cacheFile->byteAt(pos) |
191
+ (cacheFile->byteAt(pos+1) << 8) |
192
+ (cacheFile->byteAt(pos+2) << (8+8)) |
193
+ (cacheFile->byteAt(pos+3) << (8+8+8));
194
+ return i;
195
+ }
196
+
197
+ int CacheFile_Iterator::peekShort() const
198
+ {
199
+ int i = cacheFile->byteAt(pos) |
200
+ (cacheFile->byteAt(pos+1) << 8);
201
+ return i;
202
+ }
203
+
204
+ unsigned char CacheFile_Iterator::peekChar() const
205
+ {
206
+ return static_cast<unsigned char>(cacheFile->byteAt(pos));
207
+ }
208
+
209
+ float CacheFile_Iterator::peekFloat() const
210
+ {
211
+ assert(sizeof(float) == 4);
212
+
213
+ float f = 0;
214
+ unsigned char *i = reinterpret_cast<unsigned char*>(&f);
215
+ cacheFile->peekAt(i, pos, sizeof(float));
216
+ return f;
217
+ }
218
+
219
+ double CacheFile_Iterator::peekDouble() const
220
+ {
221
+ assert(sizeof(double) == 8);
222
+
223
+ double f = 0;
224
+ unsigned char *i = reinterpret_cast<unsigned char*>(&f);
225
+ cacheFile->peekAt(i, pos, sizeof(double));
226
+ return f;
227
+
228
+ }
229
+
230
+ std::string CacheFile_Iterator::peekString(int len) const
231
+ {
232
+ // TODO: This is dumb
233
+ unsigned char *tmp = new unsigned char[len+1];
234
+ try {
235
+ cacheFile->peekAt(tmp, pos, len);
236
+ tmp[len] = '\0';
237
+ std::string r(reinterpret_cast<char*>(tmp), len);
238
+ delete [] tmp;
239
+ return r;
240
+ } catch (EndOfFileException &e) {
241
+ delete [] tmp;
242
+ throw e;
243
+ }
244
+ }
245
+
246
+ void CacheFile_Iterator::seek(int lpos)
247
+ {
248
+ pos = lpos;
249
+ }
250
+
251
+ bool CacheFile_Iterator::advance(int len)
252
+ {
253
+ pos += len;
254
+ return atEnd();
255
+ }
256
+
257
+ void CacheFile_Iterator::setLimit(int len)
258
+ {
259
+ _limit = pos + len;
260
+ }
261
+
262
+
263
+ int CacheFile_Iterator::readShort()
264
+ {
265
+ int r = peekShort();
266
+ advance(2);
267
+ return r;
268
+ }
269
+
270
+ int CacheFile_Iterator::readInt()
271
+ {
272
+ int r = peekInt();
273
+ advance(4);
274
+ return r;
275
+ }
276
+
277
+ unsigned char CacheFile_Iterator::readChar()
278
+ {
279
+ unsigned char r = peekChar();
280
+ advance(1);
281
+ return r;
282
+ }
283
+
284
+ float CacheFile_Iterator::readFloat()
285
+ {
286
+ float r = peekFloat();
287
+ advance(4);
288
+ return r;
289
+ }
290
+
291
+ double CacheFile_Iterator::readDouble()
292
+ {
293
+ double r = peekDouble();
294
+ advance(8);
295
+ return r;
296
+ }
297
+
298
+ std::string CacheFile_Iterator::readString(int len)
299
+ {
300
+ std::string r = peekString(len);
301
+ advance(len);
302
+ return r;
303
+ }
304
+
305
+ long long CacheFile_Iterator::readLongLong()
306
+ {
307
+ unsigned int a = static_cast<unsigned int>(readInt());
308
+ unsigned int b = static_cast<unsigned int>(readInt());
309
+ long long c = (long long)a | ((long long)b << 32);
310
+ return c;
311
+ }
312
+
313
+
314
+ CacheFile_Iterator& CacheFile_Iterator::operator+=(int len)
315
+ {
316
+ advance(len);
317
+ return *this;
318
+ }
319
+
320
+
321
+
322
+ };
data/lib/evecache.rb ADDED
@@ -0,0 +1,83 @@
1
+ require 'evecache.bundle'
2
+
3
+ module Evecache
4
+ VERSION = "0.42.0"
5
+ end
6
+
7
+ class Evecache::MarketList
8
+ def invalid?
9
+ # I guess thats the only way to check for invalid files as the c++ code does not raise exceptions or something here
10
+ self.region == 0
11
+ end
12
+
13
+ def sell_orders
14
+ getSellOrders.collect() { |o| h={}
15
+ h[:price] = o.price
16
+ h[:vol_remaining] = o.volRemaining
17
+ h[:type_id] = o.type
18
+ h[:range] = o.range
19
+ h[:order_id] = o.orderID
20
+ h[:vol_entered] = o.volEntered
21
+ h[:min_volume] = o.minVolume
22
+ h[:issued] = o.issued
23
+ h[:duration] = o.duration
24
+ h[:station_id] = o.stationID
25
+ h[:region_id] = o.regionID
26
+ h[:system_id] = o.solarSystemID
27
+ h[:jumps] = o.jumps
28
+ h[:sell_or_buy] = :sell
29
+ h
30
+ }
31
+ end
32
+ def buy_orders
33
+ getBuyOrders.collect() { |o| h={}
34
+ h[:price] = o.price
35
+ h[:vol_remaining] = o.volRemaining
36
+ h[:type_id] = o.type
37
+ h[:range] = o.range
38
+ h[:order_id] = o.orderID
39
+ h[:vol_entered] = o.volEntered
40
+ h[:min_volume] = o.minVolume
41
+ h[:issued] = o.issued
42
+ h[:duration] = o.duration
43
+ h[:station_id] = o.stationID
44
+ h[:region_id] = o.regionID
45
+ h[:system_id] = o.solarSystemID
46
+ h[:jumps] = o.jumps
47
+ h[:sell_or_buy] = :buy
48
+ h
49
+ }
50
+ end
51
+ end
52
+
53
+ module Evecache
54
+ class << self
55
+
56
+ @@path = ""
57
+
58
+ def open(filename)
59
+ filename = path(filename) unless File.exists? filename
60
+ raise StandardError.new "File not found: #{filename}!" unless File.exists? filename
61
+ list = MarketParser.new(filename).getList
62
+ raise StandardError.new "Could not read MarketList! Invalid file?!" if list.invalid?
63
+ list
64
+ end
65
+
66
+ def path=(path)
67
+ @@path=path
68
+ end
69
+
70
+ def path(filename="")
71
+ if filename.empty?
72
+ @@path
73
+ else
74
+ @@path+"/"+filename+(filename.end_with?(".cache") ? "" : ".cache")
75
+ end
76
+ end
77
+
78
+ def list_files
79
+ Dir.glob(@@path+"/*.cache")
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,7 @@
1
+ require "evecache"
2
+
3
+ class TestEvecache < Minitest::Test
4
+ def test_extension_is_there
5
+ assert Evecache.constants.include? :VERSION
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evecache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.42.0
5
+ platform: ruby
6
+ authors:
7
+ - Marvin Frick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Ruby binding to libevecache to access Eve Online market cache files.
14
+ Does nothing more.
15
+ email:
16
+ - marv@hostin.is
17
+ executables: []
18
+ extensions:
19
+ - ext/evecache/extconf.rb
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - README.txt
24
+ - Rakefile
25
+ - evecache.gemspec
26
+ - ext/evecache/Makefile
27
+ - ext/evecache/dbtypes.cpp
28
+ - ext/evecache/evecache.cxx
29
+ - ext/evecache/evecache/config.hpp
30
+ - ext/evecache/evecache/dbtypes.hpp
31
+ - ext/evecache/evecache/exceptions.hpp
32
+ - ext/evecache/evecache/market.hpp
33
+ - ext/evecache/evecache/parser.hpp
34
+ - ext/evecache/evecache/reader.hpp
35
+ - ext/evecache/exceptions.cpp
36
+ - ext/evecache/extconf.rb
37
+ - ext/evecache/libevecache.i
38
+ - ext/evecache/market.cpp
39
+ - ext/evecache/parser.cpp
40
+ - ext/evecache/reader.cpp
41
+ - lib/evecache.rb
42
+ - test/test_evecache.rb
43
+ homepage: https://github.com/MrMarvin/evecache
44
+ licenses:
45
+ - GPL 2
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: 1.9.3
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: 1.3.6
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.0.0
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: A Ruby binding to libevecache to access Eve Online market cache files.
67
+ test_files: []