diff --git a/src/m64py/core/core.py b/src/m64py/core/core.py
index fe92ca5..0a7ea3d 100644
--- a/src/m64py/core/core.py
+++ b/src/m64py/core/core.py
@@ -411,19 +411,21 @@ class Core:
log.warn(self.error_message(rval))
return value_ptr.contents.value
- def state_load(self):
+ def state_load(self, state_path=None):
"""Loads a saved state file from the current slot."""
+ path = C.c_char_p(state_path) if state_path else None
rval = self.m64p.CoreDoCommand(
- M64CMD_STATE_LOAD, C.c_int(1), None)
+ M64CMD_STATE_LOAD, C.c_int(1), path)
if rval != M64ERR_SUCCESS:
log.debug("state_load()")
log.warn(self.error_message(rval))
return rval
- def state_save(self):
+ def state_save(self, state_path=None, state_type=1):
"""Saves a state file to the current slot."""
+ path = C.c_char_p(state_path) if state_path else None
rval = self.m64p.CoreDoCommand(
- M64CMD_STATE_SAVE, C.c_int(1), None)
+ M64CMD_STATE_SAVE, C.c_int(state_type), path)
if rval != M64ERR_SUCCESS:
log.debug("state_save()")
log.warn(self.error_message(rval))
diff --git a/src/m64py/core/defs.py b/src/m64py/core/defs.py
index 5cfaa55..6048280 100644
--- a/src/m64py/core/defs.py
+++ b/src/m64py/core/defs.py
@@ -149,6 +149,16 @@ PLUGIN_DEFAULT = {
M64PLUGIN_INPUT: "mupen64plus-input-sdl%s" % DLL_EXT
}
+M64SAV_M64P = 1
+M64SAV_PJ64C = 2
+M64SAV_PJ64 = 3
+
+M64P_SAVES = {
+ M64SAV_M64P: ("M64P (*.mp)", "mp"),
+ M64SAV_PJ64C: ("PJ64 compressed (*.zip)", "zip"),
+ M64SAV_PJ64: ("PJ64 (*.pj)", "pj")
+ }
+
m64p_error = C.c_int
m64p_GLattr = C.c_int
diff --git a/src/m64py/frontend/mainwindow.py b/src/m64py/frontend/mainwindow.py
index f67bb2e..002490a 100644
--- a/src/m64py/frontend/mainwindow.py
+++ b/src/m64py/frontend/mainwindow.py
@@ -268,6 +268,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.menuStateSlot.setEnabled(load)
self.actionLoadState.setEnabled(action)
self.actionSaveState.setEnabled(action)
+ self.actionLoadFrom.setEnabled(action)
+ self.actionSaveAs.setEnabled(action)
self.actionSaveScreenshot.setEnabled(action)
self.actionShowROMInfo.setEnabled(action)
self.actionMute.setEnabled(action)
@@ -336,6 +338,36 @@ class MainWindow(QMainWindow, Ui_MainWindow):
"""Saves state."""
self.worker.state_save()
+ @pyqtSignature("")
+ def on_actionLoadFrom_triggered(self):
+ """Loads state from file."""
+ dialog = QFileDialog()
+ dialog.setFileMode(QFileDialog.ExistingFile)
+ file_path = dialog.getOpenFileName(
+ self, "Load State From File",
+ os.path.join(self.worker.m64p.config.get_path("UserData"), "save"),
+ "M64P/PJ64 Saves (*.st* *.zip *.pj);;All files (*)")
+ if file_path:
+ self.worker.state_load(file_path)
+
+ @pyqtSignature("")
+ def on_actionSaveAs_triggered(self):
+ """Saves state to file."""
+ dialog = QFileDialog()
+ file_path, file_filter = dialog.getSaveFileNameAndFilter(
+ self, "Save State To File",
+ os.path.join(self.worker.m64p.config.get_path("UserData"), "save"),
+ ";;".join([save_filter for save_filter, save_ext in M64P_SAVES.values()]),
+ M64P_SAVES[M64SAV_M64P][0])
+ if file_path:
+ for save_type, filters in M64P_SAVES.items():
+ save_filter, save_ext = filters
+ if file_filter == save_filter:
+ if not file_path.endswith(save_ext):
+ file_path = "%s.%s" % (file_path, save_ext)
+ self.worker.state_save(file_path, save_type)
+
+
@pyqtSignature("")
def on_actionSaveScreenshot_triggered(self):
"""Saves screenshot."""
diff --git a/src/m64py/frontend/worker.py b/src/m64py/frontend/worker.py
index f9d66db..102ac3b 100644
--- a/src/m64py/frontend/worker.py
+++ b/src/m64py/frontend/worker.py
@@ -199,13 +199,13 @@ class Worker(QThread):
self.parent.emit(SIGNAL(
"save_image(PyQt_PyObject)"), False)
- def state_load(self):
+ def state_load(self, state_path=None):
"""Loads state."""
- self.m64p.state_load()
+ self.m64p.state_load(state_path)
- def state_save(self):
+ def state_save(self, state_path=None, state_type=1):
"""Saves state."""
- self.m64p.state_save()
+ self.m64p.state_save(state_path, state_type)
def state_set_slot(self, slot):
"""Sets save slot."""
diff --git a/src/m64py/ui/mainwindow.ui b/src/m64py/ui/mainwindow.ui
index 68459e4..d2b6514 100644
--- a/src/m64py/ui/mainwindow.ui
+++ b/src/m64py/ui/mainwindow.ui
@@ -79,6 +79,9 @@
+
+
+
@@ -549,6 +552,30 @@ QStatusBar { margin:0px; }
+
+
+ false
+
+
+
+ :/icons/action_state_load.png:/icons/action_state_load.png
+
+
+ Load From...
+
+
+
+
+ false
+
+
+
+ :/icons/action_state_save.png:/icons/action_state_save.png
+
+
+ Save As...
+
+
diff --git a/src/m64py/ui/mainwindow_ui.py b/src/m64py/ui/mainwindow_ui.py
index 6872256..cce4d0b 100644
--- a/src/m64py/ui/mainwindow_ui.py
+++ b/src/m64py/ui/mainwindow_ui.py
@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'mainwindow.ui'
#
-# Created: Wed Jun 5 09:01:17 2013
+# Created: Fri Jun 7 14:15:00 2013
# by: PyQt4 UI code generator 4.10.1
#
# WARNING! All changes made in this file will be lost!
@@ -240,6 +240,14 @@ class Ui_MainWindow(object):
self.actionCheats.setObjectName(_fromUtf8("actionCheats"))
self.actionCustom = QtGui.QAction(MainWindow)
self.actionCustom.setObjectName(_fromUtf8("actionCustom"))
+ self.actionLoadFrom = QtGui.QAction(MainWindow)
+ self.actionLoadFrom.setEnabled(False)
+ self.actionLoadFrom.setIcon(icon8)
+ self.actionLoadFrom.setObjectName(_fromUtf8("actionLoadFrom"))
+ self.actionSaveAs = QtGui.QAction(MainWindow)
+ self.actionSaveAs.setEnabled(False)
+ self.actionSaveAs.setIcon(icon9)
+ self.actionSaveAs.setObjectName(_fromUtf8("actionSaveAs"))
self.menuLoad.addAction(self.actionManually)
self.menuLoad.addAction(self.actionFromList)
self.menuFile.addAction(self.menuLoad.menuAction())
@@ -249,6 +257,9 @@ class Ui_MainWindow(object):
self.menuFile.addAction(self.actionSaveState)
self.menuFile.addAction(self.menuStateSlot.menuAction())
self.menuFile.addSeparator()
+ self.menuFile.addAction(self.actionLoadFrom)
+ self.menuFile.addAction(self.actionSaveAs)
+ self.menuFile.addSeparator()
self.menuFile.addAction(self.actionSaveScreenshot)
self.menuFile.addSeparator()
self.menuFile.addAction(self.actionShowROMInfo)
@@ -343,6 +354,8 @@ class Ui_MainWindow(object):
self.actionSpeedUp.setShortcut(_translate("MainWindow", "F11", None))
self.actionCheats.setText(_translate("MainWindow", "Cheats...", None))
self.actionCheats.setShortcut(_translate("MainWindow", "F2", None))
+ self.actionLoadFrom.setText(_translate("MainWindow", "Load From...", None))
+ self.actionSaveAs.setText(_translate("MainWindow", "Save As...", None))
import images_rc
import icons_rc