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

updater on windows #25

Open
szentigrad3 opened this issue Jun 4, 2017 · 10 comments · May be fixed by #67
Open

updater on windows #25

szentigrad3 opened this issue Jun 4, 2017 · 10 comments · May be fixed by #67
Labels

Comments

@szentigrad3
Copy link

szentigrad3 commented Jun 4, 2017

so i am trying to use this on windows and get this when trying to update

D:\szentigrade\Factorio\bin\x64>python update_factorio.py -u Szentigrade -t <excluded> -xDa D:\szentigrade\Factorio\bin\x64\factorio.exe
Version: 0.15.16 (build 30063, win64, alpha)
Binary version: 64
Map input version: 0.12.0-0
Map output version: 0.15.16-1
No updates available for version None (latest experimental is 0.15.18).
@narc0tiq
Copy link
Owner

narc0tiq commented Jun 4, 2017

I've honestly never tried it on Windows, and I do know for sure there's one definite incompatibility - it'll try using /tmp for temporary files by default. You will need to change that with the -O option (probably can tell it to use %TEMP%). Also, you must tell it which packages to get - it defaults to headless Linux builds - with the -p option (try "core-win64").

That said, this shouldn't apply here. To me, it looks like it's failed to read the current version out of the Factorio binary output. I have no idea why. I'll look into it when I get back to a computer tomorrow.

@narc0tiq narc0tiq added the bug label Jun 6, 2017
@narc0tiq
Copy link
Owner

narc0tiq commented Jun 8, 2017

Ok, so I have bad news -- the updater simply can't work with Factorio on Windows (to be fair, I've never tried it and am not sure why you'd want to):

  • Factorio on Windows exits immediately when called; a separate process writes to the console that spawned it, if such a console exists.
  • Therefore, the updater cannot capture output from factorio --version, so you must specify the version yourself (update_factorio.py --for-version 0.15.18)
  • The updater also can't apply more than one update at a time, because factorio --apply-update some\path\core-win64-0.15.18-0.15.19-update.zip returns immediately, but a second Factorio won't be able to apply the next update because the first one is in the middle of applying the first!
  • I needed to provide an output directory (with -O .\updates), which I needed to create first.
  • I needed to specify the package (-p core-win64).
    • the final command was python update_factorio.py -xD -u Narc -t <ellided> -p core-win64 -f 0.15.18 -O .\updates
  • Either the update didn't download correctly or something else went wrong, because trying to apply the update manually failed with Error Util.cpp:62: copy_file(p1, p2, options): invalid arguments: operation not permitted. On the other hand, it might be a UAC issue, so whatever.

The in-game updater worked flawlessly, so I'd recommend just using that.

This is the most support I can give to Windows; if you or anyone else can find a way to make it work, I accept pull requests! But that's as much time as I can spare for this.

@narc0tiq narc0tiq closed this as completed Jun 8, 2017
@Daeruun
Copy link

Daeruun commented Jun 19, 2017

on windows, you could do something like this - for example in an batch:

for /F "usebackq tokens=2,5* delims=, " %%i in ( `start "" /B "%application_path%" --version ^| findstr "Version" ` ) do (
 set current_version=%%i
 set package=core-%%j
)

and then call the python script with these variables
I'm not sure if it is possible to integrate that with the script, but i'll look into it if I find the time

@narc0tiq
Copy link
Owner

narc0tiq commented Jun 19, 2017

So you're saying that running it with start /B will let me read the output from that console?

Edit: Yup, this worked:

version_output = subprocess.check_output(["start", "/B", args.apply_to, "--version"], universal_newlines=True, shell=True)

@narc0tiq narc0tiq reopened this Jun 19, 2017
@Daeruun
Copy link

Daeruun commented Jun 19, 2017

at least it works in my batch - within the for-loop...

after that loop, this call:
echo. "python %~dp0Factorio-Updater/update_factorio.py -u username -t <secret> -p %package% -f %current_version% -O %output_path% -a %application_path% -x"
is giving me:
python J:\Factorio_0.15\Factorio-Updater/update_factorio.py -u username -t <secret> -p core-win64 -f 0.15.21 -O J:\Factorio_0.15\updates -a J:\Factorio_0.15\bin/x64/factorio.exe -x

@narc0tiq
Copy link
Owner

I finally had some time to try it again, and found the following:

  • The start call also needs a /WAIT, otherwise the script sees Factorio exiting immediately and deletes the update before it can be applied.
  • The updates often fail to apply for some reason, specifying this error: 0.000 Error Util.cpp:62: copy_file(p1, p2, options): invalid arguments: operation not permitted
  • Even when they don't fail as above, I finally discovered that even with the start /WAIT, you can only apply one update at a time, because after each update finishes, it launches Factorio.
  • And actually, I'm not convinced the updater does finish before the start returns.

I'm sorry, it's a lost cause -- Windows Factorio just doesn't want to work that way. On the other hand, all I'm doing is what the in-game updater is doing, so you should be able to use that instead.

@GideonBear
Copy link

GideonBear commented Nov 10, 2024

I'm using a modified version of your script to update the windows client, and I got it to work by constantly scanning all processes (with psutil):
The original process (that exits early) is called factorio.exe
Then there are two processes (that both live until the end of the update) named Factorio.exe. The second one only starts after you've accepted the administrator permissions.
Using this you can easily check (by assuming or checking that there are no factorio processes open beforehand) continually and wait until there are no processes left.
@narc0tiq voting to re-open, and can I make a PR for this? It should enable both using --delete-after-applying and applying multiple updates after each other.

@narc0tiq
Copy link
Owner

Well, I'm not going to officially support Windows but if you want to try to make it work I'll take the patch -- someone will find a use for it.

The only use I can think of is that if you have an unstable Internet connection, python-requests might be more lenient than the Factorio built-in (and we could fairly easily provide command-line arguments to allow the user to make it be more lenient). Actually, I just thought of another use: for a LAN party, it would probably be more efficient to download the patches once and just copy them to the other computers (but how often is that really a concern?).

Otherwise, I have a hard time figuring out why you'd want to use this given that

  • a) Factorio's in-game updater already knows how to download the patches
  • and b) we're still having to ask Factorio to process the update files

Also, please note there may not be an administrator/escalated process if your Factorio lives in an unprivileged location (e.g., I have mine in C:\Games\Factorio), but watching for any such processes is most likely going to work regardless.

@narc0tiq narc0tiq reopened this Nov 11, 2024
@GideonBear
Copy link

The only use I can think of is that if you have an unstable Internet connection, python-requests might be more lenient than the Factorio built-in (and we could fairly easily provide command-line arguments to allow the user to make it be more lenient). Actually, I just thought of another use: for a LAN party, it would probably be more efficient to download the patches once and just copy them to the other computers (but how often is that really a concern?).

Otherwise, I have a hard time figuring out why you'd want to use this given that

  • a) Factorio's in-game updater already knows how to download the patches
  • and b) we're still having to ask Factorio to process the update files

It's useful when the computer you're applying the patches on does not have a (reliable) internet connection, so you download the updates on another computer, and transfer them.

Well, I'm not going to officially support Windows but if you want to try to make it work I'll take the patch -- someone will find a use for it.

Alright, PR will be coming in the following days, probably this weekend. Thanks!

@GideonBear
Copy link

Also, although I don't run Factorio on Linux myself, I'll try to make that work too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants