win32-shortcut 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +6 -0
- data/MANIFEST +1 -1
- data/README +12 -10
- data/Rakefile +3 -4
- data/lib/win32/shortcut.rb +31 -11
- data/test/test_shortcut.rb +113 -0
- data/win32-shortcut.gemspec +3 -2
- metadata +44 -38
- data/test/tc_shortcut.rb +0 -108
data/CHANGES
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 0.2.2 - 10-Jul-2008
|
2
|
+
* Fixed a bug where creating folder shortcuts would fail if forward slashes
|
3
|
+
were used. All forward slashes are now converted to backslashes internally.
|
4
|
+
Thanks go to Ajay Sprewell for the spot.
|
5
|
+
* Some documentation, test and gemspec updates.
|
6
|
+
|
1
7
|
== 0.2.1 - 29-Jul-2007
|
2
8
|
* Added a Rakefile with tasks for installation and testing.
|
3
9
|
* Removed the install.rb file, since the Rakefile now handles installation.
|
data/MANIFEST
CHANGED
data/README
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
== Requirements
|
5
5
|
Ruby 1.8.2 or later.
|
6
|
-
The win32ole
|
6
|
+
The win32ole library (part of the Ruby standard library).
|
7
7
|
|
8
8
|
== Installation
|
9
9
|
rake test (optional)
|
@@ -13,15 +13,15 @@
|
|
13
13
|
require 'win32/shortcut'
|
14
14
|
include Win32
|
15
15
|
|
16
|
-
Shortcut.new('c
|
17
|
-
s.description
|
18
|
-
s.path
|
19
|
-
s.show_cmd
|
20
|
-
s.working_directory =
|
16
|
+
Shortcut.new('c:/test.lnk') do |s|
|
17
|
+
s.description = 'test link'
|
18
|
+
s.path = 'c:/winnt/notepad.exe'
|
19
|
+
s.show_cmd = Shortcut::SHOWNORMAL
|
20
|
+
s.working_directory = 'C:/'
|
21
21
|
end
|
22
22
|
|
23
23
|
== Notes
|
24
|
-
This code uses win32ole + wscript behind the scenes.
|
24
|
+
This code uses win32ole + wscript behind the scenes. The original C code
|
25
25
|
is not distributed as part of the release, but is still retained in the
|
26
26
|
CVS repository under the 'ext' directory should anyone ever need it.
|
27
27
|
|
@@ -32,11 +32,13 @@
|
|
32
32
|
http://rubyforge.org/projects/win32utils.
|
33
33
|
|
34
34
|
== Future Plans
|
35
|
-
|
36
|
-
|
35
|
+
None at this time.
|
36
|
+
|
37
|
+
Ideas welcome. Please submit them on the project page as
|
38
|
+
a "Feature Request".
|
37
39
|
|
38
40
|
== Copyright
|
39
|
-
(C) 2003-
|
41
|
+
(C) 2003-2008, Daniel J. Berger, All Rights Reserved
|
40
42
|
|
41
43
|
== License
|
42
44
|
Ruby's
|
data/Rakefile
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rake/testtask'
|
3
3
|
|
4
|
-
desc "Install the win32-shortcut
|
4
|
+
desc "Install the win32-shortcut library (non-gem)"
|
5
5
|
task :install do
|
6
6
|
dest = File.join(Config::CONFIG['sitelibdir'], 'win32')
|
7
7
|
Dir.mkdir(dest) unless File.exists? dest
|
8
8
|
cp 'lib/win32/shortcut.rb', dest, :verbose => true
|
9
9
|
end
|
10
10
|
|
11
|
-
desc "Install the win32-shortcut
|
11
|
+
desc "Install the win32-shortcut library as a gem"
|
12
12
|
task :install_gem do
|
13
13
|
ruby 'win32-shortcut.gemspec'
|
14
14
|
file = Dir["*.gem"].first
|
@@ -16,7 +16,6 @@ task :install_gem do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
Rake::TestTask.new do |t|
|
19
|
-
t.libs << 'lib'
|
20
19
|
t.warning = true
|
21
|
-
t.
|
20
|
+
t.verbose = true
|
22
21
|
end
|
data/lib/win32/shortcut.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'win32ole'
|
2
2
|
|
3
|
+
# The Win32 module serves as a namespace only.
|
3
4
|
module Win32
|
4
|
-
class
|
5
|
-
|
5
|
+
# The Shortcut class encapsulates an MS Windows shortcut.
|
6
|
+
class Shortcut
|
7
|
+
# The version of this library
|
8
|
+
VERSION = '0.2.2'
|
6
9
|
|
7
10
|
# Activates and displays a window. If the window is minimized or maximized,
|
8
11
|
# the system restores it to its original size and position. An application
|
@@ -19,15 +22,27 @@ module Win32
|
|
19
22
|
#
|
20
23
|
SHOWMINNOACTIVE = 7
|
21
24
|
|
22
|
-
# Creates and returns a Shortcut object.
|
25
|
+
# Creates and returns a Shortcut object. In block form it yields +self+
|
23
26
|
# and automatically ensures that Shortcut#save is called at the end of
|
24
|
-
# the block.
|
27
|
+
# the block. In non-block form it does not actually create the shortcut
|
25
28
|
# until the Shorcut#save method is called.
|
29
|
+
#
|
30
|
+
# Examples:
|
31
|
+
#
|
32
|
+
# # Create a shortcut called 'test' to a file in non-block form.
|
33
|
+
# s = Shortcut.new('test.lnk')
|
34
|
+
# s.target_path = 'C:/Documents and Settings/john/some_file.txt'
|
35
|
+
# s.save
|
36
|
+
#
|
37
|
+
# # Create a shortcut called 'test2' to a folder in block form.
|
38
|
+
# Shortcut.new('test2.lnk') do |sc|
|
39
|
+
# sc.target_path = 'C:/Documents and Settings/john/some_dir'
|
40
|
+
# end
|
26
41
|
#
|
27
42
|
def initialize(file)
|
28
|
-
@file = file
|
43
|
+
@file = file.tr('/', "\\")
|
29
44
|
@shell = WIN32OLE.new('WScript.Shell')
|
30
|
-
@link = @shell.CreateShortcut(file)
|
45
|
+
@link = @shell.CreateShortcut(@file)
|
31
46
|
|
32
47
|
if block_given?
|
33
48
|
begin
|
@@ -101,7 +116,7 @@ module Win32
|
|
101
116
|
# Sets the name of the icon file to be used for the shortcut.
|
102
117
|
#
|
103
118
|
def icon_location=(location)
|
104
|
-
@link.IconLocation = location
|
119
|
+
@link.IconLocation = location.tr('/', "\\")
|
105
120
|
end
|
106
121
|
|
107
122
|
# Returns the target of the shortcut. This is, joined with arguments, the
|
@@ -115,9 +130,12 @@ module Win32
|
|
115
130
|
alias target_path path
|
116
131
|
|
117
132
|
# Sets the target of the shortcut.
|
118
|
-
|
133
|
+
#--
|
134
|
+
# Forward slashes are converted to backslashes to ensure folder
|
135
|
+
# shortcuts work properly.
|
136
|
+
#
|
119
137
|
def path=(link_path)
|
120
|
-
@link.TargetPath = link_path
|
138
|
+
@link.TargetPath = link_path.tr('/', "\\")
|
121
139
|
end
|
122
140
|
|
123
141
|
alias target_path= path=
|
@@ -196,11 +214,13 @@ module Win32
|
|
196
214
|
# Sets the directory in which the targeted program will be executed.
|
197
215
|
#
|
198
216
|
def working_directory=(directory)
|
199
|
-
@link.WorkingDirectory = directory
|
217
|
+
@link.WorkingDirectory = directory.tr('/', "\\")
|
200
218
|
end
|
201
219
|
|
220
|
+
# Saves (creates) the link object in the current directory.
|
221
|
+
#
|
202
222
|
def save
|
203
223
|
@link.Save
|
204
224
|
end
|
205
225
|
end
|
206
|
-
end
|
226
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# tc_shortcut.rb
|
3
|
+
#
|
4
|
+
# Test suite for the win32-shortcut package. This will temporarily create
|
5
|
+
# a link to Notepad in the current directory, which should be automatically
|
6
|
+
# deleted by this test suite.
|
7
|
+
#
|
8
|
+
# You should run this test case via the 'rake test' task.
|
9
|
+
##############################################################################
|
10
|
+
require 'win32/shortcut'
|
11
|
+
require 'test/unit'
|
12
|
+
include Win32
|
13
|
+
|
14
|
+
class TC_Shortcut < Test::Unit::TestCase
|
15
|
+
def setup
|
16
|
+
@link = File.join(Dir.pwd, 'test.lnk')
|
17
|
+
@sc = Shortcut.new(@link)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_version
|
21
|
+
assert_equal('0.2.2', Shortcut::VERSION)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_arguments
|
25
|
+
assert_respond_to(@sc, :arguments)
|
26
|
+
assert_respond_to(@sc, :arguments=)
|
27
|
+
assert_nothing_raised{ @sc.arguments }
|
28
|
+
assert_nothing_raised{ @sc.arguments = '-v' }
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_description
|
32
|
+
assert_respond_to(@sc, :description)
|
33
|
+
assert_respond_to(@sc, :description=)
|
34
|
+
assert_nothing_raised{ @sc.description }
|
35
|
+
assert_nothing_raised{ @sc.description = "test link" }
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_file
|
39
|
+
assert_respond_to(@sc, :file)
|
40
|
+
assert_nothing_raised{ @sc.file }
|
41
|
+
end
|
42
|
+
|
43
|
+
# TODO: Figure out why hotkey assignment fails here. It works fine in
|
44
|
+
# the example program.
|
45
|
+
#
|
46
|
+
def test_hotkey
|
47
|
+
assert_respond_to(@sc, :hotkey)
|
48
|
+
assert_respond_to(@sc, :hotkey=)
|
49
|
+
assert_nothing_raised{ @sc.hotkey }
|
50
|
+
#assert_nothing_raised{ @sc.hotkey = "CTRL-SHIFT-F" }
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_icon_location
|
54
|
+
assert_respond_to(@sc, :icon_location)
|
55
|
+
assert_respond_to(@sc, :icon_location=)
|
56
|
+
assert_nothing_raised{ @sc.icon_location }
|
57
|
+
assert_nothing_raised{ @sc.icon_location = "notepad.exe"}
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_path
|
61
|
+
assert_respond_to(@sc, :path)
|
62
|
+
assert_respond_to(@sc, :path=)
|
63
|
+
assert_nothing_raised{ @sc.path }
|
64
|
+
assert_nothing_raised{ @sc.path = 'c:\winnt\notepad.exe' }
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_open
|
68
|
+
shortcut = Shortcut.new(@link)
|
69
|
+
shortcut.save
|
70
|
+
|
71
|
+
assert_respond_to(Shortcut, :open)
|
72
|
+
assert_nothing_raised{ Shortcut.open(@link) }
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_open_expected_errors
|
76
|
+
assert_raise(ArgumentError){ Shortcut.open('bogus') }
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_resolve
|
80
|
+
assert_respond_to(@sc, :resolve)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_save
|
84
|
+
assert_respond_to(@sc, :save)
|
85
|
+
assert_nothing_raised{ @sc.save }
|
86
|
+
assert_equal(true, File.exists?(@link))
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_window_style
|
90
|
+
assert_respond_to(@sc, :window_style)
|
91
|
+
assert_respond_to(@sc, :window_style=)
|
92
|
+
assert_nothing_raised{ @sc.window_style }
|
93
|
+
assert_nothing_raised{ @sc.window_style = Shortcut::SHOWNORMAL }
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_working_directory
|
97
|
+
assert_respond_to(@sc, :working_directory)
|
98
|
+
assert_respond_to(@sc, :working_directory=)
|
99
|
+
assert_nothing_raised{ @sc.working_directory }
|
100
|
+
assert_nothing_raised{ @sc.working_directory = "c:\\" }
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_constants
|
104
|
+
assert_not_nil(Shortcut::SHOWNORMAL)
|
105
|
+
assert_not_nil(Shortcut::SHOWMINNOACTIVE)
|
106
|
+
assert_not_nil(Shortcut::SHOWMAXIMIZED)
|
107
|
+
end
|
108
|
+
|
109
|
+
def teardown
|
110
|
+
@sc = nil
|
111
|
+
File.delete(@link) if File.exists?(@link)
|
112
|
+
end
|
113
|
+
end
|
data/win32-shortcut.gemspec
CHANGED
@@ -2,14 +2,15 @@ require "rubygems"
|
|
2
2
|
|
3
3
|
spec = Gem::Specification.new do |gem|
|
4
4
|
gem.name = "win32-shortcut"
|
5
|
-
gem.version = "0.2.
|
5
|
+
gem.version = "0.2.2"
|
6
6
|
gem.author = "Daniel J. Berger"
|
7
7
|
gem.email = "djberg96@gmail.com"
|
8
8
|
gem.homepage = "http://www.rubyforge.org/projects/win32utils"
|
9
|
+
gem.rubyforge_project = "win32utils"
|
9
10
|
gem.platform = Gem::Platform::RUBY
|
10
11
|
gem.summary = "An interface for creating or modifying Windows shortcuts."
|
11
12
|
gem.description = "An interface for creating or modifying Windows shortcuts."
|
12
|
-
gem.test_file = "test/
|
13
|
+
gem.test_file = "test/test_shortcut.rb"
|
13
14
|
gem.has_rdoc = true
|
14
15
|
gem.files = Dir["lib/win32/*.rb"] + Dir["test/*"] + Dir["[A-Z]*"]
|
15
16
|
gem.files.reject! { |fn| fn.include? "CVS" }
|
metadata
CHANGED
@@ -1,60 +1,66 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: win32-shortcut
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2007-07-29 00:00:00 -06:00
|
8
|
-
summary: An interface for creating or modifying Windows shortcuts.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: djberg96@gmail.com
|
12
|
-
homepage: http://www.rubyforge.org/projects/win32utils
|
13
|
-
rubyforge_project:
|
14
|
-
description: An interface for creating or modifying Windows shortcuts.
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.2.2
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Daniel J. Berger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-07-10 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: An interface for creating or modifying Windows shortcuts.
|
17
|
+
email: djberg96@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
- CHANGES
|
25
|
+
- MANIFEST
|
31
26
|
files:
|
32
27
|
- lib/win32/shortcut.rb
|
33
28
|
- test/CVS
|
34
|
-
- test/
|
29
|
+
- test/test_shortcut.rb
|
35
30
|
- CHANGES
|
36
31
|
- CVS
|
37
32
|
- examples
|
38
|
-
- ext
|
39
33
|
- lib
|
40
34
|
- MANIFEST
|
41
35
|
- Rakefile
|
42
36
|
- README
|
43
37
|
- test
|
44
38
|
- win32-shortcut.gemspec
|
45
|
-
|
46
|
-
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://www.rubyforge.org/projects/win32utils
|
41
|
+
post_install_message:
|
47
42
|
rdoc_options: []
|
48
43
|
|
49
|
-
|
50
|
-
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
57
58
|
requirements: []
|
58
59
|
|
59
|
-
|
60
|
-
|
60
|
+
rubyforge_project: win32utils
|
61
|
+
rubygems_version: 1.2.0
|
62
|
+
signing_key:
|
63
|
+
specification_version: 2
|
64
|
+
summary: An interface for creating or modifying Windows shortcuts.
|
65
|
+
test_files:
|
66
|
+
- test/test_shortcut.rb
|
data/test/tc_shortcut.rb
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
##############################################################################
|
2
|
-
# tc_shortcut.rb
|
3
|
-
#
|
4
|
-
# Test suite for the win32-shortcut package. This will temporarily create
|
5
|
-
# a link to Notepad on C:\, which should be automatically deleted.
|
6
|
-
#
|
7
|
-
# You should run this test case via the 'rake test' task.
|
8
|
-
##############################################################################
|
9
|
-
require 'win32/shortcut'
|
10
|
-
require 'test/unit'
|
11
|
-
include Win32
|
12
|
-
|
13
|
-
class TC_Shortcut < Test::Unit::TestCase
|
14
|
-
def setup
|
15
|
-
@link = Dir.pwd + '/test.lnk'
|
16
|
-
@s = Shortcut.new(@link)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_version
|
20
|
-
assert_equal('0.2.1', Shortcut::VERSION)
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_arguments
|
24
|
-
assert_respond_to(@s, :arguments)
|
25
|
-
assert_respond_to(@s, :arguments=)
|
26
|
-
assert_nothing_raised{ @s.arguments }
|
27
|
-
assert_nothing_raised{ @s.arguments = '-v' }
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_description
|
31
|
-
assert_respond_to(@s, :description)
|
32
|
-
assert_respond_to(@s, :description=)
|
33
|
-
assert_nothing_raised{ @s.description }
|
34
|
-
assert_nothing_raised{ @s.description = "test link" }
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_file
|
38
|
-
assert_respond_to(@s, :file)
|
39
|
-
assert_nothing_raised{ @s.file }
|
40
|
-
end
|
41
|
-
|
42
|
-
# TODO: Figure out why hotkey assignment fails here. It works fine inthe
|
43
|
-
# example program.
|
44
|
-
#
|
45
|
-
def test_hotkey
|
46
|
-
assert_respond_to(@s, :hotkey)
|
47
|
-
assert_respond_to(@s, :hotkey=)
|
48
|
-
assert_nothing_raised{ @s.hotkey }
|
49
|
-
#assert_nothing_raised{ @s.hotkey = "CTRL-SHIFT-F" }
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_icon_location
|
53
|
-
assert_respond_to(@s, :icon_location)
|
54
|
-
assert_respond_to(@s, :icon_location=)
|
55
|
-
assert_nothing_raised{ @s.icon_location }
|
56
|
-
assert_nothing_raised{ @s.icon_location = "notepad.exe"}
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_path
|
60
|
-
assert_respond_to(@s, :path)
|
61
|
-
assert_respond_to(@s, :path=)
|
62
|
-
assert_nothing_raised{ @s.path }
|
63
|
-
assert_nothing_raised{ @s.path = 'c:\winnt\notepad.exe' }
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_open
|
67
|
-
shortcut = Shortcut.new(@link)
|
68
|
-
shortcut.save
|
69
|
-
|
70
|
-
assert_respond_to(Shortcut, :open)
|
71
|
-
assert_nothing_raised{ Shortcut.open(@link) }
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_resolve
|
75
|
-
assert_respond_to(@s, :resolve)
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_save
|
79
|
-
assert_respond_to(@s, :save)
|
80
|
-
assert_nothing_raised{ @s.save }
|
81
|
-
assert_equal(true, File.exists?(@link))
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_window_style
|
85
|
-
assert_respond_to(@s, :window_style)
|
86
|
-
assert_respond_to(@s, :window_style=)
|
87
|
-
assert_nothing_raised{ @s.window_style }
|
88
|
-
assert_nothing_raised{ @s.window_style = Shortcut::SHOWNORMAL }
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_working_directory
|
92
|
-
assert_respond_to(@s, :working_directory)
|
93
|
-
assert_respond_to(@s, :working_directory=)
|
94
|
-
assert_nothing_raised{ @s.working_directory }
|
95
|
-
assert_nothing_raised{ @s.working_directory = "c:\\" }
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_constants
|
99
|
-
assert_not_nil(Shortcut::SHOWNORMAL)
|
100
|
-
assert_not_nil(Shortcut::SHOWMINNOACTIVE)
|
101
|
-
assert_not_nil(Shortcut::SHOWMAXIMIZED)
|
102
|
-
end
|
103
|
-
|
104
|
-
def teardown
|
105
|
-
@s = nil
|
106
|
-
File.delete(@link) if File.exists?(@link)
|
107
|
-
end
|
108
|
-
end
|