Example #1
0
        public static RomFsDirectoryNode Parse(IList <IArchiveFileInfo> files, UPath rootDirectory)
        {
            var root = new RomFsDirectoryNode
            {
                Name        = "/",
                Directories = new List <RomFsDirectoryNode>(),
                Files       = new List <IArchiveFileInfo>()
            };

            var directories = files.Select(x => x.FilePath.GetSubDirectory(rootDirectory.ToAbsolute()).GetDirectory()).Distinct().OrderBy(x => x).ToArray();

            foreach (var directory in directories)
            {
                var currentNode = root;
                foreach (var part in directory.Split())
                {
                    var newNode = currentNode.Directories.FirstOrDefault(x => x.Name == part);
                    if (newNode != null)
                    {
                        currentNode = newNode;
                        continue;
                    }

                    newNode = new RomFsDirectoryNode
                    {
                        _parent = currentNode,

                        Name        = part,
                        Directories = new List <RomFsDirectoryNode>(),
                        Files       = new List <IArchiveFileInfo>()
                    };
                    currentNode.Directories.Add(newNode);

                    currentNode = newNode;
                }

                foreach (var file in files.Where(x => x.FilePath.GetDirectory().ToRelative() == rootDirectory / directory.ToRelative()))
                {
                    currentNode.Files.Add(file);
                }
            }

            return(root);
        }
Example #2
0
        public void TestAbsoluteAndRelative()
        {
            var path = new UPath("x");

            Assert.True(path.IsRelative);
            Assert.False(path.IsAbsolute);

            path = new UPath("..");
            Assert.True(path.IsRelative);
            Assert.False(path.IsAbsolute);

            path = new UPath("/x");
            Assert.False(path.IsRelative);
            Assert.True(path.IsAbsolute);

            Assert.Equal(path, path.ToAbsolute());

            path = new UPath();
            Assert.True(path.IsNull);
        }
Example #3
0
 public static int CountDirectories(IList <ArchiveFileInfo> files, UPath rootDirectory)
 {
     return(files.Select(x => x.FilePath.GetSubDirectory(rootDirectory.ToAbsolute()).GetDirectory())
            .Distinct()
            .Count());
 }
        protected void Internal_FillCache()
        {
            if (_bCached)
            {
                return;
            }
            _globalLock.EnterWriteLock();

            try
            {
                if (_bCached)
                {
                    return;
                }

                var cacheDir    = new Dictionary <string, PHAssetCollection>();
                var cachePhoto  = new Dictionary <string, PHPhotoItem>();
                var collections = PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.SmartAlbum, PHAssetCollectionSubtype.SmartAlbumUserLibrary, null);
                foreach (PHAssetCollection asset in collections)
                {
                    cacheDir["/" + asset.LocalizedTitle] = asset;

                    var assets = PHAsset.FetchAssets(asset, null);
                    foreach (PHAsset photo in assets)
                    {
                        var assetResources = PHAssetResource.GetAssetResources(photo);
                        var original       = assetResources.FirstOrDefault(x => x.ResourceType == PHAssetResourceType.Video ||
                                                                           x.ResourceType == PHAssetResourceType.Photo ||
                                                                           x.ResourceType == PHAssetResourceType.Audio);

                        if (original == null)
                        {
                            continue;
                        }

                        var   dt       = photo.CreationDate.ToDateTime();
                        var   dtstr    = dt.ToLocalTime().ToString("yyyy-MM-dd HH_mm");
                        var   filename = $"{dtstr} {original.OriginalFilename}";
                        UPath up       = Path.Combine(asset.LocalizedTitle, filename);
                        var   item     = new PHPhotoItem {
                            Col   = asset,
                            Asset = photo,
                            Res   = original
                        };
                        item.Path   = new Lazy <string>(item.FillPath);
                        item.Length = new Lazy <long>(item.FillLength);

                        cachePhoto[up.ToAbsolute().ToString().ToUpperInvariant()] = item;

                        var originalName = Path.GetFileNameWithoutExtension(original.OriginalFilename);
                        foreach (var resource in assetResources)
                        {
                            if (resource == original)
                            {
                                continue;
                            }
                            if (string.IsNullOrEmpty(resource.OriginalFilename))
                            {
                                continue;
                            }

                            var extension = Path.GetExtension(resource.OriginalFilename) ?? string.Empty;
                            var fileName  = $"{dtstr} {originalName} ({resource.ResourceType:G}){extension}";

                            up = Path.Combine(asset.LocalizedTitle, fileName);


                            item = new PHPhotoItem {
                                Col   = asset,
                                Asset = photo,
                                Res   = resource
                            };
                            item.Path   = new Lazy <string>(item.FillPath);
                            item.Length = new Lazy <long>(item.FillLength);

                            cachePhoto[up.ToAbsolute().ToString().ToUpperInvariant()] = item;
                        }
                    }
                }

                _cacheDir   = cacheDir;
                _cachePhoto = cachePhoto;
                _bCached    = true;
                Task.Run(() => {
                    Parallel.ForEach(cachePhoto, new ParallelOptions {
                        MaxDegreeOfParallelism = 2 * Environment.ProcessorCount
                    },
                                     x => {
                        _ = x.Value.Length.Value;
                        _ = x.Value.Path.Value;
                    });
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                _globalLock.ExitWriteLock();
            }
        }
Example #5
0
        private async Task <SaveResult> ReloadInternalAsync(IFileState fileState, IFileSystem destinationFileSystem, UPath savePath, SaveInfo saveInfo)
        {
            // 1. Reload current state
            var temporaryStreamProvider = fileState.StreamManager.CreateTemporaryStreamProvider();

            var internalDialogManager = new InternalDialogManager(saveInfo.DialogManager, fileState.DialogOptions);
            var loadContext           = new LoadContext(temporaryStreamProvider, saveInfo.Progress, internalDialogManager);
            var reloadResult          = await TryLoadStateAsync(fileState.PluginState, destinationFileSystem, savePath.ToAbsolute(), loadContext);

            if (!reloadResult.IsSuccessful)
            {
                return(new SaveResult(reloadResult.Exception));
            }

            // 2. Set new file input, if state was loaded from a physical medium
            if (!fileState.HasParent)
            {
                fileState.SetNewFileInput(destinationFileSystem, savePath);
            }

            // 3. Reload all child states
            foreach (var archiveChild in fileState.ArchiveChildren)
            {
                var destination       = archiveChild.FileSystem.Clone(archiveChild.StreamManager);
                var reloadChildResult = await ReloadInternalAsync(archiveChild, destination, archiveChild.FilePath, saveInfo);

                if (!reloadChildResult.IsSuccessful)
                {
                    return(reloadChildResult);
                }
            }

            return(SaveResult.SuccessfulResult);
        }
Example #6
0
        public override string GetPath(TemplateContext context, SourceSpan callerSpan, string templateRelativePath)
        {
            var path = new UPath(callerSpan.FileName).GetDirectory() / templateRelativePath;

            return(path.ToAbsolute().FullName);
        }
 // Token: 0x06001A3C RID: 6716 RVA: 0x00070023 File Offset: 0x0006E223
 public Node(UPath path)
 {
     this.path = path.ToAbsolute();
 }