forked from Buizz/EUDEditor
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
267 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# We omitted cryptographic checks intentionally. | ||
# That would be handled properly by https protocol used by GitHub | ||
|
||
import atexit | ||
import io | ||
import os | ||
import sys | ||
import zipfile | ||
from threading import Thread | ||
from urllib.error import URLError | ||
from urllib.request import urlopen | ||
|
||
import msgbox | ||
|
||
VERSION_URL = ( | ||
"https://raw.githubusercontent.com/armoha/EUDEditor/master/version/version" | ||
) | ||
|
||
|
||
def download(url): | ||
try: | ||
with urlopen(url) as urlf: | ||
return urlf.read() | ||
except URLError: | ||
return None | ||
|
||
|
||
def getLatestVersion(): | ||
v = download(VERSION_URL) | ||
if v is None: | ||
return (None, None) | ||
else: | ||
return (v.decode("utf-8")).split("\n")[:2] | ||
|
||
|
||
def getRelease(url): | ||
return download(url) | ||
|
||
|
||
def checkUpdate(): | ||
# auto update only supports Win32 by now. | ||
# Also, the application should be frozen | ||
if not msgbox.isWindows or not getattr(sys, "frozen", False): | ||
return False | ||
|
||
latestVersion, release_url = getLatestVersion() | ||
if latestVersion is None: | ||
return msgbox.MessageBox( | ||
"Update failed", "Fail to get latest version info", textio=sys.stderr | ||
) | ||
|
||
# Download the needed data | ||
print("Downloading EUD Editor2 %s" % latestVersion) | ||
release = getRelease(release_url) | ||
if not release: | ||
return msgbox.MessageBox("Update failed", "No release", textio=sys.stderr) | ||
|
||
dataDir = os.path.dirname(sys.executable) | ||
updateDir = os.path.join(dataDir, "_update") | ||
|
||
with zipfile.ZipFile(io.BytesIO(release), "r") as zipf: | ||
zipf.extractall(updateDir) | ||
|
||
# Write an auto-update script. This script will run after euddraft exits | ||
with open(os.path.join(dataDir, "_update.bat"), "w") as batf: | ||
batf.write( | ||
"""\ | ||
@echo off | ||
xcopy _update . /e /y /q | ||
rd _update /s /q | ||
del _update.bat /q | ||
""" | ||
) | ||
|
||
def onExit(): | ||
from subprocess import Popen | ||
|
||
Popen("_update.bat") | ||
|
||
atexit.register(onExit) | ||
|
||
|
||
def issueAutoUpdate(): | ||
checkUpdateThread = Thread(target=checkUpdate) | ||
checkUpdateThread.start() | ||
# We don't join this thread. This thread will automatically join when | ||
# the whole euddraft process is completed. | ||
# | ||
# Also, we don't want this thread to finish before it completes its update | ||
# process, even if the main thread has already finished. So we don't make | ||
# this thread a daemon thread. | ||
|
||
|
||
if __name__ == "__main__" or __name__ == "euddraft__main__": | ||
issueAutoUpdate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Copyright (c) 2014 trgk | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
""" | ||
|
||
import ctypes | ||
import sys | ||
|
||
try: | ||
from winsound import MB_OK, MB_ICONHAND, MessageBeep | ||
|
||
def MessageBox(title, text, style=0, textio=sys.stdout): | ||
print("[%s]\n%s" % (title, text), file=textio) | ||
|
||
""" Helper function """ | ||
hWnd = ctypes.windll.kernel32.GetConsoleWindow() | ||
ctypes.windll.user32.SetForegroundWindow(hWnd) | ||
ctypes.windll.user32.BringWindowToTop(hWnd) | ||
ctypes.windll.user32.SetForegroundWindow(hWnd) | ||
return ctypes.windll.user32.MessageBoxW(0, text, title, style) | ||
|
||
isWindows = True | ||
|
||
from ctypes import WINFUNCTYPE, windll, c_int | ||
from ctypes.wintypes import HWND, SHORT | ||
|
||
prototype = WINFUNCTYPE(HWND) | ||
GetForegroundWindow = prototype(("GetForegroundWindow", windll.user32)) | ||
GetConsoleWindow = prototype(("GetConsoleWindow", windll.kernel32)) | ||
prototype = WINFUNCTYPE(HWND, HWND) | ||
SetForegroundWindow = prototype(("SetForegroundWindow", windll.user32)) | ||
prototype = WINFUNCTYPE(SHORT, c_int) | ||
GetAsyncKeyState = prototype(("GetAsyncKeyState", windll.user32)) | ||
|
||
def IsThisForeground(): | ||
return GetForegroundWindow() == GetConsoleWindow() | ||
|
||
|
||
except ImportError: | ||
MB_OK = 1 | ||
MB_ICONHAND = 2 | ||
|
||
def MessageBeep(type): | ||
for _ in range(type): | ||
sys.stdout.write("\a") | ||
|
||
def MessageBox(title, text, style=0, textio=sys.stdout): | ||
print("[%s]\n%s\n" % (title, text), file=textio) | ||
|
||
isWindows = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import sys | ||
|
||
from cx_Freeze import Executable, setup | ||
|
||
if "build_exe" not in sys.argv: | ||
sys.argv.append("build_exe") | ||
|
||
|
||
build_exe_options = { | ||
"packages": ["os", "ctypes", "sys"], | ||
"excludes": ["tkinter"], | ||
"optimize": 2, | ||
"include_msvcr": True, | ||
"include_files": [], | ||
"zip_include_packages": "*", | ||
"zip_exclude_packages": "", | ||
"small_app": True, | ||
} | ||
|
||
|
||
setup( | ||
name="EUD Editor Updater", | ||
version="1.0.0", | ||
description="EUD Editor updating system", | ||
options={"build_exe": build_exe_options}, | ||
executables=[Executable("EUDEditorUpdate.py", base="Console")], | ||
) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
0.17.9.1 | ||
https://github.com/armoha/EUDEditor/raw/master/version/EUD%20Editor2%200.17.9.1.zip | ||
0.17.9.7 | ||
https://github.com/armoha/EUDEditor/releases/download/v0.17.9.7/EUD.Editor2.0.17.9.7.zip |