win32-shortcut 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/CHANGES +3 -0
  2. data/README +27 -35
  3. data/Rakefile +19 -13
  4. data/lib/win32/shortcut.rb +219 -219
  5. data/win32-shortcut.gemspec +16 -20
  6. metadata +26 -32
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.2.4 - 18-Mar-2012
2
+ * Refactored and updated the Rakefile and gemspec.
3
+
1
4
  == 0.2.3 - 6-Aug-2009
2
5
  * License changed to Artistic 2.0.
3
6
  * Some gemspec updates, including license and description.
data/README CHANGED
@@ -1,60 +1,52 @@
1
1
  == Description
2
- This is an interface for creating and/or modifying Windows shortcuts.
3
-
4
- == Requirements
5
- Ruby 1.8.2 or later.
6
- The win32ole library (part of the Ruby standard library).
2
+ This is an interface for creating and/or modifying Windows shortcuts.
7
3
 
8
4
  == Installation
9
- rake test (optional)
10
- rake install (non-gem) or rake install_gem (gem)
5
+ gem install win32-shortcut
11
6
 
12
7
  == Synopsis
13
8
  require 'win32/shortcut'
14
- include Win32
9
+ include Win32
15
10
 
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
- end
11
+ Shortcut.new('c:/test.lnk') do |s|
12
+ s.description = 'test link'
13
+ s.path = 'c:/winnt/notepad.exe'
14
+ s.show_cmd = Shortcut::SHOWNORMAL
15
+ s.working_directory = 'C:/'
16
+ end
22
17
 
23
18
  == Notes
24
- This code uses win32ole + wscript behind the scenes. The original C code
25
- is not distributed as part of the release, but is still retained in the
26
- CVS repository under the 'ext' directory should anyone ever need it.
19
+ This code uses win32ole + wscript behind the scenes.
27
20
 
28
21
  == Known Bugs
29
- None known.
22
+ None known.
30
23
 
31
- Please report any bugs on the project page at
32
- http://rubyforge.org/projects/win32utils.
24
+ Please report any bugs on the project page at
25
+ https://github.com/djberg96/win32-shortcut
33
26
 
34
27
  == Future Plans
35
- None at this time.
28
+ None at this time.
36
29
 
37
- Ideas welcome. Please submit them on the project page as
38
- a "Feature Request".
30
+ Ideas welcome. Please submit them on the project page.
39
31
 
40
32
  == Copyright
41
- (C) 2003-2008, Daniel J. Berger, All Rights Reserved
33
+ (C) 2003-2012, Daniel J. Berger, All Rights Reserved
42
34
 
43
35
  == License
44
- Ruby's
36
+ Artistic 2.0
45
37
 
46
38
  == Warranty
47
- This package is provided "as is" and without any express or
48
- implied warranties, including, without limitation, the implied
49
- warranties of merchantability and fitness for a particular purpose.
39
+ This package is provided "as is" and without any express or
40
+ implied warranties, including, without limitation, the implied
41
+ warranties of merchantability and fitness for a particular purpose.
50
42
 
51
43
  == Acknowledgements
52
- The original win32-shortcut package was largely based on Aldo Calpini's
53
- Win32::Shortcut Perl module, and I copied some of the documentation as
54
- well.
44
+ The original win32-shortcut package was largely based on Aldo Calpini's
45
+ Win32::Shortcut Perl module, and I copied some of the documentation as
46
+ well.
55
47
 
56
- The current version (0.2.0 and later) is based on a patch by Jano Svitok.
48
+ The current version (0.2.0 and later) is based on a patch by Jano Svitok.
57
49
 
58
- == Author(s)
59
- Daniel J. Berger
60
- Park Heesob
50
+ == Authors
51
+ Daniel J. Berger
52
+ Park Heesob
data/Rakefile CHANGED
@@ -1,21 +1,27 @@
1
1
  require 'rake'
2
+ require 'rake/clean'
2
3
  require 'rake/testtask'
3
4
 
4
- desc "Install the win32-shortcut library (non-gem)"
5
- task :install do
6
- dest = File.join(Config::CONFIG['sitelibdir'], 'win32')
7
- Dir.mkdir(dest) unless File.exists? dest
8
- cp 'lib/win32/shortcut.rb', dest, :verbose => true
9
- end
5
+ CLEAN.include("**/*.gem")
6
+
7
+ namespace :gem do
8
+ desc "Create theh win32-shortcut gem"
9
+ task :create => [:clean] do
10
+ spec = eval(IO.read('win32-shortcut.gemspec'))
11
+ Gem::Builder.new(spec).build
12
+ end
10
13
 
11
- desc "Install the win32-shortcut library as a gem"
12
- task :install_gem do
13
- ruby 'win32-shortcut.gemspec'
14
- file = Dir["*.gem"].first
15
- sh "gem install #{file}"
14
+ desc "Install the win32-shortcut gem"
15
+ task :install => [:create] do
16
+ ruby 'win32-shortcut.gemspec'
17
+ file = Dir["*.gem"].first
18
+ sh "gem install #{file}"
19
+ end
16
20
  end
17
21
 
18
22
  Rake::TestTask.new do |t|
19
- t.warning = true
20
- t.verbose = true
23
+ t.warning = true
24
+ t.verbose = true
21
25
  end
26
+
27
+ task :default => :test
@@ -2,225 +2,225 @@ require 'win32ole'
2
2
 
3
3
  # The Win32 module serves as a namespace only.
4
4
  module Win32
5
- # The Shortcut class encapsulates an MS Windows shortcut.
6
- class Shortcut
7
- # The version of this library
8
- VERSION = '0.2.3'
9
-
10
- # Activates and displays a window. If the window is minimized or maximized,
11
- # the system restores it to its original size and position. An application
12
- # should specify this flag when displaying the window for the first time.
13
- #
14
- SHOWNORMAL = 1
15
-
16
- # Activates the window and displays it as a maximized window.
17
- #
18
- SHOWMAXIMIZED = 3
19
-
20
- # Displays the window in its minimized state, leaving the currently active
21
- # window as active.
22
- #
23
- SHOWMINNOACTIVE = 7
24
-
25
- # Creates and returns a Shortcut object. In block form it yields +self+
26
- # and automatically ensures that Shortcut#save is called at the end of
27
- # the block. In non-block form it does not actually create the shortcut
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
41
- #
42
- def initialize(file)
43
- @file = file.tr('/', "\\")
44
- @shell = WIN32OLE.new('WScript.Shell')
45
- @link = @shell.CreateShortcut(@file)
46
-
47
- if block_given?
48
- begin
49
- yield self
50
- ensure
51
- save
52
- end
53
- end
54
- end
55
-
56
- # Identical to Shortcut#new except that it will raise an ArgumentError
57
- # unless the +file+ already exists.
58
- #
59
- def self.open(file)
60
- raise ArgumentError, 'shortcut not found' unless File.exists?(file)
61
- self.new(file)
62
- end
63
-
64
- # Returns any arguments (i.e. command line options) for the shortcut.
65
- #
66
- def arguments
67
- @link.Arguments
68
- end
69
-
70
- # Sets the arguments (i.e. command line options) for the shortcut.
71
- #
72
- def arguments=(args)
73
- @link.Arguments = args
74
- end
75
-
76
- # Returns the description (i.e. comment) for the shortcut.
77
- #
78
- def description
79
- @link.Description
80
- end
81
-
82
- # Sets the description for the shortcut.
83
- #
84
- def description=(desc)
85
- @link.Description = desc
86
- end
87
-
88
- # Returns the file name of the shortcut.
89
- #
90
- def file
91
- @file
92
- end
93
-
94
- # Returns the hotkey (i.e. shortcut key) associated to the shortcut, in
95
- # the form of a 2-byte number of which the first byte identifies the
96
- # modifiers (Ctrl, Alt, Shift) and the second is the ASCII code of
97
- # the character key.
98
- #
99
- def hotkey
100
- @link.HotKey
101
- end
102
-
103
- # Sets the hotkey for the shortcut.
104
- #
105
- def hotkey=(key)
106
- @link.HotKey = key
107
- end
108
-
109
- # Returns the name of the file that contain the icon for the shortcut.
110
- # In practice this is almost always blank. YMMV.
111
- #
112
- def icon_location
113
- @link.IconLocation
114
- end
115
-
116
- # Sets the name of the icon file to be used for the shortcut.
117
- #
118
- def icon_location=(location)
119
- @link.IconLocation = location.tr('/', "\\")
120
- end
121
-
122
- # Returns the target of the shortcut. This is, joined with arguments, the
123
- # content of the "Target" field in a Shortcut Properties Dialog Box. The
124
- # target name is returned in 8.3 format.
125
- #
126
- def path
127
- @link.TargetPath
128
- end
129
-
130
- alias target_path path
131
-
132
- # Sets the target of the shortcut.
133
- #--
134
- # Forward slashes are converted to backslashes to ensure folder
135
- # shortcuts work properly.
136
- #
137
- def path=(link_path)
138
- @link.TargetPath = link_path.tr('/', "\\")
139
- end
140
-
141
- alias target_path= path=
142
-
143
- # Attempts to automatically resolve a shortcut and returns the resolved path,
144
- # or raises an error. In case no resolution was made, the path is returned
145
- # unchanged.
146
- #
147
- # Note that the path is automatically updated in the path attribute of the
148
- # Shortcut object.
149
- #
150
- def resolve
151
- @link.FullName
152
- end
153
-
154
- # Returns the type of window style used by a shortcut. The possible
155
- # return values are 'normal', 'maximized', or 'minimized'.
156
- #
157
- def window_style
158
- case @link.WindowStyle
159
- when SHOWNORMAL
160
- 'normal'
161
- when SHOWMAXIMIZED
162
- 'maximized'
163
- when SHOWMINNOACTIVE
164
- 'minimized'
165
- else
166
- 'unknown' # Should never reach here
167
- end
168
- end
169
-
170
- # Deprecated.
171
- alias show_cmd window_style
172
-
173
- # Sets the window style to a shortcut. The +style+ can be one of the
174
- # following three constants or equivalent string values:
175
- #
176
- # * SHOWNORMAL or 'normal'
177
- # * SHOWMAXIMIZED or 'maximized'
178
- # * SHOWMINNOACTIVE or 'minimized'
179
- #
180
- # Please see the documentation for those constants for further details.
181
- #
182
- def window_style=(style)
183
- valid = [SHOWNORMAL, SHOWMAXIMIZED, SHOWMINNOACTIVE]
184
- valid.concat(['normal', 'maximized', 'minimized'])
185
-
186
- unless valid.include?(style)
187
- raise ArgumentError, 'invalid style'
188
- end
189
-
190
- if style.is_a?(String)
191
- case style.downcase
192
- when 'normal'
193
- style = SHOWNORMAL
194
- when 'maximized'
195
- style = SHOWMAXIMIZED
196
- when 'minimized'
197
- style = SHOWMINNOACTIVE
198
- end
199
- end
200
-
201
- @link.WindowStyle = style
202
- end
203
-
204
- # Deprecated.
205
- alias show_cmd= window_style=
206
-
207
- # Returns directory in which the targeted program will be executed.
208
- # Correspond to the "Start in" field of a Shortcut Properties Dialog Box.
209
- #
210
- def working_directory
211
- @link.WorkingDirectory
212
- end
213
-
214
- # Sets the directory in which the targeted program will be executed.
215
- #
216
- def working_directory=(directory)
217
- @link.WorkingDirectory = directory.tr('/', "\\")
5
+ # The Shortcut class encapsulates an MS Windows shortcut.
6
+ class Shortcut
7
+ # The version of this library
8
+ VERSION = '0.2.4'
9
+
10
+ # Activates and displays a window. If the window is minimized or maximized,
11
+ # the system restores it to its original size and position. An application
12
+ # should specify this flag when displaying the window for the first time.
13
+ #
14
+ SHOWNORMAL = 1
15
+
16
+ # Activates the window and displays it as a maximized window.
17
+ #
18
+ SHOWMAXIMIZED = 3
19
+
20
+ # Displays the window in its minimized state, leaving the currently active
21
+ # window as active.
22
+ #
23
+ SHOWMINNOACTIVE = 7
24
+
25
+ # Creates and returns a Shortcut object. In block form it yields +self+
26
+ # and automatically ensures that Shortcut#save is called at the end of
27
+ # the block. In non-block form it does not actually create the shortcut
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
41
+ #
42
+ def initialize(file)
43
+ @file = file.tr('/', "\\")
44
+ @shell = WIN32OLE.new('WScript.Shell')
45
+ @link = @shell.CreateShortcut(@file)
46
+
47
+ if block_given?
48
+ begin
49
+ yield self
50
+ ensure
51
+ save
52
+ end
53
+ end
54
+ end
55
+
56
+ # Identical to Shortcut#new except that it will raise an ArgumentError
57
+ # unless the +file+ already exists.
58
+ #
59
+ def self.open(file)
60
+ raise ArgumentError, 'shortcut not found' unless File.exists?(file)
61
+ self.new(file)
62
+ end
63
+
64
+ # Returns any arguments (i.e. command line options) for the shortcut.
65
+ #
66
+ def arguments
67
+ @link.Arguments
68
+ end
69
+
70
+ # Sets the arguments (i.e. command line options) for the shortcut.
71
+ #
72
+ def arguments=(args)
73
+ @link.Arguments = args
74
+ end
75
+
76
+ # Returns the description (i.e. comment) for the shortcut.
77
+ #
78
+ def description
79
+ @link.Description
80
+ end
81
+
82
+ # Sets the description for the shortcut.
83
+ #
84
+ def description=(desc)
85
+ @link.Description = desc
86
+ end
87
+
88
+ # Returns the file name of the shortcut.
89
+ #
90
+ def file
91
+ @file
92
+ end
93
+
94
+ # Returns the hotkey (i.e. shortcut key) associated to the shortcut, in
95
+ # the form of a 2-byte number of which the first byte identifies the
96
+ # modifiers (Ctrl, Alt, Shift) and the second is the ASCII code of
97
+ # the character key.
98
+ #
99
+ def hotkey
100
+ @link.HotKey
101
+ end
102
+
103
+ # Sets the hotkey for the shortcut.
104
+ #
105
+ def hotkey=(key)
106
+ @link.HotKey = key
107
+ end
108
+
109
+ # Returns the name of the file that contain the icon for the shortcut.
110
+ # In practice this is almost always blank. YMMV.
111
+ #
112
+ def icon_location
113
+ @link.IconLocation
114
+ end
115
+
116
+ # Sets the name of the icon file to be used for the shortcut.
117
+ #
118
+ def icon_location=(location)
119
+ @link.IconLocation = location.tr('/', "\\")
120
+ end
121
+
122
+ # Returns the target of the shortcut. This is, joined with arguments, the
123
+ # content of the "Target" field in a Shortcut Properties Dialog Box. The
124
+ # target name is returned in 8.3 format.
125
+ #
126
+ def path
127
+ @link.TargetPath
128
+ end
129
+
130
+ alias target_path path
131
+
132
+ # Sets the target of the shortcut.
133
+ #--
134
+ # Forward slashes are converted to backslashes to ensure folder
135
+ # shortcuts work properly.
136
+ #
137
+ def path=(link_path)
138
+ @link.TargetPath = link_path.tr('/', "\\")
139
+ end
140
+
141
+ alias target_path= path=
142
+
143
+ # Attempts to automatically resolve a shortcut and returns the resolved path,
144
+ # or raises an error. In case no resolution was made, the path is returned
145
+ # unchanged.
146
+ #
147
+ # Note that the path is automatically updated in the path attribute of the
148
+ # Shortcut object.
149
+ #
150
+ def resolve
151
+ @link.FullName
152
+ end
153
+
154
+ # Returns the type of window style used by a shortcut. The possible
155
+ # return values are 'normal', 'maximized', or 'minimized'.
156
+ #
157
+ def window_style
158
+ case @link.WindowStyle
159
+ when SHOWNORMAL
160
+ 'normal'
161
+ when SHOWMAXIMIZED
162
+ 'maximized'
163
+ when SHOWMINNOACTIVE
164
+ 'minimized'
165
+ else
166
+ 'unknown' # Should never reach here
167
+ end
168
+ end
169
+
170
+ # Deprecated.
171
+ alias show_cmd window_style
172
+
173
+ # Sets the window style to a shortcut. The +style+ can be one of the
174
+ # following three constants or equivalent string values:
175
+ #
176
+ # * SHOWNORMAL or 'normal'
177
+ # * SHOWMAXIMIZED or 'maximized'
178
+ # * SHOWMINNOACTIVE or 'minimized'
179
+ #
180
+ # Please see the documentation for those constants for further details.
181
+ #
182
+ def window_style=(style)
183
+ valid = [SHOWNORMAL, SHOWMAXIMIZED, SHOWMINNOACTIVE]
184
+ valid.concat(['normal', 'maximized', 'minimized'])
185
+
186
+ unless valid.include?(style)
187
+ raise ArgumentError, 'invalid style'
218
188
  end
219
-
220
- # Saves (creates) the link object in the current directory.
221
- #
222
- def save
223
- @link.Save
189
+
190
+ if style.is_a?(String)
191
+ case style.downcase
192
+ when 'normal'
193
+ style = SHOWNORMAL
194
+ when 'maximized'
195
+ style = SHOWMAXIMIZED
196
+ when 'minimized'
197
+ style = SHOWMINNOACTIVE
198
+ end
224
199
  end
225
- end
200
+
201
+ @link.WindowStyle = style
202
+ end
203
+
204
+ # Deprecated.
205
+ alias show_cmd= window_style=
206
+
207
+ # Returns directory in which the targeted program will be executed.
208
+ # Correspond to the "Start in" field of a Shortcut Properties Dialog Box.
209
+ #
210
+ def working_directory
211
+ @link.WorkingDirectory
212
+ end
213
+
214
+ # Sets the directory in which the targeted program will be executed.
215
+ #
216
+ def working_directory=(directory)
217
+ @link.WorkingDirectory = directory.tr('/', "\\")
218
+ end
219
+
220
+ # Saves (creates) the link object in the current directory.
221
+ #
222
+ def save
223
+ @link.Save
224
+ end
225
+ end
226
226
  end
@@ -1,25 +1,21 @@
1
1
  require 'rubygems'
2
2
 
3
- spec = Gem::Specification.new do |gem|
4
- gem.name = 'win32-shortcut'
5
- gem.version = '0.2.3'
6
- gem.author = 'Daniel J. Berger'
7
- gem.license = 'Artistic 2.0'
8
- gem.email = 'djberg96@gmail.com'
9
- gem.homepage = 'http://www.rubyforge.org/projects/win32utils'
10
- gem.platform = Gem::Platform::RUBY
11
- gem.summary = 'An interface for creating or modifying Windows shortcuts.'
12
- gem.test_file = 'test/test_shortcut.rb'
13
- gem.has_rdoc = true
14
- gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'win32-shortcut'
5
+ spec.version = '0.2.4'
6
+ spec.author = 'Daniel J. Berger'
7
+ spec.license = 'Artistic 2.0'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://www.rubyforge.org/projects/win32utils'
10
+ spec.summary = 'An interface for creating or modifying Windows shortcuts.'
11
+ spec.test_file = 'test/test_shortcut.rb'
12
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
15
13
 
16
- gem.rubyforge_project = 'win32utils'
17
- gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
14
+ spec.rubyforge_project = 'win32utils'
15
+ spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
18
16
 
19
- gem.description = <<-EOF
20
- The win32-shortcut library provides an interface for creating new
21
- Windows shortcuts or querying information about existing shortcuts.
22
- EOF
17
+ spec.description = <<-EOF
18
+ The win32-shortcut library provides an interface for creating new
19
+ Windows shortcuts or querying information about existing shortcuts.
20
+ EOF
23
21
  end
24
-
25
- Gem::Builder.new(spec).build
metadata CHANGED
@@ -1,29 +1,26 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: win32-shortcut
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.4
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Daniel J. Berger
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2009-08-06 00:00:00 -06:00
13
- default_executable:
12
+ date: 2012-03-18 00:00:00.000000000 Z
14
13
  dependencies: []
15
-
16
- description: " The win32-shortcut library provides an interface for creating new\n Windows shortcuts or querying information about existing shortcuts.\n"
14
+ description: ! " The win32-shortcut library provides an interface for creating
15
+ new\n Windows shortcuts or querying information about existing shortcuts.\n"
17
16
  email: djberg96@gmail.com
18
17
  executables: []
19
-
20
18
  extensions: []
21
-
22
- extra_rdoc_files:
19
+ extra_rdoc_files:
23
20
  - README
24
21
  - CHANGES
25
22
  - MANIFEST
26
- files:
23
+ files:
27
24
  - CHANGES
28
25
  - examples/example_shortcut.rb
29
26
  - lib/win32/shortcut.rb
@@ -32,33 +29,30 @@ files:
32
29
  - README
33
30
  - test/test_shortcut.rb
34
31
  - win32-shortcut.gemspec
35
- has_rdoc: true
36
32
  homepage: http://www.rubyforge.org/projects/win32utils
37
- licenses:
33
+ licenses:
38
34
  - Artistic 2.0
39
35
  post_install_message:
40
36
  rdoc_options: []
41
-
42
- require_paths:
37
+ require_paths:
43
38
  - lib
44
- required_ruby_version: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: "0"
49
- version:
50
- required_rubygems_version: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: "0"
55
- version:
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
56
51
  requirements: []
57
-
58
52
  rubyforge_project: win32utils
59
- rubygems_version: 1.3.4
53
+ rubygems_version: 1.8.11
60
54
  signing_key:
61
55
  specification_version: 3
62
56
  summary: An interface for creating or modifying Windows shortcuts.
63
- test_files:
57
+ test_files:
64
58
  - test/test_shortcut.rb