davispuh / SteamCodec

Library for working with different Steam client (and Source engine) file formats.
The Unlicense
7 stars 0 forks source link

Can you provide examples of how to use in the documentation? #1

Open hobertro opened 10 years ago

hobertro commented 10 years ago

Hey just wanted to say thanks for starting on this, I've been searching for a gem like this. I was just wondering if you could provide certain examples of how to use the gem?

I've been trying parse a VDF file that contains information regarding the items from DOTA2. The file contains items with attributes in a hash "object" in VDFormat. Unfortunately, I haven't been able to get gem to work correctly. When I execute a method to try out the gem, the console just freezes.

Example:

File.open("test2.vdf") do |file|
vdf = SteamCodec::VDF::loadFromFile(file) puts vdf end

I was wondering if you could help me solve this problem? Thanks so much!

davispuh commented 10 years ago

Are you sure it's VDF? Also where could I find a sample of that file? As your example is correct. Might be that Steam have changed something in format or there's a bug in VDF parser.

But it works fine for me, I've 570_install.vdf file in Dota directory.

require 'steam_codec'
require 'pp'

File.open("570_install.vdf") do |file|
    vdf = SteamCodec::VDF::loadFromFile(file)
    pp vdf
end

(pp stands for PrettyPrint)

Outputs

{"InstallScript"=>
  {"Run Process"=>
    {"DirectX"=>
      {"HasRunKey"=>"HKEY_LOCAL_MACHINE\\Software\\Valve\\Steam\\Apps\\570",
       "process 1"=>"%INSTALLDIR%\\DirectX\\DXSETUP.exe",
       "command 1"=>"/silent",
       "NoCleanUp"=>"1"}}},
 "kvsignatures"=>
  {"InstallScript"=>
    "55e5a991b101ffee1d3d87b0a4b2fbc541e5b177611c3635157b2ea712fad53a33869a94c4c9ca07954c2112e966d96bf40572ef8b5a6842612d000f1892acde618e430ece8a12b7fb1e3af1d94b5be0bbcdcc93899898ee23834e317d8b0cc58561969a2f9579f30c98c82f5e8ca16178146106854dcbc7b4f8e746ef72e4b7"}}
hobertro commented 10 years ago

Hey davispuh,

Thanks for the response. I tried the method again by taking a snippet of code from the file I was trying to parse and got it to work using the KeyValues method like this:

 SteamCodec::KeyValues::loadFromFile(file)

However, when I try to parse the entire file, it just freezes. I checked the file size I was trying to parse and realized it was 6.8mb! My next question is what happens when the file is this large? Would the method call to this file timeout or should it parse within a few minutes? For reference to the Steam file:

http://cdn.dota2.com/apps/570/scripts/items/items_game.ad33c52271369e1cc0e1ac3708d8a205e99d64e4.txt

Can you parse that with your gem?

Thanks so much for your time and work!

davispuh commented 10 years ago

Actually it doesn't freeze, but just takes a really long time for such big file. I ran it for nearly hour and it did returned, only it still wasn't able to parse something as result was nil. But file seems to be fine and if I cut out some big chunk it does parse it correctly. I had never used parser for big files and I didn't knew it's so unusably slow. I did a quick profiling and all time is spent in key_values.rb#toJSON and key_values.rb#proccess. I looked what I could optimize, but didn't really found anything* as code seems to be fine and Ruby is just too slow. Speed could be improved if would rewrite that parsing part as C extension, but that's quite a bit of work and I don't have time for that. Or another way would be if could come up with some better way for parsing, better design/algorithm. Currently I don't really have any ideas what would improve speed. Also all files which I needed to parse were quite short and so this is not yet important for me.

* I improved #process method so now it will be a bit faster, but still not enough.

You might want to look for other KeyValues implementations, such as SteamKit's (it's made in C#)

Or you might just take out some parts from file to reduce it's size so it can be parsed with this gem. Also if you've any ideas how to improve parsing speed I'm accepting PRs.

hobertro commented 10 years ago

hey davispuh,

thanks for your response and your efforts. I appreciate the good news as well as the bad. For now, I think I will use your gem to parse parts of the data from the file, but I will also try to think of a solution to the large file problem and I'll let you know if I figure anything out.

Thanks again!