Skip to content

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
davispuh committed Sep 16, 2013
0 parents commit c052271
Show file tree
Hide file tree
Showing 17 changed files with 1,008 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
1 change: 1 addition & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--markup markdown
9 changes: 9 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source 'https://rubygems.org'

group :development, :test do
gem 'redcarpet', :platforms => [:ruby, :mswin, :mingw]
gem 'coveralls', require: false if ENV['CI']
end

# Specify your gem's dependencies in SteamCodec.gemspec
gemspec
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# SteamCodec

SteamCodec is a library for working with different [Steam client](http://store.steampowered.com/about/) (and [Source engine](http://source.valvesoftware.com/)) file formats.

Currently supported formats:

* [KeyValues](https://developer.valvesoftware.com/wiki/KeyValues)
* VDF (Valve Data Format)
* ACF (ApplicationCacheFile)


PKV (packed KeyValues) isn't supported yet.


## Installation

Add this line to your application's Gemfile:

```ruby
gem 'steam_codec'
```

And then execute:

```shell
bundle
```

Or install it yourself as:

```shell
gem install SteamCodec
```

### Dependencies

gem `insensitive_hash`

## Usage

```ruby
require 'steam_codec'

File.open("appmanifest_220.acf") do |file|
acf = SteamCodec::ACF::loadFromFile(file)
puts acf.UserConfig.Name
end
```

## Documentation

YARD with markdown is used for documentation (`redcarpet` required)

## Specs

RSpec and simplecov are required, to run tests just `rake spec`
code coverage will also be generated

## Code status

[![Build Status](https://travis-ci.org/davispuh/SteamCodec.png?branch=master)](https://travis-ci.org/davispuh/SteamCodec)
[![Dependency Status](https://gemnasium.com/davispuh/SteamCodec.png)](https://gemnasium.com/davispuh/SteamCodec)
[![Coverage Status](https://coveralls.io/repos/davispuh/SteamCodec/badge.png)](https://coveralls.io/r/davispuh/SteamCodec)

## Unlicense

![Copyright-Free](http://unlicense.org/pd-icon.png)

All text, documentation, code and files in this repository are in public domain (including this text, README).
It means you can copy, modify, distribute and include in your own work/code, even for commercial purposes, all without asking permission.

[About Unlicense](http://unlicense.org/)

## Contributing

Feel free to improve anything.

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request


**Warning**: By sending pull request to this repository you dedicate any and all copyright interest in pull request (code files and all other) to the public domain. (files will be in public domain even if pull request doesn't get merged)

Also before sending pull request you acknowledge that you own all copyrights or have authorization to dedicate them to public domain.

If you don't want to dedicate code to public domain or if you're not allowed to (eg. you don't own required copyrights) then DON'T send pull request.

13 changes: 13 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "bundler/gem_tasks"
require 'rspec/core/rake_task'
require 'yard'

desc 'Default: run specs.'
task :default => :spec

desc 'Run specs'
RSpec::Core::RakeTask.new(:spec) do |t|
end

YARD::Rake::YardocTask.new(:doc) do |t|
end
24 changes: 24 additions & 0 deletions UNLICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>
5 changes: 5 additions & 0 deletions lib/steam_codec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "steam_codec/version"
require "steam_codec/key_values"
require "steam_codec/value_array"
require "steam_codec/vdf"
require "steam_codec/acf"
176 changes: 176 additions & 0 deletions lib/steam_codec/ACF.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
module SteamCodec
class ACF

# More about AppID => https://developer.valvesoftware.com/wiki/Steam_Application_IDs
attr_accessor :AppID
attr_accessor :Universe
attr_accessor :StateFlags
attr_accessor :InstallDir
attr_accessor :LastUpdated
attr_accessor :UpdateResult
attr_accessor :SizeOnDisk
attr_accessor :BuildID
attr_accessor :LastOwner
attr_accessor :BytesToDownload
attr_accessor :BytesDownloaded
attr_accessor :FullValidateOnNextUpdate
attr_reader :UserConfig
attr_reader :MountedDepots
attr_reader :SharedDepots
attr_reader :CheckGuid
attr_reader :InstallScripts
def self.loadFromFile(file)
acf = KeyValues::loadFromFile(file)
return self.new(acf.AppState) if acf and acf.key?(:AppState)
nil
end

def self.load(data)
acf = KeyValues::load(data)
return self.new(acf.AppState) if acf and acf.key?(:AppState)
nil
end

def initialize(appState = nil)
load(appState || KeyValues.new)
end

def load(appState)
raise ArgumentError, "AppState must be instance of KeyValues" unless appState.is_a?(KeyValues)
@AppState = appState
@AppID = @AppState.AppID.to_i if @AppState.key?(:AppID)
@Universe = @AppState.Universe.to_i if @AppState.key?(:Universe)
@StateFlags = @AppState.StateFlags.to_i if @AppState.key?(:StateFlags)
@InstallDir = @AppState.InstallDir if @AppState.key?(:InstallDir)
@LastUpdated = @AppState.LastUpdated.to_i if @AppState.key?(:LastUpdated)
@UpdateResult = @AppState.UpdateResult.to_i if @AppState.key?(:UpdateResult)
@SizeOnDisk = @AppState.SizeOnDisk.to_i if @AppState.key?(:SizeOnDisk)
@BuildID = @AppState.BuildID.to_i if @AppState.key?(:BuildID)
@LastOwner = @AppState.LastOwner if @AppState.key?(:LastOwner)
@BytesToDownload = @AppState.BytesToDownload.to_i if @AppState.key?(:BytesToDownload)
@BytesDownloaded = @AppState.BytesDownloaded.to_i if @AppState.key?(:BytesDownloaded)
@FullValidateOnNextUpdate = !@AppState.FullValidateOnNextUpdate.to_i.zero? if @AppState.key?(:FullValidateOnNextUpdate)
userConfig = nil
mountedDepots = {}
sharedDepots = {}
checkGuid = {}
installScripts = {}
userConfig = @AppState.UserConfig if @AppState.key?(:UserConfig)
mountedDepots = @AppState.MountedDepots if @AppState.key?(:MountedDepots)
sharedDepots = @AppState.SharedDepots if @AppState.key?(:sharedDepots)
checkGuid = @AppState.CheckGuid if @AppState.key?(:CheckGuid)
installScripts = @AppState.InstallScripts if @AppState.key?(:InstallScripts)
@UserConfig = UserConfig.new(userConfig)
@MountedDepots = MountedDepots.new(mountedDepots)
@SharedDepots = SharedDepots.new(sharedDepots)
@InstallScripts = InstallScripts.new(installScripts)
end

class UserConfig
attr_accessor :Name
attr_accessor :GameID
attr_accessor :Installed
attr_accessor :AppInstallDir
attr_accessor :Language
attr_accessor :BetaKey
def initialize(userConfig = nil)
load(userConfig || KeyValues.new)
end

def load(userConfig)
raise ArgumentError, "UserConfig must be instance of KeyValues" unless userConfig.is_a?(KeyValues)
@UserConfig = userConfig
@Name = @UserConfig.name if @UserConfig.key?(:name)
@GameID = @UserConfig.gameid.to_i if @UserConfig.key?(:gameid)
@Installed = !@UserConfig.installdir.to_i.zero? if @UserConfig.key?(:installdir)
@AppInstallDir = @UserConfig.appinstalldir if @UserConfig.key?(:appinstalldir)
@Language = @UserConfig.language if @UserConfig.key?(:language)
@BetaKey = @UserConfig.BetaKey if @UserConfig.key?(:BetaKey)
end
end

class MountedDepots
def initialize(mountedDepots = {})
load(mountedDepots)
end

def load(mountedDepots)
raise ArgumentError, "MountedDepots must be instance of Hash" unless mountedDepots.is_a?(Hash)
@MountedDepots = {}
mountedDepots.each do |depot, manifest|
@MountedDepots[depot.to_i] = manifest
end
end

def depots
@MountedDepots.keys
end

def manifests
@MountedDepots.values
end

def getManifest(depotID)
@MountedDepots.each do |depot, manifest|
return manifest if depot == depotID
end
nil
end

def getDepot(manifestID)
@MountedDepots.each do |depot, manifest|
return depot if manifest == manifestID
end
nil
end

def set(depot, manifest)
@MountedDepots[depot] = manifest
end

def remove(depot)
@MountedDepots.delete(depot)
end
end

class SharedDepots
attr_reader :Depots
def initialize(sharedDepots = {})
load(sharedDepots)
end

def load(sharedDepots)
raise ArgumentError, "SharedDepots must be instance of Hash" unless sharedDepots.is_a?(Hash)
@SharedDepots = {}
sharedDepots.each do |depot, baseDepot|
@SharedDepots[depot.to_i] = baseDepot.to_i
end
end

def depots
@SharedDepots.keys
end

def getDepot(depotID)
@SharedDepots.each do |depot, baseDepot|
return baseDepot if depot == depotID
end
nil
end

def set(depot, baseDepot)
@SharedDepots[depot] = baseDepot
end

def remove(depot)
@SharedDepots.delete(depot)
end
end

class CheckGuid < ValueArray
end

class InstallScripts < ValueArray
end
end
end
Loading

0 comments on commit c052271

Please sign in to comment.