Exemplo n.º 1
0
        /// <summary>Provides package descriptor</summary>
        /// <param name="name">Mnemonic name of the package (i.e. application name)</param>
        /// <param name="source">Source directory where to take files from</param>
        /// <param name="relPath">Relative path which is appended to the root path where files will be placed</param>
        public PackageInfo(string name, FileSystemDirectory source, string relPath)
        {
          Name = name ?? CoreConsts.UNKNOWN;
          Source = source;
          RelativePath = relPath;

          ConfigSectionNode manifest = null;
          var mFile = source.GetFile(ManifestUtils.MANIFEST_FILE_NAME);
          if (mFile!=null)
               try
               {
                 manifest = LaconicConfiguration.CreateFromString(mFile.ReadAllText()).Root;
               }
               catch(Exception error)
               {
                 throw new NFXIOException(StringConsts.LOCAL_INSTALL_INSTALL_SET_PACKAGE_MANIFEST_READ_ERROR.Args(Name, error.ToMessageWithType()), error);
               }
          
          if (manifest==null)
           throw new NFXIOException(StringConsts.LOCAL_INSTALL_INSTALL_SET_PACKAGE_WITHOUT_MANIFEST_ERROR.Args(Name, ManifestUtils.MANIFEST_FILE_NAME));
           
          manifest.AttrByName(ManifestUtils.CONFIG_NAME_ATTR, true).Value = name;  
          manifest.AttrByName(ManifestUtils.CONFIG_LOCAL_PATH_ATTR, true).Value = relPath;
          manifest.ResetModified(); 
          
          Manifest = manifest; 
        }
Exemplo n.º 2
0
        public BundleCollectionCache_Write_Tests()
        {
            path      = new TempDirectory();
            directory = new FileSystemDirectory(path);

            var bundles = new BundleCollection(new CassetteSettings(), Mock.Of <IFileSearchProvider>(), Mock.Of <IBundleFactoryProvider>(), Mock.Of <IBundleCollectionInitializer>());

            scriptBundle             = new Mock <ScriptBundle>("~/test1");
            scriptBundle.CallBase    = true;
            scriptBundle.Object.Hash = new byte[] { 1, 2, 3 };
            scriptBundle.Object.Assets.Add(new StubAsset("~/test/asset.js", "script-bundle-content"));
            scriptBundle.Object.Renderer = new ScriptBundleHtmlRenderer(Mock.Of <IUrlGenerator>());
            scriptBundle.Setup(b => b.Render()).Returns("");
            bundles.Add(scriptBundle.Object);

            stylesheetBundle             = new Mock <StylesheetBundle>("~/test2");
            stylesheetBundle.CallBase    = true;
            stylesheetBundle.Object.Hash = new byte[] { 4, 5, 6 };
            stylesheetBundle.Object.Assets.Add(new StubAsset("~/test2/asset.css", "stylesheet-bundle-content"));
            stylesheetBundle.Object.Renderer = new StylesheetHtmlRenderer(Mock.Of <IUrlGenerator>());
            stylesheetBundle.Setup(b => b.Render()).Returns("");
            bundles.Add(stylesheetBundle.Object);

            var cache = new BundleCollectionCache(directory, b => null);

            cache.Write(new Manifest(bundles, "VERSION"));
        }
Exemplo n.º 3
0
        public List <string> ReadArchive <T>(string filePath, string outputDir) where T : ArchiveFile, new()
        {
            IDirectory    iDir      = new FileSystemDirectory(outputDir);
            List <string> fileNames = new List <string>();

            using (FileStream input = new FileStream(filePath, FileMode.Open))
            {
                T file = new T();
                file.Read(input);
                foreach (var exportedFile in file.ExportFiles(input))
                {
                    if (typeof(T) == typeof(SbpFile))
                    {
                        exportedFile.FileName = Path.GetFileNameWithoutExtension(filePath) + exportedFile.FileName;
                    }

                    fileNames.Add(exportedFile.FileName);

                    string exportedFileFullName = Path.Combine(outputDir, exportedFile.FileName);
                    if (!File.Exists(exportedFileFullName)) // saved roughly 1:10 when unpacking texture3 and chunk3
                    {
                        iDir.WriteFile(exportedFile.FileName, exportedFile.DataStream);
                    }
                }
            }
            return(fileNames);
        }
Exemplo n.º 4
0
        protected internal override IEnumerable <string> DoGetSubDirectoryNames(FileSystemDirectory directory, bool recursive)
        {
            var di = new DirectoryInfo(directory.Path);

            return(di.GetDirectories("*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
                   .Select(sdi => sdi.Name));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Generates packaging manifest for the specified directory. Optionally may specify root node name
        /// </summary>
        /// <param name="directory">Source directory to generate manifest for</param>
        /// <param name="rootNodeName">Name of root manifest node, if omitted then 'package' is defaulted</param>
        /// <param name="packageName">Optional 'name' attribute value under root node</param>
        /// <param name="packageLocalPath">Optional 'local-path' attribute value under root node</param>
        public static ConfigSectionNode GeneratePackagingManifest(this FileSystemDirectory directory,
                                                                  string rootNodeName     = null,
                                                                  string packageName      = null,
                                                                  string packageLocalPath = null)
        {
            if (directory == null)
            {
                throw new NFXIOException(StringConsts.ARGUMENT_ERROR + "GeneratePackagingManifest(directory==null)");
            }

            var conf = new MemoryConfiguration();

            conf.Create(rootNodeName.IsNullOrWhiteSpace()?CONFIG_PACKAGE_SECTION : rootNodeName);
            var root = conf.Root;

            if (packageName.IsNotNullOrWhiteSpace())
            {
                root.AddAttributeNode(CONFIG_NAME_ATTR, packageName);
            }

            if (packageLocalPath.IsNotNullOrWhiteSpace())
            {
                root.AddAttributeNode(CONFIG_LOCAL_PATH_ATTR, packageLocalPath);
            }

            buildDirLevel(root, directory);

            root.ResetModified();

            return(root);
        }
Exemplo n.º 6
0
        protected override FileSystemFile DoCreateFile(FileSystemDirectory directory, string name, int size)
        {
            var localFile = Path.GetTempFileName();

            using (var fs = new FileStream(localFile, FileMode.Open, FileAccess.Write, FileShare.None))
                fs.SetLength(size);
            return(doCreateFile(directory, name, localFile, remove: true));
        }
Exemplo n.º 7
0
        protected internal override IEnumerable <string> DoGetFileNames(FileSystemDirectory directory, bool recursive)
        {
            var dirPath = directory.Path;
            var di      = new DirectoryInfo(dirPath);

            return(di.GetFiles("*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
                   .Select(fi => Path.GetFileName(fi.FullName)));
        }
Exemplo n.º 8
0
        protected internal override FileSystemDirectory DoCreateDirectory(FileSystemDirectory dir, string name)
        {
            var dn = Path.Combine(dir.Path, name);

            var di = new DirectoryInfo(dn);
            di.Create();
            di.Refresh();
            return new FileSystemDirectory(dir.Session, di.Parent.FullName, name, new FSH{m_Info = di});
        }
Exemplo n.º 9
0
        protected internal override FileSystemDirectory DoCreateDirectory(FileSystemDirectory dir, string name)
        {
            var parent  = (GoogleDriveHandle)dir.Handle;
            var session = (GoogleDriveSession)dir.Session;

            var handle = session.Client.CreateDirectory(parent.Id, name);

            return(new FileSystemDirectory(dir.Session, dir.Path, name, handle));
        }
Exemplo n.º 10
0
        protected internal override FileSystemDirectory DoCreateDirectory(FileSystemDirectory dir, string name)
        {
            var parent = (GoogleDriveHandle)dir.Handle;
            var session = (GoogleDriveSession)dir.Session;

            var handle = session.Client.CreateDirectory(parent.Id, name);

            return new FileSystemDirectory(dir.Session, dir.Path, name, handle);
        }
Exemplo n.º 11
0
        protected internal override FileSystemDirectory DoCreateDirectory(FileSystemDirectory dir, string name)
        {
            var s3session = (S3V4FileSystemSession)dir.Session;
            var dirPath   = this.CombinePaths(dir.Path, name);
            var handle    = new S3V4FSH(dirPath);

            S3V4.PutFolder(handle.Path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs);

            return(new FileSystemDirectory(s3session, handle.Parent, handle.Name, handle));
        }
Exemplo n.º 12
0
 public void GivenEmptyDirectory_ThenCacheReadFails()
 {
     using (var path = new TempDirectory())
     {
         var directory = new FileSystemDirectory(path);
         var cache     = new BundleCollectionCache(directory, b => deserializers[b]);
         var result    = cache.Read();
         result.IsSuccess.ShouldBeFalse();
     }
 }
Exemplo n.º 13
0
 public InMemoryFileSystem(string root, IPhysicalFileSystem basis)
 {
     _basis = basis;
     _root  = new FileSystemDirectory(Path.GetFileName(root.TrimEnd('/', '\\')), root);
     IsPathInCone(root, out string newRoot);
     if (root != newRoot)
     {
         _root = new FileSystemDirectory(Path.GetFileName(newRoot.TrimEnd('/', '\\')), newRoot);
     }
 }
Exemplo n.º 14
0
        private List <FileSystemFileWrapper> GetFileSystemFileListFromNode(TreeNode selectedNode, bool setStatusBarInfo)
        {
            var directoryList = _currentFileSystemDrive.DirectoryList;
            List <FileSystemFileWrapper> fileSystemList = null;
            var      nodeTreversalStack = new Stack <string>();
            TreeNode rootNode           = selectedNode;

            nodeTreversalStack.Push(rootNode.Text);

            //Root node
            if (rootNode.Parent == null)
            {
                DirectoryInfoDataLabel.Text = GetRootDirectoryData(_currentFileSystemDrive);
                if (_currentFileSystemDrive.RootFileList == null)
                {
                    _currentFileSystemDrive.RootFileList = new List <FileSystemFile>();
                }
                return(_currentFileSystemDrive.RootFileList.ConvertAll(FileSystemFileWrapper.ConvertObject));
            }

            while (rootNode.Parent != null)
            {
                rootNode = rootNode.Parent;
                nodeTreversalStack.Push(rootNode.Text);
            }

            nodeTreversalStack.Pop();

            while (nodeTreversalStack.Count > 0)
            {
                string currentItem = nodeTreversalStack.Pop();
                for (int i = 0; i < directoryList.Count; i++)
                {
                    FileSystemDirectory dir = directoryList[i];
                    if (dir.Name == currentItem)
                    {
                        if (nodeTreversalStack.Count == 0 && dir.FileList != null)
                        {
                            fileSystemList = dir.FileList.ConvertAll(FileSystemFileWrapper.ConvertObject);
                        }
                        directoryList = dir.DirectoryList;


                        if (setStatusBarInfo)
                        {
                            DirectoryInfoDataLabel.Text = GetFileSystemDirectoryData(dir);
                        }

                        break;
                    }
                }
            }

            return(fileSystemList);
        }
Exemplo n.º 15
0
        }         //method ExtractArchive ends

        /*
         * WritePftxsArchive
         * Gets all of the files contained in a directory and writes them to a .pftxs file.
         */
        public static void WritePftxsArchive(string FileName, string SourceDirectory)
        {
            PftxsFile p = new PftxsFile()
            {
                Name = FileName
            };

            foreach (string file in Directory.EnumerateFiles(SourceDirectory))
            {
                if (Path.GetExtension(file) == ".ftex")
                {
                    string              nameWithoutExtension = Path.GetFileNameWithoutExtension(file);
                    PftxsFtexFile       pf  = new PftxsFtexFile();
                    PftxsFtexsFileEntry pfe = new PftxsFtexsFileEntry()
                    {
                        FilePath = nameWithoutExtension + ".ftex"
                    };
                    PftxsFtexsFileEntry pfe1 = new PftxsFtexsFileEntry()
                    {
                        FilePath = nameWithoutExtension + ".1.ftexs"
                    };
                    pf.Entries = new List <PftxsFtexsFileEntry>(0);
                    pf.Entries.Add(pfe);
                    pf.Entries.Add(pfe1);


                    if (File.Exists(SourceDirectory + "\\" + nameWithoutExtension + ".2.ftexs"))
                    {
                        PftxsFtexsFileEntry pfe2 = new PftxsFtexsFileEntry()
                        {
                            FilePath = nameWithoutExtension + ".2.ftexs"
                        };
                        pf.Entries.Add(pfe2);
                    } //if ends

                    if (File.Exists(SourceDirectory + "\\" + nameWithoutExtension + ".3.ftexs"))
                    {
                        PftxsFtexsFileEntry pfe2 = new PftxsFtexsFileEntry()
                        {
                            FilePath = nameWithoutExtension + ".3.ftexs"
                        };
                        pf.Entries.Add(pfe2);
                    } //if ends

                    p.Files.Add(pf);
                } //if ends
            }     //foreach ends

            using (FileStream outFile = new FileStream(FileName, FileMode.Create))
            {
                IDirectory fileDirectory = new FileSystemDirectory(SourceDirectory);
                p.Write(outFile, fileDirectory);
            } //using ends
        }     //method WritePftxsArchive
Exemplo n.º 16
0
        private void FolderTreeView_AfterExpand(object sender, TreeViewEventArgs e)
        {
            //Update chile nodes
            TreeNode selectedNode       = e.Node;
            var      nodeTreversalStack = new Stack <string>();
            TreeNode rootNode           = selectedNode;
            var      directoryList      = _currentFileSystemDrive.DirectoryList;

            nodeTreversalStack.Push(rootNode.Text);
            while (rootNode.Parent != null)
            {
                rootNode = rootNode.Parent;
                nodeTreversalStack.Push(rootNode.Text);
            }

            while (nodeTreversalStack.Count > 0)
            {
                string currentItem = nodeTreversalStack.Pop();
                for (int i = 0; i < directoryList.Count; i++)
                {
                    FileSystemDirectory dir = directoryList[i];
                    if (dir.Name == currentItem)
                    {
                        directoryList = dir.DirectoryList;
                        break;
                    }
                }
            }

            if (directoryList == null)
            {
                return;
            }

            TreeNode firstNode = selectedNode.FirstNode;

            while (firstNode != null)
            {
                if (firstNode.Nodes.Count == 0)
                {
                    FileSystemDirectory subDir = directoryList.SingleOrDefault(d => d.Name == firstNode.Text);
                    if (subDir != null && subDir.DirectoryList != null)
                    {
                        foreach (FileSystemDirectory fsd in subDir.DirectoryList)
                        {
                            firstNode.Nodes.Add(new TreeNode(fsd.Name));
                        }
                    }
                }

                firstNode = firstNode.NextNode;
            }
        }
Exemplo n.º 17
0
        private static void WriteArchive(ArchiveFile archiveFile, string workingDirectory)
        {
            string outputPath = Path.Combine(workingDirectory, archiveFile.Name);
            string fileSystemInputDirectory = string.Format("{0}\\{1}_{2}", workingDirectory,
                                                            Path.GetFileNameWithoutExtension(archiveFile.Name), Path.GetExtension(archiveFile.Name).Replace(".", ""));
            IDirectory inputDirectory = new FileSystemDirectory(fileSystemInputDirectory);

            using (FileStream output = new FileStream(outputPath, FileMode.Create))
            {
                archiveFile.Write(output, inputDirectory);
            }
        }
Exemplo n.º 18
0
        protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, int size)
        {
            var parent  = (GoogleDriveHandle)dir.Handle;
            var session = (GoogleDriveSession)dir.Session;

            var bytes  = new byte[size];
            var stream = new MemoryStream(bytes);

            var handle = session.Client.CreateFile(parent.Id, name, stream);

            return(new FileSystemFile(session, dir.Path, name, handle));
        }
Exemplo n.º 19
0
        protected override FileSystemDirectory DoCreateDirectory(FileSystemDirectory directory, string name)
        {
            var session = directory.Session as FTPFileSystemSession;
            var handle  = directory.Handle as Handle;
            var path    = session.Connection.CombinePaths(handle.FileInfo.FullName, name);

            session.Connection.CreateDirectory(path);

            var dirInfo = session.Connection.GetFileInfo(path);

            return(new FileSystemDirectory(directory.Session, directory.Path, name, new Handle(dirInfo)));
        }
Exemplo n.º 20
0
        protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, string localFile, bool readOnly)
        {
            var s3session = (S3V4FileSystemSession)dir.Session;
            var filePath  = this.CombinePaths(dir.Path, name);
            var handle    = new S3V4FSH(filePath);

            using (System.IO.FileStream r = new System.IO.FileStream(localFile, System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                S3V4.PutFile(filePath, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, r, s3session.TimeoutMs);
                return(new FileSystemFile(dir.Session, handle.Parent, handle.Name, handle));
            }
        }
Exemplo n.º 21
0
 protected override void RegisterBundleCollectionInitializer()
 {
     Container.Register <IBundleCollectionInitializer, BundleCollectionInitializer>();
     Container.Register <IBundleCollectionCache>((c, p) =>
     {
         var cacheDirectory = new FileSystemDirectory(Path.GetFullPath(outputDirectory));
         return(new BundleCollectionCache(
                    cacheDirectory,
                    bundleTypeName => ResolveBundleDeserializer(bundleTypeName, c)
                    ));
     });
 }
Exemplo n.º 22
0
        protected internal override FileSystemDirectory DoCreateDirectory(FileSystemDirectory dir, string name)
        {
            var dn = Path.Combine(dir.Path, name);

            var di = new DirectoryInfo(dn);

            di.Create();
            di.Refresh();
            return(new FileSystemDirectory(dir.Session, di.Parent.FullName, name, new FSH {
                m_Info = di
            }));
        }
Exemplo n.º 23
0
        protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, string localFile, bool readOnly)
        {
            var session = (GoogleDriveSession)dir.Session;
            var parent  = (GoogleDriveHandle)dir.Handle;
            var client  = session.Client;

            using (var stream = new FileStream(localFile, FileMode.Open, FileAccess.Read))
            {
                var handle = client.CreateFile(parent.Id, name, stream);
                return(new FileSystemFile(dir.Session, dir.Path, name, handle));
            }
        }
Exemplo n.º 24
0
        protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, string localFile, bool readOnly)
        {
            var fn = Path.Combine(dir.Path, name);

            File.Copy(localFile, fn, true);

            var fi = new FileInfo(fn);

            fi.IsReadOnly = readOnly;
            return(new FileSystemFile(dir.Session, fi.DirectoryName, fi.Name, new FSH {
                m_Info = fi
            }));
        }
Exemplo n.º 25
0
        protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, int size)
        {
            var s3session = (S3V4FileSystemSession)dir.Session;

            var filePath = this.CombinePaths(dir.Path, name);
            var handle   = new S3V4FSH(filePath);

            byte[]       bytes         = new byte[size];
            MemoryStream contentStream = new MemoryStream(bytes);

            S3V4.PutFile(handle.Path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, contentStream, s3session.TimeoutMs);

            return(new FileSystemFile(s3session, handle.Parent, handle.Name, handle));
        }
 private FileSystemDirectory CreateDirectory(Purl path, FileAndDirectoryRules rules)
 {
   FileSystemDirectory entry = new FileSystemDirectory(path);
   foreach (string subPath in _fileSystem.GetEntries(path.AsString))
   {
     Purl entryPath = new Purl(subPath);
     FileSystemEntry subEntry = FindEntry(entryPath, rules);
     if (subEntry != null)
     {
       entry.Entries.Add(subEntry);
     }
   }
   return entry;
 }
Exemplo n.º 27
0
        public void ReadQARArchive(string filePath, string outputDir)
        {
            IDirectory iDir = new FileSystemDirectory(outputDir);

            using (FileStream input = new FileStream(filePath, FileMode.Open))
            {
                QarFile file = new QarFile();
                file.Read(input);
                foreach (var exportedFile in file.ExportFiles(input))
                {
                    iDir.WriteFile(exportedFile.FileName, exportedFile.DataStream); // doesn't bother checking if the file already exists, since dats don't often have pre-existing stuff to overwrite. saved roughly 30 seconds when unpacking texture3
                }
            }
        }
Exemplo n.º 28
0
        private FileSystemFile doCreateFile(FileSystemDirectory directory, string name, string localFile, bool remove = false)
        {
            var session = directory.Session as FTPFileSystemSession;
            var handle  = directory.Handle as Handle;
            var path    = session.Connection.CombinePaths(handle.FileInfo.FullName, name);
            var options = new TransferOptions {
                TransferMode = TransferMode.Binary
            };
            var result = session.Connection.PutFiles(localFile, path, remove: remove, options: options);

            result.Check();
            var fileInfo = session.Connection.GetFileInfo(path);

            return(new FileSystemFile(directory.Session, directory.Path, name, new Handle(fileInfo)));
        }
Exemplo n.º 29
0
        public void GivenDirectoryWithManifest_ThenCacheReadSucceeds()
        {
            using (var path = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(path, "manifest.xml"),
                    "<?xml version=\"1.0\"?><BundleCollection Version=\"1\" IsStatic=\"false\"></BundleCollection>"
                    );

                var directory = new FileSystemDirectory(path);
                var cache     = new BundleCollectionCache(directory, b => deserializers[b]);
                var result    = cache.Read();
                result.IsSuccess.ShouldBeTrue();
            }
        }
Exemplo n.º 30
0
        protected internal override IEnumerable <string> DoGetSubDirectoryNames(FileSystemDirectory directory, bool recursive)
        {
            SVNFileSystemSession session = directory.Session as SVNFileSystemSession;

            WebDAV.Directory wdDirectory = GetSVNItem(directory) as WebDAV.Directory;

            WebDAV.Directory pathDirectory = session.WebDAV.Root.NavigatePath(wdDirectory.Path) as WebDAV.Directory;

            if (pathDirectory == null)
            {
                return(null);
            }

            return(pathDirectory.Directories.Select(c => c.Name));
        }
Exemplo n.º 31
0
        public void CreationDateTimeEqualsManifestFileLastWriteTimeUtc()
        {
            using (var path = new TempDirectory())
            {
                var manifestFilename = Path.Combine(path, "manifest.xml");
                File.WriteAllText(
                    manifestFilename,
                    "<?xml version=\"1.0\"?><BundleCollection Version=\"1\" IsStatic=\"false\"></BundleCollection>"
                    );

                var directory = new FileSystemDirectory(path);
                var cache     = new BundleCollectionCache(directory, b => deserializers[b]);
                var result    = cache.Read();
                result.Manifest.CreationDateTime.ShouldEqual(File.GetLastWriteTimeUtc(manifestFilename));
            }
        }
Exemplo n.º 32
0
        public void Variable_defined_by_nested_import_is_replaced_in_CSS_output()
        {
            using (var path = new TempDirectory())
            {
                File.WriteAllText(Path.Combine(path, "main.less"), "@import 'first.less';\np { color: @c }");
                File.WriteAllText(Path.Combine(path, "first.less"), "@import 'second.less';");
                File.WriteAllText(Path.Combine(path, "second.less"), "@c: red;");
                var directory = new FileSystemDirectory(path);
                var file      = directory.GetFile("main.less");
                var compiler  = new LessCompiler();

                var css = compiler.Compile(file.OpenRead().ReadToEnd(), file);

                css.ShouldContain("color: red;");
            }
        }
Exemplo n.º 33
0
        public void ItDeletesAllFilesInCacheDirectory()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "script/test1"));
                Directory.CreateDirectory(Path.Combine(path, "stylesheet/test2"));
                File.WriteAllText(Path.Combine(path, "manifest.xml"), "");
                File.WriteAllText(Path.Combine(path, "script/test1/010203.js"), "");
                File.WriteAllText(Path.Combine(path, "stylesheet/test2/040506.css"), "");

                var directory = new FileSystemDirectory(path);

                var cache = new BundleCollectionCache(directory, b => null);
                cache.Clear();

                Directory.GetFiles(path).Length.ShouldEqual(0);
                Directory.GetDirectories(path).Length.ShouldEqual(0);
            }
        }
Exemplo n.º 34
0
        protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, int size)
        {
            var fn = Path.Combine(dir.Path, name);

            using (var fs = new FileStream(fn, FileMode.Create, FileAccess.Write))
            {
                if (size > 0)
                {
                    fs.Seek(size - 1, SeekOrigin.Begin);
                    fs.WriteByte(0);
                }
            }

            var fi = new FileInfo(fn);

            return(new FileSystemFile(dir.Session, fi.DirectoryName, fi.Name, new FSH {
                m_Info = fi
            }));
        }
Exemplo n.º 35
0
        protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, int size)
        {
            var fn = Path.Combine(dir.Path, name);
            using(var fs = new FileStream(fn, FileMode.Create, FileAccess.Write))
            {
              if (size>0)
              {
               fs.Seek(size-1, SeekOrigin.Begin);
               fs.WriteByte(0);
              }
            }

            var fi = new FileInfo(fn);
            return new FileSystemFile(dir.Session, fi.DirectoryName, fi.Name, new FSH{m_Info = fi});
        }
Exemplo n.º 36
0
        protected internal override IEnumerable<string> DoGetSubDirectoryNames(FileSystemDirectory directory, bool recursive)
        {
            SVNFileSystemSession session = directory.Session as SVNFileSystemSession;

            WebDAV.Directory wdDirectory = GetSVNItem(directory) as WebDAV.Directory;

            WebDAV.Directory pathDirectory = session.WebDAV.Root.NavigatePath(wdDirectory.Path) as WebDAV.Directory;

            if (pathDirectory == null) return null;

            return pathDirectory.Directories.Select(c => c.Name);
        }
Exemplo n.º 37
0
 protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, string localFile, bool readOnly)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 38
0
 protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, int size)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 39
0
      private static void buildDirLevel(ConfigSectionNode pNode, FileSystemDirectory directory)
      {
        const int BUFF_SIZE = 64 * 1024;

        foreach(var sdn in directory.SubDirectoryNames)
          using(var sdir = directory.GetSubDirectory(sdn))
          {
            var dnode = pNode.AddChildNode(CONFIG_DIR_SECTION);
            dnode.AddAttributeNode(CONFIG_NAME_ATTR, sdir.Name);
            buildDirLevel(dnode, sdir);
          }

        foreach(var fn in directory.FileNames.Where(fn => !string.Equals(fn, MANIFEST_FILE_NAME, StringComparison.InvariantCultureIgnoreCase)))
          using(var file = directory.GetFile(fn))
          {
            var fnode = pNode.AddChildNode(CONFIG_FILE_SECTION);
            fnode.AddAttributeNode(CONFIG_NAME_ATTR, file.Name);
          
            long size = 0;
            var csum = new Adler32();
            var buff = new byte[BUFF_SIZE];
            using(var fs = file.FileStream)
              while(true)
              {
                var read = fs.Read(buff, 0, BUFF_SIZE);
                if (read<=0) break;
                size += read;
                csum.Add(buff, 0, read); 
              }

            fnode.AddAttributeNode(CONFIG_SIZE_ATTR, size);
            fnode.AddAttributeNode(CONFIG_CSUM_ATTR, csum.Value);
          }
      
      } 
Exemplo n.º 40
0
        protected internal override IEnumerable<string> DoGetSubDirectoryNames(FileSystemDirectory directory, bool recursive)
        {
            var di = new DirectoryInfo(directory.Path);

            return  di.GetDirectories("*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
                  .Select( sdi => sdi.Name );
        }
Exemplo n.º 41
0
      protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, string localFile, bool readOnly)
      {
        var session = (GoogleDriveSession)dir.Session;
        var parent = (GoogleDriveHandle)dir.Handle;
        var client = session.Client;

        using (var stream = new FileStream(localFile, FileMode.Open, FileAccess.Read))
        {
          var handle = client.CreateFile(parent.Id, name, stream);
          return new FileSystemFile(dir.Session, dir.Path, name, handle);
        }
      }
Exemplo n.º 42
0
      protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, int size)
      {
        var parent = (GoogleDriveHandle)dir.Handle;
        var session = (GoogleDriveSession)dir.Session;

        var bytes = new byte[size];
        var stream = new MemoryStream(bytes);

        var handle = session.Client.CreateFile(parent.Id, name, stream);

        return new FileSystemFile(session, dir.Path, name, handle);
      }
Exemplo n.º 43
0
        protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, string localFile, bool readOnly)
        {
            var fn = Path.Combine(dir.Path, name);
            File.Copy(localFile, fn, true);

            var fi = new FileInfo(fn);
            fi.IsReadOnly = readOnly;
            return new FileSystemFile(dir.Session, fi.DirectoryName, fi.Name, new FSH{m_Info = fi});
        }
Exemplo n.º 44
0
 protected internal override IEnumerable<string> DoGetSubDirectoryNames(FileSystemDirectory directory, bool recursive)
 {
   var session = (GoogleDriveSession)directory.Session;
   return session.Client.GetDirectories(directory.Path, recursive);
 }
Exemplo n.º 45
0
 protected internal override IEnumerable<string> DoGetSubDirectoryNames(FileSystemDirectory directory, bool recursive)
 {
     return getSubitemNames(directory, recursive).Where(i => i.IsFolder).Select(i => i.ItemName);
 }
Exemplo n.º 46
0
        private static void WriteQarArchive(QarFile qarFile, string workingDirectory)
        {
            string outputPath = Path.Combine(workingDirectory, qarFile.Name);
            string fileSystemInputDirectory = Path.Combine(workingDirectory,
                Path.GetFileNameWithoutExtension(qarFile.Name));
            IDirectory inputDirectory = new FileSystemDirectory(fileSystemInputDirectory);

            using (FileStream output = new FileStream(outputPath, FileMode.Create))
            {
                qarFile.Write(output, inputDirectory);
            }
        }
Exemplo n.º 47
0
 private static void WriteFpkArchive(FpkFile fpkFile, string workingDirectory)
 {
     string outputPath = Path.Combine(workingDirectory, fpkFile.Name);
     string fileSystemInputDirectory = string.Format("{0}\\{1}_{2}", workingDirectory,
         Path.GetFileNameWithoutExtension(fpkFile.Name), Path.GetExtension(fpkFile.Name).Replace(".", ""));
     IDirectory inputDirectory = new FileSystemDirectory(fileSystemInputDirectory);
     using (FileStream output = new FileStream(outputPath, FileMode.Create))
     {
         fpkFile.Write(output, inputDirectory);
     }
 }
Exemplo n.º 48
0
        private IEnumerable<S3V4ListBucketItem> getSubitemNames(FileSystemDirectory directory, bool recursive, int maxKeys = 1000)
        {
            var s3session = (S3V4FileSystemSession)directory.Session;
            var handle = directory.Handle as S3V4FSH;
            string prefix = handle.Path.ToDirectoryPath().TrimStart(PATH_SEPARATOR);

            string xml = S3V4.ListBucket(handle.Path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs,
              prefix, maxKeys: maxKeys);
            S3V4ListBucketResult list = S3V4ListBucketResult.FromXML(xml);

            while (list.IsTruncated)
            {
              xml = S3V4.ListBucket(handle.Path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs,
            prefix, marker: list.Items.Last().Key, maxKeys: maxKeys);
              list.AddXML(xml);
            }

            IEnumerable<S3V4ListBucketItem> q = list.Items;

            if (!recursive)
              q = q.Where(i => !i.IsNested);

            return q.ToList();
        }
Exemplo n.º 49
0
        protected internal override IEnumerable<string> DoGetFileNames(FileSystemDirectory directory, bool recursive)
        {
            var dirPath = directory.Path;
            var di = new DirectoryInfo(dirPath);

            return  di.GetFiles("*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
                  .Select( fi => Path.GetFileName( fi.FullName ) );
        }
Exemplo n.º 50
0
        private static void ReadQarFile(string path)
        {
            string fileDirectory = Path.GetDirectoryName(path);
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
            string outputDirectoryPath = Path.Combine(fileDirectory, fileNameWithoutExtension);
            string xmlOutputPath = Path.Combine(fileDirectory,
                string.Format("{0}.xml", Path.GetFileName(path)));
            IDirectory outputDirectory = new FileSystemDirectory(outputDirectoryPath);

            using (FileStream input = new FileStream(path, FileMode.Open))
            using (FileStream xmlOutput = new FileStream(xmlOutputPath, FileMode.Create))
            {
                QarFile qarFile = QarFile.ReadQarFile(input);
                qarFile.Name = Path.GetFileName(path);
                foreach (var exportedFile in qarFile.ExportFiles(input))
                {
                    Console.WriteLine(exportedFile.FileName);
                    outputDirectory.WriteFile(exportedFile.FileName, exportedFile.DataStream);
                }
                ArchiveSerializer.Serialize(xmlOutput, qarFile);
            }
        }
Exemplo n.º 51
0
 protected internal override IEnumerable<string> DoGetFileNames(FileSystemDirectory directory, bool recursive)
 {
   var session = (GoogleDriveSession)directory.Session;
   var handle = (GoogleDriveHandle)directory.Handle;
   return session.Client.GetFiles(handle.Id, recursive).Select(f => f.Name);
 }
Exemplo n.º 52
0
 private static void WritePftxsArchive(PftxsFile pftxsFile, string workingDirectory)
 {
     string outputPath = Path.Combine(workingDirectory, pftxsFile.Name);
     string fileSystemInputDirectory = string.Format("{0}\\{1}_pftxs", workingDirectory,
         Path.GetFileNameWithoutExtension(pftxsFile.Name));
     IDirectory inputDirectory = new FileSystemDirectory(fileSystemInputDirectory);
     using (FileStream output = new FileStream(outputPath, FileMode.Create))
     {
         pftxsFile.Write(output, inputDirectory);
     }
 }
Exemplo n.º 53
0
        protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, int size)
        {
            var s3session = (S3V4FileSystemSession)dir.Session;

            var filePath = this.CombinePaths(dir.Path, name);
            var handle = new S3V4FSH(filePath);

            byte[] bytes = new byte[size];
            MemoryStream contentStream = new MemoryStream(bytes);

            S3V4.PutFile(handle.Path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, contentStream, s3session.TimeoutMs);

            return new FileSystemFile(s3session, handle.Parent, handle.Name, handle);
        }
Exemplo n.º 54
0
        protected internal override FileSystemDirectory DoCreateDirectory(FileSystemDirectory dir, string name)
        {
            var s3session = (S3V4FileSystemSession)dir.Session;
            var dirPath = this.CombinePaths(dir.Path, name);
            var handle = new S3V4FSH(dirPath);

            S3V4.PutFolder(handle.Path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs);

            return new FileSystemDirectory(s3session, handle.Parent, handle.Name, handle);
        }
Exemplo n.º 55
0
        protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, string localFile, bool readOnly)
        {
            var s3session = (S3V4FileSystemSession)dir.Session;
            var filePath = this.CombinePaths(dir.Path, name);
            var handle = new S3V4FSH(filePath);

            using(System.IO.FileStream r = new System.IO.FileStream(localFile, System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
              S3V4.PutFile(filePath, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, r, s3session.TimeoutMs);
              return new FileSystemFile(dir.Session, handle.Parent, handle.Name, handle);
            }
        }