/// <summary> /// Checks if the destination download path external to the app exists /// and has a right name, right permissions, etc. /// </summary> /// <param name="downloadPath">Download folder path.</param> /// <returns>TRUE if all is OK or FALSE in other case.</returns> public static async Task <bool> CheckExternalDownloadPathAsync(string downloadPath) { // Extra check to try avoid null values if (string.IsNullOrWhiteSpace(downloadPath)) { UiService.OnUiThread(async() => { await DialogService.ShowAlertAsync( ResourceService.AppMessages.GetString("AM_DownloadFailed_Title"), ResourceService.AppMessages.GetString("AM_SelectFolderFailedNoErrorCode")); }); return(false); } // Check for illegal characters in the download path if (FolderService.HasIllegalChars(downloadPath)) { UiService.OnUiThread(async() => { await DialogService.ShowAlertAsync( ResourceService.AppMessages.GetString("AM_DownloadFailed_Title"), string.Format(ResourceService.AppMessages.GetString("AM_InvalidFolderNameOrPath"), downloadPath)); }); return(false); } bool pathExists = true; //Suppose that the download path exists try { await StorageFolder.GetFolderFromPathAsync(downloadPath); } catch (FileNotFoundException) { pathExists = false; } catch (UnauthorizedAccessException) { UiService.OnUiThread(async() => { await DialogService.ShowAlertAsync( ResourceService.AppMessages.GetString("AM_DowloadPathUnauthorizedAccess_Title"), ResourceService.AppMessages.GetString("AM_DowloadPathUnauthorizedAccess")); }); return(false); } catch (Exception e) { UiService.OnUiThread(async() => { await DialogService.ShowAlertAsync( ResourceService.AppMessages.GetString("AM_DownloadFailed_Title"), string.Format(ResourceService.AppMessages.GetString("AM_DownloadPathUnknownError"), e.GetType().Name + " - " + e.Message)); }); return(false); } // Create the download path if not exists if (!pathExists) { return(await CreateExternalDownloadPathAsync(downloadPath)); } return(true); }
public static void ClearLocalCache() { string localCacheDir = ApplicationData.Current.LocalFolder.Path; if (!String.IsNullOrWhiteSpace(localCacheDir) && !FolderService.HasIllegalChars(localCacheDir) && Directory.Exists(localCacheDir)) { FileService.ClearFiles(Directory.GetFiles(localCacheDir)); } }
public static void ClearUploadCache() { string uploadDir = GetUploadDirectoryPath(); if (!String.IsNullOrWhiteSpace(uploadDir) && !FolderService.HasIllegalChars(uploadDir) && Directory.Exists(uploadDir)) { FileService.ClearFiles(Directory.GetFiles(uploadDir)); } }
public static void ClearDownloadCache() { string downloadDir = GetDownloadDirectoryPath(); if (!String.IsNullOrWhiteSpace(downloadDir) && !FolderService.HasIllegalChars(downloadDir) && Directory.Exists(downloadDir)) { FolderService.Clear(downloadDir); } }
public static void ClearPreviewCache() { string previewDir = GetPreviewDirectoryPath(); if (!String.IsNullOrWhiteSpace(previewDir) && !FolderService.HasIllegalChars(previewDir) && Directory.Exists(previewDir)) { FileService.ClearFiles(Directory.GetFiles(previewDir)); } }
public static void ClearThumbnailCache() { string thumbnailDir = GetThumbnailDirectoryPath(); if (!String.IsNullOrWhiteSpace(thumbnailDir) && !FolderService.HasIllegalChars(thumbnailDir) && Directory.Exists(thumbnailDir)) { FileService.ClearFiles(Directory.GetFiles(thumbnailDir)); } }
/// <summary> /// Clear the app local cache /// </summary> /// <returns>TRUE if the cache was successfully deleted or FALSE otherwise.</returns> public static async Task <bool> ClearLocalCacheAsync() { string localCacheDir = ApplicationData.Current.LocalFolder.Path; if (string.IsNullOrWhiteSpace(localCacheDir) || FolderService.HasIllegalChars(localCacheDir) || !Directory.Exists(localCacheDir)) { return(false); } return(await FileService.ClearFilesAsync(Directory.GetFiles(localCacheDir))); }
/// <summary> /// Clear the uploads cache /// </summary> /// <returns>TRUE if the cache was successfully deleted or FALSE otherwise.</returns> public static async Task <bool> ClearUploadCacheAsync() { string uploadDir = GetUploadDirectoryPath(); if (string.IsNullOrWhiteSpace(uploadDir) || FolderService.HasIllegalChars(uploadDir) || !Directory.Exists(uploadDir)) { return(false); } return(await FileService.ClearFilesAsync(Directory.GetFiles(uploadDir))); }
/// <summary> /// Clear the downloads cache /// </summary> /// <returns>TRUE if the cache was successfully deleted or FALSE otherwise.</returns> public static async Task <bool> ClearDownloadCacheAsync() { string downloadDir = GetDownloadDirectoryPath(); if (string.IsNullOrWhiteSpace(downloadDir) || FolderService.HasIllegalChars(downloadDir) || !Directory.Exists(downloadDir)) { return(false); } return(await FolderService.ClearAsync(downloadDir)); }
public static bool ClearUploadCache() { string uploadDir = GetUploadDirectoryPath(); if (String.IsNullOrWhiteSpace(uploadDir) || FolderService.HasIllegalChars(uploadDir) || !Directory.Exists(uploadDir)) { return(false); } return(FileService.ClearFiles(Directory.GetFiles(uploadDir))); }
public static bool ClearDownloadCache() { string downloadDir = GetDownloadDirectoryPath(); if (String.IsNullOrWhiteSpace(downloadDir) || FolderService.HasIllegalChars(downloadDir) || !Directory.Exists(downloadDir)) { return(false); } return(FolderService.Clear(downloadDir)); }
public static async Task <bool> ClearThumbnailCacheAsync() { string thumbnailDir = GetThumbnailDirectoryPath(); if (String.IsNullOrWhiteSpace(thumbnailDir) || FolderService.HasIllegalChars(thumbnailDir) || !Directory.Exists(thumbnailDir)) { return(false); } return(await FileService.ClearFilesAsync(Directory.GetFiles(thumbnailDir))); }
/// <summary> /// Clear all the offline content of the app /// </summary> /// <returns>TRUE if the offline content was successfully deleted or FALSE otherwise.</returns> public static async Task <bool> ClearOfflineAsync() { bool result; string offlineDir = GetOfflineDirectoryPath(); if (string.IsNullOrWhiteSpace(offlineDir) || FolderService.HasIllegalChars(offlineDir) || !Directory.Exists(offlineDir)) { return(false); } result = await FolderService.ClearAsync(offlineDir); // Clear the offline database result = result & SavedForOfflineDB.DeleteAllNodes(); return(result); }