/// <summary> /// Copy the Android assets to the app's FilesDir /// </summary> /// <param name="context">The android context</param> /// <param name="assertName">The name of the assert</param> /// <param name="dstDir">The subfolder in the app's FilesDir</param> /// <param name="overwriteMethod">overwrite method</param> /// <returns>The resulting FileInfo</returns> public static FileInfo WritePermanantFileAsset(Context context, String assertName, String dstDir, OverwriteMethod overwriteMethod) { String fullPath = Path.Combine(context.FilesDir.AbsolutePath, dstDir, assertName); //Create the directory if it is not already exist. Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); using (Stream iStream = context.Assets.Open(assertName)) WriteStream(iStream, fullPath, overwriteMethod); return new FileInfo(fullPath); }
public AndroidCacheFileAsset(Context context, String assertName, String cacheFolderPostfix, OverwriteMethod method) { String fileName = Path.GetFileName(assertName); fileName = Path.Combine(context.GetDir(cacheFolderPostfix, FileCreationMode.Private).AbsolutePath, fileName); _file = new FileInfo(fileName); _overwriteMethod = method; using (System.IO.Stream iStream = context.Assets.Open(assertName)) WriteStream(iStream, FileFullPath, _overwriteMethod); }
public static void WriteStream(System.IO.Stream iStream, String fileFullPath, OverwriteMethod method) { if (method == OverwriteMethod.NeverOverwrite && File.Exists(fileFullPath)) { throw new IOException(String.Format("A file with the name {0} already exist.", fileFullPath)); } using (Stream os = File.OpenWrite(fileFullPath)) { byte[] buffer = new byte[8 * 1024]; int len; while ((len = iStream.Read(buffer, 0, buffer.Length)) > 0) os.Write(buffer, 0, len); } }
public static void WriteStream(System.IO.Stream iStream, String fileFullPath, OverwriteMethod method) { if (method == OverwriteMethod.NeverOverwrite && File.Exists(fileFullPath)) { throw new IOException(String.Format("A file with the name {0} already exist.", fileFullPath)); } using (Stream os = File.OpenWrite(fileFullPath)) { byte[] buffer = new byte[8 * 1024]; int len; while ((len = iStream.Read(buffer, 0, buffer.Length)) > 0) { os.Write(buffer, 0, len); } } }
/// <summary> /// Copy the Android assets to the app's FilesDir /// </summary> /// <param name="context">The android context</param> /// <param name="assertName">The name of the assert</param> /// <param name="dstDir">The subfolder in the app's FilesDir</param> /// <param name="overwriteMethod">overwrite method</param> /// <returns>The resulting FileInfo</returns> public static FileInfo WritePermanantFileAsset(Context context, String assertName, String dstDir, OverwriteMethod overwriteMethod) { String fullPath = Path.Combine(context.FilesDir.AbsolutePath, dstDir, assertName); //Create the directory if it is not already exist. Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); using (Stream iStream = context.Assets.Open(assertName)) WriteStream(iStream, fullPath, overwriteMethod); return(new FileInfo(fullPath)); }
/* ----------------------------------------------------------------- */ /// /// Close /// /// <summary> /// Sets the overwrite method and close the dialog. /// </summary> /// /* ----------------------------------------------------------------- */ private void Close(OverwriteMethod value) { Value = value; Close(); }
public AndroidCacheFileAsset(Context context, String assertName, String cacheFolderPostfix, OverwriteMethod method) { String fileName = Path.GetFileName(assertName); fileName = Path.Combine(context.GetDir(cacheFolderPostfix, FileCreationMode.Private).AbsolutePath, fileName); _file = new FileInfo(fileName); _overwriteMethod = method; using(System.IO.Stream iStream = context.Assets.Open(assertName)) WriteStream(iStream, FileFullPath, _overwriteMethod); }
public static void ExtractToDirectory(this ZipArchive archive, string destinationDirectoryName, OverwriteMethod overwrite) { if (overwrite == OverwriteMethod.Never) { archive.ExtractToDirectory(destinationDirectoryName); return; } foreach (var file in archive.Entries) { var destinationFileName = Path.Combine(destinationDirectoryName, file.FullName); var directory = Path.GetDirectoryName(destinationFileName); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } switch (overwrite) { case OverwriteMethod.Always: if (!string.IsNullOrWhiteSpace(file.Name)) { file.ExtractToFile(destinationFileName, true); } break; case OverwriteMethod.IfNewer: if (!File.Exists(destinationFileName) || File.GetLastWriteTime(destinationFileName) < file.LastWriteTime) { file.ExtractToFile(destinationFileName, true); } break; case OverwriteMethod.Never: if (!File.Exists(destinationFileName)) { file.ExtractToFile(destinationFileName); } break; } } }
/* ----------------------------------------------------------------- */ /// /// SetOverwrite /// /// <summary> /// Subscribes the message to select the overwrite method. /// </summary> /// /// <param name="src">Source ViewModel.</param> /// <param name="value"> /// Overwrite method to set when requested. /// </param> /// /// <returns>Object to clear the subscription.</returns> /// /* ----------------------------------------------------------------- */ public static IDisposable SetOverwrite(this ExtractViewModel src, OverwriteMethod value) => src.Subscribe <QueryMessage <OverwriteQuerySource, OverwriteMethod> >(e => { e.Value = value; e.Cancel = false; });