public void CopyGuideFiles(LocalModule localModule) { if (Environment.ExternalStorageState.Equals(Environment.MediaMounted)) { string curPath = AppStorageManager.GetInstance(mContext).DefaultFolder; if (!AppFileUtil.NeedScopedStorageAdaptation()) { curPath = AppFileUtil.DefaultDocumentDirectory; Java.IO.File file = new Java.IO.File(curPath); if (!file.Exists()) { if (!file.Mkdirs()) { return; } } Java.IO.File sampleFile = new Java.IO.File(curPath + Java.IO.File.Separator + "Sample.pdf"); if (!sampleFile.Exists()) { localModule.CopyFileFromAssertsToTargetFile(sampleFile); } Java.IO.File guideFile = new Java.IO.File(curPath + Java.IO.File.Separator + "complete_pdf_viewer_guide_android.pdf"); if (!guideFile.Exists()) { localModule.CopyFileFromAssertsToTargetFile(guideFile); } } else if (!TextUtils.IsEmpty(curPath)) { Uri uri = AppFileUtil.ToDocumentUriFromPath(curPath); if (AppFileUtil.IsDocumentTreeUri(uri)) { DocumentFile directory = AppStorageManager.GetInstance(mContext).GetExistingDocumentFile(uri); if (directory == null) { return; } string fileName = "Sample.pdf"; DocumentFile file = directory.FindFile(fileName); if (file == null) { file = directory.CreateFile(AppFileUtil.GetMimeType(fileName), fileName); localModule.CopyFileFromAssertsToTargetFile(file); } fileName = "complete_pdf_viewer_guide_android.pdf"; file = directory.FindFile(fileName); if (file == null) { file = directory.CreateFile(AppFileUtil.GetMimeType(fileName), fileName); localModule.CopyFileFromAssertsToTargetFile(file); } } localModule.SetCurrentPath(curPath); } } }
/// <summary> /// liefert das DocumentFile für eine Datei oder ein Verzeichnis (API level 14) /// <para>Wenn das Objekt noch nicht ex., wird es erzeugt. Auch ein notwendiger Pfad wird vollständig erzeugt.</para> /// </summary> /// <param name="storagename">z.B. "primary" oder "19F4-0903"</param> /// <param name="volpath">abs. Pfad im Volume</param> /// <param name="isDirectory">Pfad bezieht sich auf eine Datei oder ein Verzeichnis</param> /// <returns></returns> public DocumentFile GetDocumentFile(string storagename, string volpath, bool isDirectory) { global::Android.Net.Uri rooturi = GetTreeDocumentUri(storagename); DocumentFile document = DocumentFile.FromTreeUri(Activity.ApplicationContext, rooturi); string[] pathelems = volpath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; document != null && i < pathelems.Length; i++) { DocumentFile nextDocument = document.FindFile(pathelems[i]); if (nextDocument == null) { if ((i < pathelems.Length - 1) || isDirectory) { nextDocument = document.CreateDirectory(pathelems[i]); } else { nextDocument = document.CreateFile("", pathelems[i]); } } document = nextDocument; } System.Diagnostics.Debug.WriteLine("AndroidGetDocumentFile(" + storagename + ", " + volpath + ", " + isDirectory.ToString() + ") = " + (document != null && (isDirectory == document.IsDirectory)).ToString()); return(document != null ? (isDirectory == document.IsDirectory ? document : null) : null); }
public async Task <ExistenceCheckResult> CheckExistsAsync(string name, CancellationToken cancellationToken = default(CancellationToken)) { var selectedFile = folder.FindFile(name); if (selectedFile == null) { return(ExistenceCheckResult.NotFound); } else if (selectedFile.IsFile) { return(ExistenceCheckResult.FileExists); } else { return(ExistenceCheckResult.FolderExists); } }
public override async Task <StorageFile> GetFileAsync(string name, CancellationToken token) { return(await Task.Run(() => { var item = _directoryDocument.FindFile(name); if (item == null) { throw new FileNotFoundException("There is no file with this name."); } if (!item.IsFile) { throw new ArgumentException("The item with given name is a folder.", nameof(name)); } return StorageFile.GetFromSafDocument(item); }, token)); }
/// <summary> /// liefert das DocumentFile für eine Datei oder ein Verzeichnis, wenn es existiert (sonst null) (API level 14) /// </summary> /// <param name="storagename">z.B. "primary" oder "19F4-0903"</param> /// <param name="volpath">abs. Pfad im Volume</param> /// <returns></returns> public DocumentFile GetExistingDocumentFile(string storagename, string volpath) { global::Android.Net.Uri rooturi = GetTreeDocumentUri(storagename); DocumentFile document = DocumentFile.FromTreeUri(Activity.ApplicationContext, rooturi); string[] pathelems = volpath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; document != null && i < pathelems.Length; i++) { DocumentFile nextDocument = document.FindFile(pathelems[i]); document = nextDocument; } System.Diagnostics.Debug.WriteLine("AndroidGetExistingDocumentFile(" + storagename + ", " + volpath + ") = " + (document != null).ToString()); return(document); }