/// <summary> /// Saves the series to cache /// </summary> /// <param name="series">The series to save</param> public void SaveToCache(TvdbSeries series) { String root = _rootFolder + Path.DirectorySeparatorChar + series.Id; if (!Directory.Exists(root)) { Directory.CreateDirectory(root); } _seriesLock.EnterWriteLock(); try { try { //delete old cached content String[] files = Directory.GetFiles(root, "*.xml"); foreach (String f in files) { File.Delete(f); } } catch (Exception ex) { Log.Warn("Couldn't delete old cache files", ex); } foreach (KeyValuePair <TvdbLanguage, TvdbSeriesFields> kvp in series.SeriesTranslations) { //write all languages to file String fName = root + Path.DirectorySeparatorChar + kvp.Key.Abbriviation + (kvp.Value.EpisodesLoaded ? "_full" : "") + ".xml"; _xmlWriter.WriteSeriesContent(new TvdbSeries(kvp.Value), fName); } if (series.BannersLoaded) { //write the banners file _xmlWriter.WriteSeriesBannerContent(series.Banners, root + Path.DirectorySeparatorChar + "banners.xml"); } if (series.TvdbActorsLoaded) { //write the actors file _xmlWriter.WriteActorFile(series.TvdbActors, root + Path.DirectorySeparatorChar + "actors.xml"); } } finally { _seriesLock.ExitWriteLock(); } }
/// <summary> /// Saves the series to cache /// </summary> /// <param name="_series">The series to save</param> public void SaveToCache(TvdbSeries _series) { String root = m_rootFolder + Path.DirectorySeparatorChar + _series.Id; if (!Directory.Exists(root)) { Directory.CreateDirectory(root); } try {//delete old cached content String[] files = Directory.GetFiles(root, "*.xml"); foreach (String f in files) { File.Delete(f); } } catch (Exception ex) { Log.Warn("Couldn't delete old cache files", ex); } foreach (TvdbLanguage l in _series.GetAvailableLanguages()) {//write all languages to file String fName = root + Path.DirectorySeparatorChar + l.Abbriviation + (_series.EpisodesLoaded ? "_full" : "") + ".xml"; _series.SetLanguage(l); m_xmlWriter.WriteSeriesContent(_series, fName); } if (_series.BannersLoaded) {//write the banners file m_xmlWriter.WriteSeriesBannerContent(_series.Banners, root + Path.DirectorySeparatorChar + "banners.xml"); } if (_series.TvdbActorsLoaded) {//write the actors file m_xmlWriter.WriteActorFile(_series.TvdbActors, root + Path.DirectorySeparatorChar + "actors.xml"); } }
/// <summary> /// Saves the series to cache /// </summary> /// <param name="_series">The series to save</param> public void SaveToCache(TvdbSeries _series) { if (!Directory.Exists(m_rootFolder)) { Directory.CreateDirectory(m_rootFolder); } String root = m_rootFolder + "\\" + _series.Id; m_xmlWriter.WriteSeriesContent(_series, root + "\\all.xml"); TvdbLanguage defaultLang = _series.Language; foreach (TvdbLanguage l in _series.GetAvailableLanguages()) { if (l != defaultLang) { _series.SetLanguage(l); m_xmlWriter.WriteSeriesContent(_series, root + "\\" + l.Abbriviation + ".xml"); } } if (_series.BannersLoaded) { m_xmlWriter.WriteSeriesBannerContent(_series.Banners, root + "\\banners.xml"); } if (_series.TvdbActorsLoaded) { m_xmlWriter.WriteActorFile(_series.TvdbActors, root + "\\actors.xml"); } //Save all loaded banners to file foreach (TvdbBanner b in _series.Banners) { FileInfo file = new FileInfo(root + "\\banner_" + b.Id + ".jpg"); if (b.IsLoaded && !file.Exists) {//banner is cached if (!file.Directory.Exists) { file.Directory.Create(); } b.Banner.Save(file.FullName); } if (b.GetType() == typeof(TvdbFanartBanner)) {//banner is fanart -> has vignette and thumb file = new FileInfo(root + "\\bannerthumb_" + b.Id + ".jpg"); if (((TvdbFanartBanner)b).IsThumbLoaded && !file.Exists) { if (!file.Directory.Exists) { file.Directory.Create(); } ((TvdbFanartBanner)b).BannerThumb.Save(file.FullName); } file = new FileInfo(root + "\\bannervignette_" + b.Id + ".jpg"); if (((TvdbFanartBanner)b).IsVignetteLoaded && !file.Exists) { if (!file.Directory.Exists) { file.Directory.Create(); } ((TvdbFanartBanner)b).VignetteImage.Save(file.FullName); } } } if (_series.EpisodesLoaded) { foreach (TvdbEpisode e in _series.Episodes) { FileInfo file = new FileInfo(root + "\\EpisodeImages\\S" + e.SeasonNumber + "E" + e.EpisodeNumber + ".jpg"); if (e.Banner != null && e.Banner.IsLoaded && !file.Exists) { if (!file.Directory.Exists) { file.Directory.Create(); } e.Banner.Banner.Save(file.FullName); } } } if (_series.TvdbActorsLoaded) { foreach (TvdbActor a in _series.TvdbActors) { FileInfo file = new FileInfo(root + "\\actor_" + a.ActorImage.Id + ".jpg"); if (a.ActorImage.IsLoaded && !file.Exists) { if (!file.Directory.Exists) { file.Directory.Create(); } a.ActorImage.Banner.Save(file.FullName); } } } }