win32/resource.rb
DEFINITIONS
This source file includes following functions.
1 #!./miniruby -sI.
2
3 require 'rbconfig'
4
5 CONFIG = Config::MAKEFILE_CONFIG
6
7 fversion = "#{CONFIG['MAJOR']},#{CONFIG['MINOR']},#{CONFIG['TEENY']},0"
8
9 $ruby_name ||= CONFIG["RUBY_INSTALL_NAME"]
10 $rubyw_name ||= CONFIG["RUBYW_INSTALL_NAME"] || $ruby_name.sub(/ruby/, '\&w')
11 $so_name ||= CONFIG["RUBY_SO_NAME"]
12
13 icons = {}
14 def icons.find(path)
15 if File.directory?(path)
16 Dir.open(File.expand_path(path)) do |d|
17 d.grep(/\.ico$/i) {|i| self[$`] = i}
18 end
19 else
20 self[File.basename(path, '.ico')] = path
21 end
22 self
23 end
24
25 if ARGV.empty?
26 icons.find('.')
27 else
28 ARGV.each {|i| icons.find(i)}
29 end
30
31 ruby_icon = rubyw_icon = nil
32 [$ruby_name, 'ruby'].each do |i|
33 if i = icons.delete(i)
34 ruby_icon = "1 ICON DISCARDABLE "+i.dump+"\n"
35 break
36 end
37 end
38 [$rubyw_name, 'rubyw'].each do |i|
39 if i = icons.delete(i)
40 rubyw_icon = "1 ICON DISCARDABLE "+i.dump+"\n"
41 break
42 end
43 end
44 dll_icons = []
45 icons.keys.sort.each do |i|
46 dll_icons << "#{dll_icons.size + 1} ICON DISCARDABLE "+icons[i].dump+"\n"
47 end
48
49 [ # base name extension file type icons
50 [$ruby_name, CONFIG["EXEEXT"], 'VFT_APP', ruby_icon],
51 [$rubyw_name, CONFIG["EXEEXT"], 'VFT_APP', rubyw_icon],
52 [$so_name, '.dll', 'VFT_DLL', dll_icons],
53 ].each do |base, ext, type, icons|
54 open(base + '.rc', "w") { |f|
55 f.binmode if /mingw/ =~ RUBY_PLATFORM
56
57 f.print <<EOF
58 #ifndef __BORLANDC__
59 #include <windows.h>
60 #endif
61
62 #{icons}
63 VS_VERSION_INFO VERSIONINFO
64 FILEVERSION #{fversion}
65 PRODUCTVERSION #{fversion}
66 FILEFLAGSMASK 0x3fL
67 FILEFLAGS 0x0L
68 FILEOS VOS__WINDOWS32
69 FILETYPE #{type}
70 FILESUBTYPE VFT2_UNKNOWN
71 BEGIN
72 BLOCK "StringFileInfo"
73 BEGIN
74 BLOCK "000004b0"
75 BEGIN
76 VALUE "FileDescription", "Ruby interpreter\\0"
77 VALUE "FileVersion", "#{fversion}\\0"
78 VALUE "Home Page", "http://www.ruby-lang.org/\\0"
79 VALUE "InternalName", "#{base + ext}\\0"
80 VALUE "LegalCopyright", "Copyright (C) 1993-2002 Yukihiro Matsumoto\\0"
81 VALUE "OriginalFilename", "#{base + ext}\\0"
82 VALUE "Platform", "#{RUBY_PLATFORM}\\0"
83 VALUE "ProductVersion", "#{fversion}\\0"
84 VALUE "Release Date", "#{RUBY_RELEASE_DATE}\\0"
85 VALUE "Version", "#{RUBY_VERSION}\\0"
86 END
87 END
88 BLOCK "VarFileInfo"
89 BEGIN
90 VALUE "Translation", 0x0, 0x4b0
91 END
92 END
93 EOF
94 }
95 end
96