ICreateDocumentTask IDocumentService.CreateCreateDocumentTask(Uri uri, Guid guid, string persistentInfo)
        {
            return(CreateDocumentTask.FromFactory(() =>
            {
                if (uri.Scheme == Uri.UriSchemeFile)
                {
                    var path = uri.LocalPath;
                    if (path == null || !UnifiedFile.Exists(path))
                    {
                        return null;
                    }

                    var fileViewer = this.GetFileViewerService(UnifiedPath.GetExtension(path));
                    if (fileViewer == null)
                    {
                        return null;
                    }

                    return this.CreateDocument(guid, uri, fileViewer);
                }
                else if (uri.Scheme == StreamScheme)
                {
                    var streamId = uri.Host + uri.PathAndQuery;
                    StreamInfo streamInfo;
                    if (!_registeredStreams.TryGetValue(streamId, out streamInfo))
                    {
                        this.LogWarning("no registered stream with ID '{0}' found", streamId);
                        return null;
                    }

                    _registeredStreams.Remove(streamId);

                    if (!streamInfo.StreamReference.IsAlive)
                    {
                        this.LogWarning("the registered stream with ID '{0}' is no more alive", streamId);
                        return null;
                    }

                    var fileViewer = this.GetFileViewerServiceOrNotifyMissing(streamInfo.FileType);
                    if (fileViewer == null)
                    {
                        return null;
                    }


                    IFeature[] features;

                    var viewer = fileViewer.CreateViewer(streamInfo.StreamReference.Target, out features);

                    var document = DocumentInfo.CreateTemporary(streamInfo.OwnerRepository.ID, streamInfo.Title, uri, viewer, features);
                    document.Description = streamInfo.Description;

                    return document;
                }
                else
                {
                    throw new NotSupportedException();
                }
            }));
        }
示例#2
0
        private void DownloadRecursive(IVersionedRepository repository, UnifiedPath source, string target, DateTime?upToDateTime = null)
        {
            var files = repository.GetFiles(source);

            foreach (var file in files)
            {
                var history  = repository.GetFileHistory(file.Path);
                var revision = history
                               .Where(r => r.Created.HasValue && (upToDateTime == null || r.Created.Value <= upToDateTime.Value))
                               .OrderByDescending(r => r.Created.Value)
                               .FirstOrDefault();
                if (revision != null)
                {
                    Directory.CreateDirectory(target);
                    repository.EndTransfer(repository.BeginDownloadVersionTransfer(revision.RevisionPath, target, true, null));
                    // TODO: Investigate
                    //File.SetLastWriteTime(Path.Combine(target, file.Name), revision.Created.Value);
                }
            }
            var folders = repository.GetFolders(source);

            foreach (var folder in folders)
            {
                string targetFolder = Path.Combine(target, folder.Name);
                DownloadRecursive(repository, folder.Path, targetFolder, upToDateTime);
            }
        }
        public static ImageSource Load(string packagePath, string localPath, double dpi = 96)
        {
            return(s_packageImageCache.GetOrCreate(UnifiedPath.Combine(packagePath, localPath),
                                                   () =>
            {
                try
                {
                    using (var stream = new PackageStream(packagePath, localPath))
                    {
                        BitmapSource image = BitmapImageEx.FromStream(stream);

                        if (image.DpiX != dpi || image.DpiY != dpi)
                        {
                            image = image.ChangeDPI(dpi);
                        }

                        image.Freeze();
                        return (ImageSource)image;
                    }
                }
                catch (Exception)
                {
                    return null;
                }
            }));
        }
        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));
        }
示例#5
0
        public PackageFolderVM(ExplorerTreeNodeVM parent, string packageFile, string localPath)
            : base(parent, UnifiedPath.Combine(packageFile, localPath), UnifiedPath.GetFileName(localPath))
        {
            this.LocalPath   = localPath;
            this.PackagePath = packageFile;

            _childEntries = new List <ZipEntry>();
        }
示例#6
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());
        }
示例#7
0
 private void PopulateTree(IRepository repo, UnifiedPath path, TreeNode rootNode)
 {
     FolderInfo[] folders = repo.GetFolders(path);
     foreach (var folder in folders)
     {
         var newNode = new TreeNode(folder.Name)
         {
             Tag = folder.Path
         };
         PopulateTree(repo, folder.Path, newNode);
         rootNode.Nodes.Add(newNode);
     }
 }
        private DocumentInfo CreateDocument(Guid guid, Uri uri, IFileViewerService fileViewerService)
        {
            IFeature[] features;
            var        viewer   = fileViewerService.CreateViewer(uri.LocalPath, out features);
            var        document = new DocumentInfo(guid: guid,
                                                   repositoryId: this.RepositoryManager.FindOwner(uri.LocalPath).ID,
                                                   uri: uri,
                                                   title: UnifiedPath.GetFileName(uri.LocalPath),
                                                   content: viewer,
                                                   features: features)
            {
                Description = uri.LocalPath,
                IconSource  = this.RepositoryManager.FindOwner(uri.LocalPath).GetMarker()
            };

            return(document);
        }
示例#9
0
 public XmlViewerVM(XmlViewerService service, CommandBindingCollection commandBindings, string path)
     : this(service, commandBindings, new BigworldXmlReader(path))
 {
     if (!UnifiedPath.IsInPackage(path))
     {
         this.SavePath      = path;
         _defaultSaveAsPath = path;
     }
     else
     {
         var gameClient = RepositoryManager.Instance.FindOwner(path);
         if (gameClient != null)
         {
             _defaultSaveAsPath = gameClient.GetCorrespondedModPath(path);
         }
     }
 }
示例#10
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));
        }
示例#11
0
 public string GetUnifiedPath(string filename)
 {
     return(UnifiedPath.Combine(this.GetPackagePath(filename), filename));
 }
示例#12
0
        public static string Decode(string path, out EncodeType encodeType, bool wellFormatted = false)
        {
            var packedFileName = UnifiedPath.GetFileName(path).ToLower();

            using (var stream = UnifiedFile.OpenRead(path))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    Int32 header = reader.ReadInt32();
                    if (header == PackedSection.PackedHeader)
                    {
                        reader.ReadSByte();

                        var document = new XmlDocument();

                        var packedSection = new PackedSection();
                        var dictionary    = packedSection.readDictionary(reader);
                        var xmlroot       = document.CreateNode(XmlNodeType.Element, packedFileName, "");
                        packedSection.readElement(reader, xmlroot, document, dictionary);
                        document.AppendChild(xmlroot);

                        encodeType = EncodeType.Packed;

                        if (wellFormatted)
                        {
                            return(XmlDecoder.FormatXml(document.OuterXml));
                        }
                        else
                        {
                            return(document.OuterXml);
                        }
                    }
                    else if (header == BinaryHeader)
                    {
                        stream.Seek(0, SeekOrigin.Begin);

                        var document = new XmlDocument();

                        var xmlPrimitives   = document.CreateNode(XmlNodeType.Element, "primitives", "");
                        var primitiveReader = new PrimitiveReader();
                        primitiveReader.ReadPrimitives(reader, xmlPrimitives, document);
                        document.AppendChild(xmlPrimitives);

                        encodeType = EncodeType.Binary;

                        if (wellFormatted)
                        {
                            return(XmlDecoder.FormatXml(document.OuterXml));
                        }
                        else
                        {
                            return(document.OuterXml);
                        }
                    }
                    else
                    {
                        var extension = UnifiedPath.GetExtension(path);
                        if (extension == ".xml" || extension == ".def" || extension == ".visual" || extension == ".chunk" || extension == ".settings" || extension == ".model")
                        {
                            encodeType = EncodeType.Plain;
                            return(File.ReadAllText(path));
                        }
                        else
                        {
                            throw new NotSupportedException();
                        }
                    }
                }
            }
        }
示例#13
0
 public PackageFileVM(ExplorerTreeNodeVM parent, string packageFile, string localPath, string name)
     : base(parent, UnifiedPath.Combine(packageFile, localPath), name)
 {
     this.LocalPath   = localPath;
     this.PackagePath = packageFile;
 }
 public string GetNationalTechTreeLayoutFile(string nationKey)
 {
     return(UnifiedPath.Combine(this.GuiPackageFile, string.Format(@"{0}\{1}{2}", c_techTreeLayoutRelativePath, nationKey, c_techTreeLayoutFilePostfix)));
 }
示例#15
0
 public FileVM(ExplorerTreeNodeVM parent, string path)
     : this(parent, path, UnifiedPath.GetFileName(path))
 {
 }
示例#16
0
        private string GetRelativePath(IPathHelper pathHelper, UnifiedPath root, UnifiedPath path)
        {
            int rootParts = pathHelper.Split(root).Length;

            return(string.Join(pathHelper.PathSeparator.ToString(), pathHelper.Split(path).Skip(rootParts)));
        }
示例#17
0
 private IEnumerable <UnifiedPath> GetFilesRecursively(IRepository repository, UnifiedPath root)
 {
     foreach (var file in repository.GetFiles(root))
     {
         yield return(file.Path);
     }
     foreach (var folder in repository.GetFolders(root))
     {
         foreach (var path in GetFilesRecursively(repository, folder.Path))
         {
             yield return(path);
         }
     }
 }