Class: Resedit::TextConvertCommand

Inherits:
ConvertCommand show all
Defined in:
lib/resedit/app/text_convert.rb

Instance Attribute Summary collapse

Attributes inherited from ConvertCommand

#fname

Attributes inherited from AppCommand

#names, #ohash, #opts, #params, #type

Instance Method Summary collapse

Methods inherited from ConvertCommand

#backup, #getOutName, #job

Methods inherited from AppCommand

#addOption, #addParam, #job, #log, #logd, #loge, #parseParams, #run

Constructor Details

#initialize(fname, cmdname = 'text') ⇒ TextConvertCommand

Returns a new instance of TextConvertCommand.



21
22
23
24
25
26
# File 'lib/resedit/app/text_convert.rb', line 21

def initialize(fname, cmdname='text')
    super(cmdname, fname)
    @text = nil
    addOption('format','f',nil,'output file format')
    addOption('encoding','e',nil,'output file encoding')
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



20
21
22
# File 'lib/resedit/app/text_convert.rb', line 20

def text
  @text
end

Instance Method Details

#expectedLines(file) ⇒ Object



66
# File 'lib/resedit/app/text_convert.rb', line 66

def expectedLines(file); nil end

#export(outname) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/resedit/app/text_convert.rb', line 50

def export(outname)
    @iface = getInterface(@resname, @params)
    logd("exporting text #{@resname} to #{outname}")
    File.open(@resname, "rb"){|file|
        @iface.text = @iface.mktext(file, @params['format'], @params['encoding'])
        @iface.unpack(file) if @iface.text
    }
    raise "Text not unpacked" if !@iface.text
    @iface.text.save(outname)
end

#getInterface(resname, params) ⇒ Object



28
# File 'lib/resedit/app/text_convert.rb', line 28

def getInterface(resname, params); self end

#import(inname) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/resedit/app/text_convert.rb', line 30

def import(inname)
    @iface = getInterface(@resname, @params)
    logd("importing text #{inname} to #{@resname}")
    back = backup()
    File.open(back,"rb"){|file|
        @iface.text = @iface.mktext(file, @params['format'], @params['encoding'])
        @iface.text.load(inname, @iface.expectedLines())
        StringIO.open("","w+b"){|stream|
            @iface.pack(file, stream)
            if stream.length>0
                stream.seek(0)
                File.open(@resname,"wb"){|out|
                    out.write(stream.read())
                }
            end
        }
    }
end

#mktext(file, format, encoding) ⇒ Object



62
63
64
# File 'lib/resedit/app/text_convert.rb', line 62

def mktext(file, format, encoding)
    return Resedit::Text.new(format, encoding)
end

#pack(file, outstream) ⇒ Object



68
69
70
# File 'lib/resedit/app/text_convert.rb', line 68

def pack(file, outstream)
    raise "Not implemented."
end

#unpack(file) ⇒ Object



72
73
74
# File 'lib/resedit/app/text_convert.rb', line 72

def unpack(file)
    raise "Not implemented."
end