windows-shutdown-timer 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/windows-shutdown-timer +6 -6
- data/lib/windows-shutdown-timer.rb +91 -88
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6bb12218d76cf41b3a10d5d1e29b7a872850976
|
4
|
+
data.tar.gz: 805aa77ee11cd70235c99dd9e1450bb1da726fe3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a767438c139758e832e1d251f984dc6f208da89e5b657cc1933c90be69644ccf6d7901f94eb293cdd7efd9ccbc52b48edd4dbc0c950866fc925bce761d56f4dc
|
7
|
+
data.tar.gz: 855cc1a5a51388e437befe9c36a1cd0a8d7e13f2f7f2e62f4d72fb1b6f051e76dacadefaaa5ec2ca24acdba98450f0d7babb543df684f604d6c6044e4b1dbf94
|
data/bin/windows-shutdown-timer
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'windows-shutdown-timer'
|
4
|
-
|
5
|
-
starter = WindowsShutdownTimer::ShutdownStarter.new(ARGV)
|
6
|
-
starter.start_timer
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'windows-shutdown-timer'
|
4
|
+
|
5
|
+
starter = WindowsShutdownTimer::ShutdownStarter.new(ARGV)
|
6
|
+
starter.start_timer
|
@@ -1,88 +1,91 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'net/http'
|
3
|
-
require 'fileutils'
|
4
|
-
require 'zip'
|
5
|
-
|
6
|
-
module WindowsShutdownTimer
|
7
|
-
# Shutdown!
|
8
|
-
class ShutdownStarter
|
9
|
-
|
10
|
-
INSOMNIA = 'Insomnia.exe'
|
11
|
-
PATH_TO_TEMP = Dir.tmpdir + '/windows-shutdown-timer'
|
12
|
-
PATH_TO_INSOMNIA = PATH_TO_TEMP + '/' + INSOMNIA
|
13
|
-
PATH = 'insomnia/64-bit'
|
14
|
-
COMMAND_SHUTDOWN = 'shutdown /s /t '
|
15
|
-
COMMAND_CANCEL_SHUTDOWN = 'shutdown /a'
|
16
|
-
COMMAND_INSOMNIA = "start #{PATH_TO_INSOMNIA}"
|
17
|
-
|
18
|
-
def initialize(arguments)
|
19
|
-
|
20
|
-
# Get the first arg as the time
|
21
|
-
@time = %w(-h --help -c).include?(arguments.first) ? nil : arguments.shift
|
22
|
-
|
23
|
-
create_options_parser(arguments)
|
24
|
-
end
|
25
|
-
|
26
|
-
def create_options_parser(args)
|
27
|
-
args.options do |opts|
|
28
|
-
opts.banner = 'Usage: windows-shutdown-timer MINUTES_UNTIL_SHUTDOWN [OPTIONS]'
|
29
|
-
opts.separator ''
|
30
|
-
opts.separator 'Options'
|
31
|
-
opts.on('-c', '--cancel', 'Cancel a pending shutdown') do
|
32
|
-
@time = 0
|
33
|
-
end
|
34
|
-
opts.on('-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
FileUtils.
|
51
|
-
FileUtils.
|
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
|
-
end
|
1
|
+
require 'optparse'
|
2
|
+
require 'net/http'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'zip'
|
5
|
+
|
6
|
+
module WindowsShutdownTimer
|
7
|
+
# Shutdown!
|
8
|
+
class ShutdownStarter
|
9
|
+
|
10
|
+
INSOMNIA = 'Insomnia.exe'
|
11
|
+
PATH_TO_TEMP = Dir.tmpdir + '/windows-shutdown-timer'
|
12
|
+
PATH_TO_INSOMNIA = PATH_TO_TEMP + '/' + INSOMNIA
|
13
|
+
PATH = 'insomnia/64-bit'
|
14
|
+
COMMAND_SHUTDOWN = 'shutdown /s /t '
|
15
|
+
COMMAND_CANCEL_SHUTDOWN = 'shutdown /a'
|
16
|
+
COMMAND_INSOMNIA = "start #{PATH_TO_INSOMNIA}"
|
17
|
+
|
18
|
+
def initialize(arguments)
|
19
|
+
|
20
|
+
# Get the first arg as the time
|
21
|
+
@time = %w(-h --help -c).include?(arguments.first) ? nil : arguments.shift
|
22
|
+
|
23
|
+
create_options_parser(arguments)
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_options_parser(args)
|
27
|
+
args.options do |opts|
|
28
|
+
opts.banner = 'Usage: windows-shutdown-timer MINUTES_UNTIL_SHUTDOWN [OPTIONS]'
|
29
|
+
opts.separator ''
|
30
|
+
opts.separator 'Options'
|
31
|
+
opts.on('-c', '--cancel', 'Cancel a pending shutdown') do
|
32
|
+
@time = 0
|
33
|
+
end
|
34
|
+
opts.on('-i', '--insomnia', 'Just runs Insomnia') do
|
35
|
+
@time = -1
|
36
|
+
end
|
37
|
+
opts.on('-h', '--help', 'Displays help') do
|
38
|
+
puts opts.help
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
opts.parse!
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def start_timer
|
46
|
+
unless File.file?(PATH_TO_INSOMNIA)
|
47
|
+
puts 'Downloading Insomnia.exe'
|
48
|
+
download('dlaa.me', '/Samples/Insomnia/Insomnia.zip', 'Insomnia.zip')
|
49
|
+
unzip('Insomnia.zip', 'insomnia')
|
50
|
+
FileUtils.mkdir(PATH_TO_TEMP)
|
51
|
+
FileUtils.mv('insomnia/64-bit/Insomnia.exe', PATH_TO_INSOMNIA)
|
52
|
+
# Cleanup
|
53
|
+
FileUtils.rm_rf('insomnia')
|
54
|
+
FileUtils.rm('Insomnia.zip')
|
55
|
+
end
|
56
|
+
if @time == nil
|
57
|
+
puts 'Please enter the number of minutes until shutdown (0 to cancel):'
|
58
|
+
@time = gets
|
59
|
+
end
|
60
|
+
if @time.to_i == 0
|
61
|
+
`#{COMMAND_CANCEL_SHUTDOWN}`
|
62
|
+
elsif @time.to_i == -1
|
63
|
+
`#{COMMAND_INSOMNIA}`
|
64
|
+
else
|
65
|
+
time_in_seconds = @time.to_i * 60
|
66
|
+
`#{COMMAND_SHUTDOWN} #{time_in_seconds}`
|
67
|
+
`#{COMMAND_INSOMNIA}`
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def download(base_url, path, file_name)
|
72
|
+
Net::HTTP.start(base_url) do |http|
|
73
|
+
resp = http.get(path)
|
74
|
+
open(file_name, 'wb') do |file|
|
75
|
+
file.write(resp.body)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def unzip(file, destination)
|
81
|
+
Zip::File.open(file) do |zip_file|
|
82
|
+
zip_file.each do |f|
|
83
|
+
f_path = File.join(destination, f.name)
|
84
|
+
FileUtils.mkdir_p(File.dirname(f_path))
|
85
|
+
zip_file.extract(f, f_path) unless File.exist?(f_path)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: windows-shutdown-timer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Carlson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 1.0.0
|
33
|
-
description:
|
33
|
+
description: Shut down Windows machine after keeping it awake
|
34
34
|
email:
|
35
35
|
- jawnnypoo@gmail.com
|
36
36
|
executables:
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
61
|
version: '0'
|
62
62
|
requirements: []
|
63
63
|
rubyforge_project:
|
64
|
-
rubygems_version: 2.
|
64
|
+
rubygems_version: 2.4.5.2
|
65
65
|
signing_key:
|
66
66
|
specification_version: 4
|
67
67
|
summary: Starts a timer, keeping the Windows machine awake and shutting it down when
|