windows-shutdown-timer 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9831e87cb92f49bbfa7a3bc55dfbda6cbd143778
4
+ data.tar.gz: 9b4f5802c79324667f617c31fe52b4265f0a9f8c
5
+ SHA512:
6
+ metadata.gz: db7b25f8b820d2167d272c91208681ee3afdad2a7008e92072532e87bb9a7b0f9e50cc13ca6dd1cc1450b6fa4c61c26980f0b8694c8cc6bb22d8b8434699ec46
7
+ data.tar.gz: d2e998bfc9a1ccd1ecf3870ee0f50e37d8ed88bd072096e9c71ee81c3ec2b1b66d35bf2802bfa3fd0eb483f8c61c175e1157250444732a6f53a535a090cb261f
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'windows-shutdown-timer'
4
+
5
+ starter = WindowsShutdownTimer::ShutdownStarter.new(ARGV)
6
+ starter.start_timer
@@ -0,0 +1,77 @@
1
+ require 'optparse'
2
+ require 'net/http'
3
+ require 'fileutils'
4
+ require 'zip'
5
+
6
+ module WindowsShutdownTimer
7
+ # Shutdown!
8
+ class ShutdownStarter
9
+
10
+ EXE = 'Insomnia.exe'
11
+ PATH = 'insomnia/64-bit'
12
+ COMMAND_SHUTDOWN = 'shutdown /s /t '
13
+ COMMAND_CANCEL_SHUTDOWN = 'shutdown /a'
14
+
15
+ def initialize(arguments)
16
+ @time = nil
17
+ create_options_parser(arguments)
18
+ end
19
+
20
+ def create_options_parser(args)
21
+ args.options do |opts|
22
+ opts.banner = 'Usage: windows-shutdown-timer [OPTIONS]'
23
+ opts.separator ''
24
+ opts.separator 'Options'
25
+ opts.on('-t', '--time', 'The amount of time in minutes before shutdown. 0 will cancel the shutdown') do |time|
26
+ @time = time
27
+ end
28
+ opts.on('-h', '--help', 'Displays help') do
29
+ puts opts.help
30
+ exit
31
+ end
32
+ opts.parse!
33
+ end
34
+ end
35
+
36
+ def start_timer
37
+ unless File.file?(EXE)
38
+ download('dlaa.me', '/Samples/Insomnia/Insomnia.zip', 'Insomnia.zip')
39
+ unzip('Insomnia.zip', 'insomnia')
40
+ FileUtils.mv('insomnia/64-bit/Insomnia.exe', Dir.pwd + '/Insomnia.exe')
41
+ FileUtils.rm_rf('insomnia')
42
+ FileUtils.rm('Insomnia.zip')
43
+ end
44
+ if @time == nil
45
+ puts 'Please enter the number of minutes until shutdown (0 to cancel):'
46
+ @time = gets
47
+ end
48
+ if @time.to_i == 0
49
+ `#{COMMAND_CANCEL_SHUTDOWN}`
50
+ else
51
+ time_in_seconds = @time.to_i * 60
52
+ `#{COMMAND_SHUTDOWN} #{time_in_seconds}`
53
+ `#{EXE}`
54
+ end
55
+ end
56
+
57
+ def download(base_url, path, file_name)
58
+ Net::HTTP.start(base_url) do |http|
59
+ resp = http.get(path)
60
+ open(file_name, 'wb') do |file|
61
+ file.write(resp.body)
62
+ end
63
+ end
64
+ end
65
+
66
+ def unzip(file, destination)
67
+ Zip::File.open(file) do |zip_file|
68
+ zip_file.each do |f|
69
+ f_path = File.join(destination, f.name)
70
+ FileUtils.mkdir_p(File.dirname(f_path))
71
+ zip_file.extract(f, f_path) unless File.exist?(f_path)
72
+ end
73
+ end
74
+ end
75
+
76
+ end
77
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: windows-shutdown-timer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - John Carlson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubyzip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ description:
28
+ email:
29
+ - jawnnypoo@gmail.com
30
+ executables:
31
+ - windows-shutdown-timer
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - bin/windows-shutdown-timer
36
+ - lib/windows-shutdown-timer.rb
37
+ homepage: https://github.com/Jawnnypoo/windows-shutdown-timer
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.0.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.6.11
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Starts a timer, keeping the Windows machine awake and shutting it down when
62
+ the timer expires
63
+ test_files: []