Example #1
0
 public bool AssociateContainerWithExistingFiles(string password, GetExistingFileContentIdDelegate getExistingFileContentId)
 {
     throw new NotImplementedException();
 }
Example #2
0
		// We don't actually support RAR's in protect so not worth implementing this
		public Collection<IContainer> AssociateContainerWithExistingFiles(FileData fileData, string password, GetExistingFileContentIdDelegate getExistingFileContentId)
		{
			throw new NotImplementedException();
		}
Example #3
0
		public bool AssociateContainerWithExistingFiles(string password, GetExistingFileContentIdDelegate getExistingFileContentId)
		{
			return m_impl.AssociateContainerWithExistingFiles(password, getExistingFileContentId);
		}
Example #4
0
		public virtual bool AssociateContainerWithExistingFiles(string sPassword, GetExistingFileContentIdDelegate GetExistingFileContentId)
		{
			// Not a container, do nothing
			return false;
		}
Example #5
0
		// This function virtually expands the representation of a newly created zip
		// with file content already existing on disk. This is especially for the case
		// where the Zip Action creates zips for each document, but the zip IFile is not
		// in the expanded state. This method associates the zip with it's files.
		public Collection<IContainer> AssociateContainerWithExistingFiles(FileData fileData, string password, GetExistingFileContentIdDelegate getExistingFileContentId)
		{
			try
			{
				fileData.Password = password;
				// Setting the status back to false. Next call may be with correct password.
				fileData.FileEncrypted = false;
				fileData.ReadPasswordProtected = false;

				// For this association operation to succeed the zip file should already exist.
				if (!System.IO.File.Exists(fileData.Filename))
				{
					throw new FileNotFoundException( "The zip should already exist.", fileData.Filename);
				}

				Collection<IContainer> fileList = new Collection<IContainer>();

				Logger.LogDebug(string.Format("Opening zip file \"{0}\".", fileData.Filename));
				using (ZipOpener zo = new ZipOpener(fileData.Filename, password))
				{
					ZipWrapper zip = zo.Zip;

					// For each entry in the zip, ask the GetExistingFileContentId delegate for the existing file's content ID.
					for (int index = 0; index < zip.NumEntries; ++index)
					{
						Logger.LogDebug(string.Format("Zip entry {0}.", index));
						
						using (Chilkat.ZipEntry zipEntry = zip.GetEntryByIndex(index))
						{
							if (zipEntry == null)
							{
								Logger.LogDebug("Zip entry is null.");
								break;
							}

							// Try to get file path and content ID.
							string contentId, filePath;
							if (!getExistingFileContentId(zipEntry.FileName, out contentId, out filePath))
							{
								throw new KeyNotFoundException(string.Format("Couldn't find the content item relating to the file \"{0}\".", zipEntry.FileName));
							}

							Logger.LogDebug(string.Format("Adding file \"{0}\".", filePath));
							IFile file = new File(filePath, zipEntry.FileName, contentId);
							fileList.Add(file);
						}
					}
				}

				Logger.LogDebug("Completed zip container to existing files association.");
				return fileList;
			}
			catch (Exception ex)
			{
				Logger.LogError(ex);
				fileData.FileEncrypted = true;
				fileData.ReadPasswordProtected = true;
				return null;
			}
		}
		// This function virtually expands the representation of a newly created zip
		// with file content already existing on disk. This is especially for the case
		// where the Zip Action creates zips for each document, but the zip IFile is not
		// in the expanded state. This method associates the zip with it's files.
		public override bool AssociateContainerWithExistingFiles(string password, GetExistingFileContentIdDelegate getExistingFileContentId)
		{
			if (IsExpanded)
			{
				Logger.LogInfo("Container is already expanded.");
				return true;
			}

			m_fileList = new ObservableCollection<IContainer>();

			Collection<IContainer> unpackedFiles = m_decompressor.AssociateContainerWithExistingFiles(m_fileData, password, getExistingFileContentId);
			if (unpackedFiles == null)
			{
				Logger.LogError("Failed to associate the container with existing files.");
				return false;
			}
			
			Logger.LogInfo("Succeeded in associating the container with existing files.");
			foreach (IFile file in unpackedFiles)
			{
				Logger.LogDebug(string.Format("Adding file \"{0}\" to container.", file.FileName));
				Add(file);
			}
			
			Logger.LogDebug("Completed associating the container with existing files.");
			m_expanded = true;
			return true;
		}