Class: Device::ParamsDat
- Inherits:
-
Object
- Object
- Device::ParamsDat
- Includes:
- DaFunk::Helper
- Defined in:
- lib/device/params_dat.rb
Constant Summary collapse
- FILE_NAME =
"./main/params.dat"
Class Attribute Summary collapse
-
.apps ⇒ Object
Returns the value of attribute apps.
-
.file ⇒ Object
Returns the value of attribute file.
-
.files ⇒ Object
Returns the value of attribute files.
-
.valid ⇒ Object
Returns the value of attribute valid.
Class Method Summary collapse
- .application_menu ⇒ Object
- .download ⇒ Object
- .executable_app ⇒ Object
- .executable_apps ⇒ Object
- .exists? ⇒ Boolean
- .format! ⇒ Object
- .get_app(name) ⇒ Object
- .get_file(name) ⇒ Object
-
.parse ⇒ Object
TODO Scalone: Change after @bmsatierf change the format For each apps on apps_list We’ll have: Today: <label>,<arquivo>,<pages>,<crc>; After: <label>,<arquivo>,<type>,<crc>; Today: “1 - App,pc2_app.posxml,1,E0A0;” After: “1 - App,pc2_app.posxml,posxml,E0A0;” After: “1 - App,pc2_app.zip,ruby,E0A0;”.
- .parse_apps ⇒ Object
- .parse_files ⇒ Object
- .ready? ⇒ Boolean
- .setup ⇒ Object
- .update_app(application, index = 1, all = 1, force = false) ⇒ Object
- .update_apps(force = false) ⇒ Object
- .update_file(file_parameter, index = 1, all = 1, force = false) ⇒ Object
Class Attribute Details
.apps ⇒ Object
Returns the value of attribute apps.
8 9 10 |
# File 'lib/device/params_dat.rb', line 8 def apps @apps end |
.file ⇒ Object
Returns the value of attribute file.
8 9 10 |
# File 'lib/device/params_dat.rb', line 8 def file @file end |
.files ⇒ Object
Returns the value of attribute files.
8 9 10 |
# File 'lib/device/params_dat.rb', line 8 def files @files end |
.valid ⇒ Object
Returns the value of attribute valid.
8 9 10 |
# File 'lib/device/params_dat.rb', line 8 def valid @valid end |
Class Method Details
.application_menu ⇒ Object
180 181 182 183 184 |
# File 'lib/device/params_dat.rb', line 180 def self. = Hash.new executable_apps.each { |app| [app.label] = app } ("Application Menu", , {:number => true}) end |
.download ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/device/params_dat.rb', line 97 def self.download if attach parse ret = try(3) do |tried| Device::Display.clear I18n.pt(:downloading_content, :args => ["PARAMS", 1, 1]) ret = Device::Transaction::Download.request_param_file(FILE_NAME) check_download_error(ret) end parse if ret ret end end |
.executable_app ⇒ Object
169 170 171 172 173 174 |
# File 'lib/device/params_dat.rb', line 169 def self.executable_app selected = self.executable_apps if selected && selected.size == 1 selected.first end end |
.executable_apps ⇒ Object
176 177 178 |
# File 'lib/device/params_dat.rb', line 176 def self.executable_apps self.apps.select{|app| app.label != "X"} end |
.exists? ⇒ Boolean
26 27 28 |
# File 'lib/device/params_dat.rb', line 26 def self.exists? File.exists?(FILE_NAME) end |
.format! ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/device/params_dat.rb', line 126 def self.format! Device::Application.delete(self.apps) DaFunk::FileParameter.delete(self.files) File.delete(FILE_NAME) if exists? @apps = [] @files = [] end |
.get_app(name) ⇒ Object
87 88 89 90 |
# File 'lib/device/params_dat.rb', line 87 def self.get_app(name) @apps.each {|app| return app if app.original == name } nil end |
.get_file(name) ⇒ Object
92 93 94 95 |
# File 'lib/device/params_dat.rb', line 92 def self.get_file(name) @files.each {|file_| return file_ if file_.original == name} nil end |
.parse ⇒ Object
TODO Scalone: Change after @bmsatierf change the format For each apps on apps_list We’ll have: Today: <label>,<arquivo>,<pages>,<crc>; After: <label>,<arquivo>,<type>,<crc>; Today: “1 - App,pc2_app.posxml,1,E0A0;” After: “1 - App,pc2_app.posxml,posxml,E0A0;” After: “1 - App,pc2_app.zip,ruby,E0A0;”
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/device/params_dat.rb', line 74 def self.parse return unless self.setup parse_apps parse_files if (@apps.size >= 1) self.valid = true else self.valid = false end self.valid end |
.parse_apps ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/device/params_dat.rb', line 37 def self.parse_apps new_apps = [] self.file["apps_list"].to_s.gsub("\"", "").split(";").each do |app| label, name, type, crc = app.split(",") if application = get_app(name) application.crc = crc else application = Device::Application.new(label, name, type, crc) end new_apps << application end Device::Application.delete(@apps - new_apps) @apps = new_apps end |
.parse_files ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/device/params_dat.rb', line 52 def self.parse_files new_files = [] self.file["files_list"].to_s.gsub("\"", "").split(";").each do |f| name, crc = f.split(",") if file_ = get_file(name) file_.crc = crc else file_ = DaFunk::FileParameter.new(name, crc) end new_files << file_ end Device::Application.delete(@files - new_files) @files = new_files end |
.ready? ⇒ Boolean
30 31 32 33 34 35 |
# File 'lib/device/params_dat.rb', line 30 def self.ready? return unless exists? apps.each {|app| return false if app.outdated? } if apps.size > 0 files.each {|f| return false if f.outdated? } if files.size > 0 true end |
.setup ⇒ Object
22 23 24 |
# File 'lib/device/params_dat.rb', line 22 def self.setup @file = FileDb.new(FILE_NAME) end |
.update_app(application, index = 1, all = 1, force = false) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/device/params_dat.rb', line 134 def self.update_app(application, index = 1, all = 1, force = false) if attach && application try(3) do |tried| Device::Display.clear I18n.pt(:downloading_content, :args => [I18n.t(:apps), index, all]) ret = check_download_error(application.download(force)) sleep(1) ret end end end |
.update_apps(force = false) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/device/params_dat.rb', line 111 def self.update_apps(force = false) self.download if force || ! self.valid if self.valid size_apps = @apps.size @apps.each_with_index do |app, index| self.update_app(app, index+1, size_apps) end size_files = @files.size @files.each_with_index do |file_, index| self.update_file(file_, index+1, size_files) end end end |
.update_file(file_parameter, index = 1, all = 1, force = false) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/device/params_dat.rb', line 146 def self.update_file(file_parameter, index = 1, all = 1, force = false) if attach && file_parameter try(3) do |tried| Device::Display.clear I18n.pt(:downloading_content, :args => [I18n.t(:files), index, all]) ret = check_download_error(file_parameter.download(force)) file_parameter.unzip if ret sleep(1) ret end end end |