Skip to content

Commit

Permalink
file handling improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazuhiro committed Mar 7, 2018
1 parent 3050a46 commit 926f624
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
41 changes: 29 additions & 12 deletions editor_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,10 @@ def script_database_changed(self, tagname='TRANSLATED'):

xml_file = self.script_name.text()

xml_file_file = join('script_data', self.current_game,
xml_file.split('.')[0], xml_file)
if not xml_file.startswith('e'):
xml_file_file = join('script_data', self.current_game, xml_file.split('-')[0], xml_file.split('.')[0], xml_file)
else:
xml_file_file = join('script_data', self.current_game, xml_file.split('.')[0], xml_file)
# open file in binary mode
f = open(xml_file_file, 'rb')
# store everything in a variable
Expand Down Expand Up @@ -590,6 +592,8 @@ def script_database_changed(self, tagname='TRANSLATED'):

def modification_has_been_made(self, tagname):

if self.txt_files.currentItem() is None:
return 0
prev_script_index = self.txt_files.currentItem().text()
translated_backup = self.data[self.current_game].script_data[tagname][
self.script_name.text()][int(prev_script_index)]
Expand All @@ -601,8 +605,11 @@ def modification_has_been_made(self, tagname):

xml_file = self.script_name.text()

xml_file_file = join('script_data', self.current_game,
xml_file.split('.')[0], xml_file)
if not xml_file.startswith('e'):
xml_file_file = join('script_data', self.current_game, xml_file.split('-')[0], xml_file.split('.')[0], xml_file)
else:
xml_file_file = join('script_data', self.current_game, xml_file.split('.')[0], xml_file)

# open file in binary mode
f = open(xml_file_file, 'rb')
# store everything in a variable
Expand Down Expand Up @@ -736,8 +743,10 @@ def save(self):
self.setWindowTitle(self.script_name.text() + ' - Another SDSE 1.0')

def save_file(self, xml_file, tagname):
xml_file_file = join('script_data', self.current_game,
xml_file.split('.')[0], xml_file)
if not xml_file.startswith('e'):
xml_file_file = join('script_data', self.current_game, xml_file.split('-')[0], xml_file.split('.')[0], xml_file)
else:
xml_file_file = join('script_data', self.current_game, xml_file.split('.')[0], xml_file)
try:
xml_file_data = self.data[self.current_game].script_data[tagname][xml_file]
# open file in binary mode
Expand Down Expand Up @@ -814,12 +823,20 @@ def search_in_all_database(self):
'index': i
}
except:
self.search_data[file] = {
'TRANSLATED': script['TRANSLATED'][file][i],
'ORIGINAL': script['ORIGINAL'][file][i],
'JAPANESE': "",
'index': i
}
try:
self.search_data[file] = {
'TRANSLATED': script['TRANSLATED'][file][i],
'ORIGINAL': script['ORIGINAL'][file][i],
'JAPANESE': script['COMMENT'][file][i],
'index': i
}
except:
self.search_data[file] = {
'TRANSLATED': script['TRANSLATED'][file][i],
'ORIGINAL': script['ORIGINAL'][file][i],
'JAPANESE': "",
'index': i
}
i += 1
self.search_ui.file_list.sortItems()
self.search_ui.file_list.setCurrentRow(0)
Expand Down
22 changes: 10 additions & 12 deletions script_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import os, sys

from os import walk
from os.path import exists


Expand Down Expand Up @@ -190,19 +191,16 @@ def __init__(self, path):
def analyse_scripts(self, tag_name='TRANSLATED'):
new_script_data = dict()

xml_list = os.listdir(self.xml_path)

for xml_dir in xml_list:
if not xml_dir.startswith('e') or xml_dir.find('.') != -1:
continue

xml_file = os.path.join(self.xml_path, xml_dir, xml_dir + '.xml')
try:
buf = open_file(xml_file)
except FileNotFoundError:
continue
for dirpath, dirnames, filenames in walk(self.xml_path):
for filen in filenames:
if filen.endswith(".xml"):
xml_file = os.path.join(dirpath, filen)
try:
buf = open_file(xml_file)
except FileNotFoundError:
continue

new_script_data[xml_dir + '.xml'] = get_file_script(buf, tag_name)
new_script_data[filen] = get_file_script(buf, tag_name)

self.script_data[tag_name] = new_script_data

Expand Down

0 comments on commit 926f624

Please sign in to comment.