Skip to content

Commit

Permalink
Release Version 1.1.4
Browse files Browse the repository at this point in the history
Support checking update when start up
  • Loading branch information
Lixuannan committed Nov 19, 2023
1 parent f780f8b commit d5cdcfa
Show file tree
Hide file tree
Showing 14 changed files with 763 additions and 506 deletions.
986 changes: 497 additions & 489 deletions build-installer.nsi

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import platform
import logging

VERSION = "1.1.3"
VERSION = "v1.1.4"


def build_windows():
Expand Down
68 changes: 65 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# -*- coding: utf-8 -*-

import base64
import json
import sys
import os.path
import os
import sqlite3
import shutil
import socket
import platform
from threading import Thread

import requests
import pyperclip
from PySide6.QtCore import Signal
from PySide6.QtWidgets import QApplication, QWidget, QDialog
from PySide6.QtGui import QShortcut, QKeySequence

import syncer
import ui.show_problem
from logger import Logger
from ui import main_window, setting, chooseOJ, massage, log
from ui import main_window, setting, chooseOJ, massage, log, update

RESET_SQL = ("DROP TABLE problems; DROP TABLE settings; DROP TABLE default_sync; CREATE TABLE problems( pid text, "
"site text, code text); CREATE TABLE settings( option TEXT, value TEXT, number_i INT, number_f FLOAT); "
Expand All @@ -28,6 +33,7 @@
"default_sync VALUES('Oiclass',0); INSERT INTO default_sync VALUES('HydroOJ',0); INSERT INTO "
"default_sync VALUES('UOJ',0); INSERT INTO default_sync VALUES('Codeforces',0);")
LOGGER = Logger()
VERSION = "v1.1.4"


def load_list():
Expand Down Expand Up @@ -196,14 +202,46 @@ def __init__(self):
LOGGER.show()


class Update(update.Ui_UpdateDialog, QDialog):
update_progress = Signal(int)
finish = Signal()

def __init__(self, update_url):
super(Update, self).__init__()
self.setupUi(self)
self.update_url = update_url
self.update_progress.connect(self.downloadProgress.setValue)
self.ifUpdate.accepted.connect(self.update)
self.ifUpdate.rejected.connect(self.close)
self.finish.connect(self.close)
self.exec()

def download(self, url):
LOGGER.log(20, f"Start Downloading from {self.update_url}")
with open(os.path.join(os.getenv("APPDATA"), "CodeLib-Local", self.update_url.split("/")[-1]), "wb") as f:
r = requests.get(self.update_url, stream=True)
size = r.headers.get("content-length")
for data in r.iter_content(chunk_size=1048576):
f.write(data)
self.update_progress.emit(int(f.tell() / int(size) * 100))
LOGGER.log(20, "Finish Downloading")
self.finish.emit()

def update(self):
self.downloadProgress.setEnabled(True)
self.progressLabel.setEnabled(True)

download_thread = Thread(target=self.download, args=(self.update_url,))
download_thread.start()


class ChooseOJ(chooseOJ.Ui_chooseOJ, QDialog):
def __init__(self):
LOGGER.log(10, str(default_site))
super(ChooseOJ, self).__init__()
self.setupUi(self)
self.buttonBox.accepted.connect(self.sync)
self.load_default_sites()

self.exec()

def load_default_sites(self):
Expand Down Expand Up @@ -265,6 +303,25 @@ def sync(self):
if platform.system() == 'Windows':
slash = '\\'

region = requests.get(f"https://ipapi.co/{requests.get('https://ipapi.co/ip/').text}/country_code").text
LOGGER.log(10, f"Region: {region}")
if region == 'CN':
result = json.loads(requests.get("https://gitee.com/api/v5/repos/lixuannan/CodeLib-Local/releases/latest").text)
tag = result["tag_name"]
url = result["assets"]
else:
result = json.loads(requests.get("https://api.github.com/repos/lixuannan/CodeLib-Local/releases/latest").text)
tag = result["tag_name"]
url = result["assets"]

update_url = ""
if tag != VERSION:
if platform.system() == 'Windows':
for i in url:
if "name" in i and i["name"] == f"CodeLib-Local-Setup-{tag}.exe":
update_url = i["browser_download_url"]
break

db_location = os.path.join(os.getenv('APPDATA'), 'CodeLib-Local', 'data.db')
db_template_location = ""
db_template_location_l = os.path.join(os.path.abspath(sys.argv[0]))
Expand Down Expand Up @@ -353,5 +410,10 @@ def sync(self):

load_list()

if update_url != "":
Update(update_url)
os.system(f"\"{os.path.join(os.getenv('APPDATA'), 'CodeLib-Local', update_url.split('/')[-1])}\"")
sys.exit(0)

widget.show()
sys.exit(app.exec())
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PySide6~=6.5.2
requests~=2.31.0
beautifulsoup4~=4.12.2
pyperclip~=1.8.2
requests~=2.31.0
lxml~=4.9.3
Pyside6
pyperclip
beautifulsoup4
requests
lxml
pyinstaller
2 changes: 1 addition & 1 deletion resources_rc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Resource object code (Python 3)
# Created by: object code
# Created by: The Resource Compiler for Qt version 6.5.2
# Created by: The Resource Compiler for Qt version 6.6.0
# WARNING! All changes made in this file will be lost!

from PySide6 import QtCore
Expand Down
2 changes: 1 addition & 1 deletion ui/chooseOJ.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
################################################################################
## Form generated from reading UI file 'chooseOJ.ui'
##
## Created by: Qt User Interface Compiler version 6.5.2
## Created by: Qt User Interface Compiler version 6.6.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
Expand Down
1 change: 1 addition & 0 deletions ui/generate.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pyside6-uic setting.ui > setting.py
pyside6-uic massage.ui > massage.py
pyside6-uic show_problem.ui > show_problem.py
pyside6-uic log.ui > log.py
pyside6-uic update.ui > update.py
pyside6-rcc resources.qrc > ..\resources_rc.py
2 changes: 1 addition & 1 deletion ui/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
################################################################################
## Form generated from reading UI file 'log.ui'
##
## Created by: Qt User Interface Compiler version 6.5.2
## Created by: Qt User Interface Compiler version 6.6.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
Expand Down
2 changes: 1 addition & 1 deletion ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
################################################################################
## Form generated from reading UI file 'main_window.ui'
##
## Created by: Qt User Interface Compiler version 6.5.2
## Created by: Qt User Interface Compiler version 6.6.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
Expand Down
2 changes: 1 addition & 1 deletion ui/massage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
################################################################################
## Form generated from reading UI file 'massage.ui'
##
## Created by: Qt User Interface Compiler version 6.5.2
## Created by: Qt User Interface Compiler version 6.6.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
Expand Down
2 changes: 1 addition & 1 deletion ui/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
################################################################################
## Form generated from reading UI file 'setting.ui'
##
## Created by: Qt User Interface Compiler version 6.5.2
## Created by: Qt User Interface Compiler version 6.6.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
Expand Down
2 changes: 1 addition & 1 deletion ui/show_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
################################################################################
## Form generated from reading UI file 'show_problem.ui'
##
## Created by: Qt User Interface Compiler version 6.5.2
## Created by: Qt User Interface Compiler version 6.6.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
Expand Down
90 changes: 90 additions & 0 deletions ui/update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'update.ui'
##
## Created by: Qt User Interface Compiler version 6.6.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QAbstractButton, QApplication, QDialog, QDialogButtonBox,
QHBoxLayout, QLabel, QProgressBar, QSizePolicy,
QVBoxLayout, QWidget)
import resources_rc

class Ui_UpdateDialog(object):
def setupUi(self, UpdateDialog):
if not UpdateDialog.objectName():
UpdateDialog.setObjectName(u"UpdateDialog")
UpdateDialog.resize(406, 117)
icon = QIcon()
icon.addFile(u":/icon/icon.png", QSize(), QIcon.Normal, QIcon.Off)
UpdateDialog.setWindowIcon(icon)
self.verticalLayout = QVBoxLayout(UpdateDialog)
self.verticalLayout.setObjectName(u"verticalLayout")
self.question = QLabel(UpdateDialog)
self.question.setObjectName(u"question")
font = QFont()
font.setPointSize(11)
self.question.setFont(font)

self.verticalLayout.addWidget(self.question)

self.horizontalLayout = QHBoxLayout()
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.progressLabel = QLabel(UpdateDialog)
self.progressLabel.setObjectName(u"progressLabel")
self.progressLabel.setEnabled(False)
sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.progressLabel.sizePolicy().hasHeightForWidth())
self.progressLabel.setSizePolicy(sizePolicy)
self.progressLabel.setFont(font)

self.horizontalLayout.addWidget(self.progressLabel)

self.downloadProgress = QProgressBar(UpdateDialog)
self.downloadProgress.setObjectName(u"downloadProgress")
self.downloadProgress.setEnabled(False)
sizePolicy1 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
sizePolicy1.setHorizontalStretch(0)
sizePolicy1.setVerticalStretch(0)
sizePolicy1.setHeightForWidth(self.downloadProgress.sizePolicy().hasHeightForWidth())
self.downloadProgress.setSizePolicy(sizePolicy1)
self.downloadProgress.setMinimum(0)
self.downloadProgress.setValue(0)
self.downloadProgress.setTextVisible(True)
self.downloadProgress.setInvertedAppearance(False)

self.horizontalLayout.addWidget(self.downloadProgress)


self.verticalLayout.addLayout(self.horizontalLayout)

self.ifUpdate = QDialogButtonBox(UpdateDialog)
self.ifUpdate.setObjectName(u"ifUpdate")
self.ifUpdate.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)

self.verticalLayout.addWidget(self.ifUpdate)


self.retranslateUi(UpdateDialog)

QMetaObject.connectSlotsByName(UpdateDialog)
# setupUi

def retranslateUi(self, UpdateDialog):
UpdateDialog.setWindowTitle(QCoreApplication.translate("UpdateDialog", u"\u7248\u672c\u66f4\u65b0", None))
self.question.setText(QCoreApplication.translate("UpdateDialog", u"\u68c0\u6d4b\u5230\u65b0\u7248\u672c\uff0c\u662f\u5426\u66f4\u65b0\uff1f", None))
self.progressLabel.setText(QCoreApplication.translate("UpdateDialog", u"\u4e0b\u8f7d\u8fdb\u5ea6\uff1a", None))
# retranslateUi

Loading

0 comments on commit d5cdcfa

Please sign in to comment.