private void _CleanFiles(UpdateSettings settings)
        {
            var           fileInfo = new FileInfo(typeof(UpdaterServiceBase).Assembly.Location);
            DirectoryInfo appDi    = fileInfo.Directory;

            //var updaterPath = UnzipDirPath;// Path.Combine(appDi.FullName, "updates", UnzipDirPath);
            string[] extensions = new[] { ".dll", ".pdb" };
            var      filesLst   = appDi.GetFiles()
                                  .Where(f => extensions.Contains(f.Extension.ToLower()))
                                  .ToArray();

            foreach (FileInfo file in filesLst)
            {
                file.Delete();
            }
            //string[] folders = { "clientSources", "refs", "runtimes", "Views", "wwwroot" };
            string[] foldersNotToDelete = { "updates", "logs" };
            if (settings?.ExcludedDirectoriesFromClean != null)
            {
                foldersNotToDelete = foldersNotToDelete.Concat(settings.ExcludedDirectoriesFromClean).Select(x => x.ToLower()).ToArray();
            }
            foreach (DirectoryInfo dir in appDi.GetDirectories())
            {
                if (!foldersNotToDelete.Contains(dir.Name.ToLower()))
                {
                    dir.Delete(true);
                }
            }
        }
        public async Task CompleteUpdateAsync(Action onSuccess)
        {
            //_logger.LogInformation("NeedsUpdate");
            LogInfo("NeedsUpdate");
            await Task.Delay(3000);

            //System.Threading.Thread.Sleep(3000); //perimeno na einai sigouros oti sou ir8e to updating.html
            var fileInfo = new FileInfo(typeof(UpdaterServiceBase).Assembly.Location);

            //do update
            if (CurrentOS == OSPlatform.Windows)
            {
                using (var s = typeof(UpdaterServiceBase).Assembly.GetManifestResourceStream("AspNetCoreAutoUpdater.Resources.AspNetCoreAutoUpdater.IISHandler.zip"))
                {
                    ExtractFromStream(s, fileInfo.Directory.FullName);
                }
                var webconfig = Path.Combine(fileInfo.Directory.FullName, "web.config");
                if (File.Exists(webconfig))
                {
                    _replaceNetCoreDllInWebConfig(webconfig, _options.AppEntryDll, "AspNetCoreAutoUpdater.IISHandler.dll");
                }
            }
            else //OSPlatform.Linux
            {
                //_logger.LogInformation("Linux Update Start copying files");
                LogInfo("Linux Update Start copying files");
                try
                {
                    DirectoryInfo  appDi        = fileInfo.Directory;
                    var            settingsFile = Path.Combine(appDi.FullName, "UpdateSettings.json");
                    var            ser          = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(UpdateSettings));
                    UpdateSettings settings     = null;
                    using (Stream stream = File.OpenRead(settingsFile))
                    {
                        settings = ser.ReadObject(stream) as UpdateSettings;
                    }
                    _CleanFiles(settings);

                    //Now Create all of the directories
                    foreach (string dirPath in Directory.GetDirectories(UnzipDirPath, "*", SearchOption.AllDirectories))
                    {
                        Directory.CreateDirectory(dirPath.Replace(UnzipDirPath, appDi.FullName));
                    }
                    //Copy all the files & Replaces any files with the same name
                    foreach (string newPath in Directory.GetFiles(UnzipDirPath, "*.*", SearchOption.AllDirectories))
                    {
                        System.IO.File.Copy(newPath, newPath.Replace(UnzipDirPath, appDi.FullName), true);
                    }
                }
                catch (Exception ex)
                {
                    LogError("Linux Update Failed! \n Exception:{Exception} \n StackTrace: {StackTrace}", ex.GetAllMessages(), ex.StackTrace);
                    //_logger.LogError("Linux Update Failed! \n Exception:{Exception} \n StackTrace: {StackTrace}", ex.GetAllMessages(), ex.StackTrace);
                }
            }

            LogInfo("Program.Shutdown");
            onSuccess.Invoke();  //on the app ---> Program.Shutdown();
        }
        public void CreateSettingsFile()
        {
            var src  = Path.Combine(UnzipDirPath, "UpdateSettings.json");
            var dest = Path.Combine(_options.ContentRootPath, "UpdateSettings.json");

            if (File.Exists(src))
            {
                LogDebug("Copying from {0} to {1}", src, dest);
                File.Copy(src, dest, true);
            }
            else
            {
                //onCreatingUpdateSettings();
                LogDebug("Creating UpdateSettings.json");
                var updateSettings = new UpdateSettings()
                {
                    AppEntryDll   = _options.AppEntryDll,
                    DirectoryName = new DirectoryInfo(UnzipDirPath).Name,
                    ExcludedDirectoriesFromClean = new string[] { }
                };
                var s = Newtonsoft.Json.JsonConvert.SerializeObject(updateSettings);
                File.WriteAllText(dest, s);
            }
        }