Skip to content

Commit

Permalink
added updates for module edition and shortened code
Browse files Browse the repository at this point in the history
  • Loading branch information
SpamixOfficial committed Mar 1, 2023
1 parent b88c414 commit 8160b94
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 64 deletions.
28 changes: 6 additions & 22 deletions linux/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
import requests, argparse, os, time, re, threading, json, zipfile, glob, getpass, subprocess
import requests, argparse, os, time, re, threading, json, zipfile, glob, getpass, subprocess, shutil

settingsfile = "settings.json"

Expand Down Expand Up @@ -37,7 +37,7 @@
hotkeynames = [
'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9'
]
parser = argparse.ArgumentParser(description='OpenClick Help')
parser = argparse.ArgumentParser(description='OpenClick Full Edition Help')
parser.add_argument("--c", "--custom", help="Opens the customization menu", action="store_true")
parser.add_argument("--deb", help="Debug", action="store_true")
parser.add_argument("-cd", help="Constant Click Delay", action="store", type=float)
Expand Down Expand Up @@ -120,19 +120,11 @@
if installp.returncode != 0:
print("Installation failed. \nRemoving temporary files and exiting.")
# remove all files if installation script fails
dowdirfiles = glob.glob("/tmp/openclick/" + dowdirname + "/*")
for f in dowdirfiles:
os.remove(f)
os.rmdir("/tmp/openclick/" + dowdirname)
os.rmdir("/tmp/openclick")
shutil.rmtree("/tmp/openclick")
quit()
print("Update was successful! Removing update files...")
# remove directory when done
dowdirfiles = glob.glob("/tmp/openclick/" + dowdirname + "/*")
for f in dowdirfiles:
os.remove(f)
os.rmdir("/tmp/openclick/" + dowdirname)
os.rmdir("/tmp/openclick")
shutil.rmtree("/tmp/openclick")
print("Exiting...")
quit()
else:
Expand Down Expand Up @@ -199,19 +191,11 @@
if installp.returncode != 0:
print("Installation failed. \nRemoving temporary files and exiting.")
# remove all files if installation script fails
dowdirfiles = glob.glob("/tmp/openclick/" + dowdirname + "/*")
for f in dowdirfiles:
os.remove(f)
os.rmdir("/tmp/openclick/" + dowdirname)
os.rmdir("/tmp/openclick")
shutil.rmtree("/tmp/openclick")
quit()
print("Update was successful! Removing update files...")
# remove directory when done
dowdirfiles = glob.glob("/tmp/openclick/" + dowdirname + "/*")
for f in dowdirfiles:
os.remove(f)
os.rmdir("/tmp/openclick/" + dowdirname)
os.rmdir("/tmp/openclick")
shutil.rmtree("/tmp/openclick")
print("Exiting...")
quit()
else:
Expand Down
8 changes: 4 additions & 4 deletions universal/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Startup Check
debugswitch = 1
import os, time, re, argparse
import threading
import json
parser = argparse.ArgumentParser(description="OpenClick Help")
import os, time, re, argparse, subprocess, threading, json
parser = argparse.ArgumentParser(description="OpenClick Module Edition Help")
parser.add_argument("-cd", help="Constant Click Delay", action="store", type=float)
args = parser.parse_args()
firststartup = False
Expand All @@ -30,6 +28,8 @@
from pynput.mouse import Button, Controller
from colorama import Fore, Back, init
color = Fore.RED
if data["autoupdate"] == True:
subprocess.run("ucheck.py")



Expand Down
10 changes: 9 additions & 1 deletion universal/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,21 @@
cdelay = float(choose_key)
data['constantclickdelay'] = float(choose_key)
except ValueError:
print("You must input a number.")
print("You must input a number.")
elif menuinput == "--au":
print("Should Openclick check for updates automatically (y/n)?")
au = input("$\"AU\">").lower()
if au == "y":
data['autoupdate'] = True
else:
data['autoupdate'] = False
elif menuinput == "--help":
print("\r Textcolor (--textcolor) - The color of the text you see in the terminal.")
print("\r Color Examples (--colorexamples) - Shows you the colors you can choose from.")
print("\r Key (--key) - The key for the \"Normal\" mode.")
print("\r Constant Key (--ckey) - The key for the \"Constant\" mode.")
print("\r Constant Click Delay (--cdelay) - The delay for the \"Constant\" mode.")
print("\r AU (--au) - If Openclick should check for updates automatically (wifi is necessary!)")
print("\r Explainer (--help) (This one explains all settings!")
print("\r Exit (--exit)")

Expand Down
21 changes: 21 additions & 0 deletions universal/ucheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import requests, json
from colorama import Fore, init

init(autoreset=True)

# opening settings.json file
jsfile = json.load(open("settings.json"))
##

# getting new release json
response = requests.get("https://api.github.com/repos/SpamixOfficial/OpenClick/releases/latest")
respdata = response.json()
##

# getting new release info
newid = respdata["id"]

if not str(jsfile["release"]) == str(newid):
print(Fore.YELLOW + "New release available to download! " + Fore.RED + "\nConsider updating using the \"update.py\" file since we dont support older versions of our software!")
else:
print("Version is up to date!")
85 changes: 48 additions & 37 deletions universal/update.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import requests, json, os, zipfile, glob, getpass, subprocess
import requests, json, os, zipfile, glob, getpass, shutil

# opening settings.json file
jsfile = open("settings.json")
Expand Down Expand Up @@ -26,46 +26,57 @@
download = requests.get(downurl)
##

def install():
global source
try:
shutil.move("tmp/universal", source, copy_function = shutil.copytree)
return 0
except:
return 1

# filename and dir setting
downdir = "/tmp/"
downname = "openclick-" + tag + "-release.zip"
finalfile = os.path.join(downdir, downname)
##
print("Newest release: " + str(newid) + "\nLocal release: " + str(locdata))
updateinp = input("\nDo you want to update? y/n: ").lower()

if not str(newid) == str(locdata):
print("Newest release: " + str(newid) + "\nYour release: " + str(locdata))
updateinp = input("\nDo you want to update? y/n: ").lower()

if updateinp == "y":
# downloading and renaming zip file
with open(finalfile, 'wb') as fd:
fd.write(download.content)
# outputing into directory and removing zip file
with zipfile.ZipFile(finalfile, 'r') as dezip:
dezip.extractall(path="/tmp/openclick")
os.remove(finalfile)
if updateinp == "y":
# downloading and renaming zip file
with open(downname, 'wb') as fd:
print("Downloading...")
fd.write(download.content)
# outputing into directory and removing zip file
with zipfile.ZipFile(downname, 'r') as dezip:
print("Extracting into folder...")
dezip.extractall(path="tmp")
os.remove(downname)

# scanning folder name inside directory
dowrelname = os.listdir("/tmp/openclick")
dowdirname = " ".join(str(x) for x in dowrelname)
print(dowdirname)
# scanning folder name inside directory
dowrelname = os.listdir("tmp")
dowdirname = " ".join(str(x) for x in dowrelname)
print(dowdirname)

# run installation script
installp = subprocess.run("/tmp/openclick/" + dowdirname + "/install.sh")
# run installation script
print("Installing...")
bdest = "old"
source = os.getcwd()
# Backup files if something goes wrong
if os.path.isdir(bdest) == True:
shutil.move(source, bdest, copy_function = shutil.copytree)
else:
os.mkdir(bdest)
shutil.move(source, bdest, copy_function = shutil.copytree)
installp = install()

if installp.returncode != 0:
print("Installation failed. \nRemoving temporary files and exiting.")
# remove all files if installation script fails
dowdirfiles = glob.glob("/tmp/openclick/" + dowdirname + "/*")
for f in dowdirfiles:
os.remove(f)
os.rmdir("/tmp/openclick/" + dowdirname)
os.rmdir("/tmp/openclick")
quit()

# remove directory when done
dowdirfiles = glob.glob("/tmp/openclick/" + dowdirname + "/*")
for f in dowdirfiles:
os.remove(f)
os.rmdir("/tmp/openclick/" + dowdirname)
os.rmdir("/tmp/openclick")
if installp != 0:
print("Installation failed. \nRemoving temporary files and exiting.")
# remove all files if installation script fails
sutil.rmtree("tmp")
quit()
print("Update was successful! Removing update files...")
# remove directory when done
shutil.rmtree("tmp")
print("Exiting...")
quit()
else:
quit()

0 comments on commit 8160b94

Please sign in to comment.