mirror of
https://github.com/1j01/textual-paint.git
synced 2024-08-16 19:30:22 +03:00
Add max file size limit when opening or pasting from files
This commit is contained in:
parent
e37255fc98
commit
5a0f1dacfe
@ -145,7 +145,7 @@ cat samples/ship.ans
|
||||
- The Zoom submenu flickers as it opens, and may not always open in the right place.
|
||||
- The canvas flickers when zooming in with the Magnifier tool.
|
||||
- Some languages don't display correctly.
|
||||
- Large files can make the program very slow, as can magnifying the canvas.
|
||||
- Large files can make the program very slow, as can magnifying the canvas. There is a 500 KB limit when opening files to prevent it from freezing.
|
||||
- Saved ANSI files are unnecessarily large, because they include escape sequences for every cell, even if the colors match the previous cell.
|
||||
- Free-Form Select stamping/finalizing is incorrect when the selection is off-screen to the left or top.
|
||||
- Moving the selection with the arrow keys does not cut out the selection from the canvas, it only moves the selection box.
|
||||
|
@ -42,6 +42,8 @@ from wallpaper import get_config_dir, set_wallpaper
|
||||
|
||||
from __init__ import __version__
|
||||
|
||||
MAX_FILE_SIZE = 500000 # 500 KB
|
||||
|
||||
observer = None
|
||||
|
||||
def restart_program():
|
||||
@ -1898,6 +1900,9 @@ class PaintApp(App[None]):
|
||||
print("Checking for backup at:", backup_file_path, "...it exists" if os.path.exists(backup_file_path) else "...it does not exist")
|
||||
if os.path.exists(backup_file_path):
|
||||
try:
|
||||
if os.path.getsize(backup_file_path) > MAX_FILE_SIZE:
|
||||
self.message_box(_("Open"), _("A backup file was found, but was not recovered.") + "\n" + _("The file is too large to open."), "ok")
|
||||
return
|
||||
with open(backup_file_path, "r") as f:
|
||||
backup_content = f.read()
|
||||
backup_image = AnsiArtDocument.from_text(backup_content)
|
||||
@ -2218,6 +2223,9 @@ class PaintApp(App[None]):
|
||||
return
|
||||
|
||||
try:
|
||||
if os.path.getsize(file_path) > MAX_FILE_SIZE:
|
||||
self.message_box(_("Open"), _("The file is too large to open."), "ok")
|
||||
return
|
||||
with open(file_path, "r") as f:
|
||||
content = f.read() # f is out of scope in go_ahead()
|
||||
def go_ahead():
|
||||
@ -2283,6 +2291,9 @@ class PaintApp(App[None]):
|
||||
def handle_selected_file_path(file_path: str) -> None:
|
||||
# TODO: DRY error handling with open_from_file_path
|
||||
try:
|
||||
if os.path.getsize(file_path) > MAX_FILE_SIZE:
|
||||
self.message_box(_("Paste"), _("The file is too large to open."), "ok")
|
||||
return
|
||||
with open(file_path, "r") as f:
|
||||
self.paste(f.read())
|
||||
window.close()
|
||||
|
Loading…
Reference in New Issue
Block a user