| 1 |
#! /usr/bin/ruby -Ks |
| 2 |
|
| 3 |
#==============================================================================# |
| 4 |
# $Id: exerb-win32.rb,v 1.10 2003/02/12 07:01:50 yuya Exp $ |
| 5 |
#==============================================================================# |
| 6 |
|
| 7 |
require 'vr/vruby' |
| 8 |
require "vr/vrcontrol" |
| 9 |
require 'vr/vrdialog' |
| 10 |
require 'vr/contrib/vrwincomponent' |
| 11 |
require 'vr/contrib/msgboxconst' |
| 12 |
require 'exerb/exerb' |
| 13 |
require 'win32' |
| 14 |
require 'm17n' |
| 15 |
require 'version' |
| 16 |
|
| 17 |
#==============================================================================# |
| 18 |
|
| 19 |
class MainForm < VRForm |
| 20 |
|
| 21 |
# including modules. |
| 22 |
include VRMenuUseable |
| 23 |
|
| 24 |
SELF_PATH = (defined?(Exerb) && Exerb.methods.include?("runtime?") ? Exerb.filepath : $0) |
| 25 |
BASE_DIR = File.dirname(SELF_PATH.gsub(/\\/, '/')) |
| 26 |
|
| 27 |
def construct |
| 28 |
# initializeing properties. |
| 29 |
self.caption = "Exerb for Windows" |
| 30 |
self.sizebox = false |
| 31 |
self.maximizebox = false |
| 32 |
|
| 33 |
# centering the window. |
| 34 |
w, h = 450, 190 |
| 35 |
self.move(@screen.w / 2 - w / 2, @screen.h / 2 - h / 2, w, h) |
| 36 |
|
| 37 |
# loading icon resouce. and setting window class icon. |
| 38 |
if defined?(Exerb) && Exerb.methods.include?("runtime?") |
| 39 |
Win32::SetClassLongA.call(self.hWnd, Win32::GCL_HICON, Exerb.loadicon(102)) |
| 40 |
end |
| 41 |
|
| 42 |
# creating menu items. |
| 43 |
menu = newMenu.set( |
| 44 |
[ |
| 45 |
[ |
| 46 |
:menu_file._, |
| 47 |
[ |
| 48 |
[:menu_file_exit._, "menu_file_exit"], |
| 49 |
] |
| 50 |
], |
| 51 |
[ |
| 52 |
:menu_help._, |
| 53 |
[ |
| 54 |
[:menu_help_about._, "menu_help_about"], |
| 55 |
] |
| 56 |
], |
| 57 |
] |
| 58 |
) |
| 59 |
self.setMenu(menu) |
| 60 |
|
| 61 |
# creating controls. |
| 62 |
ctrls = [] |
| 63 |
ctrls << self.addControl(VRStatic, "lab_core", :lab_corefile._, 10, 10, 90, 20) |
| 64 |
ctrls << self.addControl(VRCombobox, "cmb_core", "", 100, 10, 180, 120) |
| 65 |
ctrls << self.addControl(VRStatic, "lab_rbcfile", :lab_rbcfile._, 10, 35, 90, 20) |
| 66 |
ctrls << self.addControl(VREdit, "txt_rbcfile", "", 100, 35, 310, 20) |
| 67 |
ctrls << self.addControl(VRButton, "btn_rbcfile", "...", 410, 35, 20, 20) |
| 68 |
ctrls << self.addControl(VRStatic, "lab_exefile", :lab_exefile._, 10, 60, 90, 20) |
| 69 |
ctrls << self.addControl(VREdit, "txt_exefile", "", 100, 60, 310, 20) |
| 70 |
ctrls << self.addControl(VRButton, "btn_exefile", "...", 410, 60, 20, 20) |
| 71 |
ctrls << self.addControl(VRStatic, "lab_options", :lab_option._, 10, 85, 90, 20) |
| 72 |
ctrls << self.addControl(VRCheckbox, "chk_compress", :lab_compress._, 100, 85, 180, 20) |
| 73 |
|
| 74 |
ctrls << self.addControl(VRStatic, "lab_status", "", 10, 120, 260, 20, WStyle::SS_SUNKEN | WStyle::SS_CENTERIMAGE) |
| 75 |
ctrls << self.addControl(VRButton, "btn_create", :btn_build._, 290, 120, 140, 20) |
| 76 |
|
| 77 |
ctrls << self.addControl(VRStatic, "line1", "", 0, 0, 450, 0, WStyle::SS_ETCHEDHORZ) |
| 78 |
ctrls << self.addControl(VRStatic, "line2", "", 0, 110, 450, 0, WStyle::SS_ETCHEDHORZ) |
| 79 |
|
| 80 |
# setting font to controls. |
| 81 |
font = @screen.factory.newfont("Terminal", 14) |
| 82 |
ctrls.each { |ctrl| ctrl.setFont(font) } |
| 83 |
end |
| 84 |
|
| 85 |
def self_created |
| 86 |
# finding core files. and add to the combobox. |
| 87 |
Dir.glob(File.join(BASE_DIR, "*.rbx")) { |filename| |
| 88 |
@cmb_core.addString(File.basename(filename)) |
| 89 |
} |
| 90 |
@cmb_core.select(0) |
| 91 |
end |
| 92 |
|
| 93 |
def menu_file_exit_clicked |
| 94 |
self.close |
| 95 |
end |
| 96 |
|
| 97 |
def menu_help_about_clicked |
| 98 |
VRLocalScreen.openModalDialog(self, nil, AboutDialog) |
| 99 |
end |
| 100 |
|
| 101 |
def btn_rbcfile_clicked |
| 102 |
filename = SWin::CommonDialog.openFilename(self, [[:filter_rbc._, "*.rbc"],[:filter_all._, "*.*"]], WConst::OFN_HIDEREADONLY | WConst::OFN_FILEMUSTEXIST, nil, ".rbc") |
| 103 |
if filename |
| 104 |
@txt_rbcfile.text = filename |
| 105 |
@txt_exefile.text = filename.sub(/(\.rbc$|$)/, '.exe') |
| 106 |
end |
| 107 |
end |
| 108 |
|
| 109 |
def btn_exefile_clicked |
| 110 |
filename = SWin::CommonDialog.saveFilename(self, [[:filter_exe._, "*.exe"],[:filter_all._, "*.*"]], WConst::OFN_OVERWRITEPROMPT | WConst::OFN_PATHMUSTEXIST, nil, ".exe") |
| 111 |
if filename |
| 112 |
@txt_exefile.text = filename |
| 113 |
end |
| 114 |
end |
| 115 |
|
| 116 |
def btn_create_clicked |
| 117 |
@btn_create.enabled = false |
| 118 |
@lab_status.caption = :state_preparing._ |
| 119 |
|
| 120 |
if @cmb_core.selectedIndex == -1 || @cmb_core.getTextOf(@cmb_core.selectedIndex).empty? |
| 121 |
msgbox_err(:msg_core_empty._) |
| 122 |
@cmb_core.focus |
| 123 |
return |
| 124 |
end |
| 125 |
|
| 126 |
corefile = @cmb_core.getTextOf(@cmb_core.selectedIndex) |
| 127 |
rbcfile = @txt_rbcfile.text |
| 128 |
exefile = @txt_exefile.text |
| 129 |
compress = @chk_compress.checked? |
| 130 |
|
| 131 |
if rbcfile.empty? |
| 132 |
msgbox_err(:msg_rbc_empty._) |
| 133 |
@txt_rbcfile.focus |
| 134 |
return |
| 135 |
end |
| 136 |
|
| 137 |
if exefile.empty? |
| 138 |
msgbox_err(:msg_exe_empty._) |
| 139 |
@txt_exefile.focus |
| 140 |
return |
| 141 |
end |
| 142 |
|
| 143 |
corepath = File.join(BASE_DIR, corefile) |
| 144 |
|
| 145 |
begin |
| 146 |
@lab_status.caption = :state_read_rbc._; rbc = Exerb::RecipeFile.new(rbcfile) |
| 147 |
@lab_status.caption = :state_read_arc._; arc = rbc.archive |
| 148 |
@lab_status.caption = :state_build_arc._; arcbin = Exerb::Binary::Archive.new(arc.pack, compress) |
| 149 |
@lab_status.caption = :state_read_core._; corebin = Exerb::Binary::Core.new_from_file(corepath) |
| 150 |
@lab_status.caption = :state_build_exe._; exebin = Exerb::Binary::Executable.new(arcbin, corebin) |
| 151 |
@lab_status.caption = :state_verify_exe._; exebin.selfcheck |
| 152 |
|
| 153 |
if File.exist?(exefile) |
| 154 |
if msgbox(format(:msg_overwrite._, exefile), WConst::MB_ICONQUESTION | WConst::MB_YESNO) == 7 |
| 155 |
return |
| 156 |
end |
| 157 |
end |
| 158 |
|
| 159 |
@lab_status.caption = :state_write_exe._ |
| 160 |
File.open(exefile, 'wb') { |file| |
| 161 |
exebin.output(file) |
| 162 |
} |
| 163 |
|
| 164 |
msg = format(:msg_created._, exefile, corefile, rbcfile, exefile, File.size(exefile).to_s, (compress ? :str_enable._ : :str_disable._)) |
| 165 |
msgbox_info(msg) |
| 166 |
rescue ScriptError, StandardError => e |
| 167 |
msgbox_err(format(:msg_failed._, exefile, e.class.name, e.message)) |
| 168 |
end |
| 169 |
ensure |
| 170 |
@btn_create.enabled = true |
| 171 |
@lab_status.caption = "" |
| 172 |
end |
| 173 |
|
| 174 |
def msgbox(message, flag) |
| 175 |
messageBox(message, "Exerb", flag) |
| 176 |
end |
| 177 |
|
| 178 |
def msgbox_err(message) |
| 179 |
msgbox(message, WConst::MB_ICONERROR) |
| 180 |
end |
| 181 |
|
| 182 |
def msgbox_info(message) |
| 183 |
msgbox(message, WConst::MB_ICONINFORMATION) |
| 184 |
end |
| 185 |
|
| 186 |
end |
| 187 |
|
| 188 |
#==============================================================================# |
| 189 |
|
| 190 |
class AboutDialog < VRModalDialog |
| 191 |
|
| 192 |
def construct |
| 193 |
self.caption = :title_about._ |
| 194 |
|
| 195 |
w, h = 405, 125 |
| 196 |
self.move(@screen.w / 2 - w / 2, @screen.h / 2 - h / 2, w, h) |
| 197 |
|
| 198 |
ctrls = [] |
| 199 |
ctrls << self.addControl(VRStatic, "rect", "", 10, 10, 380, 80, WStyle::SS_SUNKEN) |
| 200 |
ctrls << self.addControl(VRStatic, "lab1", "Exerb for Windows", 20, 20, 365, 20) |
| 201 |
ctrls << self.addControl(VRStatic, "lab2", "Version #{Exerb32::VERSION}", 30, 40, 355, 20) |
| 202 |
ctrls << self.addControl(VRStatic, "lab3", Exerb32::COPYRIGHT, 30, 60, 355, 20) |
| 203 |
|
| 204 |
font = @screen.factory.newfont("Terminal", 14) |
| 205 |
ctrls.each { |ctrl| ctrl.setFont(font) } |
| 206 |
end |
| 207 |
|
| 208 |
end |
| 209 |
|
| 210 |
#==============================================================================# |
| 211 |
|
| 212 |
VRLocalScreen.showForm(MainForm) |
| 213 |
VRLocalScreen.messageloop |
| 214 |
|
| 215 |
#==============================================================================# |
| 216 |
#==============================================================================# |