def load(self, umdimage): dir = os.path.join(umdimage, "18_mapname.pak") self.map_names.clear() try: files = list_all_files(dir) except: return for file in files: name = os.path.basename(file) index = int(os.path.splitext(name)[0]) script = ScriptFile(file) room_name = script.translated if room_name == "": room_name = script.original if room_name == u"※" or room_name == "": continue self.map_names[index] = room_name self.untranslated[index] = script.original
def changedSelection(self, current, prev): if current == None or current.childCount() != 0: return file = common.qt_to_unicode(current.text(0)) path = tree.tree_item_to_path(current.parent()) path = dir_tools.expand_dir(path) filename = os.path.join(common.editor_config.data01_dir, path, file) if not os.path.isfile(filename): self.ui.txtTranslated.setPlainText("Could not load \"%s\"." % file) self.ui.txtOriginal.setPlainText("") self.ui.txtComments.setPlainText("") return script_file = ScriptFile(filename) notags = self.search_flags & script_analytics.SEARCH_NOTAGS self.ui.txtTranslated.setPlainText(script_file.notags[common.editor_config.lang_trans] if notags else script_file[common.editor_config.lang_trans]) self.ui.txtOriginal.setPlainText(script_file.notags[common.editor_config.lang_orig] if notags else script_file[common.editor_config.lang_orig]) self.ui.txtComments.setPlainText(script_file.comments) self.update_highlights()
def load_file(self, filename): if not os.path.isfile(filename): return stats = os.stat(filename) data = ScriptFile(filename) self.filesize = int(stats.st_size) self.last_edited = int(stats.st_mtime) self.data = data
def load_scripts(self): paths = [] paths.extend(map(lambda p: p.root_dir, self.projects)) paths.append('scripts') # paths.append('scripts') # TODO PUT temp?? self.script_files = [] for path in paths: dirs, filenames = dirs_and_files_of(path) for filename in filenames: if re.match(PY_CODE_FILENAME_REGEX, filename): self.script_files.append(ScriptFile(path, filename))
def load_file(self, filename): if filename == self.filename and not self.needs_update(): return if not os.path.isfile(filename): return stats = os.stat(filename) data = ScriptFile(filename) self.filename = filename self.filesize = int(stats.st_size) self.last_edited = int(stats.st_mtime) self.data = data
def get_map_name(map_id, umdimage=common.editor_config.umdimage_dir): dir = os.path.join(umdimage, "18_mapname.pak") filename = os.path.join(dir, "%04d.txt" % map_id) if not os.path.isfile(filename): return None map_file = ScriptFile(filename) room_name = map_file.translated if room_name == "": room_name = map_file.original if room_name == u"※" or room_name == "": return None room_name = room_name.strip() return room_name
def list_untranslated(): files = list_files.list_all_files(common.editor_config.umdimage_dir) #files = list_files.list_all_files("X:\\Danganronpa\\FULL_TEST\\best-normal") text_files = [] for i, file in enumerate(files): if os.path.splitext(file)[1] == ".txt": text_files.append(file) for file in text_files: try: script_file = ScriptFile(file) except: print file continue if not script_file.translated == "": print file
def get_label(id, dir): if not isinstance(id, int): return None filename = os.path.join(dir, "%04d.txt" % id) if not os.path.isfile(filename): return None line = ScriptFile(filename) label = line[common.editor_config.lang_trans] if label == "": label = line[common.editor_config.lang_orig] if label == u"※" or label == "": return None label = label.strip() return label
def pack_txt(filename): if os.path.basename(os.path.dirname(filename)) in SCRIPT_NONSTOP: is_nonstop = True else: is_nonstop = False script = ScriptFile(filename) text = script[common.editor_config.lang_trans] if not text: text = script[common.editor_config.lang_orig] # Nonstop Debate lines need an extra newline at the end # so they show up in the backlog properly. if is_nonstop and not text[-1] == u"\n": text += u"\n" text = SCRIPT_BOM + text + SCRIPT_NULL text = BitStream(bytes = text.encode("UTF-16LE")) return text
def script_for_counting(data): # A little faster than using the ScriptFile's built-in # parser because we don't need as much of the data. file = ScriptFile() data = script_file.TAG_KILLER.sub("", data) data = script_file.LINE_BREAKS.sub("\n", data) match = script_file.TEXT_PARSER.search(data) if match: first_part = match.group(1) second_part = match.group(2) if not second_part: file.original_notags = first_part else: file.translated_notags = first_part file.original_notags = second_part return file
def changedSelection(self, current, prev): if current == None or current.childCount() != 0: return file = common.qt_to_unicode(current.text(0)) path = tree.tree_item_to_path(current.parent()) self.setWindowTitle("%s - %s" % (self.menu_name, os.path.join(path, file))) path = dir_tools.expand_dir(path) file = os.path.join(path, file) file1 = os.path.join(self.folder1, file) file2 = os.path.join(self.folder2, file) if not os.path.isfile(file1): script1 = ScriptFile() else: script1 = ScriptFile(file1) if not os.path.isfile(file2): script2 = ScriptFile() else: script2 = ScriptFile(file2) # So we can loop this shit. to_diff = [ # Text 1 Text 2 Text Box 1 Text Box 2 (script1.translated, script2.translated, self.ui.txtTranslated1, self.ui.txtTranslated2), (script1.original, script2.original, self.ui.txtOriginal1, self.ui.txtOriginal2), (script1.comments, script2.comments, self.ui.txtComments1, self.ui.txtComments2), ] # Save us a little bit of time recalculating. if file in self.saved_diffs: diffs = self.saved_diffs[file] else: diffs = [None] * len(to_diff) for i, (text1, text2, box1, box2) in enumerate(to_diff): if diffs[i] == None: diffs[i] = DIFFER.diff_main(text1, text2) DIFFER.diff_cleanupSemantic(diffs[i]) box1.setPlainText(text1) box2.setPlainText(text2) highlight1, highlight2 = parse_diffs(diffs[i]) cursor1 = box1.textCursor() cursor2 = box2.textCursor() cursor1.select(QTextCursor.Document) cursor2.select(QTextCursor.Document) cursor1.setCharFormat(self.format_plain) cursor2.setCharFormat(self.format_plain) cursor1.movePosition(QTextCursor.Start) cursor2.movePosition(QTextCursor.Start) for pos, length in highlight1: cursor1.setPosition(pos, QTextCursor.MoveAnchor) cursor1.setPosition(pos + length, QTextCursor.KeepAnchor) cursor1.setCharFormat(self.format1) cursor1.movePosition(QTextCursor.Start) for pos, length in highlight2: cursor2.setPosition(pos, QTextCursor.MoveAnchor) cursor2.setPosition(pos + length, QTextCursor.KeepAnchor) cursor2.setCharFormat(self.format2) cursor2.movePosition(QTextCursor.Start) box1.setTextCursor(cursor1) box2.setTextCursor(cursor2) # for i, (text1, text2, box1, box2) in enumerate(to_diff): self.saved_diffs[file] = diffs
def load(self, filename): if not os.path.isfile(filename): self.filename = None return dat_file = ConstBitStream(filename=self.filename) type = dat_file.read(16) if not type == DEMO_FLAG and not type == FULL_FLAG: raise Exception("Invalid Anagram", "Invalid anagram type.") if type == DEMO_FLAG: type = ANAGRAM_TYPE.Demo else: type = ANAGRAM_TYPE.Full num_letters = dat_file.read('uintle:16') magic = dat_file.read(16) if not magic == ANAGRAM_MAGIC: raise Exception("Invalid Anagram", "Invalid anagram magic.") solution_index = dat_file.read('uintle:16') extra_index = dat_file.read('uintle:16') unknown = dat_file.read(UNKNOWN_LENGTH[type] * 8) easy = dat_file.read(num_letters * 2 * 8) normal = dat_file.read(num_letters * 2 * 8) hard = None if type == ANAGRAM_TYPE.Full: hard = dat_file.read(num_letters * 2 * 8) easy_orig = None normal_orig = None hard_orig = None if dat_file.pos >= dat_file.len: # If we don't have more data, then consider this untranslated. # Therefore, the data we collected becomes the data for the original anagram. easy_orig = easy normal_orig = normal hard_orig = hard num_letters = 0 easy = None normal = None hard = None else: # If we DO have more data, consider this translated and grab the # info about the untranslated anagram. This data is not used by the game, # only the translators. letters_orig = dat_file.read('uintle:16') easy_orig = dat_file.read(letters_orig * 2 * 8) normal_orig = dat_file.read(letters_orig * 2 * 8) if type == ANAGRAM_TYPE.Full: hard_orig = dat_file.read(letters_orig * 2 * 8) ########################################################## ### Now convert all this into a useful format. ########################################################## base_dir = os.path.dirname(self.filename) self.type = type self.solution_index = solution_index self.solution = ScriptFile( os.path.join(base_dir, ANAGRAM_DIR, "%04d.txt" % self.solution_index)) self.extra_index = extra_index self.extra = ScriptFile( os.path.join(base_dir, ANAGRAM_DIR, "%04d.txt" % self.extra_index)) self.__unknown = unknown self.easy = self.parse_shown(easy) self.normal = self.parse_shown(normal) self.hard = self.parse_shown(hard) self.easy_orig = self.parse_shown(easy_orig) self.normal_orig = self.parse_shown(normal_orig) self.hard_orig = self.parse_shown(hard_orig)
def load_dir(self, directory, umdimage="umdimage"): self.script_files = [] self.directory = directory self.wrd = None self.wrd_file = None self.py_file = None base_name = directory directory, wrd_file = dir_tools.parse_dir(directory, umdimage) if directory == None: self.directory = "" raise Exception("Directory \"" + base_name + "\" not found.") full_dir = os.path.join(umdimage, directory) scene_info = [] if not wrd_file == None and os.path.isfile(wrd_file): # Even of the first directory existed and we have a .wrd file, # it's possible there aren't actually any text files here. if not os.path.isdir(full_dir): raise Exception("There are no text files in \"" + directory + "\".") self.wrd = WrdFile() py_file = os.path.splitext(wrd_file)[0] + ".py" if os.path.isfile(py_file): try: self.wrd.load_python(py_file) except: _LOGGER.warning( "%s failed to load. Parsing wrd file instead. Exception info:\n%s" % (py_file, traceback.format_exc())) self.wrd.load_bin(wrd_file) else: # If we succeeded in loading the python file, compile it to binary. # _LOGGER.info("%s loaded successfully. Compiling to binary." % py_file) # self.wrd.save_bin(wrd_file) _LOGGER.info("%s loaded successfully." % py_file) else: _LOGGER.info("Decompiled wrd file not found. Generating %s" % py_file) self.wrd.load_bin(wrd_file) self.wrd.save_python(py_file) scene_info = self.wrd.to_scene_info() self.wrd_file = wrd_file self.py_file = py_file else: scene_info = None self.wrd = None self.wrd_file = None self.script_files = [] if scene_info == None: text_files = list_all_files(full_dir) for file in text_files: self.script_files.append(ScriptFile(file)) else: # Get our files in the order listed by the wrd. for info in scene_info: filename = os.path.join(full_dir, "%04d.txt" % info.file_id) script_file = ScriptFile(filename, info) if script_file.filename == None: _LOGGER.warning( "File %s referenced by %s does not exist." % (filename, wrd_file)) continue self.script_files.append(script_file) chapter, scene, room, mode = common.get_dir_info(base_name) for file in self.script_files: if file.scene_info.chapter == -1: file.scene_info.chapter = chapter if file.scene_info.scene == -1: file.scene_info.scene = scene if file.scene_info.room == -1: file.scene_info.room = room if file.scene_info.mode == None: file.scene_info.mode = mode
def load_dir(self, directory, base_dir="data01"): if not directory: return # directory, wrd_file = dir_tools.parse_dir(directory, base_dir) # Only expands if necessary. full_dir = dir_tools.expand_script_pak(directory) directory1 = normalize(directory) match = RE_FONT_PAK.match(directory1) if match: full_dir = os.path.join(base_dir, SCRIPT_BIN_DIR, full_dir) # if not os.path.isdir(full_dir): # full_dir = os.path.join(base_dir, SCRIPT_BIN_DIR, directory) else: full_dir = os.path.join(base_dir, SCRIPT_DIR, full_dir) if not os.path.isdir(full_dir): raise Exception("Directory \"" + full_dir + "\" not found.") self.script_files = [] self.directory = directory self.wrd = None self.wrd_file = None self.py_file = None scene_info = [] wrd_file = os.path.join(full_dir, os.path.splitext(directory)[0] + ".scp.wrd") if os.path.isfile(wrd_file): self.wrd = WrdFile() py_file = os.path.splitext(wrd_file)[0] + ".py" if os.path.isfile(py_file): try: self.wrd.load_python(py_file) except: _LOGGER.warning( "%s failed to load. Parsing wrd file instead. Exception info:\n%s" % (py_file, traceback.format_exc())) self.wrd.load_bin(wrd_file) else: # If we succeeded in loading the python file, compile it to binary. # _LOGGER.info("%s loaded successfully. Compiling to binary." % py_file) # self.wrd.save_bin(wrd_file) _LOGGER.info("%s loaded successfully." % py_file) else: _LOGGER.info("Decompiled wrd file not found. Generating %s" % py_file) self.wrd.load_bin(wrd_file) self.wrd.save_python(py_file) scene_info = self.wrd.to_scene_info() self.wrd_file = wrd_file self.py_file = py_file else: scene_info = None self.wrd = None self.wrd_file = None self.py_file = None self.script_files = [] if scene_info == None: text_files = [ filename for filename in os.listdir(full_dir) if os.path.splitext(filename)[1].lower() == ".txt" ] for filename in text_files: self.script_files.append( ScriptFile(os.path.join(full_dir, filename))) else: # Get our files in the order listed by the wrd. for info in scene_info: if info.file_id == None: script_file = ScriptJump(info) else: filename = os.path.join(full_dir, "%04d.txt" % info.file_id) script_file = ScriptFile(filename, info) if script_file.filename == None: _LOGGER.warning( "File %s referenced by %s does not exist." % (filename, wrd_file)) continue self.script_files.append(script_file) chapter, scene, room, mode = common.get_dir_info(directory) for file in self.script_files: if file.scene_info.chapter == -1: file.scene_info.chapter = chapter if file.scene_info.scene == -1: file.scene_info.scene = scene if file.scene_info.room == -1: file.scene_info.room = room if file.scene_info.mode == None: file.scene_info.mode = mode