22#type: ignore
33#Early load variables
44APP_VERSION = 1 #The API Version.
5- APP_UF_VERSION = "1.54.6 "
5+ APP_UF_VERSION = "1.54.7 "
66#The semver version
77print (f"CraftServerSetup by Enderbyte Programs v{ APP_UF_VERSION } (c) 2023-2026, some rights reserved" )
88
7070
7171else :
7272 DEBUG = False
73+
7374#Third party libraries below here
7475import cursesplus #Terminal Display Control
7576from cursesplus import CheckBoxItem
@@ -138,13 +139,6 @@ def sigint(signal,frame):
138139 if cursesplus .messagebox .askyesno (_SCREEN ,message ):
139140 safe_exit (0 )
140141
141- def internet_on ():
142- try :
143- urllib .request .urlopen ('http://google.com' , timeout = 10 )
144- return True
145- except :
146- return False
147-
148142def assemble_package_file_path (serverdir :str ):
149143 return TEMPDIR + "/packages-spigot-" + serverdir .replace ("\\ " ,"/" ).split ("/" )[- 1 ]+ ".json"
150144
@@ -1695,6 +1689,7 @@ def update_s_software_postinit(PACKAGEDATA:dict,chosenserver:int):
16951689def update_vanilla_software (stdscr ,serverdir :str ,chosenserver :int ):
16961690 update_s_software_preinit (serverdir )
16971691 stdscr .erase ()
1692+ VERSION_MANIFEST_DATA = requests .get (VERSION_MANIFEST ).json ()
16981693 downloadversion = uicomponents .menu (stdscr ,["Cancel" ]+ [v ["id" ] for v in VERSION_MANIFEST_DATA ["versions" ]],"Please choose a version" )
16991694 if downloadversion == 0 :
17001695 return
@@ -3347,6 +3342,7 @@ def manage_server(stdscr,_sname: str,chosenserver: int):
33473342 stdscr .addstr (4 ,0 ,"Server Size" )
33483343 stdscr .addstr (5 ,0 ,"Moddable server?" )
33493344 stdscr .addstr (6 ,0 ,"Number of Plugins" )
3345+ stdscr .addstr (7 ,0 ,"Server ID" )
33503346 stdscr .refresh ()
33513347 sdat = appdata .APPDATA ["servers" ][chosenserver - 1 ]
33523348 stdscr .addstr (0 ,20 ,sdat ["name" ])
@@ -3359,7 +3355,8 @@ def manage_server(stdscr,_sname: str,chosenserver: int):
33593355 stdscr .refresh ()
33603356 stdscr .addstr (5 ,20 ,["Yes" if sdat ["moddable" ] else "No" ][0 ])
33613357 stdscr .addstr (6 ,20 ,str (len (glob .glob (SERVER_DIR + "/plugins/*.jar" )) if os .path .isdir (SERVER_DIR + "/plugins" ) else "N/A" ))
3362- stdscr .addstr (7 ,0 ,"Press any key to continue" ,cursesplus .set_colour (cursesplus .WHITE ,cursesplus .BLACK ))
3358+ stdscr .addstr (7 ,20 ,str (sdat ["id" ]))
3359+ stdscr .addstr (8 ,0 ,"Press any key to continue" ,cursesplus .set_colour (cursesplus .WHITE ,cursesplus .BLACK ))
33633360 stdscr .refresh ()
33643361 stdscr .getch ()
33653362 elif w == 11 :
@@ -4161,19 +4158,27 @@ def compare_versions(version1, version2):
41614158 return 0
41624159
41634160def windows_update_software (stdscr ,interactive = True ):
4161+
41644162 if interactive :
41654163 cursesplus .displaymsg (stdscr ,["Checking for updates" ],False )
4166- td = requests .get ("https://github.com/Enderbyte-Programs/CraftServerSetup/raw/refs/heads/main/update.txt" ).text
4167- tdz = td .split ("|" )
4168- svr = tdz [1 ]
4169- url = tdz [0 ]
4170- if compare_versions (svr ,APP_UF_VERSION ) == 1 :
4171- #NUA
4172- if cursesplus .messagebox .askyesno (stdscr ,["There is a new update available." ,f"{ svr } over { APP_UF_VERSION } " ,"Would you like to install it?" ]):
4173- cursesplus .displaymsg (stdscr ,["Downloading new update..." ],False )
4174- urllib .request .urlretrieve (url ,os .path .expandvars ("%TEMP%/crssupdate.exe" ))
4164+
4165+ lastreleaseinfo = requests .get ("https://api.github.com/repos/Enderbyte-Programs/CraftServerSetup/releases/latest" ).json ()
4166+ foundurl = None
4167+ ver = lastreleaseinfo ["tag_name" ]
4168+
4169+ if compare_versions (ver .replace ("v" ,"" ),APP_UF_VERSION .replace ("v" ,"" )) == 1 :
4170+
4171+ for releaseasset in lastreleaseinfo ["assets" ]:
4172+
4173+ url = releaseasset ["browser_download_url" ]
4174+ if "installer" in url and url .endswith ("exe" ):
4175+ foundurl = url
4176+
4177+ if foundurl is not None :
4178+ urllib .request .urlretrieve (foundurl ,os .path .expandvars ("%TEMP%/crssupdate.exe" ))
41754179 os .startfile (os .path .expandvars ("%TEMP%/crssupdate.exe" ))
4176- sys .exit ()
4180+ else :
4181+ cursesplus .messagebox .showerror (stdscr ,["No suitable release asset could be found." ,"Please report this to devs AT ONCE" ])
41774182 else :
41784183 if interactive :
41794184 cursesplus .messagebox .showinfo (stdscr ,["No new updates are available" ])
@@ -4717,13 +4722,9 @@ def main(stdscr):
47174722 curses .curs_set (0 )
47184723 try :
47194724 cursesplus .displaymsg (stdscr ,["Craft Server Setup" ],False )
4720- stdscr .addstr (0 ,0 ,"Waiting for internet connection..." )
4721- stdscr .refresh ()
47224725 cursesplus .utils .hidecursor ()
47234726 issue = False
4724- if not internet_on ():
4725- cursesplus .messagebox .showerror (stdscr ,["No internet connection could be found." ,"An internet connection is required to run this program." ],colour = True )
4726- #cursesplus.messagebox.showerror(stdscr,[str(_transndt)])
4727+
47274728 if _transndt :
47284729 urllib .request .urlretrieve ("https://github.com/Enderbyte-Programs/CraftServerSetup/raw/main/src/translations.toml" ,APPDATADIR + "/translations.toml" )
47294730 eptranslate .load (APPDATADIR + "/translations.toml" )
@@ -4758,7 +4759,7 @@ def main(stdscr):
47584759 inc = 0
47594760 for server in appdata .APPDATA ["servers" ]:
47604761 if server ["id" ] == AUTOMANAGE_ID :
4761- manage_server (stdscr ,server ["name" ],inc )
4762+ manage_server (stdscr ,server ["name" ],inc + 1 ) #chosenserver-1 used... sorry
47624763 _scc = True
47634764 break
47644765
@@ -4771,7 +4772,7 @@ def main(stdscr):
47714772 for server in appdata .APPDATA ["servers" ]:
47724773 if server ["id" ] == AUTOSTART_ID :
47734774 os .chdir (server ["dir" ])
4774- start_server (stdscr ,server ["name" ],inc ,server ["dir" ])
4775+ start_server (stdscr ,server ["name" ],inc + 1 ,server ["dir" ])
47754776 _scc = True
47764777 break
47774778
0 commit comments