|
23 | 23 | image = builder.get_object("image1") |
24 | 24 | aboutdialog = builder.get_object('aboutdialog1') |
25 | 25 |
|
| 26 | +def reset_view(msg): |
| 27 | + global opk_path |
| 28 | + opk_path = "" |
| 29 | + textbuffer.set_text(msg) |
| 30 | + |
26 | 31 | # 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) |
28 | 50 |
|
29 | 51 | def load_opk(path): |
| 52 | + global opk_path |
| 53 | + opk_path = path |
30 | 54 | filename = path |
31 | 55 | opk = SquashFsImage(path) |
32 | 56 | image.clear() |
@@ -144,18 +168,30 @@ def onDestroy(self, *args): |
144 | 168 | Gtk.main_quit() |
145 | 169 |
|
146 | 170 | def onOpen(self, *args): |
147 | | - dialog = Gtk.FileChooserDialog("Please choose a file", window, |
| 171 | + dialog = Gtk.FileChooserDialog("Select an OPK file", window, |
148 | 172 | Gtk.FileChooserAction.OPEN, |
149 | 173 | (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, |
150 | 174 | Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) |
151 | 175 | response = dialog.run() |
152 | 176 | if response == Gtk.ResponseType.OK: |
153 | 177 | filepath = dialog.get_filename() |
154 | | - load_opk(filepath) |
| 178 | + try: |
| 179 | + load_opk(filepath) |
| 180 | + except: |
| 181 | + reset_view("OPK loading failed.") |
155 | 182 | dialog.destroy() |
156 | 183 |
|
157 | 184 | 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() |
159 | 195 |
|
160 | 196 | def onAbout(self, *args): |
161 | 197 | aboutdialog.show() |
|
0 commit comments