TechieGuy12 / PlexServerAutoUpdater

Automatically update Plex when running the Plex service.
MIT License
118 stars 10 forks source link

SilentUpdate Only Checks Once #34

Open Hossy opened 5 years ago

Hossy commented 5 years ago

When using the -silent option, silentUpdate.Run() gets called and only calls CheckIfCanUpdate() once. If playCount is greater than 0, CheckIfCanUpdate() merely logs this and exits with success. There is a timer set (_timer), but it isn't allowed to run as the application exits. There is no loop to recheck playCount. _timer appears to be referenced in MainForm.cs, but is not used in SilentUpdate.cs.

https://github.com/TechieGuy12/PlexServerAutoUpdater/blob/651d6a431c20634decb3130471b1b631e232dd4d/MainForm.cs#L93

In windowed mode, you're running _timer which then calls OnTimedEvent which calls CheckIfCanUpdate(). This establishes the loop on WaitTime because CheckIfCanUpdate() will restart the timer if playCount is greater than 0.

In console mode, you have to keep the main thread busy doing something or the process will exit and all Timers will stop running.

My suggestion:

  1. Add a private boolean variable to MediaServer named _updateComplete and set to false
  2. Add an IsUpdateComplete() function to MediaServer to return _updateComplete
  3. Set _updateComplete in the finally block in MediaServer.Update() at the very end.
  4. Add a do-while loop inside the if (_server.IsUpdateAvailable()) block of SilentUpdate.Run() that checks !MediaServer.IsUpdateComplete() and sleeps WaitTime as an else to if (CheckIfCanUpdate())
Hossy commented 5 years ago

Log file:

2019-05-30 20:32:16 Getting windows user.
2019-05-30 20:32:17 Checking if user is an administrator.
2019-05-30 20:32:17 Initializing the silent update.
2019-05-30 20:32:20 Getting the service user.
2019-05-30 20:32:20 The Plex service is installed. Let's get the user associated with the service.
2019-05-30 20:32:20 The Plex service user: serviceaccount.
2019-05-30 20:32:20 Get the local data folder for Plex.
2019-05-30 20:32:20 Plex local data folder: C:\Users\serviceaccount\AppData\Local
2019-05-30 20:32:20 Verify the updates folder is specified.
2019-05-30 20:32:21 Getting ready to download the latest package.
2019-05-30 20:32:21 Checking for the latest version from Plex.
2019-05-30 20:32:21 The update channel is set for Plex Pass.
2019-05-30 20:32:22 Parsing the information from Plex.
2019-05-30 20:32:23 Creating folder: C:\Users\serviceaccount\AppData\Local\Plex Media Server\Updates\1.15.8.1163-005053bb5\packages.
2019-05-30 20:32:23 Downloading the latest installation package from Plex.
2019-05-30 20:32:28 Checking if the installation package is valid.
2019-05-30 20:32:28 The package is valid. The checksums match.
2019-05-30 20:32:28 Verify the updates folder, C:\Users\serviceaccount\AppData\Local\Plex Media Server\Updates exists.
2019-05-30 20:32:28 Checking to see if updates folder exists.
2019-05-30 20:32:28 Getting the latest update folder.
2019-05-30 20:32:28 Checking for the latest Plex packages folder.
2019-05-30 20:32:28 Get the latest packages file.
2019-05-30 20:32:28 Latest packages file: C:\Users\serviceaccount\AppData\Local\Plex Media Server\Updates\1.15.8.1163-005053bb5\packages\PlexMediaServer-1.15.8.1163-005053bb5-x86.exe
2019-05-30 20:32:29 Checking for server update.
2019-05-30 20:32:29 The server is in use. Waiting for all media to be stopped before performing the update.
TechieGuy12 commented 5 years ago

Thanks. I will look at this soon and make the necessary changes.

Hossy commented 5 years ago

Just wondering if you've had a chance to look at this

TechieGuy12 commented 5 years ago

I have not yet looked at it as life got a little busy. I am hoping to look at it this weekend.

Hossy commented 4 years ago

Just checking back in on this. :-) I really appreciate you writing this tool. It's been a life saver for my system!

AnthonyBe commented 4 years ago

Seeing same FYI :)