Beispiel #1
0
        private async void Import()
        {
            using (var handle = Insights.TrackTime("Import Music"))
            {
                UiBlockerUtility.Block("Scanning...");
                var localMusic = await LocalMusicHelper.GetFilesInMusicAsync();

                handle.Data.Add("TotalCount", localMusic.Count.ToString());
                var failedCount = 0;

                App.Locator.CollectionService.Songs.SuppressEvents   = true;
                App.Locator.CollectionService.Artists.SuppressEvents = true;
                App.Locator.CollectionService.Albums.SuppressEvents  = true;

                App.Locator.SqlService.BeginTransaction();
                for (var i = 0; i < localMusic.Count; i++)
                {
                    StatusBarHelper.ShowStatus(
                        string.Format("Importing {0} of {1} items", i + 1, localMusic.Count),
                        (double)i / localMusic.Count);
                    try
                    {
                        await LocalMusicHelper.SaveTrackAsync(localMusic[i]);
                    }
                    catch
                    {
                        failedCount++;
                    }
                }

                App.Locator.SqlService.Commit();

                App.Locator.CollectionService.Songs.Reset();
                App.Locator.CollectionService.Artists.Reset();
                App.Locator.CollectionService.Albums.Reset();

                UiBlockerUtility.Unblock();

                if (failedCount > 0)
                {
                    CurtainPrompt.ShowError("Couldn't import {0} song(s).", failedCount);
                    handle.Data.Add("Failed", failedCount.ToString());
                }
            }

            await CollectionHelper.DownloadAlbumsArtworkAsync();

            await CollectionHelper.DownloadArtistsArtworkAsync();
        }
Beispiel #2
0
        public async override void NavigatedTo(Windows.UI.Xaml.Navigation.NavigationMode mode, object parameter)
        {
            base.NavigatedTo(mode, parameter);

            var reset = App.Locator.AppSettingsHelper.Read <bool>("FactoryReset");

            var startingMsg = "Restoring (this may take a bit)...";

            if (reset)
            {
                startingMsg = "Factory resetting...";
            }

            using (Insights.TrackTime(reset ? "Factory Reset" : "Restore Collection"))
            {
                StatusBarHelper.ShowStatus(startingMsg);

                var file = reset ? null : await StorageHelper.GetFileAsync("_current_restore.autcp");

                //delete artowkr and mp3s
                var artworkFolder = await StorageHelper.GetFolderAsync("artworks");

                var artistFolder = await StorageHelper.GetFolderAsync("artists");

                var songFolder = await StorageHelper.GetFolderAsync("songs");

                if (artworkFolder != null)
                {
                    await artworkFolder.DeleteAsync();
                }

                if (artistFolder != null)
                {
                    await artistFolder.DeleteAsync();
                }

                if (songFolder != null)
                {
                    await songFolder.DeleteAsync();
                }

                if (!reset)
                {
                    using (var stream = await file.OpenAsync(FileAccess.ReadAndWrite))
                    {
                        await AutcpFormatHelper.UnpackBackup(ApplicationData.Current.LocalFolder, stream);
                    }

                    await file.DeleteAsync();

                    App.Locator.CollectionService.LibraryLoaded += async(sender, args) =>
                    {
                        await CollectionHelper.DownloadArtistsArtworkAsync(false);

                        await CollectionHelper.DownloadAlbumsArtworkAsync(false);
                    };

                    App.Locator.AppSettingsHelper.Write("Restore", false);
                }
                else
                {
                    var dbs = (await ApplicationData.Current.LocalFolder.GetFilesAsync())
                              .Where(p => p.FileType == ".sqldb").ToList();

                    foreach (var db in dbs)
                    {
                        await db.DeleteAsync();
                    }

                    App.Locator.AppSettingsHelper.Write("FactoryReset", false);
                }

                StatusBarHelper.HideStatus();
            }

            (Application.Current as App).BootAppServicesAsync();
            App.Navigator.GoTo <HomePage, ZoomOutTransition>(null, false);
        }