mirror of
https://github.com/ciromattia/kcc
synced 2025-12-19 04:31:50 +00:00
last version check (#518)
This commit is contained in:
@@ -16,11 +16,12 @@
|
|||||||
# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||||
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
# PERFORMANCE OF THIS SOFTWARE.
|
# PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
from urllib.request import urlretrieve
|
from urllib.request import urlretrieve, urlopen
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from shutil import move, rmtree
|
from shutil import move, rmtree
|
||||||
from subprocess import STDOUT, PIPE
|
from subprocess import STDOUT, PIPE
|
||||||
@@ -142,64 +143,27 @@ class VersionThread(QtCore.QThread):
|
|||||||
self.wait()
|
self.wait()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# TODO adapt with github releases
|
try:
|
||||||
pass
|
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))
|
||||||
|
|
||||||
# try:
|
html_url = json_parser["html_url"]
|
||||||
# XML = parse(urlopen(Request('https://kcc.iosphe.re/Version/',
|
latest_version = json_parser["tag_name"]
|
||||||
# headers={'User-Agent': 'KindleComicConverter/' + __version__})))
|
latest_version = re.sub(r'^v', "", latest_version)
|
||||||
# except Exception:
|
|
||||||
# return
|
if ("b" not in __version__ and StrictVersion(latest_version) > StrictVersion(__version__)) \
|
||||||
# latestVersion = XML.childNodes[0].getElementsByTagName('LatestVersion')[0].childNodes[0].toxml()
|
or ("b" in __version__
|
||||||
# if ("beta" not in __version__ and StrictVersion(latestVersion) > StrictVersion(__version__)) \
|
and StrictVersion(latest_version) >= StrictVersion(re.sub(r'b.*', '', __version__))):
|
||||||
# or ("beta" in __version__
|
MW.addMessage.emit('<a href="' + html_url + '"><b>The new version is available!</b></a>', 'warning',
|
||||||
# and StrictVersion(latestVersion) >= StrictVersion(re.sub(r'-beta.*', '', __version__))):
|
False)
|
||||||
# if sys.platform.startswith('win'):
|
except Exception:
|
||||||
# self.newVersion = latestVersion
|
return
|
||||||
# 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)
|
|
||||||
|
|
||||||
def setAnswer(self, dialoganswer):
|
def setAnswer(self, dialoganswer):
|
||||||
self.answer = 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):
|
class ProgressThread(QtCore.QThread):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -506,7 +470,8 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
|
|||||||
fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
|
fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
|
||||||
'Comic (*.cbz *.cbr *.cb7 *.zip *.rar *.7z *.pdf);;All (*.*)')
|
'Comic (*.cbz *.cbr *.cb7 *.zip *.rar *.7z *.pdf);;All (*.*)')
|
||||||
else:
|
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]:
|
for fname in fnames[0]:
|
||||||
if fname != '':
|
if fname != '':
|
||||||
if sys.platform.startswith('win'):
|
if sys.platform.startswith('win'):
|
||||||
|
|||||||
Reference in New Issue
Block a user