private async Task <bool> UpdateFolderList() { if (pi != null && await pi.CheckAuthenitcationAsync() && CurrentFolder != null) { BusyOn(true); ppd.BusyText = "Refreshing folder view from " + CurrentProvider.ToString() + " " + CurrentDisplayFolder; List <string> folders = await pi.GetFoldersAsync(CurrentFolder); //FolderList.ItemsSource = folders; DirectoryList.Clear(); foreach (string d in folders) { DirectoryList.Add(new DirectoryEntry() { DirectoryName = d }); } BusyOn(false); return(true); } else { return(false); } }
#pragma warning disable AvoidAsyncVoid private async void DeleteFolder_Clicked(object sender, EventArgs e) { bool result = await DisplayAlert(AppResources.RemoveFolderTitle, AppResources.RemoveFolder, AppResources.Continue, AppResources.Cancel); if (result) { Track t = FindTrack((View)sender); if (t.CloudProvider != CloudStorage.CloudProviders.NULL) { ProviderInfo pi = await ProviderInfo.GetCloudProviderAsync(t.CloudProvider); if (await pi.CheckAuthenitcationAsync()) { bool removeWorked = await pi.RemoveFolder(t.CloudRoot, t.Project, UpdateStatus); if (removeWorked) { // Are we goint to remove a song that is playing? if (this.tvm.SelectedSong.Project == t.Project) { this.tvm.StopPlayer(); this.tvm.ResetPlayer(); } string projectPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), t.Project); Directory.Delete(projectPath, true); t.CloudProvider = CloudStorage.CloudProviders.NULL; t.CloudRoot = null; if (selectedTrack?.Project == t.Project) { selectedTrack = null; } // Remove folder from current list for (int i = LoadedTracks.Count - 1; i >= 0; i--) { if (LoadedTracks[i].Project == t.Project) { LoadedTracks.RemoveAt(i); } } // If part of playlist, remove from there for (int i = this.tvm.Playlist.Count - 1; i >= 0; i--) { if (t.Project == this.tvm.Playlist[i].Project) { this.tvm.Playlist.RemoveAt(i); } } } else { await DisplayAlert(AppResources.RemoveFolderRemoteFailedTitle, AppResources.RemoveFolderRemoteFailed, AppResources.OK); } } } else { Analytics.TrackEvent("Cloud Provider for folder invalid"); await DisplayAlert("Cloud Provider incorrect", "The cloud provider saved in local storage is missing or incorrect. This is not an expected error, contact the developer.", "OK"); } } }
private async Task SyncProjectsAsync() { Dictionary <string, List <string> > AllSongs = new Dictionary <string, List <string> >(); foreach (MixLocation ml in PersistentData.MixLocationList) { UpdateStatus(ml.Provider.ToString() + " " + ml.Path); ProviderInfo pi = await ProviderInfo.GetCloudProviderAsync(ml.Provider); if (await pi.CheckAuthenitcationAsync()) { List <string> l = await pi.GetFoldersAsync(ml.Path); if (l != null) { foreach (string f in l) { UpdateStatus(ml.Provider.ToString() + " " + ml.Path + " " + f); var retList = await pi.UpdateProjectAsync(ml.Path, f, UpdateStatus); if (AllSongs.ContainsKey(f)) { AllSongs[f].AddRange(retList); } else { AllSongs[f] = retList; } } } } } string rootPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); foreach (string p in Directory.GetDirectories(rootPath)) { if (!AllSongs.ContainsKey(Path.GetFileName(p))) { Debug.Print("Remove dir " + p + "\n"); UpdateStatus("Removing " + p); Directory.Delete(p, true); } else { foreach (string s in Directory.GetDirectories(p)) { if (AllSongs[p].Contains(Path.GetFileName(s))) { UpdateStatus("Removing " + s); Debug.Print("Remove file " + s + "\n"); File.Delete(s); } } } } foreach (string p in AllSongs.Keys) { foreach (string f in AllSongs[p]) { UpdateStatus(p + " " + f); } } PersistentData.Save(); }