Skip to content

Commit

Permalink
Fix savedata (un)mounting
Browse files Browse the repository at this point in the history
  • Loading branch information
AileenLumina committed May 15, 2018
1 parent fe29ec8 commit 4b8d31b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 4 additions & 1 deletion _nx.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import nx


def account_initialize():
"""Initializes the account service."""
pass
Expand All @@ -17,7 +20,7 @@ def fs_mount_savedata(name: str, title_id: int, user_id: int):
user_id: int
The user ID of the user whose savedata filesystem to mount.
"""
pass
nx.filesystem.SAVEDATA_BASE_PATH = '../save/'


def fsdev_unmount_device(mountpoint: str):
Expand Down
6 changes: 4 additions & 2 deletions nx/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def unmount(self):

def __enter__(self):
self.mount()
return self

def __exit__(self):
def __exit__(self, exc_type, exc_val, exc_tb):
self.commit()
self.unmount()

Expand Down Expand Up @@ -111,7 +112,7 @@ def unmount(self):
"""Unmounts the mounted RomFS."""
_nx.fsdev_unmount_device('romfs')

def __exit__(self):
def __exit__(self, exc_type, exc_val, exc_tb):
self.unmount()


Expand Down Expand Up @@ -150,6 +151,7 @@ def mount(self):

def commit(self):
"""Commits the savedata filesystem."""
print(_nx.__dict__)
_nx.fsdev_commit_device('save')

def unmount(self):
Expand Down
7 changes: 2 additions & 5 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@


def main():
nx.filesystem.SAVEDATA_BASE_PATH = '../save/'
nx.filesystem.ROMFS_BASE_PATH = '../romfs/'

botw = nx.titles[BOTW_TITLE_ID] # get botw Title object

try:
with botw.savedata as savedata: # mount BotW savedata partition
with savedata.open(SAVEGAME_PATH) as savegame_file: # open save game file
with open(OUTPUT_PATH, 'w') as destination_file: # open destination file on SD card
with savedata.open(SAVEGAME_PATH, 'rb') as savegame_file: # open save game file
with open(OUTPUT_PATH, 'wb') as destination_file: # open destination file on SD card
shutil.copyfileobj(savegame_file, destination_file) # copy file from savedata to SD card
except FileNotFoundError:
print("No such file:", SAVEGAME_PATH)
Expand Down

0 comments on commit 4b8d31b

Please sign in to comment.