Пример #1
0
        private void Verify(string targetFolder, int processId)
        {
            _logger.Info("Verifying requirements before update...");

            if (string.IsNullOrWhiteSpace(targetFolder))
            {
                throw new ArgumentException("Target folder can not be null or empty");
            }

            if (!_diskProvider.FolderExists(targetFolder))
            {
                throw new DirectoryNotFoundException("Target folder doesn't exist " + targetFolder);
            }

            if (processId < 1)
            {
                throw new ArgumentException("Invalid process ID: " + processId);
            }

            if (!_processProvider.Exists(processId))
            {
                throw new ArgumentException("Process with ID doesn't exist " + processId);
            }

            _logger.Info("Verifying Update Folder");
            if (!_diskProvider.FolderExists(_appFolderInfo.GetUpdatePackageFolder()))
            {
                throw new DirectoryNotFoundException("Update folder doesn't exist " + _appFolderInfo.GetUpdatePackageFolder());
            }
        }
Пример #2
0
        public AppType GetAppType()
        {
            if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME) &&
                _serviceProvider.IsServiceRunning(ServiceProvider.NZBDRONE_SERVICE_NAME))
            {
                return(AppType.Service);
            }

            if (_processProvider.Exists(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME))
            {
                return(AppType.Console);
            }

            return(AppType.Normal);
        }
Пример #3
0
        public AppType GetAppType()
        {
            if (OsInfo.IsNotWindows)
            {
                // Technically it is the console, but it has been renamed for mono (Linux/OS X)
                return(AppType.Normal);
            }

            if (_serviceProvider.ServiceExist(ServiceProvider.OmbiServiceName))
            {
                return(AppType.Service);
            }

            if (_processProvider.Exists(ProcessProvider.OmbiProcessName))
            {
                return(AppType.Console);
            }

            return(AppType.Normal);
        }
Пример #4
0
        public AppType GetAppType()
        {
            if (OsInfo.IsNotWindows)
            {
                //Tehcnically its the console, but its been renamed for mono (Linux/OS X)
                return(AppType.Normal);
            }

            if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME) &&
                _serviceProvider.IsServiceRunning(ServiceProvider.NZBDRONE_SERVICE_NAME))
            {
                return(AppType.Service);
            }

            if (_processProvider.Exists(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME))
            {
                return(AppType.Console);
            }

            return(AppType.Normal);
        }
Пример #5
0
        public void Start(UpdateStartupContext ctx)
        {
            var dector = new DetectApplicationType();

            var processId = _processProvider.FindProcessByName(ProcessProvider.OmbiProcessName)?.FirstOrDefault()?.Id ?? -1;

            // Log if process is -1

            var dir = CreateTempPath();

            TempPath = Path.Combine(dir.FullName, "OmbiUpdate.zip");
            using (var client = new WebClient())
            {
                client.DownloadProgressChanged += (s, e) =>
                {
                    Console.WriteLine($"{e.ProgressPercentage}%");
                };
                client.DownloadFile(ctx.DownloadPath, TempPath);
            }

            var appType = dector.GetAppType();

            _processProvider.FindProcessByName(ProcessProvider.OmbiProcessName);
            var installationFolder = GetInstallationDirectory(ctx);
            var terminator         = new TerminateOmbi(new ServiceProvider(_processProvider), _processProvider);

            if (OsInfo.IsWindows)
            {
                terminator.Terminate(processId);
            }
            try
            {
                BackupCurrentVersion();
                EmptyInstallationFolder();

                using (var archive = ZipFile.OpenRead(TempPath))
                {
                    foreach (var entry in archive.Entries)
                    {
                        var fullname = string.Empty;
                        if (entry.FullName.Contains("Release/")) // Don't extract the release folder, we are already in there
                        {
                            fullname = entry.FullName.Replace("Release/", string.Empty);
                        }
                        if (entry.Name.Contains("UpdateService"))
                        {
                            fullname = entry.FullName.Replace("UpdateService", "UpdateService_New");
                        }

                        var fullPath = Path.Combine(PathUp(Path.GetDirectoryName(Application.ExecutablePath), 1), fullname);



                        if (string.IsNullOrEmpty(entry.Name))
                        {
                            Directory.CreateDirectory(fullPath);
                        }
                        else
                        {
                            if (entry.Name.Contains("Updater"))
                            {
                                continue;
                            }

                            entry.ExtractToFile(fullPath, true);
                            Console.WriteLine("Restored {0}", entry.FullName);
                        }
                    }
                }

                // Need to install here
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                RestoreBackup();
                throw;
            }
            finally
            {
                var startOmbi = new StartOmbi(new ServiceProvider(_processProvider), _processProvider);
                if (OsInfo.IsWindows)
                {
                    startOmbi.Start(appType, installationFolder);
                }
                else
                {
                    terminator.Terminate(processId);

                    Logger.Info("Waiting for external auto-restart.");
                    for (int i = 0; i < 5; i++)
                    {
                        System.Threading.Thread.Sleep(1000);

                        if (_processProvider.Exists(ProcessProvider.OmbiProcessName))
                        {
                            Logger.Info("Ombi was restarted by external process.");
                            break;
                        }
                    }

                    if (!_processProvider.Exists(ProcessProvider.OmbiProcessName))
                    {
                        startOmbi.Start(appType, installationFolder, ctx.StartupArgs);
                    }
                }
            }
        }