Class: SteamCodec::ACF

Inherits:
Object
  • Object
show all
Defined in:
lib/steam_codec/acf.rb

Defined Under Namespace

Classes: CheckGuid, InstallScripts, MountedDepots, SharedDepots, UserConfig

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(appState = nil) ⇒ ACF

Returns a new instance of ACF.



46
47
48
# File 'lib/steam_codec/acf.rb', line 46

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

Instance Attribute Details

#AppIDObject



6
7
8
# File 'lib/steam_codec/acf.rb', line 6

def AppID
  @AppID
end

#BuildIDObject

Returns the value of attribute BuildID.



13
14
15
# File 'lib/steam_codec/acf.rb', line 13

def BuildID
  @BuildID
end

#BytesDownloadedObject

Returns the value of attribute BytesDownloaded.



16
17
18
# File 'lib/steam_codec/acf.rb', line 16

def BytesDownloaded
  @BytesDownloaded
end

#BytesToDownloadObject

Returns the value of attribute BytesToDownload.



15
16
17
# File 'lib/steam_codec/acf.rb', line 15

def BytesToDownload
  @BytesToDownload
end

#CheckGuidObject (readonly)

Returns the value of attribute CheckGuid.



21
22
23
# File 'lib/steam_codec/acf.rb', line 21

def CheckGuid
  @CheckGuid
end

#FullValidateOnNextUpdateObject

Returns the value of attribute FullValidateOnNextUpdate.



17
18
19
# File 'lib/steam_codec/acf.rb', line 17

def FullValidateOnNextUpdate
  @FullValidateOnNextUpdate
end

#InstallDirObject

Returns the value of attribute InstallDir.



9
10
11
# File 'lib/steam_codec/acf.rb', line 9

def InstallDir
  @InstallDir
end

#InstallScriptsObject (readonly)

Returns the value of attribute InstallScripts.



22
23
24
# File 'lib/steam_codec/acf.rb', line 22

def InstallScripts
  @InstallScripts
end

#LastOwnerObject

Returns the value of attribute LastOwner.



14
15
16
# File 'lib/steam_codec/acf.rb', line 14

def LastOwner
  @LastOwner
end

#LastUpdatedObject

Returns the value of attribute LastUpdated.



10
11
12
# File 'lib/steam_codec/acf.rb', line 10

def LastUpdated
  @LastUpdated
end

#MountedDepotsObject (readonly)

Returns the value of attribute MountedDepots.



19
20
21
# File 'lib/steam_codec/acf.rb', line 19

def MountedDepots
  @MountedDepots
end

#SharedDepotsObject (readonly)

Returns the value of attribute SharedDepots.



20
21
22
# File 'lib/steam_codec/acf.rb', line 20

def SharedDepots
  @SharedDepots
end

#SizeOnDiskObject

Returns the value of attribute SizeOnDisk.



12
13
14
# File 'lib/steam_codec/acf.rb', line 12

def SizeOnDisk
  @SizeOnDisk
end

#StateFlagsObject

Returns the value of attribute StateFlags.



8
9
10
# File 'lib/steam_codec/acf.rb', line 8

def StateFlags
  @StateFlags
end

#UniverseObject

Returns the value of attribute Universe.



7
8
9
# File 'lib/steam_codec/acf.rb', line 7

def Universe
  @Universe
end

#UpdateResultObject

Returns the value of attribute UpdateResult.



11
12
13
# File 'lib/steam_codec/acf.rb', line 11

def UpdateResult
  @UpdateResult
end

#UserConfigObject (readonly)

Returns the value of attribute UserConfig.



18
19
20
# File 'lib/steam_codec/acf.rb', line 18

def UserConfig
  @UserConfig
end

Class Method Details

.extendedFieldsObject



30
31
32
# File 'lib/steam_codec/acf.rb', line 30

def self.extendedFields
    return [:UserConfig, :MountedDepots, :SharedDepots, :CheckGuid, :InstallScripts]
end

.load(data) ⇒ Object



40
41
42
43
44
# File 'lib/steam_codec/acf.rb', line 40

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

.loadFromFile(file) ⇒ Object



34
35
36
37
38
# File 'lib/steam_codec/acf.rb', line 34

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

.scalarFieldsObject



23
24
25
26
27
28
# File 'lib/steam_codec/acf.rb', line 23

def self.scalarFields
    return [:AppID, :Universe, :StateFlags, :InstallDir,
        :LastUpdated, :UpdateResult, :SizeOnDisk,
        :BuildID, :LastOwner, :BytesToDownload,
        :BytesDownloaded, :FullValidateOnNextUpdate]
end

Instance Method Details

#get(path = '', seperator = '.') ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/steam_codec/acf.rb', line 81

def get(path = '', seperator = '.')
    return nil unless @AppState
    fields = path.split(seperator)
    first = fields.shift
    return to_hash unless first
    self.class.scalarFields.each do |field|
        if field.to_s.downcase == first.downcase
            return self.send(field)
        end
    end
    self.class.extendedFields.each do |field|
        if field.to_s.downcase == first.downcase
            return self.send(field).to_hash if fields.count == 0
            return self.send(field).get(fields.join(seperator), seperator)
        end
    end
    @AppState.get(path, seperator)
end

#load(appState) ⇒ Object

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/steam_codec/acf.rb', line 50

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

#to_hashObject



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/steam_codec/acf.rb', line 100

def to_hash
    result = {}
    self.class.scalarFields.each do |field|
        result[field.to_s] = self.send(field)
    end
    self.class.extendedFields.each do |field|
        result[field.to_s] = self.send(field)
        result[field.to_s] = result[field.to_s].to_hash if result[field.to_s]
    end
    result
end