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

Add support for command-line args #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/*
dist/*
rel/*
44 changes: 44 additions & 0 deletions RemotePlayTogetherHelper.exe.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(
['Scripts\\main.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='RemotePlayTogetherHelper.exe',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
3 changes: 2 additions & 1 deletion Scripts/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from pathlib import Path


class Const:
version = "1.0.0"
updateurl = "https://raw.githubusercontent.com/tiuub/RemotePlayTogetherHelper/master/VERSION"
Expand All @@ -26,4 +27,4 @@ class Const:

settingsEnableUpdatesKey = "ENABLEUPDATES"
settingsLastUpdatePollStampKey = "LASTUPDATEPOLLSTAMP"
settingsUpdateIntervalKey = "UPDATEINTERVAL"
settingsUpdateIntervalKey = "UPDATEINTERVAL"
188 changes: 131 additions & 57 deletions Scripts/forms.py

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions Scripts/games.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os


class Games:
games = []

Expand All @@ -21,8 +22,8 @@ def savegames(self):
return True
return False

def addgame(self, name, path, host=False):
game = { "name": name, "path": path, "host": host }
def addgame(self, name, path, host=False, args=''):
game = {"name": name, "path": path, "host": host, "args": args}
self.games.append(game)
if self.savegames():
return True
Expand Down Expand Up @@ -50,6 +51,11 @@ def gethost(self, index):
return self.games[index]["host"]
return False

def getargs(self, index):
if 0 <= index < len(self.games) and "args" in self.games[index]:
return self.games[index]["args"]
return False

def setname(self, index, name):
if 0 <= index < len(self.games) and "name" in self.games[index]:
self.games[index]["name"] = name
Expand All @@ -70,3 +76,10 @@ def sethost(self, index, host):
if self.savegames():
return True
return False

def setargs(self, index, args):
if 0 <= index < len(self.games) and "args" in self.games[index]:
self.games[index]["args"] = args
if self.savegames():
return True
return False
2 changes: 1 addition & 1 deletion Scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
while True:
forms.showGamelist()

# C:\Python\Python3.7.2\Scripts\pyinstaller.exe --onefile main.py
# C:\Python\Python3.7.2\Scripts\pyinstaller.exe --onefile main.py
49 changes: 28 additions & 21 deletions Scripts/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def poll(self):

if r.status_code == 200:
self.rawresponse = r.text
self.printc(" Local version: %s - Newes version: %s" % (self.version, r.text.split(":")[0]), self.B)
self.printc(" Local version: %s - Newes version: %s" %
(self.version, r.text.split(":")[0]), self.B)
self.printc()
if version.parse(r.text.split(":")[0]) > version.parse(self.version):
return True
Expand All @@ -46,12 +47,15 @@ def update(self):

if re.fullmatch("([0-9\.]+(alpha|beta|dev)?)(:)((http[s]?|ftp)://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)", self.rawresponse.rstrip()) is not None:
self.printc()
self.printc(" New version: %s" % self.rawresponse.split(":")[0], self.G)
self.printc(" New version: %s" %
self.rawresponse.split(":")[0], self.G)
self.printc()
self.printc(" Downloading the newer version. (May take a while.)")
r = requests.get(str.join(":", self.rawresponse.split(":")[1:]).rstrip())
r = requests.get(
str.join(":", self.rawresponse.split(":")[1:]).rstrip())
if r.status_code == 200:
tmpexepath = Path("%s/%s.%s.%s" % (os.getenv("TEMP"), Path(sys.executable).name, time.strftime("%Y%m%d_%H%M%S"), "tmp"))
tmpexepath = Path("%s/%s.%s.%s" % (os.getenv("TEMP"), Path(
sys.executable).name, time.strftime("%Y%m%d_%H%M%S"), "tmp"))
self.printc(" Downloaded the newer version.")
self.printc(" Writing it to a temp directory.")
with open(tmpexepath, 'wb') as f:
Expand All @@ -64,29 +68,32 @@ def update(self):
batchpath = Path(
"%s/%s.%s.%s" % (os.getenv("TEMP"), "PythonUpdater", time.strftime("%Y%m%d_%H%M%S"), "bat"))
with open(batchpath.__str__(), "w") as f:
f.write(("@echo off\r\n" \
"echo This batch script will switch the old with the new file.\r\n" \
"timeout 5 /nobreak\r\n" \
"echo. & echo Killing now the running task.\r\n" \
"TASKKILL /F /pid {pid}\r\n" \
"echo. & echo Deleting the old file.\r\n" \
"DEL \"{exepath}\"\r\n" \
"timeout 3 /nobreak\r\n" \
"echo. & echo Moving the new file to the old location.\r\n" \
f.write(("@echo off\r\n"
"echo This batch script will switch the old with the new file.\r\n"
"timeout 5 /nobreak\r\n"
"echo. & echo Killing now the running task.\r\n"
"TASKKILL /F /pid {pid}\r\n"
"echo. & echo Deleting the old file.\r\n"
"DEL \"{exepath}\"\r\n"
"timeout 3 /nobreak\r\n"
"echo. & echo Moving the new file to the old location.\r\n"
"move \"{tmpexepath}\" \"{exepath}\"\r\n"
"timeout 3 /nobreak\r\n" \
"echo. & echo Starting the new version!\r\n" \
"start \"{exepath}\" \"{exepath}\"\r\n" \
"echo. & echo The update is now finished. Ignore the following error message and press Enter or close the window.\r\n" \
"DEL \"%~f0\"\r\n" \
"timeout 3 /nobreak\r\n"
"echo. & echo Starting the new version!\r\n"
"start \"{exepath}\" \"{exepath}\"\r\n"
"echo. & echo The update is now finished. Ignore the following error message and press Enter or close the window.\r\n"
"DEL \"%~f0\"\r\n"
"Pause\r\n").format(pid=os.getpid(), exepath=sys.executable, tmpexepath=tmpexepath))
if os.path.isfile(batchpath.__str__()):
subprocess.Popen([batchpath.__str__()], shell=True,
stdin=None, stderr=None, close_fds=None)
sys.exit(0)
else:
self.printc(" There happened an error, during calling the batch script.", self.R)
self.printc(
" There happened an error, during calling the batch script.", self.R)
else:
self.printc(" There was an error, during downloading the new version.", self.R)
self.printc(
" There was an error, during downloading the new version.", self.R)
else:
self.printc(" There was an error, during fetching the version.", self.R)
self.printc(
" There was an error, during fetching the version.", self.R)