internal static async Task <ReportItem> CreateReportItemAsync(string title, string description, IMappablePoint point, IStorageFile image) { var item = new ReportItem() { Title = title, Description = description, NativeId = Guid.NewGuid().ToString(), Status = ReportItemStatus.New }; item.SetLocation(point); // save... var conn = StreetFooRuntime.GetUserDatabase(); await conn.InsertAsync(item); // stage the image... if (image != null) { // new path... var manager = new ReportImageCacheManager(); var folder = await manager.GetCacheFolderAsync(); // create... await image.CopyAsync(folder, item.NativeId + ".jpg"); } // return... return(item); }
public async Task <IBook> AddBookAsync(IStorageFile file) { if (file == null) { throw new ArgumentNullException(nameof(file)); } var document = await DjvuDocument.LoadAsync(file); var bookDto = new EfBookDto { PageCount = document.PageCount, Title = Path.GetFileNameWithoutExtension(file.Name), LastOpeningTime = DateTime.Now }; _context.Books.Add(bookDto); await _context.SaveChangesAsync(); var booksFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Books", CreationCollisionOption.OpenIfExists); var bookFile = await file.CopyAsync(booksFolder, $"{bookDto.Id}.djvu", NameCollisionOption.ReplaceExisting); bookDto.BookPath = bookFile.Path; await _context.SaveChangesAsync(); var book = new EfBook(bookDto, _context, _books); await book.UpdateThumbnailAsync(); _books.Add(book); return(book); }
public static void SetFileProvider(this DataPackage package, IStorageFile file, string fileName) { if (file is null) { throw new ArgumentNullException(nameof(file)); } fileName = StorageHelper.ToValidFileName(fileName); var fileList = new List <IStorageFile> { file }; PrepareFileShare(package, fileList); package.SetDataProvider(StandardDataFormats.StorageItems, async req => { var def = req.GetDeferral(); try { var tempFolder = await ApplicationData.Current.TemporaryFolder.CreateFolderAsync("DataRequested", CreationCollisionOption.OpenIfExists); var tempFile = await file.CopyAsync(tempFolder, fileName, NameCollisionOption.ReplaceExisting); req.SetData(new StorageItemContainer(tempFile)); } finally { def.Complete(); } }); }
public async Task CopyFileAsync(IFile destinationFile) { if (_storageFile == null) { return; } StorageFolder destinationStorageFolder = await StorageFolder.GetFolderFromPathAsync(destinationFile.FilePath); await _storageFile.CopyAsync(destinationStorageFolder, destinationFile.NameWithExtension, NameCollisionOption.ReplaceExisting); }
//public async Task RenameAsync(string newName) //{ // if (string.IsNullOrEmpty(newName)) // throw new ArgumentNullException($"{nameof(newName)} cannot be null or empty."); // await _root.RenameAsync(newName, NameCollisionOption.FailIfExists); //} public async Task SaveIconAsync(IStorageFile file) { if (file == null) { throw new ArgumentNullException($"{nameof(file)} cannot be null."); } var folder = await _root.CreateFolderAsync("Icons", CreationCollisionOption.OpenIfExists); await file.CopyAsync(folder, file.Name, NameCollisionOption.ReplaceExisting); }
public async Task SaveModelAsync(IStorageFile model) { if (model == null) { throw new ArgumentNullException($"{nameof(model)} cannot be null."); } var folder = await _root.CreateFolderAsync("Model", CreationCollisionOption.OpenIfExists); await model.CopyAsync(folder, model.Name, NameCollisionOption.ReplaceExisting); }
private async Task copyDemoROM(string path) { IStorageFile file = await this.GetAssetFileAsync(path); if (file != null) { await file.CopyAsync(this.romDirectory); await this.RefreshROMListAsync(); } }
private static async void CopyTorrent(IStorageFile torrentFile) { if (!Directory.Exists(AppState.TorrentsDirectory)) { Directory.CreateDirectory(AppState.TorrentsDirectory); } if (File.Exists(Path.Combine(AppState.TorrentsDirectory, Path.GetFileName(torrentFile.Path)))) { return; } await torrentFile.CopyAsync(await StorageFolder.GetFolderFromPathAsync(AppState.TorrentsDirectory)); }
public static async Task <StorageFile> ImportAsync(IStorageFile file) { IStorageItem rootDir = await ApplicationData.Current.RoamingFolder.TryGetItemAsync("Music"); var dir = rootDir as StorageFolder; if (dir == null || file == null) { return(null); } if (dir.TryGetItemAsync(file.Name) != null) { return(await file.CopyAsync(dir, file.Name, Windows.Storage.NameCollisionOption.GenerateUniqueName)); } return(null); }
private async void CopyFolder(string path) { IStorageFolder destination = Windows.Storage.ApplicationData.Current.LocalFolder; IStorageFolder root = Windows.ApplicationModel.Package.Current.InstalledLocation; if (path.Equals(ROOT) && !await FolderExistAsync(ROOT)) { await destination.CreateFolderAsync(ROOT); } destination = await destination.GetFolderAsync(path); root = await root.GetFolderAsync(path); IReadOnlyList <IStorageItem> items = await root.GetItemsAsync(); foreach (IStorageItem item in items) { if (item.GetType() == typeof(StorageFile)) { IStorageFile presFile = await StorageFile.GetFileFromApplicationUriAsync( new Uri("ms-appx:///" + path.Replace("\\", "/") + "/" + item.Name)); // Do copy file to destination folder await presFile.CopyAsync(destination); } else { // If folder doesn't exist, than create new one on destination folder if (!await FolderExistAsync(path + "\\" + item.Name)) { await destination.CreateFolderAsync(item.Name); } // Do recursive copy for every items inside CopyFolder(path + "\\" + item.Name); } } }
/// <summary> /// Copy a file. /// </summary> /// <param name="newPath">The new full path of the file.</param> /// <param name="collisionOption">How to deal with collisions with existing files.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A task which will complete after the file is moved.</returns> public async Task CopyAsync(string newPath, NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting, CancellationToken cancellationToken = default(CancellationToken)) { Requires.NotNullOrEmpty(newPath, "newPath"); var newFolder = await StorageFolder.GetFolderFromPathAsync(System.IO.Path.GetDirectoryName(newPath)).AsTask(cancellationToken).ConfigureAwait(false); string newName = System.IO.Path.GetFileName(newPath); try { await _wrappedFile.CopyAsync(newFolder, newName, (Windows.Storage.NameCollisionOption) collisionOption).AsTask(cancellationToken).ConfigureAwait(false); } catch (Exception ex) { if (ex.HResult == FILE_ALREADY_EXISTS) { throw new IOException("File already exists.", ex); } throw; } }
public async Task <BatNode> AddNode(BatProject project, IStorageFile rawDataFile) { BatNode newNode = new BatNode(); newNode.NodeData = new BatNodeData(); project.AddNode(newNode); StorageFolder projectFolder = await GetProjectFolder(project); StorageFolder nodeFolder = await projectFolder.CreateFolderAsync(newNode.FolderName, CreationCollisionOption.FailIfExists); await rawDataFile.CopyAsync(nodeFolder, RawFileName, NameCollisionOption.ReplaceExisting); await AnalyzeNode(project, newNode, rawDataFile); StorageFile nodeFile = await nodeFolder.CreateFileAsync(NodeFileName, CreationCollisionOption.ReplaceExisting); await SerializeJson(newNode.NodeData, nodeFile); await UpdateProjectFile(project); return(newNode); }
public static async Task<string> SetupChmFileFromPhone(IStorageFile storageFile) { ChmFile ret = new ChmFile(); Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; ret.Key = Guid.NewGuid().ToString("N"); ret.HasThumbnail = false; var file = await storageFile.CopyAsync(localFolder, ret.Key + ChmFileExtension); try { ret.Chm = await LoadChm(file.Path, false); MetaInfo meta = new MetaInfo(); meta.SetOriginalPath(storageFile.Path); if (ret.Chm.Title != null) { meta.SetDisplayName(ret.Chm.Title); } else { meta.SetDisplayName(System.IO.Path.GetFileNameWithoutExtension(storageFile.Name)); } ret.ChmMeta = meta; await ret.Save(); FileHistory.AddToHistory(ret.Key); } catch { ret.Chm = null; } if (ret.Chm == null) { await MetaInfo.DeleteMetaFile(ret.Key); await DeleteFile(ret.Key); return null; } return ret.Key; }
private async void CopyFolder(string path) { IStorageFolder Destination = Windows.Storage.ApplicationData.Current.LocalFolder; IStorageFolder root = Windows.ApplicationModel.Package.Current.InstalledLocation; if (path.Equals("root") && !await FolderExistAsync("root")) { await Destination.CreateFolderAsync("root"); } Destination = await Destination.GetFolderAsync(path); root = await root.GetFolderAsync(path); IReadOnlyList <IStorageItem> items = await root.GetItemsAsync(); foreach (IStorageItem item in items) { if (item.GetType() == typeof(StorageFile)) { IStorageFile presFile = await StorageFile.GetFileFromApplicationUriAsync( new Uri("ms-appx:///" + path.Replace("\\", "/") + "/" + item.Name)); await presFile.CopyAsync(Destination, item.Name); } else { if (!await FolderExistAsync(path + "\\" + item.Name)) { await Destination.CreateFolderAsync(item.Name); } CheckFolder(path + "\\" + item.Name); } } }
internal static async Task<ReportItem> CreateReportItemAsync(string title, string description, IMappablePoint point, IStorageFile image) { var item = new ReportItem() { Title = title, Description = description, NativeId = Guid.NewGuid().ToString(), Status = ReportItemStatus.New }; item.SetLocation(point); // save... var conn = StreetFooRuntime.GetUserDatabase(); await conn.InsertAsync(item); // stage the image... if (image != null) { // new path... var manager = new ReportImageCacheManager(); var folder = await manager.GetCacheFolderAsync(); // create... await image.CopyAsync(folder, item.NativeId + ".jpg"); } // return... return item; }
/// <summary> /// Registers the specified storage file. /// </summary> /// <param name="file">The database file.</param> /// <returns>The database registration information.</returns> public async Task <DatabaseRegistration> RegisterAsync(IStorageFile file) { using (var input = await file.OpenReadAsync()) { var headers = await FileFormat.Headers(input); switch (headers.Format) { case FileFormats.KeePass1x: case FileFormats.NewVersion: case FileFormats.NotSupported: case FileFormats.OldVersion: await _events.PublishOnUIThreadAsync( new DatabaseSupportMessage { FileName = file.Name, Format = headers.Format, }); return(null); case FileFormats.PartialSupported: await _events.PublishOnUIThreadAsync( new DatabaseSupportMessage { FileName = file.Name, Format = headers.Format, }); break; } } var meta = new DatabaseMetaData { Name = GetName(file.Name), }; // Check already registered database file var exists = _accessList.CheckAccess(file); if (exists) { await _events.PublishOnUIThreadAsync( new DuplicateDatabaseMessage()); return(null); } // Register for future access var token = _accessList.Add(file, JsonConvert.SerializeObject(meta)); await file.CopyAsync(await _cacheFolder, token + ".kdbx"); var info = new DatabaseRegistration { Id = token, Name = meta.Name, }; // Send notification message await _events.PublishOnUIThreadAsync( new DatabaseRegistrationMessage { Id = info.Id, Registration = info, Action = DatabaseRegistrationActions.Added, }); return(info); }
private async Task ContinueAfterFilePickAsync(IStorageFile file, IStorageFolder directory, Folder folder, Wallet parentWallet, bool deleteFile = false) { bool isImported = false; try { if (directory != null && file != null && await file.GetFileSizeAsync().ConfigureAwait(false) <= ConstantData.MAX_IMPORTABLE_MEDIA_FILE_SIZE) { _animationStarter.StartAnimation(AnimationStarter.Animations.Updating); StorageFile newFile = await file.CopyAsync(directory, file.Name, NameCollisionOption.GenerateUniqueName).AsTask().ConfigureAwait(false); if (parentWallet == null) { isImported = await folder.ImportMediaFileIntoNewWalletAsync(newFile).ConfigureAwait(false); } else { isImported = await parentWallet.ImportFileAsync(newFile).ConfigureAwait(false); } if (!isImported) { // delete the copied file if something went wrong if (newFile != null) await newFile.DeleteAsync(StorageDeleteOption.PermanentDelete).AsTask().ConfigureAwait(false); Logger.Add_TPL("isImported = false", Logger.AppEventsLogFilename, Logger.Severity.Info); } // delete the original file if it was a photo taken with CameraCaptureUI if (deleteFile) await file.DeleteAsync(StorageDeleteOption.PermanentDelete).AsTask().ConfigureAwait(false); } } catch (Exception ex) { await Logger.AddAsync(ex.ToString(), Logger.AppEventsLogFilename).ConfigureAwait(false); } _animationStarter.EndAllAnimations(); _animationStarter.StartAnimation(isImported ? AnimationStarter.Animations.Success : AnimationStarter.Animations.Failure); IsImportingMedia = false; }