Make sure we are flushing for log

This commit is contained in:
dazedanon 2025-11-10 10:12:18 -06:00
parent 74fe4bb637
commit 0e7f62af84
3 changed files with 27 additions and 4 deletions

View file

@ -73,6 +73,7 @@ class LogViewer(QWidget):
self._tail_timer.timeout.connect(self._poll_tail)
self._tail_interval = 300 # ms
self._tail_f = None
self._tail_buffer = "" # Buffer for incomplete lines
# Default: prefer the most recent file in log/history, else legacy path
try:
latest = self._latest_history_file()
@ -118,7 +119,8 @@ class LogViewer(QWidget):
"""Clear the log display and reset tracking."""
self.log_display.clear()
self.status_label.setText("Log cleared")
# Reset tail file pointer if active
# Reset tail file pointer and buffer if active
self._tail_buffer = ""
if self._tail_f:
try:
# Move pointer to end so we continue only with new lines
@ -196,8 +198,26 @@ class LogViewer(QWidget):
new_data = self._tail_f.read()
if not new_data:
return
# Split into lines and append
for line in new_data.splitlines():
# Combine buffer with new data
combined = self._tail_buffer + new_data
# Split by newlines, keeping the separator info
lines = combined.split('\n')
# If the data ends with a newline, the last element will be empty
# Otherwise, it's an incomplete line that should be buffered
if combined.endswith('\n'):
# All lines are complete
self._tail_buffer = ""
complete_lines = lines[:-1] # Exclude the empty last element
else:
# Last line is incomplete, save it for next time
self._tail_buffer = lines[-1]
complete_lines = lines[:-1]
# Append complete lines to the display
for line in complete_lines:
if line.strip():
self.append_log_message(line)
except Exception:

View file

@ -1669,7 +1669,7 @@ def searchCodes(page, pbar, jobList, filename):
## Event Code: 122 [Set Variables]
if "code" in codeList[i] and codeList[i]["code"] == 122 and CODE122 is True:
# This is going to be the var being set. (IMPORTANT)
if codeList[i]["parameters"][0] not in list(range(2, 3)):
if codeList[i]["parameters"][0] not in list(range(0, 2000)):
i += 1
continue

View file

@ -23,6 +23,7 @@ PROTECTED_PATTERNS = [
r'\\ME\[[^\]]+\]', # \ME[music_effect_name]
r'\\BGM\[[^\]]+\]', # \BGM[background_music_name]
r'\\BGS\[[^\]]+\]', # \BGS[background_sound_name]
r'_pum\[[^\]]+\]', # \BGS[background_sound_name]
]
def protect_script_codes(text):
@ -1033,6 +1034,7 @@ def translateAI(text, history, fullPromptFlag, config, filename=None, pbar=None,
with open(config.logFilePath, "a", encoding="utf-8") as logFile:
logFile.write(f"Input:\n{subbedT}\n")
logFile.write(f"Output:\n{formatted_output}\n")
logFile.flush() # Ensure data is written to disk immediately
except Exception:
pass # Don't fail if logging fails
@ -1064,6 +1066,7 @@ def translateAI(text, history, fullPromptFlag, config, filename=None, pbar=None,
mismatchFile.write(f"Failed after retries: {filename}\n")
mismatchFile.write(f"Input:\n{subbedT}\n")
mismatchFile.write(f"Final Output:\n{formatted_mismatch_output}\n")
mismatchFile.flush() # Ensure data is written to disk immediately
if filename and mismatchList is not None and filename not in mismatchList:
mismatchList.append(filename)