diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2014-07-17 16:59:12 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2014-07-17 16:59:12 (GMT) |
commit | ebc553b55581cbf8fb9086a635a746c946dceee0 (patch) | |
tree | f0a7ebd3383c14e30deb2ab1cdb3f52d11594c68 | |
parent | 845bbb495eebf064e3eaa63f992423585b3e258e (diff) |
Solve the problems saving games with images or sounds
Moved the logic to copy the files to the temporary directories
to tthe model. This change allow saving images or sounds in
games based on art4apps possible.
-rw-r--r-- | activity.py | 10 | ||||
-rw-r--r-- | cardlist.py | 19 | ||||
-rw-r--r-- | model.py | 41 |
3 files changed, 47 insertions, 23 deletions
diff --git a/activity.py b/activity.py index 5362015..7aa2f13 100644 --- a/activity.py +++ b/activity.py @@ -296,14 +296,16 @@ class MemorizeActivity(Activity): # asnd asnd = self.game.model.pairs[pair].get_property('asnd') if asnd is not None: - game_zip.write(os.path.join(temp_snd_folder, asnd), - os.path.join('sounds', asnd)) + if os.path.exists(os.path.join(temp_snd_folder, asnd)): + game_zip.write(os.path.join(temp_snd_folder, asnd), + os.path.join('sounds', asnd)) # bsnd bsnd = self.game.model.pairs[pair].get_property('bsnd') if bsnd is not None: - game_zip.write(os.path.join(temp_snd_folder, bsnd), - os.path.join('sounds', bsnd)) + if os.path.exists(os.path.join(temp_snd_folder, bsnd)): + game_zip.write(os.path.join(temp_snd_folder, bsnd), + os.path.join('sounds', bsnd)) self.game.model.game_path = self.game.model.temp_folder self.game.model.data['name'] = str(self.get_title()) diff --git a/cardlist.py b/cardlist.py index 96ba5c7..4d0f347 100644 --- a/cardlist.py +++ b/cardlist.py @@ -14,8 +14,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -import os -import shutil from gi.repository import Gtk from gi.repository import Gdk @@ -118,8 +116,6 @@ class CardList(Gtk.EventBox): def update_model(self, game_model): game_model.pairs = {} - game_model.create_temp_directories() - temp_img_folder = game_model.data['pathimg'] for pair in range(len(self.pairs)): pair_card = Pair() @@ -146,26 +142,11 @@ class CardList(Gtk.EventBox): if aimg is not None: aimgfile = self.pairs[pair].get_image_path(1) pair_card.set_property('aimg', basename(aimgfile)) - if not os.path.exists(aimgfile): - destination_path = join(temp_img_folder, - basename(aimgfile)) - if not os.path.exists(destination_path): - GObject.idle_add(shutil.copyfile, aimgfile, - destination_path) - logging.error('copy img to %s', destination_path) # bimg bimg = self.pairs[pair].get_image_path(2) if bimg is not None: bimgfile = self.pairs[pair].get_image_path(2) pair_card.set_property('bimg', basename(bimgfile)) - if not os.path.exists(bimgfile): - destination_path = join(temp_img_folder, - basename(bimgfile)) - if not os.path.exists(destination_path): - GObject.idle_add(shutil.copyfile, bimgfile, - destination_path) - logging.error('copy img to %s', destination_path) - # asnd asnd = self.pairs[pair].get_sound(1) logging.debug('update_model asnd %s', asnd) @@ -16,6 +16,7 @@ # import os +import shutil from xml.etree.ElementTree import Element, SubElement, tostring, parse from os import environ, makedirs, chmod from os.path import join, basename, isdir, split, normpath, exists @@ -435,8 +436,48 @@ class Model(object): self.grid = grid def create_temp_directories(self): + logging.error('creating temp directories model: %s', self.data) temp_img_folder = join(self.temp_folder, 'images') temp_snd_folder = join(self.temp_folder, 'sounds') + + if 'origin' in self.data and self.data['origin'] == 'art4apps': + + if not self.modified: + # if was not modified, don't change the temp directtories + return + else: + # we need copy the files used in the game to the new path + if not exists(temp_img_folder): + makedirs(temp_img_folder) + if not exists(temp_snd_folder): + makedirs(temp_snd_folder) + for key in self.pairs.keys(): + # all the images exist, but not all the sounds + for img in (self.pairs[key].props.aimg, + self.pairs[key].props.bimg): + if img is not None: + origin_path = join(ART4APPS_IMAGE_PATH, img) + destination_path = join(temp_img_folder, img) + if not os.path.exists(destination_path): + shutil.copyfile(origin_path, destination_path) + logging.error('copy %s to %s', origin_path, + destination_path) + + for snd in (self.pairs[key].props.asnd, + self.pairs[key].props.bsnd): + if snd is not None: + origin_path = join(ART4APPS_AUDIO_PATH, + self.data['language'], snd) + destination_path = join(temp_snd_folder, snd) + if os.path.exists(origin_path) and \ + not os.path.exists(destination_path): + shutil.copyfile(origin_path, destination_path) + logging.error('copy %s to %s', origin_path, + destination_path) + # Don't look for the images in the art4apps directory + # after this + self.data['origin'] = '' + self.data['pathimg'] = temp_img_folder self.data['pathsnd'] = temp_snd_folder |