private async Task UploadChangedDeckImages(IReadOnlyList <StorageFile> files) { var remoteItems = await syncInstance.GetChildrenInRemoteFolder(Constant.DEFAULT_DECK_IMAGE_FOLDER_SYNC_PATH); var localCacheItems = await deckImageCacheFolder.GetFilesAsync(); foreach (var file in files) { if (file.Name == DeckInformation.DEFAULT_IMAGE_NAME) { continue; } var cacheItem = DeckInformation.TryGetCacheItem(localCacheItems, file.Name); long localFileDateCreated = 0; if (cacheItem != null) { localFileDateCreated = long.Parse(cacheItem.Name.Split(DeckInformation.IMAGE_NAME_SEPARATOR)[1]); } bool isHasFile = false; foreach (var item in remoteItems) { var splitString = item.Name.Split(DeckInformation.IMAGE_NAME_SEPARATOR); if (splitString.Length != 2) { continue; } string name = splitString[0]; long itemDateCreated = long.Parse(splitString[1]); if (name == file.Name) { if (itemDateCreated < localFileDateCreated) { await syncInstance.DeleteItemWithPathAsync(Constant.DEFAULT_DECK_IMAGE_FOLDER_SYNC_PATH + "/" + item.Name); await UploadDeckImageFile(file, localFileDateCreated); } isHasFile = true; remoteItems.Remove(item); break; } } if (!isHasFile) { await UploadDeckImageFile(file, localFileDateCreated); } } await DeleteUnusedDeckImagesOnServer(remoteItems); }
/// <summary> /// Get a file from sync folder /// </summary> /// <param name="itemName">Name of the file</param> /// <returns>The requested file. Null if not found.</returns> public async Task <RemoteItem> TryGetItemInSyncFolderAsync(string itemName) { var items = await syncInstance.GetChildrenInRemoteFolder(Constant.ANKIROOT_SYNC_FOLDER); foreach (var item in items) { if (item.Name == itemName) { return(item); } } return(null); }