コード例 #1
0
        public static async void CheckNewMusic(FolderTree tree, Action <FolderTree> afterTreeUpdated = null)
        {
            MainPage.Instance?.Loader.ShowIndeterminant("ProcessRequest");
            var data = new TreeUpdateData();

            if (!await tree.CheckNewFile(data))
            {
                if (!string.IsNullOrEmpty(data.Message))
                {
                    MainPage.Instance.ShowNotification(data.Message);
                }
                MainPage.Instance?.Loader.Hide();
                return;
            }
            if (data.More != 0 || data.Less != 0)
            {
                Settings.settings.Tree.FindTree(tree).CopyFrom(tree);
                MusicLibraryPage.SortAndSetAllSongs(Settings.settings.Tree.Flatten());
                foreach (var listener in listeners)
                {
                    listener.PathSet(tree.Path);
                }
                if (data.Less != 0)
                {
                    MediaHelper.RemoveBadMusic();
                }
                afterTreeUpdated?.Invoke(tree);
                App.Save();
            }
            MainPage.Instance?.Loader.Hide();
            string message;

            if (data.More == 0 && data.Less == 0)
            {
                message = Helper.LocalizeMessage("CheckNewMusicResultNoChange");
            }
            else if (data.More == 0)
            {
                message = Helper.LocalizeMessage("CheckNewMusicResultRemoved", data.Less);
            }
            else if (data.Less == 0)
            {
                message = Helper.LocalizeMessage("CheckNewMusicResultAdded", data.More);
            }
            else
            {
                message = Helper.LocalizeMessage("CheckNewMusicResultChange", data.More, data.Less);
            }
            Helper.ShowNotificationWithoutLocalization(message);
        }
コード例 #2
0
        public static async Task <bool> UpdateMusicLibrary(StorageFolder folder, string message = null)
        {
            MainPage.Instance.Loader.ShowDeterminant(message ?? "LoadMusicLibrary", true);
            loadingTree = new FolderTree();
            if (!await loadingTree.Init(folder, (treeFolder, file, progress, max) =>
            {
                bool isDeterminant = max != 0;
                if (MainPage.Instance.Loader.IsDeterminant != isDeterminant)
                {
                    MainPage.Instance.Loader.IsDeterminant = isDeterminant;
                }
                if (isDeterminant)
                {
                    MainPage.Instance.Loader.Max = max;
                    MainPage.Instance.Loader.Progress = progress;
                    MainPage.Instance.Loader.Text = message ?? file;
                }
            }))
            {
                return(false);
            }
            MainPage.Instance.Loader.SetLocalizedText(message ?? "UpdateMusicLibrary");
            Helper.CurrentFolder = folder;
            await Task.Run(() =>
            {
                loadingTree.MergeFrom(Settings.settings.Tree);
                Settings.settings.Tree     = loadingTree;
                Settings.settings.RootPath = folder.Path;
            });

            MusicLibraryPage.SortAndSetAllSongs(await Task.Run(Settings.settings.Tree.Flatten));
            MainPage.Instance.Loader.Progress = 0;
            MainPage.Instance.Loader.Max      = listeners.Count;
            for (int i = 0; i < listeners.Count;)
            {
                var listener = listeners[i];
                listener.PathSet(folder.Path);
                MainPage.Instance.Loader.Progress = ++i;
            }
            MediaHelper.RemoveBadMusic();
            App.Save();
            MainPage.Instance.Loader.Hide();
            return(true);
        }