Module: Six::Appmanager

Defined in:
lib/six-updater-web/vendor/plugins/six-app_manager/lib/six/appmanager.rb

Defined Under Namespace

Modules: Appsetting

Constant Summary collapse

FOLDER =
/(.*)\/(.*)/

Class Method Summary collapse

Class Method Details

.find_process(name) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/six-updater-web/vendor/plugins/six-app_manager/lib/six/appmanager.rb', line 69

def find_process(name)
  pids = []

  begin
    case RUBY_PLATFORM
      when /-mingw32$/, /-mswin32$/
        out = %x[tasklist]
        out.split("\n").each do |line|
          if line =~ /\A#{name}[\t| ]*([0-9]*)/
            pid = $1
            if pid.size > 0
              pid = pid.to_i
              pids << pid
            end
          end
        end
      else
        %x[ps -A | grep #{name}].split("\n").each do |line|
          unless line[/grep/]
            line[/^\s*([0-9]*)/]
            pids << $1
          end
        end
    end
  rescue => e
    logger.warn "Failed checking tasklist for #{name}"
    logger.debug "#{e.class}: #{e.message} #{e.backtrace.join("\n")}"
  end
  pids
=begin
  wmi_init
  ar = []
  processes = @wmi.ExecQuery("select * from win32_process")
  processes.each do |process|
    if process.Name == name
      logger.debug "Found m! #{process.ProcessId}"
      ar << process
    end
  end
  ar
=end
end

.kill(process) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/six-updater-web/vendor/plugins/six-app_manager/lib/six/appmanager.rb', line 50

def kill(process)
  Process.kill(9, process).each do |kill| #.ProcessId
    logger.debug "Killed: #{kill}"
    #        if kill == process.ProcessId
    #          logger.debug "Succesfully killed!"
    #        else
    #          logger.debug "Not succesfully killed, forcing!"
    #          sleep 3
    #          Process.kill(9, process.ProcessId)
    #        end
  end
end

.kill_by_name(name) ⇒ Object

TODO: Kill by … multiple properties. gamefolder, etc.



65
66
67
# File 'lib/six-updater-web/vendor/plugins/six-app_manager/lib/six/appmanager.rb', line 65

def kill_by_name(name)
  find_process(name).each { |process| kill(process) }
end

.loggerObject



37
38
39
# File 'lib/six-updater-web/vendor/plugins/six-app_manager/lib/six/appmanager.rb', line 37

def logger
  ActionController::Base.logger
end

.read_logfile(file) ⇒ Object



130
131
132
133
134
135
136
137
138
# File 'lib/six-updater-web/vendor/plugins/six-app_manager/lib/six/appmanager.rb', line 130

def read_logfile(file)
  begin
    File.open('C:/Users/SB/Test.txt') do |file|
      file.read
    end
  rescue
    'Error while reading logfile!'
  end
end

.tail(file, interval = 1) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/six-updater-web/vendor/plugins/six-app_manager/lib/six/appmanager.rb', line 112

def tail(file, interval=1)
  raise "Illegal interval #{interval}" if interval < 0

  # Read to a table and display with ajax???
  # RE: http://onlamp.com/pub/a/onlamp/2005/06/09/rails_ajax.html
  File.open(file) do |io|
    loop do
      while ( line = io.gets )
        puts line
      end

      # uncomment next to watch what is happening
      # puts "-"
      sleep interval
    end
  end
end

.wmi_initObject



41
42
43
44
45
46
47
48
# File 'lib/six-updater-web/vendor/plugins/six-app_manager/lib/six/appmanager.rb', line 41

def wmi_init
  if @wmi.nil?
    WIN32OLE.codepage = WIN32OLE::CP_UTF8
    #swbemloc = WIN32OLE.new("WbemScripting.SWbemLocator")
    #@wmi = swbemloc.ConnectServer#(@address.to_s, namespace, @user, @password)
    @wmi = WIN32OLE.connect('winmgmts://')
  end
end