Module: WindowsGUI::UIRibbon::UIResources

Defined in:
lib/windows_gui/uiribbon.rb

Class Method Summary collapse

Class Method Details

.Build(opts = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/windows_gui/uiribbon.rb', line 34

def Build(opts = {})
	opts[:name] ||= File.basename($0, '.rbw')

	path = File.dirname(File.expand_path($0))

	xml_path = "#{path}/#{opts[:name]}.xml"
	rb_path = "#{path}/#{opts[:name]}.rb"
	dll_path = "#{path}/#{opts[:name]}.dll"
	log_path = "#{path}/#{opts[:name]}.log"

	opts[:sdkroot] ||= "#{ENV['ProgramFiles']}/Windows Kits/10"
	opts[:vcroot] ||= "#{ENV['ProgramFiles']}/Microsoft Visual Studio 14.0/VC"

	opts[:uicc] ||= "#{opts[:sdkroot]}/bin/x86/uicc.exe"
	opts[:rc] ||= "#{opts[:sdkroot]}/bin/x86/rc.exe"
	opts[:vcvars] ||= "#{opts[:vcroot]}/bin/vcvars32.bat"
	opts[:link] ||= "#{opts[:vcroot]}/bin/link.exe"

	raise 'Building the UIRibbon resources requires Windows SDK and VC' unless
		[:uicc, :rc, :vcvars, :link].all? { |tool| File.exist?(opts[tool]) }

	STDERR.puts "UIRibbon resources build toolchain OK"

	File.delete(log_path) if File.exist?(log_path)

	system <<-CMD
@echo off && \
"#{opts[:uicc]}" "#{opts[:name]}.xml" "#{opts[:name]}.bml" /header:"#{opts[:name]}.h" /res:"#{opts[:name]}.rc" > "#{opts[:name]}.log" && \
"#{opts[:rc]}" /nologo /fo"#{ENV['TEMP']}/#{opts[:name]}.res" "#{opts[:name]}.rc" >> "#{opts[:name]}.log" && \
call "#{opts[:vcvars]}" >> "#{opts[:name]}.log" && \
"#{opts[:link]}" /nologo /machine:x86 /dll /noentry /out:"#{opts[:name]}.dll" "#{ENV['TEMP']}/#{opts[:name]}.res" >> "#{opts[:name]}.log"
	CMD

	if File.read(log_path) =~ /error/im
		ShellExecute(nil, L('open'), L(log_path.dup), nil, nil, SW_SHOWNORMAL) if
			opts[:open_log_if_failed]

		raise "UIRibbon resources build FAILED - see #{log_path} for details"
	end

	File.open(rb_path, 'w') { |rb|
		rb.puts "# Generated by the UIRibbon build, do NOT modify\n\n"

		File.foreach("#{path}/#{opts[:name]}.h") { |line|
			rb.puts "#{$1[0].upcase}#{$1[1..-1]} = #{$2}" if line =~ /^\s*#define\s+(\w+)\s+(\d+)/
		}
	}

	%w{bml h rc}.each { |ext|
		File.delete("#{path}/#{opts[:name]}.#{ext}") if File.exist?("#{path}/#{opts[:name]}.#{ext}")
	} if opts[:clean_byproducts]

	STDERR.puts "UIRibbon resources build succeeded"
end

.BuildNeeded?(opts = {}) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/windows_gui/uiribbon.rb', line 16

def BuildNeeded?(opts = {})
	opts[:name] ||= File.basename($0, '.rbw')

	path = File.dirname(File.expand_path($0))

	dll_path = "#{path}/#{opts[:name]}.dll"
	xml_path = "#{path}/#{opts[:name]}.xml"

	yeah = !File.exist?(dll_path) || (
		File.exist?(xml_path) &&
		test(?M, xml_path) > test(?M, dll_path)
	)

	STDERR.puts "UIRibbon resources build needed" if yeah

	yeah
end

.Load(opts = {}) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/windows_gui/uiribbon.rb', line 89

def Load(opts = {})
	opts[:name] ||= File.basename($0, '.rbw')

	path = File.dirname(File.expand_path($0))

	dll_path = "#{path}/#{opts[:name]}.dll"

	# pull in generated UIRibbon constants
	require "#{path}/#{opts[:name]}"

	# load UIRibbon dll
	hdll = DetonateLastError(FFI::Pointer::NULL, :LoadLibrary,
		L(dll_path.dup)
	)

	STDERR.puts "#{dll_path} loaded (hdll: #{hdll})" if $DEBUG

	at_exit {
		FreeLibrary(hdll)

		STDERR.puts "#{dll_path} unloaded" if $DEBUG
	}

	hdll
end