Ejemplo n.º 1
0
        private void WaitForEvent()
        {
            trayLockService.WaitForSignal();
            logger.Info("Received signal from tray lock service");

            if (windowsService.ServiceExists() && windowsService.ServiceRunning())
            {
                //We won't be able to start the tray app up again from the updater, as when running via a windows service there is no interaction with the desktop
                //Fire off a console process that will start the tray 20 seconds later

                var trayExePath = Assembly.GetEntryAssembly().Location;

                var startInfo = new ProcessStartInfo()
                {
                    Arguments       = $"/c timeout 20 > NUL & \"{trayExePath}\" --UpdatedVersion yes",
                    FileName        = "cmd.exe",
                    UseShellExecute = true,
                    CreateNoWindow  = true,
                    WindowStyle     = ProcessWindowStyle.Hidden
                };

                logger.Info("Starting 20 second delay tray launch as Jackett is running as a Windows service: " + startInfo.FileName + " " + startInfo.Arguments);
                Process.Start(startInfo);
            }

            CloseTrayApplication();
        }
Ejemplo n.º 2
0
        private void WaitForEvent()
        {
            trayLockService.WaitForSignal();
            logger.Info("Received signal from tray lock service");

            if (windowsService.ServiceExists() && windowsService.ServiceRunning())
            {
                // We won't be able to start the tray app up again from the updater, as when running via a windows service
                // there is no interaction with the desktop.
                // Fire off a console process that will start the tray 30 seconds later
                // changed to 120 seconds as a result of https://github.com/Jackett/Jackett/issues/10068
                var trayExePath = Process.GetCurrentProcess().MainModule.FileName;

                var startInfo = new ProcessStartInfo()
                {
                    Arguments       = $"/c timeout 120 > NUL & \"{trayExePath}\" --UpdatedVersion yes",
                    FileName        = "cmd.exe",
                    UseShellExecute = true,
                    CreateNoWindow  = true,
                    WindowStyle     = ProcessWindowStyle.Hidden
                };

                logger.Info($"Starting 120 second delay tray launch as Jackett is running as a Windows service: {startInfo.FileName} {startInfo.Arguments}");
                Process.Start(startInfo);
            }

            CloseTrayApplication();
        }
Ejemplo n.º 3
0
        private void WaitForEvent()
        {
            trayLockService.WaitForSignal();
            logger.Info("Received signal from tray lock service");

            if (windowsService.ServiceExists() && windowsService.ServiceRunning())
            {
                // We won't be able to start the tray app up again from the updater, as when running via a windows
                // service there is no interaction with the desktop.

                var scriptPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "jackett_launcher.bat");
                var startInfo  = new ProcessStartInfo()
                {
                    Arguments       = $"/c \"{scriptPath}\"",
                    FileName        = "cmd.exe",
                    UseShellExecute = true,
                    CreateNoWindow  = true,
                    WindowStyle     = ProcessWindowStyle.Hidden
                };

                logger.Info($"Starting launcher script as Jackett is running as a Windows service: {startInfo.FileName} {startInfo.Arguments}");
                Process.Start(startInfo);
            }

            CloseTrayApplication();
        }
Ejemplo n.º 4
0
        private void StartUpdate(string updaterExePath, string installLocation, bool isWindows, bool noRestart, bool trayIsRunning)
        {
            var appType = "Console";

            if (isWindows && windowsService.ServiceExists() && windowsService.ServiceRunning())
            {
                appType = "WindowsService";
            }

            var exe  = Path.GetFileName(ExePath());
            var args = string.Join(" ", Environment.GetCommandLineArgs().Skip(1).Select(a => a.Contains(" ") ? "\"" + a + "\"" : a)).Replace("\"", "\\\"");

            var startInfo = new ProcessStartInfo
            {
                UseShellExecute = false,
                CreateNoWindow  = true
            };

            // Note: add a leading space to the --Args argument to avoid parsing as arguments
            if (variant == Variants.JackettVariant.Mono)
            {
                // Wrap mono
                args = exe + " " + args;

                startInfo.Arguments = $"{Path.Combine(updaterExePath)} --Path \"{installLocation}\" --Type \"{appType}\" --Args \" {args}\"";
                startInfo.FileName  = "mono";
            }
            else
            {
                startInfo.Arguments = $"--Path \"{installLocation}\" --Type \"{appType}\" --Args \" {args}\"";
                startInfo.FileName  = Path.Combine(updaterExePath);
            }

            try
            {
                var pid = Process.GetCurrentProcess().Id;
                startInfo.Arguments += $" --KillPids \"{pid}\"";
            }
            catch (Exception e)
            {
                logger.Error($"Unexpected error while retriving the PID.\n{e}");
            }

            if (noRestart)
            {
                startInfo.Arguments += " --NoRestart";
            }

            if (trayIsRunning && appType == "Console")
            {
                startInfo.Arguments += " --StartTray";
            }

            // create .lock file to detect errors in the update process
            var lockFilePath = Path.Combine(installLocation, ".lock");

            if (!File.Exists(lockFilePath))
            {
                File.Create(lockFilePath).Dispose();
            }

            logger.Info($"Starting updater: {startInfo.FileName} {startInfo.Arguments}");
            var procInfo = Process.Start(startInfo);

            logger.Info($"Updater started process id: {procInfo.Id}");

            if (!noRestart)
            {
                if (isWindows)
                {
                    logger.Info("Signal sent to lock service");
                    lockService.Signal();
                    Thread.Sleep(2000);
                }

                logger.Info("Exiting Jackett..");
                Environment.Exit(0);
            }
        }