void UpdaterDoWork(object sender, DoWorkEventArgs e) { BackgroundWorker bw = (BackgroundWorker)sender; string status = Processing.GetResourceString("update_downloading_status"); string progressFmt = Processing.GetResourceString("update_downloading_progress"); string unzippingStatus = Processing.GetResourceString("update_unzipping"); string reloadStatus = Processing.GetResourceString("update_reload_versions"); string finishedStatus = Processing.GetResourceString("update_finished"); string importProfiles = Processing.GetResourceString("update_import_profiles"); string tempPath = AppSettings.TempPath; foreach (ToolVersions item in _tempToolCollection) { string showName = item.ToolName; bw.ReportProgress(-1, string.Format(status, showName, item.ServerVersion)); string outFPath = Path.GetDirectoryName(item.FileName); if (!string.IsNullOrEmpty(outFPath) && !Directory.Exists(outFPath)) Directory.CreateDirectory(outFPath, DirSecurity.CreateDirSecurity(SecurityClass.Everybody)); tempPath = outFPath; WebClient downloader = new WebClient {UseDefaultCredentials = true}; downloader.DownloadFileAsync(new Uri(item.DownloadUri), item.FileName); ToolVersions lItem = item; downloader.DownloadProgressChanged += (s, ev) => { string progress = string.Format(progressFmt, showName, lItem.ServerVersion, ev.ProgressPercentage); bw.ReportProgress(ev.ProgressPercentage, progress); }; while (downloader.IsBusy) Thread.Sleep(200); switch (lItem.DownloadType) { case AppType.Updater: if (!string.IsNullOrEmpty(AppSettings.UpdaterPath) && !Directory.Exists(AppSettings.UpdaterPath)) Directory.CreateDirectory(AppSettings.UpdaterPath, DirSecurity.CreateDirSecurity(SecurityClass.Everybody)); bw.ReportProgress(-1, unzippingStatus); try { using (ZipFile zFile = new ZipFile(lItem.FileName)) { foreach (ZipEntry entry in zFile) { if (AppSettings.UpdaterPath == null) continue; string outPath = Path.Combine(AppSettings.UpdaterPath, entry.Name); if (entry.IsDirectory) Directory.CreateDirectory(outPath, DirSecurity.CreateDirSecurity(SecurityClass.Everybody)); else if (entry.IsFile) { using (Stream zStream = zFile.GetInputStream(entry), outFile = new FileStream(outPath, FileMode.Create)) { zStream.CopyTo(outFile); } } } } File.Delete(item.FileName); } catch (Exception ex) { Log.ErrorFormat("Error reading \"{0:s}\" -> {1:s}", item.FileName, ex.Message); } break; case AppType.Profiles: try { bw.ReportProgress(-1, importProfiles); List<EncoderProfile> importedProfiles = ProfilesHandler.ImportProfiles(lItem.FileName); ProfilesHandler profiles = new ProfilesHandler(); foreach (EncoderProfile profile in profiles.ProfileList) { try { EncoderProfile selProfile = importedProfiles.Single( encoderProfile => encoderProfile.Name == profile.Name && encoderProfile.Type == profile.Type); importedProfiles.Remove(selProfile); } catch (Exception importException) { Log.Error(importException); } } foreach (EncoderProfile encoderProfile in importedProfiles) { profiles.AddProfile(encoderProfile); } profiles.Destroy(); AppSettings.LastProfilesVer = lItem.ServerVersion; } catch (Exception exProfiles) { Log.Error(exProfiles); } break; default: { _mainAppUpdate = true; PackageInfo package = new PackageInfo { PackageName = item.ToolName, PackageLocation = item.FileName, Version = item.ServerVersion, Destination = item.Destination, WriteVersion = item.DownloadType == AppType.AviSynthPlugins, ClearDirectory = item.DownloadType == AppType.MainApp, RecursiveClearDirectory = item.DownloadType == AppType.AviSynthPlugins }; _packages.Add(package); } break; } bw.ReportProgress(-20, item); } if (_packages.Count > 0) { if (tempPath != null) MainAppUpdateFile = Path.Combine(tempPath, "update.xml"); Updater.SaveUpdateList(MainAppUpdateFile, _packages); } else { bw.ReportProgress(-1, reloadStatus); Processing.GetAppVersions(); } bw.ReportProgress(0, finishedStatus); }
void ProfilesWorkerDoWork(object sender, DoWorkEventArgs e) { _profiles = new ProfilesHandler(); }