/// <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); }
/// <summary> /// Removes a folder recursively from the offline DB /// </summary> /// <param name="folderPath">Path of the folder</param> /// <returns>TRUE if all went weel or FALSE in other case.</returns> public static bool RemoveFolderFromOfflineDB(string folderPath) { if (string.IsNullOrWhiteSpace(folderPath)) { return(false); } bool result = true; if (FolderService.FolderExists(folderPath)) { try { IEnumerable <string> childFolders = Directory.GetDirectories(folderPath); if (childFolders != null) { foreach (var folder in childFolders) { if (folder != null) { result &= RemoveFolderFromOfflineDB(folder); result &= SavedForOfflineDB.DeleteNodeByLocalPath(folder); } } } } catch (Exception e) { LogService.Log(MLogLevel.LOG_LEVEL_ERROR, string.Format("Error removing from the offline DB the subfolders of '{0}'", folderPath), e); result = false; } try { IEnumerable <string> childFiles = Directory.GetFiles(folderPath); if (childFiles != null) { foreach (var file in childFiles) { if (file != null) { result &= SavedForOfflineDB.DeleteNodeByLocalPath(file); } } } } catch (Exception e) { LogService.Log(MLogLevel.LOG_LEVEL_ERROR, string.Format("Error removing from the offline DB the files of '{0}'", folderPath), e); result = false; } } result &= SavedForOfflineDB.DeleteNodeByLocalPath(folderPath); return(result); }
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)); } }
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 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 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)); }
/// <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))); }
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)); }
/// <summary> /// Checks if the previous folders of an offline folder node path are empty /// and removes them from the offline folder and the DB on this case. /// </summary> /// <param name="folderNodePath">Path of the folder node</param> /// <returns>TRUE if the process finished successfully or FALSE in other case.</returns> public static bool CleanOfflineFolderNodePath(string folderNodePath) { if (string.IsNullOrWhiteSpace(folderNodePath)) { return(false); } var result = true; while (string.CompareOrdinal(folderNodePath, AppService.GetOfflineDirectoryPath()) != 0) { try { if (!FolderService.FolderExists(folderNodePath)) { return(false); } var folderPathToRemove = folderNodePath; if (!FolderService.IsEmptyFolder(folderPathToRemove)) { return(true); } var directoryInfo = new DirectoryInfo(folderNodePath).Parent; if (directoryInfo == null) { return(true); } folderNodePath = directoryInfo.FullName; result &= FolderService.DeleteFolder(folderPathToRemove); result &= SavedForOfflineDB.DeleteNodeByLocalPath(folderPathToRemove); } catch (Exception e) { LogService.Log(MLogLevel.LOG_LEVEL_ERROR, string.Format("Error cleaning offline node path '{0}'", folderNodePath), e); return(false); } } return(result); }
/// <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); }
private static List <string> GetDownloadDirectoryFiles(string path) { var files = new List <string>(); if (FolderService.FolderExists(path)) { try { files.AddRange(Directory.GetFiles(path)); var folders = new List <string>(); folders.AddRange(Directory.GetDirectories(path)); foreach (var folder in folders) { files.AddRange(GetDownloadDirectoryFiles(folder)); } } catch (Exception e) { throw e.GetBaseException(); } } return(files); }
/// <summary> /// Get the size of the offline content /// </summary> /// <returns>Offline content size</returns> public static async Task <ulong> GetOfflineSizeAsync() => await FolderService.GetFolderSizeAsync(GetOfflineDirectoryPath());