Exemplo n.º 1
0
 /// <summary>
 /// raises the FileDeleted event.
 /// </summary>
 /// <param name="file"></param>
 protected virtual void OnFileDeleted(ArchiveFile file)
 {
     if (FileDeleted != null)
     {
         FileDeleted(this, new FileEventArgs()
         {
             File = file
         });
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// extract an archive file from the source stream.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static ArchiveFile ExtractArchive(Stream source, ArchiveFileIndex index)
        {
            // seek to the start index of the file:
            source.Seek(index.FileStartIndex, SeekOrigin.Begin);

            // read the block of data:
            byte[] archiveData = ReadBuffer(source, index.FileLength);

            // deserialize the file:
            return(ArchiveFile.FromByteArray(archiveData));
        }
Exemplo n.º 3
0
        /// <summary>
        /// adds a new file to the end of the archive.
        /// </summary>
        /// <param name="file"></param>
        public void AddFile(ArchiveFile file)
        {
            // add the specified file to this archive.
            List <ArchiveFile> fileList = new List <ArchiveFile>();

            fileList.Add(file);

            using (Stream s = GetStream())
            {
                AddData(fileList, s, _index);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// add a file from disk into the specified folder of the archive.
        /// </summary>
        /// <param name="sourceFileName">the source file path</param>
        /// <param name="destDir">the target directory in the archive.</param>
        /// <returns>the archive-file details.</returns>
        public ArchiveFile AddExistingFile(string sourceFileName, string destDir)
        {
            // create the archive file object:
            ArchiveFile file = new ArchiveFile(sourceFileName);

            // create the archive path:
            string path = destDir + "\\" + file.Name;

            // add into this
            this[path] = file;

            // return the file.
            return(file);
        }
Exemplo n.º 5
0
        /// <summary>
        /// add the archive file into the specific directory with the specific name.
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="value"></param>
        public void AddFile(String fileName, ArchiveFile value)
        {
            // extract the path and name of the file.
            string path = Path.GetDirectoryName(fileName);
            string name = Path.GetFileName(fileName);

            // the name and path and owner are modified to match:
            value.Path = path;
            value.Name = name;

            // does the path already exist?
            if (!_fileSystem.ContainsKey(path))
            {
                // create the folder:
                _fileSystem.Add(path, new List <ArchiveFile>());

                // raise the event;
                OnDirAdded(path);
            }

            // does the folder already contain the file?
            if (_fileSystem[path].Contains(value))
            {
                // yes.. get the index of the file:
                int i = _fileSystem[path].IndexOf(value);

                // set the specific index to the input value:
                _fileSystem[path][i] = value;

                // now raise the file-updated event.
                OnFileUpdated(value);
            }
            else
            {
                // add the file.
                _fileSystem[path].Add(value);

                // raise the file added event:
                OnFileAdded(value);
            }
        }
Exemplo n.º 6
0
        public static void TestOpen()
        {
            // open the existing archive file:
            StreamingArchiveFile arc = new StreamingArchiveFile(@"C:\Temp\streamingArchive.arc");

            // iterate the files in the archive:
            foreach (string fileName in arc.FileIndex.IndexedFileNames)
            {
                // write the name of the file
                Debug.Print("File: " + fileName);

                // extract the file:
                ArchiveFile file = arc.GetFile(fileName);

                // save it to disk:
                String tempFileName = Path.GetTempPath() + "\\" + file.Name;
                file.SaveAs(tempFileName);

                // open the file:
                Process.Start(tempFileName);
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// determine if the two archive files are equivalent.
 /// </summary>
 /// <param name="file"></param>
 /// <returns></returns>
 public bool Equals(ArchiveFile file)
 {
     return(file.Name == this.Name && file.Path == this.Path);
 }
Exemplo n.º 8
0
 /// <summary>
 /// determine if the two archive files are equivalent.
 /// </summary>
 /// <param name="file"></param>
 /// <returns></returns>
 public bool Equals(ArchiveFile file)
 {
     return (file.Name == this.Name && file.Path == this.Path);
 }
Exemplo n.º 9
0
        /// <summary>
        /// adds a new file to the end of the archive.
        /// </summary>
        /// <param name="file"></param>
        public void AddFile(ArchiveFile file)
        {
            // add the specified file to this archive.
            List<ArchiveFile> fileList = new List<ArchiveFile>();
            fileList.Add(file);

            using (Stream s = GetStream())
            {
                AddData(fileList, s, _index);
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// add the file using it's directory and name.
 /// </summary>
 /// <param name="value"></param>
 public void AddFile(ArchiveFile value)
 {
     AddFile(value.Path + "\\" + value.Name, value);
 }
Exemplo n.º 11
0
 /// <summary>
 /// raises the FileDeleted event.
 /// </summary>
 /// <param name="file"></param>
 protected virtual void OnFileDeleted(ArchiveFile file)
 {
     if (FileDeleted != null)
         FileDeleted(this, new FileEventArgs() { File = file });
 }
Exemplo n.º 12
0
        /// <summary>
        /// add a file from disk into the specified folder of the archive.
        /// </summary>
        /// <param name="sourceFileName">the source file path</param>
        /// <param name="destDir">the target directory in the archive.</param>
        /// <returns>the archive-file details.</returns>
        public ArchiveFile AddExistingFile(string sourceFileName, string destDir)
        {
            // create the archive file object:
            ArchiveFile file = new ArchiveFile(sourceFileName);

            // create the archive path:
            string path = destDir + "\\" + file.Name;

            // add into this
            this[path] = file;

            // return the file.
            return file;
        }
Exemplo n.º 13
0
        /// <summary>
        /// add the archive file into the specific directory with the specific name.
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="value"></param>
        public void AddFile(String fileName, ArchiveFile value)
        {
            // extract the path and name of the file.
            string path = Path.GetDirectoryName(fileName);
            string name = Path.GetFileName(fileName);

            // the name and path and owner are modified to match:
            value.Path = path;
            value.Name = name;

            // does the path already exist?
            if (!_fileSystem.ContainsKey(path))
            {
                // create the folder:
                _fileSystem.Add(path, new List<ArchiveFile>());

                // raise the event;
                OnDirAdded(path);
            }

            // does the folder already contain the file?
            if (_fileSystem[path].Contains(value))
            {
                // yes.. get the index of the file:
                int i = _fileSystem[path].IndexOf(value);

                // set the specific index to the input value:
                _fileSystem[path][i] = value;

                // now raise the file-updated event.
                OnFileUpdated(value);
            }
            else
            {
                // add the file.
                _fileSystem[path].Add(value);

                // raise the file added event:
                OnFileAdded(value);
            }
        }
Exemplo n.º 14
0
 /// <summary>
 /// add the file using it's directory and name.
 /// </summary>
 /// <param name="value"></param>
 public void AddFile(ArchiveFile value)
 {
     AddFile(value.Path + "\\" + value.Name, value);
 }