mirror of
https://github.com/Huluti/Curtail.git
synced 2024-10-05 18:17:08 +03:00
Compare commits
7 Commits
8ff42ab262
...
d070fdb346
Author | SHA1 | Date | |
---|---|---|---|
|
d070fdb346 | ||
|
e6900c98aa | ||
|
e45a18b01b | ||
|
92c5dbf4f2 | ||
|
3e0944d778 | ||
|
e3149d39bd | ||
|
1a3a6ec01e |
@ -18,6 +18,7 @@
|
||||
import threading
|
||||
import subprocess
|
||||
import logging
|
||||
import shutil
|
||||
from gi.repository import GLib, Gio
|
||||
from pathlib import Path
|
||||
|
||||
@ -76,6 +77,12 @@ class Compressor():
|
||||
GLib.idle_add(self.c_enable_compression, True)
|
||||
|
||||
def run_command(self, command, result_item):
|
||||
if not self.do_new_file:
|
||||
# Creates a copy of the input file
|
||||
# This is done in case the output file is larger than the input file
|
||||
temp_filename = result_item.filename + ".temp"
|
||||
shutil.copy2(result_item.filename, temp_filename)
|
||||
|
||||
error = False
|
||||
error_message = ''
|
||||
try:
|
||||
@ -97,6 +104,17 @@ class Compressor():
|
||||
new_file_data = Path(result_item.new_filename)
|
||||
if new_file_data.is_file():
|
||||
result_item.new_size = new_file_data.stat().st_size
|
||||
|
||||
# This check is mainly for compressors that don't have a way
|
||||
# to automatically detect and skip files
|
||||
if result_item.new_size > result_item.size:
|
||||
if self.do_new_file:
|
||||
shutil.copy2(result_item.filename, result_item.new_filename)
|
||||
else:
|
||||
shutil.copy2(temp_filename, result_item.new_filename)
|
||||
result_item.new_size = new_file_data.stat().st_size
|
||||
Path(temp_filename).unlink(True)
|
||||
|
||||
else:
|
||||
logging.error(str(output))
|
||||
error_message = _("Can't find the compressed file")
|
||||
@ -105,7 +123,7 @@ class Compressor():
|
||||
GLib.idle_add(self.c_update_result_item, result_item, error, error_message)
|
||||
|
||||
def build_png_command(self, result_item):
|
||||
pngquant = 'pngquant --quality=0-{} -f "{}" --output "{}"'
|
||||
pngquant = 'pngquant --quality=0-{} -f "{}" --output "{}" --skip-if-larger'
|
||||
oxipng = 'oxipng -o {} -i 1 "{}" --out "{}"'
|
||||
|
||||
if not self.metadata:
|
||||
|
@ -351,6 +351,7 @@ class CurtailWindow(Adw.ApplicationWindow):
|
||||
def banner_change_mode(self, *args):
|
||||
self._settings.set_boolean('new-file', True)
|
||||
self.show_warning_banner()
|
||||
self.set_saving_subtitle()
|
||||
|
||||
def on_preferences(self, *args):
|
||||
if self.prefs_dialog is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user