module WindowsGUI::UIRibbon::UIResources

Public Class Methods

Build(opts = {}) click to toggle source
# 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[:showLog]

                                        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]

                                STDERR.puts "UIRibbon resources build succeeded"
                        end
BuildNeeded?(opts = {}) click to toggle source
# 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 = {}) click to toggle source
# 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

Private Instance Methods

Build(opts = {}) click to toggle source
# 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[:showLog]

                                        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]

                                STDERR.puts "UIRibbon resources build succeeded"
                        end
BuildNeeded?(opts = {}) click to toggle source
# 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 = {}) click to toggle source
# 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