Exemple #1
0
 public async Task <IList <NicoVideoCacheRequest> > LoadDownloadRequestItems()
 {
     if (await _CacheRequestedItemsFileAccessor.ExistFile())
     {
         return(await _CacheRequestedItemsFileAccessor.Load());
     }
     else
     {
         return(new List <NicoVideoCacheRequest>());
     }
 }
Exemple #2
0
		public async Task<bool> LoadFeedStream(FileAccessor<List<FeedItem>> fileAccessor)
		{
			try
			{
				var items = await fileAccessor.Load();
				this.FeedItems = items ?? new List<FeedItem>();

				return true;
			}
			catch
			{
				return false;
			}
		}
Exemple #3
0
        public async Task Load(IReadOnlyList <StorageFile> files)
        {
            var feedGroupFolder = await GetFeedGroupFolder();

            var feedStreamDataFolder = await GetFeedStreamDataFolder();

            var legacyFeedSettingsFolder = await HohoemaApp.GetFeedSettingsFolder();


            foreach (var file in files)
            {
                if (file.FileType == ".json")
                {
                    var fileName     = file.Name;
                    var fileAccessor = new FileAccessor <FeedGroup2>(feedGroupFolder, fileName);

                    try
                    {
                        var item = await fileAccessor.Load(FeedGroupSerializerSettings);

                        bool isLoadFromLegacyFile = false;
                        if (item == null)
                        {
                            var legacyFeedGroupFileAccessor = new FileAccessor <FeedGroup>(legacyFeedSettingsFolder, fileName);
                            var item_legacy = await legacyFeedGroupFileAccessor.Load(FeedGroupSerializerSettings);

                            if (item_legacy != null)
                            {
                                item = new FeedGroup2(item_legacy);

                                isLoadFromLegacyFile = true;
                            }
                        }

                        if (item != null)
                        {
                            item.HohoemaApp  = this.HohoemaApp;
                            item.FeedManager = this;
                            FeedGroupDict.Add(item, fileAccessor);
                            var itemId = item.Id.ToString();

                            var streamFileAccessor = new FileAccessor <List <FeedItem> >(feedStreamDataFolder, $"{itemId}.json");
                            FeedStreamFileAccessors.Add(item.Id, streamFileAccessor);

                            await item.LoadFeedStream(streamFileAccessor);

                            // 古いファイルは新しいフォーマットで上書きして消しておく
                            if (isLoadFromLegacyFile)
                            {
                                await SaveOne(item, isSkipSyncRoaming : true);
                            }

                            // FeedGroupの更新処理情報を構築
                            _FeedGroupUpdaters.Add(item,
                                                   HohoemaApp.BackgroundUpdater.RegistrationBackgroundUpdateScheduleHandler(
                                                       item, item.Label, nameof(FeedGroup), label: $"FeedGroup:{item.Label}")
                                                   );

                            Debug.WriteLine($"FeedManager: [Sucesss] load {item.Label}");
                        }
                        else
                        {
                            Debug.WriteLine($"FeedManager: [?] .json but not FeedGroup file < {fileName}");
                        }
                    }
                    catch
                    {
                        Debug.WriteLine($"FeedManager: [Failed] load {file.Path}");
                    }
                }
            }
        }
Exemple #4
0
        public async Task Load()
        {
            var files = await HohoemaApp.GetSyncRoamingData(PlaylistsSaveFolder);

            // ファイルがない場合
            if (files.Count == 0)
            {
                // デフォルトプレイリストを作成
                MakeDefaultPlaylist();
                CurrentPlaylist = DefaultPlaylist;

                return;
            }


            // 古いデータを解放
            foreach (var playlist in _Playlists)
            {
                playlist.Dispose();
            }

            _PlaylistFileAccessorMap.Clear();
            _Playlists.Clear();
            DefaultPlaylist = null;


            // 読み込み
            List <LocalMylist> loadedItem = new List <LocalMylist>();

            foreach (var file in files)
            {
                var playlistFileAccessor = new FileAccessor <LocalMylist>(PlaylistsSaveFolder, file.Name);
                var playlist             = await playlistFileAccessor.Load();

                if (playlist != null)
                {
                    playlist.HohoemaPlaylist = this;

                    // 重複登録されている場合、ファイルの日付が古いほうを削除
                    // (本来はリネームのミスがないようにするべき)
                    if (_PlaylistFileAccessorMap.ContainsKey(playlist.Id))
                    {
                        var prevFileAccessor = _PlaylistFileAccessorMap[playlist.Id];

                        var prevFile = await prevFileAccessor.TryGetFile();

                        var prevFileProp = await prevFile.GetBasicPropertiesAsync();

                        var fileProp = await file.GetBasicPropertiesAsync();

                        if (prevFileProp.DateModified < fileProp.DateModified)
                        {
                            await prevFileAccessor.Delete(StorageDeleteOption.PermanentDelete);

                            _PlaylistFileAccessorMap.Remove(playlist.Id);

                            _PlaylistFileAccessorMap.Add(playlist.Id, playlistFileAccessor);
                            loadedItem.Add(playlist);
                        }
                        else
                        {
                            await HohoemaApp.RoamingDataRemoved(file);

                            await file.DeleteAsync();
                        }
                    }
                    else
                    {
                        _PlaylistFileAccessorMap.Add(playlist.Id, playlistFileAccessor);
                        loadedItem.Add(playlist);
                    }
                }

                if (playlist.Id == WatchAfterPlaylistId)
                {
                    DefaultPlaylist = playlist;
                }
            }

            loadedItem.Sort((x, y) => x.SortIndex - y.SortIndex);

            foreach (var sortedPlaylist in loadedItem)
            {
                _Playlists.Add(sortedPlaylist);
            }


            // デフォルトプレイリストが削除されていた場合に対応
            if (DefaultPlaylist == null)
            {
                MakeDefaultPlaylist();
            }

            // Live Item は削除
            foreach (var i in DefaultPlaylist.PlaylistItems.Where(x => x.ContentId.StartsWith("lv")).ToArray())
            {
                DefaultPlaylist.Remove(i);
            }
        }