Skip to content

Commit b5830ee

Browse files
committed
OPK extracting
1 parent 0127496 commit b5830ee

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ A simple tool for viewing OpenDingux and RetroFW packages. It supports opening O
77
- image viewer navigation in case of multiple images in the root directory
88
- windows port
99
- maybe C++ port
10-
- extract OPK

opkview.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,34 @@
2323
image = builder.get_object("image1")
2424
aboutdialog = builder.get_object('aboutdialog1')
2525

26+
def reset_view(msg):
27+
global opk_path
28+
opk_path = ""
29+
textbuffer.set_text(msg)
30+
2631
# initialization
27-
textbuffer.set_text("to be loaded")
32+
reset_view("Load an OPK file to see its description.")
33+
34+
def extract_node(node, destpath):
35+
if node.isFolder():
36+
if node.getName() == "":
37+
dirpath = destpath
38+
else:
39+
dirpath = destpath + "/" + node.getName().decode("utf-8")
40+
os.mkdir(dirpath)
41+
for c in node.children:
42+
extract_node(c, dirpath)
43+
else:
44+
with open(destpath + "/" + node.getName().decode("utf-8"), "wb") as f:
45+
f.write(node.getContent())
46+
47+
def extract_opk(path, dest):
48+
opk = SquashFsImage(path)
49+
extract_node(opk.getRoot(), dest)
2850

2951
def load_opk(path):
52+
global opk_path
53+
opk_path = path
3054
filename = path
3155
opk = SquashFsImage(path)
3256
image.clear()
@@ -144,18 +168,30 @@ def onDestroy(self, *args):
144168
Gtk.main_quit()
145169

146170
def onOpen(self, *args):
147-
dialog = Gtk.FileChooserDialog("Please choose a file", window,
171+
dialog = Gtk.FileChooserDialog("Select an OPK file", window,
148172
Gtk.FileChooserAction.OPEN,
149173
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
150174
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
151175
response = dialog.run()
152176
if response == Gtk.ResponseType.OK:
153177
filepath = dialog.get_filename()
154-
load_opk(filepath)
178+
try:
179+
load_opk(filepath)
180+
except:
181+
reset_view("OPK loading failed.")
155182
dialog.destroy()
156183

157184
def onExtract(self, *args):
158-
print("Extract clicked")
185+
dialog = Gtk.FileChooserDialog("Select a destination folder", window,
186+
Gtk.FileChooserAction.SELECT_FOLDER,
187+
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
188+
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
189+
response = dialog.run()
190+
if response == Gtk.ResponseType.OK:
191+
filepath = dialog.get_filename()
192+
if opk_path != "":
193+
extract_opk(opk_path, filepath)
194+
dialog.destroy()
159195

160196
def onAbout(self, *args):
161197
aboutdialog.show()

0 commit comments

Comments
 (0)