forked from LagoLunatic/DSVEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
armips_patcher_dialog.rb
54 lines (42 loc) · 1.48 KB
/
armips_patcher_dialog.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require_relative 'ui_armips_patcher'
class ArmipsPatcherDialog < Qt::Dialog
slots "browse_for_patch_path()"
slots "apply_patch()"
def initialize(main_window, game)
super(main_window, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
@ui = Ui_ArmipsPatcher.new
@ui.setup_ui(self)
@game = game
connect(@ui.patch_path_browse_button, SIGNAL("clicked()"), self, SLOT("browse_for_patch_path()"))
connect(@ui.apply_patch_button, SIGNAL("clicked()"), self, SLOT("apply_patch()"))
self.show()
end
def browse_for_patch_path
default_folder = "./asm"
filename_prefix = @game.armips_patch_filename_prefix()
filter = "Assembly Files (#{filename_prefix}_*.asm);;All Files (*)"
patch_path = Qt::FileDialog.getOpenFileName(self, "Select ARMIPS patch location", default_folder, filter)
return if patch_path.nil?
@ui.patch_path.text = patch_path
end
def apply_patch
patch_path = @ui.patch_path.text
if !File.file?(patch_path)
Qt::MessageBox.warning(self,
"No patch specified",
"No ARMIPS patch specified."
)
return
end
@game.apply_armips_patch(patch_path, full_path: true)
Qt::MessageBox.warning(self,
"Patch applied",
"Successfully applied the ARMIPS patch."
)
rescue StandardError => e
Qt::MessageBox.warning(self,
"Failed to apply patch",
"Failed to apply patch with error:\n#{e.message}\n\n#{e.backtrace.join("\n")}"
)
end
end