public static ImageSource Load(string path, double dpi = 96)
        {
            string packagePath, localPath;

            UnifiedPath.ParsePath(path, out packagePath, out localPath);

            return(PackageImage.Load(packagePath, localPath, dpi));
        }
예제 #2
0
        private List <ExtractFileInfo> BuildExtractFileListFromSpecifiedFileList()
        {
            _progressController.SetIndeterminate();
            var distinctFileList = new Dictionary <string, ExtractFileInfo>();

            foreach (var file in this.FileList)
            {
                var fileInfo = distinctFileList.GetOrCreate(file, () =>
                {
                    var info = new ExtractFileInfo();
                    string packagePath, localPath;
                    UnifiedPath.ParsePath(file, out packagePath, out localPath);
                    info.PackagePath     = packagePath;
                    info.DestinationRoot = this.GetDestinationRoot(localPath);
                    info.RelativePath    = localPath;
                    return(info);
                });
            }

            var packageGroups = distinctFileList.Values.Aggregate(new Dictionary <string, List <ExtractFileInfo> >(),
                                                                  (dict, item) =>
            {
                var list = dict.GetOrCreate(item.PackagePath.ToLower(),
                                            () => new List <ExtractFileInfo>());
                list.Add(item);
                return(dict);
            });

            var nonExistedFiles = new List <ExtractFileInfo>();

            foreach (var item in packageGroups)
            {
                var zipFile = new ZipFile(File.OpenRead(item.Key));

                foreach (var info in item.Value)
                {
                    var entryIndex = zipFile.FindEntry(info.RelativePath, true);
                    if (entryIndex == -1)
                    {
                        nonExistedFiles.Add(info);
                    }
                    else
                    {
                        info.Entry   = zipFile[entryIndex];
                        info.ZipFile = zipFile;
                    }
                }
            }

            // todo: handle non exisiting files

            return(packageGroups.Values.SelectMany(i => i).ToList());
        }
예제 #3
0
        public string GetCorrespondedModPath(string unifiedPath)
        {
            string packagePath, localPath;

            UnifiedPath.ParsePath(unifiedPath, out packagePath, out localPath);
            if (string.IsNullOrEmpty(packagePath))
            {
                throw new ArgumentException("this is not a package path", nameof(unifiedPath));
            }

            packagePath = PathEx.NormalizeDirectorySeparators(packagePath);

            var pathDirectory  = Path.GetDirectoryName(packagePath);
            var resPackagePath = Path.Combine("res", "packages");

            if (!pathDirectory.ToLower().EndsWith(resPackagePath))
            {
                throw new ArgumentException("package is located in an invalid localtion", nameof(unifiedPath));
            }

            return(Path.Combine(this.ModDirectory, localPath));
        }