Skip to content

Commit

Permalink
Version bump to 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
beaucollins committed Dec 30, 2010
0 parents commit 07dfe03
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
*.bundle
13 changes: 13 additions & 0 deletions README.markdown
@@ -0,0 +1,13 @@
## libmpq-ruby

A very basic wrapper to the [libmpq](https://libmpq.org/) library. It allows you to read, decrypt and unpack MPQ files.

### Usage

require 'mpq'

archive = MPQ("path/to/file.mpq")

# list the files in the archive
archive.manifest

50 changes: 50 additions & 0 deletions Rakefile
@@ -0,0 +1,50 @@
require 'rake/clean'
require 'digest/md5'

DLEXT = Config::MAKEFILE_CONFIG['DLEXT']
RUBYDIGEST = Digest::MD5.hexdigest(`#{RUBY} --version`)

file "ext/ruby-#{RUBYDIGEST}" do |f|
rm_f FileList["ext/ruby-*"]
touch f.name
end

CLEAN.include "ext/ruby-*"

file 'ext/Makefile' => FileList['ext/*.{c,h,rb}', "ext/ruby-#{RUBYDIGEST}"] do
chdir('ext') { ruby 'extconf.rb' }
end
CLEAN.include 'ext/Makefile', 'ext/mkmf.log'

file "ext/mpq_archive.#{DLEXT}" => FileList["ext/Makefile"] do |f|
sh 'cd ext && make clean && make && rm -rf conftest.dSYM'
end
CLEAN.include 'ext/*.{o,bundle,so,dll}'

file "lib/mpq_archive.#{DLEXT}" => "ext/mpq_archive.#{DLEXT}" do |f|
cp f.prerequisites, "lib/", :preserve => true
end

namespace :ext do
desc 'Build the mpq extension'
task :build => "lib/mpq_archive.#{DLEXT}"
end

# PACKAGING ============

require 'rubygems'
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "libmpq-ruby"
gem.summary = %Q{ Library for reading MPQ files using libmpq }
gem.description = %Q{ Uses libmpq to provie access to read, decrypting and unpacking
MPQ files in Ruby }
gem.email = "beaucollins@gmail.com"
gem.homepage = "http://github.com/beaucollins/libmpq-ruby"
gem.authors = ["Beau Collins"]
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
1 change: 1 addition & 0 deletions VERSION
@@ -0,0 +1 @@
0.1.0
3 changes: 3 additions & 0 deletions ext/.gitignore
@@ -0,0 +1,3 @@
*.o
Makefile
ruby-*
13 changes: 13 additions & 0 deletions ext/extconf.rb
@@ -0,0 +1,13 @@
require 'mkmf'

if have_library('mpq')
find_library('mpq', '/usr/local/lib')
end

if have_header('mpq.h')
puts "no prefix"
elsif have_header('libmpq/mpq.h')
puts "prefix libmpq"
end

create_makefile('mpq_archive')
70 changes: 70 additions & 0 deletions ext/mpq_archive.c
@@ -0,0 +1,70 @@
#include <stdio.h>
#include <libmpq/mpq.h>
#include "ruby.h"

static VALUE rb_mMPQ;
static VALUE rb_cMPQArchive;


static VALUE rb_mpq_archive_read_file(VALUE self, VALUE name){

// archive struct
mpq_archive_s *archive;
// stores the index number for "(listfile)"
unsigned int file_index;
// stores the contents of the "(listfile)"
char *contents;
// stores the file size for string malloc
off_t file_size;
// retrieve the file path from the class
VALUE file_path = rb_funcall(self, rb_intern("path"), 0);
// make sure we have a string
Check_Type(file_path, T_STRING);
Check_Type(name, T_STRING);

VALUE buf = rb_str_buf_new(1024);

// start your engines
libmpq__init();
int return_code;
if(return_code = libmpq__archive_open(&archive, RSTRING_PTR(file_path), -1) != 0)
{
// raise an error? or just return the non-zero int?
return INT2FIX(return_code) ;
}

// get filenumber and size for listfile
if (return_code = libmpq__file_number(archive, RSTRING_PTR(name), &file_index) != 0) {
printf("No %s in '%s'.\n", RSTRING_PTR(name), RSTRING_PTR(file_path));
libmpq__archive_close(archive);
return INT2FIX(return_code);
}

// we've succesffully opene the archive
libmpq__file_unpacked_size(archive, file_index, &file_size);

// read listfile content into memory
contents = malloc(file_size);

libmpq__file_read(archive, file_index, contents, file_size, NULL);

rb_str_cat(buf, contents, file_size);

free(contents);

// free up your shit
libmpq__shutdown();

return buf;

}


void Init_mpq_archive(){

rb_mMPQ = rb_define_module("MPQ");
rb_cMPQArchive = rb_define_class_under(rb_mMPQ, "Archive", rb_cObject);

rb_define_method(rb_cMPQArchive, "read_file", rb_mpq_archive_read_file, 1);

}
27 changes: 27 additions & 0 deletions lib/mpq.rb
@@ -0,0 +1,27 @@

require 'mpq_archive'


class MPQ::Archive

attr_reader :path

LISTFILE = "(listfile)"

def initialize(path)
@path = path
end

def listfile
read_file LISTFILE
end

def manifest
listfile.split("\n").collect(&:strip)
end

end

def MPQ(file)
MPQ::Archive.new(file)
end
46 changes: 46 additions & 0 deletions libmpq-ruby.gemspec
@@ -0,0 +1,46 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{libmpq-ruby}
s.version = "0.0.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Beau Collins"]
s.date = %q{2010-12-30}
s.description = %q{ Uses libmpq to provie access to read, decrypting and unpacking
MPQ files in Ruby }
s.email = %q{beaucollins@gmail.com}
s.extensions = ["ext/extconf.rb"]
s.extra_rdoc_files = [
"README.markdown"
]
s.files = [
".gitignore",
"Rakefile",
"VERSION",
"ext/.gitignore",
"ext/extconf.rb",
"ext/mpq_archive.c",
"lib/mpq.rb",
"test/fixtures/replay.SC2Replay"
]
s.homepage = %q{http://github.com/beaucollins/libmpq-ruby}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.7}
s.summary = %q{Library for reading MPQ files using libmpq}

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
else
end
else
end
end

Binary file added test/fixtures/replay.SC2Replay
Binary file not shown.

0 comments on commit 07dfe03

Please sign in to comment.