private void moveToPath(string destinationPath) { try { System.IO.File.Move(filePath, destinationPath); } catch (System.IO.IOException e) { // If the destination file already exists (0x800700B7 is "Cannot create a file when that file already // exists"), then delete it and retry the move. if (e.HResult == unchecked ((int)0x800700B7)) { try { System.IO.File.Delete(destinationPath); System.IO.File.Move(filePath, destinationPath); } catch (System.IO.IOException e2) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e2); } } else { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } } }
public override void visitChildren(FileVisitor fileVisitor, DirectoryVisitor directoryVisitor, VisitFailed visitFailed) { try { IReadOnlyList <IStorageItem> storageItems = getStorageFolder().GetItemsAsync().DoSynchronously(); foreach (IStorageItem storageItem in storageItems) { StorageItemPathAttributes pathAttributes = new StorageItemPathAttributes(storageItem); if (storageItem is IStorageFolder) { if (directoryVisitor != null) { directoryVisitor(new StorageFolderDirectory(this, (StorageFolder)storageItem)); } } else if (storageItem is IStorageFile) { if (fileVisitor != null) { fileVisitor(new StorageFileFile(this, (StorageFile)storageItem)); } } else { throw new Exception("Unknown type of StorageItem: " + storageItem); } } } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override long getLastModifiedTime() { try { return(SystemUtils.toMillisFromDateTime(System.IO.File.GetLastWriteTimeUtc(filePath))); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override long getSize() { try { return(new FileInfo(filePath).Length); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override void setLastModifiedTime(long value) { try { System.IO.File.SetLastWriteTimeUtc(filePath, SystemUtils.toDotNetDateTimeFromMillis(value)); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override OutputStream openForCreate() { try { FileStream fileStream = System.IO.File.OpenWrite(filePath); return(new DotNetStreamOutputStream(fileStream)); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override long getLastModifiedTime() { try { return(SystemUtils.toMillisFromDateTimeOffset(storageFolder.GetBasicPropertiesAsync().DoSynchronously().DateModified)); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override void write(int oneByte) { try { dotNetStream.WriteByte((byte)oneByte); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override int read() { try { return(dotNetStream.ReadByte()); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override void delete() { try { System.IO.Directory.Delete(directoryPath); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
protected internal override void doClose() { try { dotNetStream.Dispose(); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override void flush() { try { dotNetStream.Flush(); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override void write(sbyte[] buffer, int offset, int length) { try { dotNetStream.Write((byte[])(Array)buffer, offset, length); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override bool exists() { try { var directoryInfo = new DirectoryInfo(directoryPath); return(directoryInfo.Exists); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override void renameTo(string newName) { var destinationPath = getChildPath(newName); try { System.IO.Directory.Move(directoryPath, destinationPath); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override void delete() { try { // Delete the file; if it doesn't exist, nothing happens System.IO.File.Delete(filePath); } catch (System.IO.DirectoryNotFoundException e) { // If the directory doesn't exist, ignore the error } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override long getSize() { ensureGotStorageFile(); try { return((long)storageFile.GetBasicPropertiesAsync().DoSynchronously().Size); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override void moveTo(File destination) { ensureGotStorageFile(); StorageFileFile destinationStorageFile = (StorageFileFile)destination; try { storageFile.MoveAsync(destinationStorageFile.ParentStorageFolderDirectory.getStorageFolder(), destinationStorageFile.getName(), NameCollisionOption.ReplaceExisting); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override void renameTo(string newName) { ensureGotStorageFile(); try { storageFile.RenameAsync(newName, NameCollisionOption.ReplaceExisting).DoSynchronously(); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
private void ensureGotStorageFile() { if (storageFile == null) { try { storageFile = parent.getStorageFolder().GetFileAsync(name).DoSynchronously(); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } } }
public override void create() { try { var directoryInfo = new DirectoryInfo(directoryPath); if (!directoryInfo.Exists) { directoryInfo.Create(); } } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public StorageFolder getStorageFolder() { if (storageFolder == null) { try { storageFolder = parent.getStorageFolder().GetFolderAsync(name).DoSynchronously(); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } } return(storageFolder); }
public override InputStream openForRead() { ensureGotStorageFile(); try { IInputStream inputStream = storageFile.OpenSequentialReadAsync().DoSynchronously(); // TODO: Need to close the inputStream itself; add a closedListener to InputStream, i think // Use the default 16K buffer for AsStreamForRead() return(new DotNetStreamInputStream(inputStream.AsStreamForRead())); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override int read(sbyte[] buffer, int offset, int length) { try { int bytesRead = dotNetStream.Read((byte[])(Array)buffer, offset, length); if (bytesRead == 0) { return(-1); // JSimple input streams return -1 at end of stream, not 0 } else { return(bytesRead); } } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override OutputStream openForCreate() { try { storageFile = parent.getStorageFolder().CreateFileAsync(name, CreationCollisionOption.ReplaceExisting) .DoSynchronously(); IRandomAccessStream randomAccessStream = storageFile.OpenAsync(FileAccessMode.ReadWrite).DoSynchronously(); IOutputStream outputStream = randomAccessStream.GetOutputStreamAt(0); // Use the default buffer for AsStreamForWrite() return(new DotNetStreamOutputStream(outputStream.AsStreamForWrite())); } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }
public override void visitChildren(FileVisitor fileVisitor, DirectoryVisitor directoryVisitor, VisitFailed visitFailed) { var directoryInfo = new DirectoryInfo(directoryPath); try { foreach (var fileSystemInfo in directoryInfo.EnumerateFileSystemInfos()) { if ((fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory) { directoryVisitor(new FileSystemDirectory(fileSystemInfo.FullName)); } else { fileVisitor(new FileSystemFile(this, fileSystemInfo.FullName)); } } } catch (System.IO.IOException e) { throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e); } }