Class: Device::ParamsDat

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/device/params_dat.rb

Constant Summary collapse

FILE_NAME =
"./main/params.dat"

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Helper

#attach, #check_download_error, #form, #ljust, #menu, #number_to_currency, #rjust

Class Attribute Details

.appsObject

Returns the value of attribute apps.



8
9
10
# File 'lib/device/params_dat.rb', line 8

def apps
  @apps
end

.fileObject

Returns the value of attribute file.



8
9
10
# File 'lib/device/params_dat.rb', line 8

def file
  @file
end

.statusObject

Returns the value of attribute status.



8
9
10
# File 'lib/device/params_dat.rb', line 8

def status
  @status
end

Class Method Details

.application_menuObject



114
115
116
117
118
# File 'lib/device/params_dat.rb', line 114

def self.application_menu
  options = Hash.new
  executable_apps.each { |app| options[app.label] = app }
  menu("Application Menu", options, {:number => true})
end

.downloadObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/device/params_dat.rb', line 47

def self.download
  if attach
    Device::Display.clear
    puts "Downloading Params"
    ret = Device::Transaction::Download.request_param_file(FILE_NAME)
    if value = check_download_error(ret)
      puts "Downloaded Successfully"
      Device::Network.close_socket
      # TODO
      #Device::Network.walk_socket.close unless Device::Network.walk_socket.closed?
      parse_apps
    end
    value
  end
end

.executable_appObject



103
104
105
106
107
108
# File 'lib/device/params_dat.rb', line 103

def self.executable_app
  selected = self.executable_apps
  if selected.size == 1
    selected[selected.keys.first]
  end
end

.executable_appsObject



110
111
112
# File 'lib/device/params_dat.rb', line 110

def self.executable_apps
  self.apps.select{|app| app.label != "X"}
end

.format!Object



74
75
76
77
78
79
80
81
# File 'lib/device/params_dat.rb', line 74

def self.format!
  self.apps.each do |app|
    File.delete(app.zip) if File.exists?(app.zip)
    Dir.delete(app.file_no_ext) if File.exists?(app.file_no_ext) && File.exists?(app.file_no_ext)
  end
  File.delete(FILE_NAME) if File.exists?(FILE_NAME)
  Device::System.restart
end

.parse_appsObject

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;”



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/device/params_dat.rb', line 32

def self.parse_apps
  @apps = []
  return unless self.setup

  self.file["apps_list"].to_s.gsub("\"", "").split(";").each do |app|
    @apps << Device::Application.new(*app.split(","))
  end

  if (@apps.size >= 1)
    self.status = true
  else
    self.status = false
  end
end

.setupObject



21
22
23
# File 'lib/device/params_dat.rb', line 21

def self.setup
  @file = FileDb.new(FILE_NAME)
end

.update_app(application) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/device/params_dat.rb', line 83

def self.update_app(application)
  if attach && application
    Device::Display.clear
    puts "Downloading #{application.file}..."
    ret = Device::Transaction::Download.request_file(application.file, application.zip)
    Device::Network.close_socket
    # TODO
    #Device::Network.walk_socket.close unless Device::Network.walk_socket.closed?

    unless check_download_error ret
      sleep 2
    end
  end
end

.update_apps(force = false) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/device/params_dat.rb', line 63

def self.update_apps(force = false)
  if force || ! self.status
    self.download
  end
  if self.status
    @apps.each do |app|
      self.update_app(app)
    end
  end
end