diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 3585e5c97..dd116eee0 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -159,7 +159,7 @@ class ThemeManager(QtGui.QWidget): encoding = get_filesystem_encoding() files = SettingsManager.get_files(self.settingsSection, u'.otz') for file in files: - file = os.path.join(self.path, file).encode(encoding) + file = os.path.join(self.path, file) self.unzipTheme(file, self.path) delete_file(file) Receiver.send_message(u'cursor_normal') diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 9fa5bcd77..67d624b6b 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -400,7 +400,7 @@ def clean_filename(filename): """ if not isinstance(filename, unicode): filename = unicode(filename, u'utf-8') - return re.sub(r'[/\\?*|<>\[\]":<>+%]+', u'_', filename).strip(u'_') + return re.sub(r'[/\\?*|<>\[\]":<>+%\n]+', u'_', filename).strip(u'_') def delete_file(file_path_name): """ diff --git a/openlp/plugins/songs/lib/wowimport.py b/openlp/plugins/songs/lib/wowimport.py index 1ea43b22a..625dd8de2 100644 --- a/openlp/plugins/songs/lib/wowimport.py +++ b/openlp/plugins/songs/lib/wowimport.py @@ -31,6 +31,7 @@ Worship songs into the OpenLP database. import os import logging +from openlp.core.lib import translate from openlp.plugins.songs.lib.songimport import SongImport BLOCK_TYPES = (u'V', u'C', u'B') @@ -52,18 +53,19 @@ class WowImport(SongImport): * A block can be a verse, chorus or bridge. File Header: - Bytes are counted from one, i.e. the first byte is byte 1. These bytes, - up to the 56 byte, can change but no real meaning has been found. The + Bytes are counted from one, i.e. the first byte is byte 1. The first 19 + bytes should be "WoW File \\nSong Words" The bytes after this and up to + the 56th byte, can change but no real meaning has been found. The 56th byte specifies how many blocks there are. The first block starts with byte 83 after the "CSongDoc::CBlock" declaration. Blocks: Each block has a starting header, some lines of text, and an ending - footer. Each block starts with 4 bytes, the first byte specifies how - many lines are in that block, the next three bytes are null bytes. + footer. Each block starts with a 32 bit number, which specifies how + many lines are in that block. - Each block ends with 4 bytes, the first of which defines what type of - block it is, and the rest which are null bytes: + Each block ends with a 32 bit number, which defines what type of + block it is: * ``NUL`` (0x00) - Verse * ``SOH`` (0x01) - Chorus @@ -76,7 +78,6 @@ class WowImport(SongImport): Each line starts with a byte which specifies how long that line is, the line text, and ends with a null byte. - Footer: The footer follows on after the last block, the first byte specifies the length of the author text, followed by the author text, if @@ -107,22 +108,28 @@ class WowImport(SongImport): for file in self.importSource: if self.stopImportFlag: return - file_name = os.path.split(file)[1] - # Get the song title - self.title = file_name.rpartition(u'.')[0] + self.setDefaults() song_data = open(file, 'rb') if song_data.read(19) != u'WoW File\nSong Words': - self.logError(file) + self.logError(file, unicode( + translate('SongsPlugin.WordsofWorshipSongImport', + ('Invalid Words of Worship song file. Missing ' + '"Wow File\\nSong Words" header.')))) continue # Seek to byte which stores number of blocks in the song song_data.seek(56) no_of_blocks = ord(song_data.read(1)) + song_data.seek(66) + if song_data.read(16) != u'CSongDoc::CBlock': + self.logError(file, unicode( + translate('SongsPlugin.WordsofWorshipSongImport', + ('Invalid Words of Worship song file. Missing ' + '"CSongDoc::CBlock" string.')))) + continue # Seek to the beging of the first block song_data.seek(82) for block in range(no_of_blocks): - self.linesToRead = ord(song_data.read(1)) - # Skip 3 nulls to the beginnig of the 1st line - song_data.seek(3, os.SEEK_CUR) + self.linesToRead = ord(song_data.read(4)[:1]) block_text = u'' while self.linesToRead: self.lineText = unicode( @@ -132,9 +139,7 @@ class WowImport(SongImport): block_text += u'\n' block_text += self.lineText self.linesToRead -= 1 - block_type = BLOCK_TYPES[ord(song_data.read(1))] - # Skip 3 nulls at the end of the block - song_data.seek(3, os.SEEK_CUR) + block_type = BLOCK_TYPES[ord(song_data.read(4)[:1])] # Blocks are seperated by 2 bytes, skip them, but not if # this is the last block! if block + 1 < no_of_blocks: @@ -150,6 +155,9 @@ class WowImport(SongImport): if copyright_length: self.addCopyright(unicode( song_data.read(copyright_length), u'cp1252')) + file_name = os.path.split(file)[1] + # Get the song title + self.title = file_name.rpartition(u'.')[0] song_data.close() if not self.finish(): self.logError(file)