Ejemplo n.º 1
0
        private static string CreateIsolatedPath(IsolatedStorageFile isf, string path, FileMode mode)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (!Enum.IsDefined(typeof(FileMode), mode))
            {
                throw new ArgumentException("mode");
            }

            if (isf == null)
            {
                // we can't call GetUserStoreForDomain here because it depends on
                // Assembly.GetCallingAssembly (), which would be our constructor,
                // i.e. the result would always be mscorlib.dll. So we need to do
                // a small stack walk to find who's calling the constructor

                StackFrame sf = new StackFrame(3);                  // skip self and constructor
                isf = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly,
                                                   IsolatedStorageFile.GetDomainIdentityFromEvidence(AppDomain.CurrentDomain.Evidence),
                                                   IsolatedStorageFile.GetAssemblyIdentityFromEvidence(sf.GetMethod().ReflectedType.Assembly.UnprotectedGetEvidence()));
            }

            // ensure that the _root_ isolated storage can be (and is) created.
            FileInfo fi = new FileInfo(isf.Root);

            if (!fi.Directory.Exists)
            {
                fi.Directory.Create();
            }

            // other directories (provided by 'path') must already exists
            string file = Path.Combine(isf.Root, path);

            fi = new FileInfo(file);
            if (!fi.Directory.Exists)
            {
                // don't leak the path information for isolated storage
                string msg = Locale.GetText("Could not find a part of the path \"{0}\".");
                throw new DirectoryNotFoundException(String.Format(msg, path));
            }

            // FIXME: this is probably a good place to Assert our security
            // needs (once Mono supports imperative security stack modifiers)

            return(file);
        }
Ejemplo n.º 2
0
        private static string CreateIsolatedPath(IsolatedStorageFile isf, string path, FileMode mode)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (!Enum.IsDefined(typeof(FileMode), mode))
            {
                throw new ArgumentException("mode");
            }
            if (isf == null)
            {
                StackFrame stackFrame = new StackFrame(3);
                isf = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, IsolatedStorageFile.GetDomainIdentityFromEvidence(AppDomain.CurrentDomain.Evidence), IsolatedStorageFile.GetAssemblyIdentityFromEvidence(stackFrame.GetMethod().ReflectedType.Assembly.UnprotectedGetEvidence()));
            }
            FileInfo fileInfo = new FileInfo(isf.Root);

            if (!fileInfo.Directory.Exists)
            {
                fileInfo.Directory.Create();
            }
            if (Path.IsPathRooted(path))
            {
                string pathRoot = Path.GetPathRoot(path);
                path = path.Remove(0, pathRoot.Length);
            }
            string text     = Path.Combine(isf.Root, path);
            string fullPath = Path.GetFullPath(text);

            fullPath = Path.GetFullPath(text);
            if (!fullPath.StartsWith(isf.Root))
            {
                throw new IsolatedStorageException();
            }
            fileInfo = new FileInfo(text);
            if (!fileInfo.Directory.Exists)
            {
                string text2 = Locale.GetText("Could not find a part of the path \"{0}\".");
                throw new DirectoryNotFoundException(string.Format(text2, path));
            }
            return(text);
        }