|
| 1 | +module SteamCodec |
| 2 | + class ACF |
| 3 | + |
| 4 | + # More about AppID => https://developer.valvesoftware.com/wiki/Steam_Application_IDs |
| 5 | + attr_accessor :AppID |
| 6 | + attr_accessor :Universe |
| 7 | + attr_accessor :StateFlags |
| 8 | + attr_accessor :InstallDir |
| 9 | + attr_accessor :LastUpdated |
| 10 | + attr_accessor :UpdateResult |
| 11 | + attr_accessor :SizeOnDisk |
| 12 | + attr_accessor :BuildID |
| 13 | + attr_accessor :LastOwner |
| 14 | + attr_accessor :BytesToDownload |
| 15 | + attr_accessor :BytesDownloaded |
| 16 | + attr_accessor :FullValidateOnNextUpdate |
| 17 | + attr_reader :UserConfig |
| 18 | + attr_reader :MountedDepots |
| 19 | + attr_reader :SharedDepots |
| 20 | + attr_reader :CheckGuid |
| 21 | + attr_reader :InstallScripts |
| 22 | + def self.loadFromFile(file) |
| 23 | + acf = KeyValues::loadFromFile(file) |
| 24 | + return self.new(acf.AppState) if acf and acf.key?(:AppState) |
| 25 | + nil |
| 26 | + end |
| 27 | + |
| 28 | + def self.load(data) |
| 29 | + acf = KeyValues::load(data) |
| 30 | + return self.new(acf.AppState) if acf and acf.key?(:AppState) |
| 31 | + nil |
| 32 | + end |
| 33 | + |
| 34 | + def initialize(appState = nil) |
| 35 | + load(appState || KeyValues.new) |
| 36 | + end |
| 37 | + |
| 38 | + def load(appState) |
| 39 | + raise ArgumentError, "AppState must be instance of KeyValues" unless appState.is_a?(KeyValues) |
| 40 | + @AppState = appState |
| 41 | + @AppID = @AppState.AppID.to_i if @AppState.key?(:AppID) |
| 42 | + @Universe = @AppState.Universe.to_i if @AppState.key?(:Universe) |
| 43 | + @StateFlags = @AppState.StateFlags.to_i if @AppState.key?(:StateFlags) |
| 44 | + @InstallDir = @AppState.InstallDir if @AppState.key?(:InstallDir) |
| 45 | + @LastUpdated = @AppState.LastUpdated.to_i if @AppState.key?(:LastUpdated) |
| 46 | + @UpdateResult = @AppState.UpdateResult.to_i if @AppState.key?(:UpdateResult) |
| 47 | + @SizeOnDisk = @AppState.SizeOnDisk.to_i if @AppState.key?(:SizeOnDisk) |
| 48 | + @BuildID = @AppState.BuildID.to_i if @AppState.key?(:BuildID) |
| 49 | + @LastOwner = @AppState.LastOwner if @AppState.key?(:LastOwner) |
| 50 | + @BytesToDownload = @AppState.BytesToDownload.to_i if @AppState.key?(:BytesToDownload) |
| 51 | + @BytesDownloaded = @AppState.BytesDownloaded.to_i if @AppState.key?(:BytesDownloaded) |
| 52 | + @FullValidateOnNextUpdate = !@AppState.FullValidateOnNextUpdate.to_i.zero? if @AppState.key?(:FullValidateOnNextUpdate) |
| 53 | + userConfig = nil |
| 54 | + mountedDepots = {} |
| 55 | + sharedDepots = {} |
| 56 | + checkGuid = {} |
| 57 | + installScripts = {} |
| 58 | + userConfig = @AppState.UserConfig if @AppState.key?(:UserConfig) |
| 59 | + mountedDepots = @AppState.MountedDepots if @AppState.key?(:MountedDepots) |
| 60 | + sharedDepots = @AppState.SharedDepots if @AppState.key?(:sharedDepots) |
| 61 | + checkGuid = @AppState.CheckGuid if @AppState.key?(:CheckGuid) |
| 62 | + installScripts = @AppState.InstallScripts if @AppState.key?(:InstallScripts) |
| 63 | + @UserConfig = UserConfig.new(userConfig) |
| 64 | + @MountedDepots = MountedDepots.new(mountedDepots) |
| 65 | + @SharedDepots = SharedDepots.new(sharedDepots) |
| 66 | + @InstallScripts = InstallScripts.new(installScripts) |
| 67 | + end |
| 68 | + |
| 69 | + class UserConfig |
| 70 | + attr_accessor :Name |
| 71 | + attr_accessor :GameID |
| 72 | + attr_accessor :Installed |
| 73 | + attr_accessor :AppInstallDir |
| 74 | + attr_accessor :Language |
| 75 | + attr_accessor :BetaKey |
| 76 | + def initialize(userConfig = nil) |
| 77 | + load(userConfig || KeyValues.new) |
| 78 | + end |
| 79 | + |
| 80 | + def load(userConfig) |
| 81 | + raise ArgumentError, "UserConfig must be instance of KeyValues" unless userConfig.is_a?(KeyValues) |
| 82 | + @UserConfig = userConfig |
| 83 | + @Name = @UserConfig.name if @UserConfig.key?(:name) |
| 84 | + @GameID = @UserConfig.gameid.to_i if @UserConfig.key?(:gameid) |
| 85 | + @Installed = !@UserConfig.installdir.to_i.zero? if @UserConfig.key?(:installdir) |
| 86 | + @AppInstallDir = @UserConfig.appinstalldir if @UserConfig.key?(:appinstalldir) |
| 87 | + @Language = @UserConfig.language if @UserConfig.key?(:language) |
| 88 | + @BetaKey = @UserConfig.BetaKey if @UserConfig.key?(:BetaKey) |
| 89 | + end |
| 90 | + end |
| 91 | + |
| 92 | + class MountedDepots |
| 93 | + def initialize(mountedDepots = {}) |
| 94 | + load(mountedDepots) |
| 95 | + end |
| 96 | + |
| 97 | + def load(mountedDepots) |
| 98 | + raise ArgumentError, "MountedDepots must be instance of Hash" unless mountedDepots.is_a?(Hash) |
| 99 | + @MountedDepots = {} |
| 100 | + mountedDepots.each do |depot, manifest| |
| 101 | + @MountedDepots[depot.to_i] = manifest |
| 102 | + end |
| 103 | + end |
| 104 | + |
| 105 | + def depots |
| 106 | + @MountedDepots.keys |
| 107 | + end |
| 108 | + |
| 109 | + def manifests |
| 110 | + @MountedDepots.values |
| 111 | + end |
| 112 | + |
| 113 | + def getManifest(depotID) |
| 114 | + @MountedDepots.each do |depot, manifest| |
| 115 | + return manifest if depot == depotID |
| 116 | + end |
| 117 | + nil |
| 118 | + end |
| 119 | + |
| 120 | + def getDepot(manifestID) |
| 121 | + @MountedDepots.each do |depot, manifest| |
| 122 | + return depot if manifest == manifestID |
| 123 | + end |
| 124 | + nil |
| 125 | + end |
| 126 | + |
| 127 | + def set(depot, manifest) |
| 128 | + @MountedDepots[depot] = manifest |
| 129 | + end |
| 130 | + |
| 131 | + def remove(depot) |
| 132 | + @MountedDepots.delete(depot) |
| 133 | + end |
| 134 | + end |
| 135 | + |
| 136 | + class SharedDepots |
| 137 | + attr_reader :Depots |
| 138 | + def initialize(sharedDepots = {}) |
| 139 | + load(sharedDepots) |
| 140 | + end |
| 141 | + |
| 142 | + def load(sharedDepots) |
| 143 | + raise ArgumentError, "SharedDepots must be instance of Hash" unless sharedDepots.is_a?(Hash) |
| 144 | + @SharedDepots = {} |
| 145 | + sharedDepots.each do |depot, baseDepot| |
| 146 | + @SharedDepots[depot.to_i] = baseDepot.to_i |
| 147 | + end |
| 148 | + end |
| 149 | + |
| 150 | + def depots |
| 151 | + @SharedDepots.keys |
| 152 | + end |
| 153 | + |
| 154 | + def getDepot(depotID) |
| 155 | + @SharedDepots.each do |depot, baseDepot| |
| 156 | + return baseDepot if depot == depotID |
| 157 | + end |
| 158 | + nil |
| 159 | + end |
| 160 | + |
| 161 | + def set(depot, baseDepot) |
| 162 | + @SharedDepots[depot] = baseDepot |
| 163 | + end |
| 164 | + |
| 165 | + def remove(depot) |
| 166 | + @SharedDepots.delete(depot) |
| 167 | + end |
| 168 | + end |
| 169 | + |
| 170 | + class CheckGuid < ValueArray |
| 171 | + end |
| 172 | + |
| 173 | + class InstallScripts < ValueArray |
| 174 | + end |
| 175 | + end |
| 176 | +end |
0 commit comments