2
2
require 'shellwords' # fingers crossed this works on win32
3
3
require 'win32/registry'
4
4
require "arduino_ci/arduino_downloader"
5
+ require 'open-uri'
5
6
6
7
module ArduinoCI
7
8
@@ -27,19 +28,28 @@ def prepare
27
28
# (for logging purposes)
28
29
# @return [string]
29
30
def downloader
30
- "wget "
31
+ "open-uri "
31
32
end
32
33
33
34
# Download the package_url to package_file
34
35
# @return [bool] whether successful
35
36
def download
36
- powershell ( "(New-Object Net.WebClient).DownloadFile('#{ package_url } ', '#{ package_file } ')" )
37
+ puts 'Downloading from ' + package_url
38
+ # Turned off ssl verification
39
+ open ( URI . parse ( package_url ) , ssl_verify_mode : 0 ) do |url |
40
+ File . open ( package_file , 'wb' ) { |file | file . write ( url . read ) }
41
+ end
37
42
end
38
43
39
44
# Move the extracted package file from extracted_file to the force_install_location
40
45
# @return [bool] whether successful
41
46
def install
42
- powershell ( "Move-Item" , extracted_file , self . class . force_install_location )
47
+ puts 'Installing to ' + self . class . force_install_location
48
+ # Move only the content of the directory
49
+ powershell ( "Move-Item" , extracted_file + "\* " , self . class . force_install_location )
50
+ # clean up the no longer required root extracted folder
51
+ puts 'Removing ' + package_file
52
+ powershell ( "Remove-Item" , extracted_file )
43
53
end
44
54
45
55
# The local filename of the desired IDE package (zip/tar/etc)
@@ -58,7 +68,11 @@ def extracter
58
68
# Extract the package_file to extracted_file
59
69
# @return [bool] whether successful
60
70
def extract
61
- powershell ( "Expand-Archive" , package_file , "-dest" , extracted_file )
71
+ puts 'Extracting ' + package_file + " to " + extracted_file
72
+ powershell ( "Expand-Archive" , "-Path" , package_file , "-DestinationPath" , extracted_file )
73
+ # clean up the no longer required zip
74
+ puts 'Removing ' + package_file
75
+ powershell ( "Remove-Item" , package_file )
62
76
end
63
77
64
78
# The local file (dir) name of the extracted IDE package (zip/tar/etc)
@@ -78,25 +92,22 @@ def self.existing_installation
78
92
# The executable Arduino file in an existing installation, or nil
79
93
# @return [string]
80
94
def self . existing_executable
81
- arduino_reg = 'Software\ SOFTWARE\Classes \Arduino file\shell\open\command '
95
+ arduino_reg = 'SOFTWARE\WOW6432Node \Arduino'
82
96
Win32 ::Registry ::HKEY_LOCAL_MACHINE . open ( arduino_reg ) do |reg |
83
- reg . each_key do |key |
84
- k = reg . open ( key )
85
- puts key
86
- puts k
87
- return k
88
- # puts k["DisplayName"] rescue "?"
89
- # puts k["DisplayVersion"] rescue "?"
90
- # puts
91
- end
97
+ path = reg . read_s ( 'Install_Dir' )
98
+ exe = File . join ( path , "arduino_debug.exe" )
99
+ puts "Using existing exe located at " + exe
100
+ return exe if File . exist? exe
92
101
end
102
+ rescue
93
103
nil
94
104
end
95
105
96
106
# The executable Arduino file in a forced installation, or nil
97
107
# @return [string]
98
108
def self . force_installed_executable
99
- exe = File . join ( self . force_install_location , "arduino.exe" )
109
+ exe = File . join ( self . force_install_location , "arduino_debug.exe" )
110
+ puts "Using force installed exe located at " + exe
100
111
return nil if exe . nil?
101
112
exe
102
113
end
0 commit comments