HIllya51 / LunaHook

Visual Novel Text Hook Engine / LunaTranslator 核心文本提取器
https://lunatranslator.xyz/
GNU General Public License v3.0
210 stars 14 forks source link

[Feature Request] Auto Updater #9

Closed rampaa closed 3 months ago

rampaa commented 3 months ago

LunaHook is getting updated frequently, which is a pretty good thing, but manually checking for new versions and installing them is a bit bothersome. If LunaHook were to have an option to auto check and install newer versions that would be awesome.

HIllya51 commented 3 months ago

I can only show the current version and auto query the latest version, and I will not auto install the new version. This project's module must inject to other process, which makes it uneasy to update.

rampaa commented 3 months ago

This project's module must inject to other process, which makes it uneasy to update

Wouldn't something like the following work regardless? 1) Check if there's any update, and if there is, ask the user if they want to install the latest version 2) If the user says they want to install the latest version, download the appropriate version from GitHub (e.g., Release_English.zip) 3) Unzip it to a folder like ../LunaHookDirectory/tmp 4) Run a .cmd file which will terminate LunaHook and move the contents of ../LunaHookDirectory/tmp to ../LunaHookDirectory and preferably re-launch LunaHook.

I've employed a similar technique for JL (see the update-helper.cmd file for inspiration), and it works decently well.

HIllya51 commented 3 months ago

In fact, in Lunatranslator, I have tried something similar like this. But the result is that many people have reported to me that the software cannot be opened after automatic updates. After checking, it was found that the file versions in the software were inconsistent after the update, because some files were updated to the new version but some files stayed in the old version due to being occupied, resulting in a crash. So I don't want to implement auto-update feature by this way anymore. And I think the currently implemented annotation of the latest version and the current version is enough.

rampaa commented 2 months ago

If I understand correctly, that script only retries terminating the process but it doesn't retry when copying a file fails, in fact it simply ignores any errors with the /c flag. In update-helper.cmd file, I retry to copy files 30 times with 1 second interval, which does work quite nicely. Here's what I would recommend in general:

1) Pass the PID of your process to the script and use that PID to forcibly terminate the process and any child processes it might have, so that you don't accidentally terminate a program that has the same name as your program (e.g., use TASKKILL with the /T, /F and /PID parameters). 2) When overwriting a file fails due to it apparently being used by another process retry the copy operation for a reasonable duration of time. See the /R:N and /W:N parameters of ROBOCOPY. Retrying it for a minute with 1 second intervals would be pretty reasonable IMO.

Before I started using the retry mechanism, JL did have a similar problem with its auto update functionality and the retry mechanism did solve the problem quite reliably.

I think the currently implemented annotation of the latest version and the current version is enough

Manually downloading and unzipping the file to the previous location I've placed LunaHook is still bothersome. 😢

HIllya51 commented 2 months ago

Because this program will interact with other game processes. When LunaHookX.dll is injected into the game, LunaHookX.dll will be occupied by the game process instead of this program, and it is impossible for me to kill the game process for this. And when this software crashes, usually taskkill by low privileges will not be able to kill the process, and taskkill must be performed using administrator privileges to realy kill the process. And I often like to update release without updating the version, so sometimes the latest version number does not mean that the software is really the latest. And I think it is not necessary to update this software very frequently. It is only necessary to update when you encounter a game that cannot be hooked correctly, then try to see if the latest version can solve the problem?

rampaa commented 2 months ago

When LunaHookX.dll is injected into the game, LunaHookX.dll will be occupied by the game process instead of this program

Wouldn't checking for updates and asking the user if they want to install the latest version at program start up (i.e., before injecting any games) solve this problem? Or can't you simply detach from the game before update, wouldn't that free LunaHookX.dll?

And I often like to update release without updating the version, so sometimes the latest version number does not mean that the software is really the latest.

Even ignoring my auto update feature request, from a user point-of-view, that makes things pretty confusing.

It is only necessary to update when you encounter a game that cannot be hooked correctly, then try to see if the latest version can solve the problem

That is fair. But I like to keep the software I use up-to-date. And the less manual effort I need to exercise for that the better. Being able to update a software with a single click is a pretty nice thing.

HIllya51 commented 2 months ago

I really don't want to do it at all, it's way beyond what a hooker should do. And actually you can write a simple script to do this, it's too complicated to do this in C++. And you can also use script to check the hash value of the file to determine whether it is truly the latest version.