private void LoadPlaylist(ProgressInfo progress) { JRPlaylist pl = progress.args[0] as JRPlaylist; pl.Files = new List <JRFile>(); progress.totalItems = pl.Count; int i = 0; List <string> fields = new List <string>(); foreach (var f in state.TableFields) { if (jrAPI.FieldMap.TryGetValue(f.ToLower(), out string name)) { fields.Add(name); } } foreach (var file in jrAPI.getFiles(pl, fields)) { pl.Files.Add(file); progress.currentItem = ++i; progress.subtitle = $"{file.Name} ({file.Year})"; progress.Update(false); } }
private void ConnectJRiver(ProgressInfo progress) { progress.result = false; progress.subtitle = "Starting MediaCenter"; progress.Update(true); if (!jrAPI.Connect()) { return; } progress.subtitle = "Reading fields"; progress.Update(); jrAPI.getFields(); // syntax highlighter foreach (var tab in expressionTabs) { tab.highlighter = new ELSyntax(jrAPI.FieldsHighlight, settings.ExtraFunctions); } progress.subtitle = "Reading playlists"; progress.Update(true); var lists = jrAPI.getPlaylists(settings.PlaylistFilter, !settings.FastStart).ToList(); progress.result = true; }
public static void FindLatestRelease(ProgressInfo progress) { try { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://api.github.com"); client.DefaultRequestHeaders.Add("User-Agent", "Microsoft .Net HttpClient"); // needed for github HttpResponseMessage response = client.GetAsync(GitHubReleaseURL).Result; if (response.IsSuccessStatusCode) { string result = response.Content.ReadAsStringAsync().Result; lastCheck = DateTime.Now; LatestVersion = VersionInfo.Parse(result); if (progress != null) { progress.result = true; } return; } } } catch { } if (progress != null) { progress.result = false; } }
public ProgressUI(string title, Action <ProgressInfo> action, bool canCancel = true, params object[] args) { InitializeComponent(); bgAction = action; this.progress = new ProgressInfo(title) { args = args, canCancel = canCancel }; init(); }
public static void DoUpgrade(ProgressInfo progress) { try { string tmpFile = Path.Combine(Path.GetTempPath(), $"Zelda.{LatestVersion.version}.tmp"); if (File.Exists(tmpFile)) { File.Delete(tmpFile); } using (var client = new WebClient()) { progress.subtitle = "downloading new version"; progress.Update(); client.Headers.Add("User-Agent", "Microsoft .Net HttpClient"); client.DownloadFile(LatestVersion.package, tmpFile); progress.subtitle = "upgrading"; string currEXE = Assembly.GetEntryAssembly().Location; string bakFile = Path.ChangeExtension(currEXE, ".bak"); if (File.Exists(bakFile)) { File.Delete(bakFile); } File.Move(currEXE, bakFile); File.Move(tmpFile, currEXE); progress.result = true; restartNeeded = true; progress.subtitle = "starting new version"; Application.Restart(); return; } } catch { } progress.result = false; }