Пример #1
0
        public void TestExtensions()
        {
            {
                var path = new UPath("/a/b/c/d.txt");
                Assert.Equal(new UPath("/a/b/c"), path.GetDirectory());
                Assert.Equal("d.txt", path.GetName());
                Assert.Equal("d", path.GetNameWithoutExtension());
                Assert.Equal(".txt", path.GetExtensionWithDot());
                var newPath = path.ChangeExtension(".zip");
                Assert.Equal("/a/b/c/d.zip", newPath.FullName);
                Assert.Equal(new UPath("a/b/c/d.txt"), path.ToRelative());
                Assert.Equal(path, path.AssertAbsolute());
                Assert.Throws <ArgumentNullException>(() => new UPath().AssertNotNull());
                Assert.Throws <ArgumentException>(() => new UPath("not_absolute").AssertAbsolute());
            }

            {
                var path = new UPath("d.txt");
                Assert.Equal(UPath.Empty, path.GetDirectory());
                Assert.Equal("d.txt", path.GetName());
                Assert.Equal("d", path.GetNameWithoutExtension());
                Assert.Equal(".txt", path.GetExtensionWithDot());
                var newPath = path.ChangeExtension(".zip");
                Assert.Equal("d.zip", newPath.FullName);
                Assert.Equal(new UPath("d.txt"), path.ToRelative());
            }
        }
Пример #2
0
 protected override UPath?TryConvertPath(UPath pathFromEvent)
 {
     if (!_mountPath.IsNull)
     {
         return(_mountPath / pathFromEvent.ToRelative());
     }
     else
     {
         return(pathFromEvent);
     }
 }
Пример #3
0
 protected override Stream OpenFileImpl(UPath path, FileMode mode, FileAccess access, FileShare share)
 {
     if (mode == FileMode.Open)
     {
         var entry = zip.GetEntry(path.ToRelative().FullName);
         AssertV2.IsTrue(entry != null && entry.IsFile, "Not a file: " + entry);
         return(zip.GetInputStream(entry));
     }
     throw new NotImplementedException("Only read via FileMode.Open supported!");
     // var stream = new ZipOutputStream(File.Open(zip.Name, mode, access, share));
     // stream.PutNextEntry(new ZipEntry(path.ToRelative().FullName));
     // return stream;
 }
Пример #4
0
 private static UPath CombinePrefix(UPath prefix, UPath remaining)
 {
     return(prefix.IsNull ? remaining
         : prefix / remaining.ToRelative());
 }
Пример #5
0
        /// <inheritdoc />
        protected override UPath ConvertPathToDelegate(UPath path)
        {
            var safePath = path.ToRelative();

            return(SubPath / safePath);
        }
Пример #6
0
 public static UPath AddPrefix(this UPath self, UPath prefix)
 {
     return(prefix.IsNull ? self : prefix / self.ToRelative());
 }
Пример #7
0
        /// <inheritdoc />
        public Task <LoadResult> LoadFile(IFileSystem fileSystem, UPath path, Guid pluginId, IStateInfo parentStateInfo, LoadFileContext loadFileContext)
        {
            // Downside of not having ArchiveChildren is not having the states saved below automatically when opened file is saved

            // If file is loaded
            var absoluteFilePath = UPath.Combine(fileSystem.ConvertPathToInternal(UPath.Root), path.ToRelative());

            if (IsLoaded(absoluteFilePath))
            {
                return(Task.FromResult(new LoadResult(GetLoadedFile(absoluteFilePath))));
            }

            // 1. Create file system action
            var fileSystemAction = new Func <IStreamManager, IFileSystem>(fileSystem.Clone);

            // 2. Load file
            // Only if called by a SubPluginManager the parent state is not null
            // Does not add ArchiveChildren to parent state
            return(LoadFile(fileSystemAction, path, parentStateInfo, pluginId, loadFileContext));
        }
Пример #8
0
        public static IEnumerable <IArchiveFileInfo> EnumerateFiles(IList <Stream> streams, ApkTocEntry entry, UPath path, IList <ApkPackHeader> apkHeaders, IList <string> strings, IList <ApkTocEntry> entries)
        {
            var headerName = strings[apkHeaders[entry.headerIndex].stringIndex];
            var name       = strings[entry.stringIndex];

            var isDirectory  = (entry.flags & 0x1) > 0;
            var isCompressed = (entry.flags & 0x200) > 0;

            if (isDirectory)
            {
                foreach (var subEntry in entries.Skip(entry.offset).Take(entry.count))
                {
                    foreach (var file in EnumerateFiles(streams, subEntry, path / name, apkHeaders, strings, entries))
                    {
                        yield return(file);
                    }
                }
            }
            else
            {
                var stream = streams[entry.headerIndex];
                if (stream == null)
                {
                    yield break;
                }

                if (isCompressed)
                {
                    yield return(new ApkArchiveFileInfo(new SubStream(stream, entry.offset, entry.compSize), (headerName / path.ToRelative() / name).FullName, entry.headerIndex, Compressions.ZLib, entry.decompSize));
                }
                else
                {
                    yield return(new ApkArchiveFileInfo(new SubStream(stream, entry.offset, entry.decompSize), (headerName / path.ToRelative() / name).FullName, entry.headerIndex));
                }
            }
        }
        // Token: 0x06001A1F RID: 6687 RVA: 0x0006FC58 File Offset: 0x0006DE58
        protected override Stream OpenFileImpl(UPath path, FileMode mode, FileAccess access, FileShare share)
        {
            SteamworksRemoteStorageFileSystem.EnterFileSystemShared();
            if (!path.IsAbsolute)
            {
                throw new ArgumentException(string.Format("'{0}' must be absolute. {0} = {1}", "path", path));
            }
            Stream result;

            try
            {
                bool flag = false;
                switch (mode)
                {
                case FileMode.CreateNew:
                    flag = true;
                    break;

                case FileMode.Create:
                    flag = true;
                    break;

                case FileMode.Append:
                    throw new NotImplementedException();
                }
                flag &= (access == FileAccess.Write);
                if (flag)
                {
                    this.treeIsDirty = true;
                    result           = SteamworksRemoteStorageFileSystem.remoteStorage.CreateFile(path.ToRelative().FullName).OpenWrite();
                }
                else if (access != FileAccess.Read)
                {
                    if (access != FileAccess.Write)
                    {
                        throw new NotImplementedException();
                    }
                    SteamworksRemoteStorageFileSystem.FileNode fileNode = this.GetFileNode(path);
                    result = ((fileNode != null) ? fileNode.OpenWrite() : null);
                }
                else
                {
                    SteamworksRemoteStorageFileSystem.FileNode fileNode2 = this.GetFileNode(path);
                    result = ((fileNode2 != null) ? fileNode2.OpenRead() : null);
                }
            }
            finally
            {
                SteamworksRemoteStorageFileSystem.ExitFileSystemShared();
            }
            return(result);
        }