async Task addNewOrFromMru(StorageFile sf) { var sz = (await sf.GetBasicPropertiesAsync()).Size; if (sz > 10000) // 500,000 <== a typical pod.anons is 200k ==> anything below 10k is corrupt. { var fsMid = new MediaInfoDto(sf); var liMid = LibLst.FirstOrDefault(r => r.FileOnly.Equals(fsMid.FileOnly, StringComparison.OrdinalIgnoreCase)); if (liMid != null) // already in the Lib list { return; } var mrMid = MruLst.FirstOrDefault(r => r.FileOnly.Equals(fsMid.FileOnly, StringComparison.OrdinalIgnoreCase)); if (mrMid != null) { await mrMid.SetThumbnail(sf); LibLst.Add(mrMid); } else { await fsMid.SetThumbnail(sf); LibLst.Add(fsMid); } } else { Debug.WriteLine($"{sf.DisplayName}\t Too tiny to add: {(sz * .001):N0} kb "); } }
async Task setNext(MediaInfoDto mid) { await addToMruListIfNotThere(mid); //SlctPLs = PLsLst.FirstOrDefault(r => r.FileOnly.Equals(mid.FileOnly, StringComparison.OrdinalIgnoreCase)); SlctMru = MruLst.FirstOrDefault(r => r.FileOnly.Equals(mid.FileOnly, StringComparison.OrdinalIgnoreCase)); SlctLib = LibLst.FirstOrDefault(r => r.FileOnly.Equals(mid.FileOnly, StringComparison.OrdinalIgnoreCase)); }
async Task <Tuple <bool, string> > trySetNextFromMru(MediaInfoDto mid) { if (MruLst.Count <= 1) { return(Tuple.Create(false, "Nothing to play in the MRU list")); } var nxtFromMru = MruLst.FirstOrDefault(r => !r.FileOnly.Equals(mid.FileOnly, StringComparison.OrdinalIgnoreCase)); if (nxtFromMru == null) { return(Tuple.Create(false, "This is the last file in the MRU list.")); } else { await setNext(nxtFromMru); return(Tuple.Create(true, "")); } }
async void updateSaveSettings() { try { if (Cur == null) { return; } try { var cur = MruLst.FirstOrDefault(r => r.FileOnly.Equals(Cur.FileOnly, StringComparison.OrdinalIgnoreCase)); if (cur == null) { return; } if (!Cur.Equals(cur)) { Cur = cur; } if ( Cur.PlayPosn == mp_Xm.PlaybackSession.Position && Cur.PlayLeng == mp_Xm.PlaybackSession.NaturalDuration && Cur.LastPcNm == DevOp.MachineName) { return; } Cur.PlayPosn = mp_Xm.PlaybackSession.Position; Cur.PlayLeng = mp_Xm.PlaybackSession.NaturalDuration; Cur.LastPcNm = DevOp.MachineName; Cur.LastUsed = DateTime.Now; //AppSettingsHelper.RemoVal(AppSetConst.Mru4Roam); AppSettingsHelper.SaveVal(AppSetConst.Mru4Roam, JsonHelper.ToJson(MruLst)); AppSettingsHelper.SaveVal(AppSetConst.PagesTtl, PagesTtl); AppSettingsHelper.SaveVal(AppSetConst.PlayRate, mp_Xm.PlaybackSession.PlaybackRate); tbDbg3.Text = tbInfo.Text += "."; } catch (COMException ex) { Debug.WriteLine($"$#~>{ex.Message}"); var min = MruLst.Min(x => x.LastUsed); if (MruLst.Any(r => r.LastUsed == min)) { var mru = MruLst.FirstOrDefault(r => r.LastUsed == min); MruLst.Remove(mru); await Speak($"Max limit exceeded. Removing {mru.FileOnly}"); updateSaveSettings(); } else { await Speak($"the history has {MruLst.Count} files. i.e.: nothing to remove."); } } catch (Exception ex) { Debug.WriteLine($"$#~>{ex.Message}"); if (Debugger.IsAttached) { Debugger.Break(); } else { await popEx(ex, "updateStngs"); } } } finally { Debug.WriteLine("--- UpdtStng "); } }
async void updateSaveSettings(string s) { try { if (SlctMru == null) { return; } try { if (mp_Vm.PlaybackSession.NaturalDuration == TimeSpan.Zero || ( SlctMru.PlayPosn.TotalSeconds >= mp_Vm.PlaybackSession.Position.TotalSeconds && SlctMru.PlayLeng == mp_Vm.PlaybackSession.NaturalDuration && SlctMru.LastPcNm == DevOp.MachineName)) { return; } if (SlctMru.PlayPosn < mp_Vm.PlaybackSession.Position) { SlctMru.PlayPosn = mp_Vm.PlaybackSession.Position; } SlctMru.PlayLeng = mp_Vm.PlaybackSession.NaturalDuration; SlctMru.LastPcNm = DevOp.MachineName; SlctMru.LastUsed = DateTime.Now; AppSettingsHelper.SaveStr(AppSetConst.Mru4Roam, JsonHelper.ToJson(MruLst)); AppSettingsHelper.SaveVal(AppSetConst.PagesTtl, PagesTtl); AppSettingsHelper.SaveVal(AppSetConst.PlayRate, mp_Vm.PlaybackSession.PlaybackRate); if (Dispatcher.HasThreadAccess) { TbInfo += $"{s}"; } else { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => TbInfo += $"{s}°"); } } catch (COMException ex) { Debug.WriteLine($"$#~>{ex.Message}"); var min = MruLst.Min(x => x.LastUsed); if (MruLst.Any(r => r.LastUsed == min)) { var mru = MruLst.FirstOrDefault(r => r.LastUsed == min); await Speak($"Max limit exceeded. Removing {mru.FileOnly}"); MruLst.Remove(mru); updateSaveSettings("x"); } else { await Speak($"the history has {MruLst.Count} files. i.e.: nothing to remove."); } } catch (Exception ex) { Debug.WriteLine($"$#~>{ex.Message}"); if (Debugger.IsAttached) { Debugger.Break(); } else { await popEx(ex, GetType().FullName); } } } finally { Debug.WriteLine($"{s}·"); } }