Class: Win32::MC

Inherits:
Object
  • Object
show all
Defined in:
lib/win32/mc.rb

Overview

The MC class encapsulates the mc (eventlog message compiler) commands.

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =

The version of the win32-mc library.

'0.1.6'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mc_file, res_file = nil, dll_file = nil) ⇒ MC

Accepts three file names as arguments and returns an MC object. The mc_file is the name of the .mc file to be used to ultimately generate the .dll file.

If res_file or dll_file are not specified, then the basename of mc_file is used to generate their names, with .res and .dll extensions, respectively.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/win32/mc.rb', line 30

def initialize(mc_file, res_file=nil, dll_file=nil)
  @mc_file = mc_file

  if res_file
    @res_file = res_file
  else
    @res_file = File.basename(mc_file, '.mc') + '.res'
  end

  if dll_file
    @dll_file = dll_file
  else
    @dll_file = File.basename(mc_file, '.mc') + '.dll'
  end
end

Instance Attribute Details

#dll_fileObject

The name of the dll file generated by the link command.



20
21
22
# File 'lib/win32/mc.rb', line 20

def dll_file
  @dll_file
end

#mc_fileObject

The name of the message category file initially processed.



14
15
16
# File 'lib/win32/mc.rb', line 14

def mc_file
  @mc_file
end

#res_fileObject

The name of the resource file generated by the mc command.



17
18
19
# File 'lib/win32/mc.rb', line 17

def res_file
  @res_file
end

Instance Method Details

#cleanObject

Delete .h, .rc and .res files created from the corresponding .mc file (but not the .dll file). This also deletes all MSG*.bin files in the current directory.



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/win32/mc.rb', line 90

def clean
  base = File.basename(@mc_file, '.mc')

  %w[.h .rc .res].each do |ext|
    file = base + ext
    File.delete(file) if File.exist?(file)
  end

  Dir["MSG*.bin"].each do |binfile|
    File.delete(binfile)
  end
end

#create_allObject

A shortcut for MC#create_header + MC#create_res_file + MC#create_dll_file.



80
81
82
83
84
# File 'lib/win32/mc.rb', line 80

def create_all
  create_header
  create_res_file
  create_dll_file
end

#create_dll_fileObject

Creates the .dll file from the .res file generated by the MC#create_res_file method. Raises an MC::Error if the .res file is not found.



70
71
72
73
74
75
# File 'lib/win32/mc.rb', line 70

def create_dll_file
  unless File.exist?(@res_file)
    raise MC::Error, "No .res file found: #{@res_file}"
  end
  system("link -dll -noentry -out:#{@dll_file} #{@res_file}")
end

#create_headerObject

Uses the message compiler (mc) program to generate the .h and .rc files based on the .mc (message category) file. This method must be called before MC#create_res_file or MC#create_dll_file.



50
51
52
# File 'lib/win32/mc.rb', line 50

def create_header
  system("mc #{@mc_file}")
end

#create_res_fileObject

Creates the .res (resource) file from the .rc file generated by the MC#create_header method. Raises an MC::Error if the .rc file is not found.



58
59
60
61
62
63
64
# File 'lib/win32/mc.rb', line 58

def create_res_file
  rc_file = File.basename(@mc_file, '.mc') + '.rc'
  unless File.exist?(rc_file)
    raise MC::Error, "No .rc file found: #{@rc_file}"
  end
  system("rc -r -fo #{@res_file} #{rc_file}")
end