11
11
from pathlib import Path
12
12
13
13
try :
14
- with Path (__file__ , ".." , "packages.txt" ).open ("r" , encoding = "utf-8" ) as f :
14
+ with Path (__file__ , ".." , "packages.txt" ).resolve (). open ("r" , encoding = "utf-8" ) as f :
15
15
pkg_resources .require (f .read ().splitlines ())
16
16
except (DistributionNotFound , VersionConflict ) as ex :
17
17
traceback .print_exc ()
18
18
print ("\n Dependencies not met. Run `pip install -r packages.txt` to install missing dependencies." )
19
19
sys .exit (1 )
20
20
21
+ import glob
21
22
import argparse
22
23
import configparser
23
24
import datetime
@@ -169,7 +170,7 @@ def checkUpdate(reverseUpdateTest:bool = False):
169
170
try :
170
171
print ("checking for updates" )
171
172
latestUpdates = json .loads (urllib .request .urlopen ('https://cdn.jsdelivr.net/gh/L0laapk3/FactorioMaps@latest/updates.json' , timeout = 30 ).read ())
172
- with Path (__file__ , ".." , "updates.json" ).open ("r" , encoding = "utf-8" ) as f :
173
+ with Path (__file__ , ".." , "updates.json" ).resolve (). open ("r" , encoding = "utf-8" ) as f :
173
174
currentUpdates = json .load (f )
174
175
if reverseUpdateTest :
175
176
latestUpdates , currentUpdates = currentUpdates , latestUpdates
@@ -294,7 +295,7 @@ def buildAutorun(args: Namespace, workFolder: Path, outFolder: Path, isFirstSnap
294
295
def lowerBool (value : bool ):
295
296
return str (value ).lower ()
296
297
297
- with open ( "autorun.lua " , "w" , encoding = "utf-8" ) as f :
298
+ with Path ( __file__ , ".. " , "autorun.lua" ). resolve (). open ( "w" , encoding = "utf-8" ) as f :
298
299
surfaceString = '{"' + '", "' .join (args .surface ) + '"}' if args .surface else "nil"
299
300
autorunString = \
300
301
f'''fm.autorun = {{
@@ -335,6 +336,8 @@ def buildConfig(args: Namespace, tmpDir, basepath):
335
336
config ["path" ] = {}
336
337
config ["path" ]["write-data" ] = tmpDir
337
338
339
+ config ["path" ]["script-output" ] = str (basepath )
340
+
338
341
if "graphics" not in config :
339
342
config ["graphics" ] = {}
340
343
config ["graphics" ]["screenshots-threads-count" ] = str (args .screenshotthreads if args .screenshotthreads else args .maxthreads )
@@ -344,9 +347,6 @@ def buildConfig(args: Namespace, tmpDir, basepath):
344
347
configFile .writelines (("; version=3\n " , ))
345
348
config .write (configFile , space_around_delimiters = False )
346
349
347
- # TODO: change this when https://forums.factorio.com/viewtopic.php?f=28&t=81221 is implemented
348
- linkDir (Path (tmpDir , "script-output" ), basepath )
349
-
350
350
copy (Path (userFolder , 'player-data.json' ), tmpDir )
351
351
352
352
return configPath
@@ -427,8 +427,9 @@ def kill(pid, onlyStall=False):
427
427
428
428
saveGames = OrderedSet ()
429
429
for saveName in saveNames :
430
- globResults = list (saves .glob (saveName ))
431
- globResults += list (saves .glob (f"{ saveName } .zip" ))
430
+ saveNameEscaped = glob .escape (saveName ).replace ("[*]" , "*" )
431
+ globResults = list (saves .glob (saveNameEscaped ))
432
+ globResults += list (saves .glob (f"{ saveNameEscaped } .zip" ))
432
433
433
434
if not globResults :
434
435
print (f'Cannot find savefile: "{ saveName } "' )
@@ -601,7 +602,7 @@ def kill(pid, onlyStall=False):
601
602
time .sleep (0.4 )
602
603
603
604
# empty autorun.lua
604
- open ( "autorun.lua " , 'w' , encoding = "utf-8" ).close ()
605
+ Path ( __file__ , ".. " , "autorun.lua" ). resolve (). open ( 'w' , encoding = "utf-8" ).close ()
605
606
606
607
latest = []
607
608
with datapath .open ('r' , encoding = "utf-8" ) as f :
@@ -701,9 +702,10 @@ def refZoom():
701
702
for surfaceName , surfaceStuff in mapStuff ["surfaces" ].items ():
702
703
if "chunks" in surfaceStuff :
703
704
data ["maps" ][int (mapIndex )]["surfaces" ][surfaceName ]["chunks" ] = surfaceStuff ["chunks" ]
704
- for linkIndex , link in enumerate (surfaceStuff ["links" ]):
705
- data ["maps" ][int (mapIndex )]["surfaces" ][surfaceName ]["links" ][linkIndex ]["path" ] = link ["path" ]
706
- data ["maps" ][int (mapIndex )]["surfaces" ][surfaceName ]["links" ][linkIndex ]["zoom" ]["min" ] = link ["zoom" ]["min" ]
705
+ if "links" in surfaceStuff :
706
+ for linkIndex , link in enumerate (surfaceStuff ["links" ]):
707
+ data ["maps" ][int (mapIndex )]["surfaces" ][surfaceName ]["links" ][linkIndex ]["path" ] = link ["path" ]
708
+ data ["maps" ][int (mapIndex )]["surfaces" ][surfaceName ]["links" ][linkIndex ]["zoom" ]["min" ] = link ["zoom" ]["min" ]
707
709
destf .seek (0 )
708
710
json .dump (data , destf )
709
711
destf .truncate ()
0 commit comments