Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

last version check #518

Merged
merged 1 commit into from
May 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 25 additions & 60 deletions kindlecomicconverter/KCC_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

import json
import os
import re
import sys
from urllib.parse import unquote
from urllib.request import urlretrieve
from urllib.request import urlretrieve, urlopen
from time import sleep
from shutil import move, rmtree
from subprocess import STDOUT, PIPE
Expand Down Expand Up @@ -142,64 +143,27 @@ def __del__(self):
self.wait()

def run(self):
# TODO adapt with github releases
pass

# try:
# XML = parse(urlopen(Request('https://kcc.iosphe.re/Version/',
# headers={'User-Agent': 'KindleComicConverter/' + __version__})))
# except Exception:
# return
# latestVersion = XML.childNodes[0].getElementsByTagName('LatestVersion')[0].childNodes[0].toxml()
# if ("beta" not in __version__ and StrictVersion(latestVersion) > StrictVersion(__version__)) \
# or ("beta" in __version__
# and StrictVersion(latestVersion) >= StrictVersion(re.sub(r'-beta.*', '', __version__))):
# if sys.platform.startswith('win'):
# self.newVersion = latestVersion
# self.md5 = XML.childNodes[0].getElementsByTagName('MD5')[0].childNodes[0].toxml()
# MW.showDialog.emit('<b>New version released!</b> <a href="https://github.com/ciromattia/kcc/releases/">'
# 'See changelog.</a><br/><br/>Installed version: ' + __version__ +
# '<br/>Current version: ' + latestVersion +
# '<br/><br/>Would you like to start automatic update?', 'question')
# self.getNewVersion()
# else:
# MW.addMessage.emit('<a href="https://kcc.iosphe.re/">'
# '<b>The new version is available!</b></a> '
# '(<a href="https://github.com/ciromattia/kcc/releases/">'
# 'Changelog</a>)', 'warning', False)
try:
last_version_url = urlopen("https://api.github.com/repos/ciromattia/kcc/releases/latest")
data = last_version_url.read()
encoding = last_version_url.info().get_content_charset('utf-8')
json_parser = json.loads(data.decode(encoding))

html_url = json_parser["html_url"]
latest_version = json_parser["tag_name"]
latest_version = re.sub(r'^v', "", latest_version)

if ("b" not in __version__ and StrictVersion(latest_version) > StrictVersion(__version__)) \
or ("b" in __version__
and StrictVersion(latest_version) >= StrictVersion(re.sub(r'b.*', '', __version__))):
MW.addMessage.emit('<a href="' + html_url + '"><b>The new version is available!</b></a>', 'warning',
False)
except Exception:
return

def setAnswer(self, dialoganswer):
self.answer = dialoganswer

def getNewVersion(self):
while self.answer is None:
sleep(1)
if self.answer == QtWidgets.QMessageBox.Yes:
try:
MW.modeConvert.emit(-1)
MW.progressBarTick.emit('Downloading update')
path = urlretrieve('https://kcc.iosphe.re/Windows/KindleComicConverter_win_' +
self.newVersion + '.exe', reporthook=self.getNewVersionTick)
if self.md5 != md5Checksum(path[0]):
raise Exception
move(path[0], path[0] + '.exe')
MW.hideProgressBar.emit()
MW.modeConvert.emit(1)
Popen(path[0] + '.exe /SP- /silent /noicons', stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=True)
MW.forceShutdown.emit()
except Exception:
MW.addMessage.emit('Failed to download the update!', 'warning', False)
MW.hideProgressBar.emit()
MW.modeConvert.emit(1)

def getNewVersionTick(self, size, blocksize, totalsize):
progress = int((size / (totalsize // blocksize)) * 100)
if size == 0:
MW.progressBarTick.emit('100')
if progress > self.barProgress:
self.barProgress = progress
MW.progressBarTick.emit('tick')


class ProgressThread(QtCore.QThread):
def __init__(self):
Expand Down Expand Up @@ -506,7 +470,8 @@ def selectFile(self):
fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
'Comic (*.cbz *.cbr *.cb7 *.zip *.rar *.7z *.pdf);;All (*.*)')
else:
fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath, 'Comic (*.pdf);;All (*.*)')
fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
'Comic (*.pdf);;All (*.*)')
for fname in fnames[0]:
if fname != '':
if sys.platform.startswith('win'):
Expand Down Expand Up @@ -617,7 +582,7 @@ def togglegammaBox(self, value):

def togglecroppingBox(self, value):
if value:
GUI.croppingWidget.setVisible(True)
GUI.croppingWidget.setVisible(True)
else:
GUI.croppingWidget.setVisible(False)
self.changeCroppingPower(100) # 1.0
Expand Down Expand Up @@ -731,8 +696,8 @@ def showDialog(self, message, kind):
QtWidgets.QMessageBox.critical(MW, 'KCC - Error', message, QtWidgets.QMessageBox.Ok)
elif kind == 'question':
GUI.versionCheck.setAnswer(QtWidgets.QMessageBox.question(MW, 'KCC - Question', message,
QtWidgets.QMessageBox.Yes,
QtWidgets.QMessageBox.No))
QtWidgets.QMessageBox.Yes,
QtWidgets.QMessageBox.No))

def updateProgressbar(self, command):
if command == 'tick':
Expand Down