-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWindowsController.rb
More file actions
93 lines (83 loc) · 2.41 KB
/
WindowsController.rb
File metadata and controls
93 lines (83 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
class WindowsController
def setup(app, browser, proxy=nil, url=nil)
@app = app
@browser = browser
@proxy = proxy
@url = url
end
def start
command = 'start ' + @browser
if @url != nil
command += ' "' + @url + '"'
end
if @proxy != nil
command += ' --args --proxy-server=' + @proxy
end
puts "Command to run #{command}"
`#{command}` ; result=$?.success?
result
end
def stop
command = 'taskkill /F /IM ' + @browser
puts "Command to run #{command}"
`#{command}` ; result=$?.success?
result
end
def chrome_cleanup
puts "Chrome cleanup called"
user = ENV['USERNAME']
chrome_path = "C:\\Users\\#{user}\\AppData\\Local\\Google\\Chrome\\\"User Data\""
cleanup_commands = ["del /Q /S /F #{chrome_path}", "rd /Q /S #{chrome_path}"]
cleanup_commands.each do |command|
puts "Command to run #{command}"
`#{command}`; result=$?.success?
if !result
puts "Error while running command"
return false
end
end
puts "Chrome cleanup completed"
return true
end
def firefox_cleanup
puts "Firefox cleanup called"
user = ENV['USERNAME']
moz_path = "C:\\Users\\#{user}\\AppData\\Local\\Mozilla\\Firefox\\Profiles"
cleanup_commands = ["del /Q /S /F #{moz_path}", "rd /Q /S #{moz_path}"]
cleanup_commands.each do |command|
puts "Command to run #{command}"
`#{command}`; result=$?.success?
if !result
puts "Error while running command"
return false
end
end
puts "Firefox cleanup completed"
return true
end
def explorer_cleanup
puts "Explorer cleanup called"
user = ENV['USERNAME']
ie_path = "C:\\Users\\#{user}\\AppData\\Local\\Microsoft\\\"Internet Explorer\""
history_path = "C:\\Users\\#{user}\\AppData\\Local\\Microsoft\\Windows\\History"
cookies_path = "C:\\Users\\#{user}\\AppData\\Roaming\\Microsoft\\Windows\\Cookies"
cleanup_commands = ["del /q #{ie_path}", "rd /Q /S #{ie_path}", "del /Q /S /F #{history_path}", "rd /Q /S #{history_path}", "del /Q /S /F #{cookies_path}", "rd /Q /S #{cookies_path}"]
cleanup_commands.each do |command|
puts "Command to run #{command}"
`#{command}`; result=$?.success?
if !result
puts "Error while running command"
return false
end
end
puts "Explorer cleanup completed"
return true
end
def cleanup(browser)
case browser.downcase
when "chrome" then self.chrome_cleanup
when "firefox" then self.firefox_cleanup
when "explorer" then self.explorer_cleanup
end
end
end