Exemplo n.º 1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (DestinationLocation != null)
                    {
                        DestinationLocation.Clear();
                    }
                    if (SourceLocation != null)
                    {
                        SourceLocation.Clear();
                    }
                    FileList.Clear();
                    FileList = null;
                    ArchiveMemoryStream.Dispose();
                    if (File.Exists(WorkingArchive))
                    {
                        File.Delete(WorkingArchive);
                    }
                }

                disposedValue = true;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the files in the archive with the files found in specified folder.
        /// </summary>
        /// <param name="SourceFolder">The folder specified.</param>
        public void UpdateArchive(string SourceFolder)
        {
            List <String> SourceFiles = new List <String>();

            SourceFiles = PullFiles(SourceFolder);
            foreach (string file in SourceFiles)
            {
                var entry = ArchiveMemoryStream.GetEntry(file.Replace(SourceFolder + GetFolderCharacter(), ""));
                if (entry != null)
                {
                    string originalFileHash;
                    string targetFileHash;
                    using (var algo = SHA256.Create())
                    {
                        var archivedFile          = entry.Open();
                        var targetFile            = File.OpenRead(file);
                        var originalFileSignature = algo.ComputeHash(archivedFile);
                        originalFileHash      = BitConverter.ToString(originalFileSignature);
                        originalFileSignature = algo.ComputeHash(targetFile);
                        targetFileHash        = BitConverter.ToString(originalFileSignature);
                        archivedFile.Dispose();
                        targetFile.Close();
                    }
                    if (originalFileHash != targetFileHash)
                    {
                        RemoveFileFromList(entry.FullName);
                        AddFileToList(SourceFolder, file.Replace(SourceFolder + GetFolderCharacter(), ""));
                    }
                }
                else
                {
                    AddFileToList(SourceFolder, file.Replace(SourceFolder + GetFolderCharacter(), ""));
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds files from a specific folder. The folder relative location is used to avoid messing up the folder structure.
        /// </summary>
        /// <param name="sourceLocation">The location of the source folder</param>
        /// <param name="SourceFolderRelativeLocation">The relatice location of the source folder.</param>
        public void AddFilesFromAFolder(string sourceLocation, string SourceFolderRelativeLocation)
        {
            var tempList = PullFiles(Path.Combine(sourceLocation, SourceFolderRelativeLocation));

            foreach (string fileEntry in tempList)
            {
                ArchiveMemoryStream.CreateEntryFromFile(fileEntry,
                                                        fileEntry.Replace(sourceLocation + GetFolderCharacter(), ""), CompressionLevel.NoCompression);
                FileList.Add(fileEntry.Replace(sourceLocation + GetFolderCharacter(), ""));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds files from a specific folder.
        /// </summary>
        /// <param name="source">The location of the source folder.</param>
        public void AddFilesFromAFolder(string source)
        {
            var tempList = PullFiles(source);

            foreach (string fileEntry in tempList)
            {
                ArchiveMemoryStream.CreateEntryFromFile(fileEntry,
                                                        fileEntry.Replace(source + GetFolderCharacter(), ""), CompressionLevel.NoCompression);
                FileList.Add(fileEntry.Replace(source + GetFolderCharacter(), ""));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Removes a specified file from the archive.
        /// </summary>
        /// <param name="fileLocation">The file you want to remove. This must be in a relative path. ("folder1/file.extension")</param>
        public void RemoveFileFromList(string fileLocation)
        {
            var entry = ArchiveMemoryStream.GetEntry(fileLocation);

            if (entry == null)
            {
                return;
            }
            entry.Delete();
            FileList.Remove(fileLocation);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Adds a specified file to the list. This method is better suited for preserving the folder structure.
 /// </summary>
 /// <param name="source">The base folder that holds the file.</param>
 /// <param name="fileRelativeLocation">The relative location of the file.</param>
 public void AddFileToList(string source, string fileRelativeLocation)
 {
     FileList.Add(fileRelativeLocation);
     ArchiveMemoryStream.CreateEntryFromFile(Path.Combine(source, fileRelativeLocation), fileRelativeLocation, CompressionLevel.NoCompression);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Adds a specified file to the list. This method only works if the file is in the source folder.
 /// </summary>
 /// <param name="fileLocation">The location of the file.</param>
 public void AddFileToList(string fileLocation)
 {
     FileList.Add(fileLocation.Replace(SourceLocation + GetFolderCharacter(), ""));
     ArchiveMemoryStream.CreateEntryFromFile(fileLocation, fileLocation.Replace(SourceLocation + GetFolderCharacter(), ""), CompressionLevel.NoCompression);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Extracts a specified file to a location specified.
        /// </summary>
        /// <param name="entry">The file you want to extract. This must be in a relative path. ("folder1\\file.extension")</param>
        /// <param name="exportLocation">The location where the file will be extracted to.</param>
        public void ExtractFile(string entry, string exportLocation)
        {
            var candidateFile = ArchiveMemoryStream.GetEntry(entry);

            candidateFile.ExtractToFile(exportLocation, true);
        }
 /// <summary>
 /// Closes the archive.
 /// </summary>
 public void CloseArchive()
 {
     ArchiveMemoryStream.Dispose();
     EncryptedPackageUtilities.CompressArchive(WorkingArchive, DestinationLocation.ToString(), Password);
 }