Ejemplo n.º 1
0
        //creates a local ioc where the sourceIoc can be stored to
        public static IOConnectionInfo GetInternalIoc(IOConnectionInfo sourceIoc, Context ctx, IKp2aApp app)
        {
            Java.IO.File internalDirectory = IoUtil.GetInternalDirectory(ctx);
            var          filestorage       = app.GetFileStorage(sourceIoc);

            string targetPath = filestorage.GetFilenameWithoutPathAndExt(sourceIoc);

            targetPath = targetPath.Trim("|\\?*<\":>+[]/'".ToCharArray());
            if (targetPath == "")
            {
                targetPath = "internal";
            }
            if (new File(internalDirectory, targetPath).Exists())
            {
                int c   = 1;
                var ext = UrlUtil.GetExtension(targetPath);
                var filenameWithoutExt = UrlUtil.StripExtension(targetPath);
                do
                {
                    c++;
                    targetPath = filenameWithoutExt + c;
                    if (!String.IsNullOrEmpty(ext))
                    {
                        targetPath += "." + ext;
                    }
                } while (new File(internalDirectory, targetPath).Exists());
            }
            return(IOConnectionInfo.FromPath(new File(internalDirectory, targetPath).CanonicalPath));
        }
Ejemplo n.º 2
0
        public void PrepareFileUsage(IFileStorageSetupInitiatorActivity activity, IOConnectionInfo ioc, int requestCode, bool alwaysReturnSuccess)
        {
            //check if we need to request the external-storage-permission at runtime
            if (ioc.IsLocalFile())
            {
                bool requiresPermission = !(ioc.Path.StartsWith(activity.Activity.FilesDir.CanonicalPath) ||
                                            ioc.Path.StartsWith(IoUtil.GetInternalDirectory(activity.Activity).CanonicalPath) ||
                                            ioc.Path.StartsWith(IoUtil.GetInternalDirectory(activity.Activity).CanonicalPath));

                var extDirectory = activity.Activity.GetExternalFilesDir(null);
                if ((extDirectory != null) && (ioc.Path.StartsWith(extDirectory.CanonicalPath)))
                {
                    requiresPermission = false;
                }

                if (requiresPermission && (Build.VERSION.SdkInt >= BuildVersionCodes.M))
                {
                    if ((activity.Activity.CheckSelfPermission(Manifest.Permission.WriteExternalStorage) ==
                         Permission.Denied)
                        ||
                        (activity.Activity.CheckSelfPermission(Manifest.Permission.ReadExternalStorage) ==
                         Permission.Denied))

                    {
                        activity.StartFileUsageProcess(ioc, requestCode, alwaysReturnSuccess);
                        return;
                    }
                }
            }
            Intent intent = new Intent();

            activity.IocToIntent(intent, ioc);
            activity.OnImmediateResult(requestCode, (int)FileStorageResults.FileUsagePrepared, intent);
        }
Ejemplo n.º 3
0
        public static IOConnectionInfo ImportFileToInternalDirectory(IOConnectionInfo sourceIoc, Context ctx, IKp2aApp app)
        {
            var targetIoc = GetInternalIoc(sourceIoc, ctx, app);


            IoUtil.Copy(targetIoc, sourceIoc, app);
            return(targetIoc);
        }
Ejemplo n.º 4
0
        private bool IsLocalBackup(IOConnectionInfo ioc)
        {
            bool result;

            if (_isLocalBackupCache.TryGetValue(ioc.Path, out result))
            {
                return(result);
            }

            result = (PreferenceManager.GetDefaultSharedPreferences(Application.Context)
                      .GetBoolean(IoUtil.GetIocPrefKey(ioc, "is_local_backup"), false));
            _isLocalBackupCache[ioc.Path] = result;
            return(result);
        }
Ejemplo n.º 5
0
        public CachingFileStorage(IFileStorage cachedStorage, Context cacheDirContext, ICacheSupervisor cacheSupervisor)
        {
            _cachedStorage   = new OfflineSwitchableFileStorage(cachedStorage);
            _cacheSupervisor = cacheSupervisor;
            _legacyCacheDir  = cacheDirContext.CacheDir.Path + Java.IO.File.Separator + "OfflineCache" + Java.IO.File.Separator;
            if (!Directory.Exists(_legacyCacheDir))
            {
                Directory.CreateDirectory(_legacyCacheDir);
            }

            _cacheDir = IoUtil.GetInternalDirectory(cacheDirContext).Path + Java.IO.File.Separator + "OfflineCache" + Java.IO.File.Separator;
            if (!Directory.Exists(_cacheDir))
            {
                Directory.CreateDirectory(_cacheDir);
            }
        }
Ejemplo n.º 6
0
 public IOConnectionInfo GetParentPath(IOConnectionInfo ioc)
 {
     return(IoUtil.GetParentPath(ioc));
 }
Ejemplo n.º 7
0
 public void ClearCache()
 {
     IoUtil.DeleteDir(new Java.IO.File(_streamCacheDir), true);
 }
Ejemplo n.º 8
0
 public void ClearCache()
 {
     IoUtil.DeleteDir(new Java.IO.File(_legacyCacheDir), true);
     IoUtil.DeleteDir(new Java.IO.File(_cacheDir), true);
 }