Esempio n. 1
0
        /// <summary>
        /// Copies an existing file to a new file. Notifies the application of its progress through a callback function. If the source file has verification data, the contents of the file are verified during the copy operation.
        /// </summary>
        /// <param name="sourceFile">The name of an existing .wim file.</param>
        /// <param name="destinationFile">The name of the new file.</param>
        /// <param name="options">Specifies how the file is to be copied.</param>
        /// <param name="copyFileProgressCallback">A <see cref="CopyFileProgressCallback"/> method to call when progress is made copying the file and allowing the user to cancel the operation.</param>
        /// <param name="userData">An object containing data to be used by the progress callback method.</param>
        /// <exception cref="ArgumentNullException">sourceFile or destinationFile is null.</exception>
        /// <exception cref="Win32Exception">The Windows® Imaging API reported a failure.</exception>
        public static void CopyFile(string sourceFile, string destinationFile, WimCopyFileOptions options, CopyFileProgressCallback copyFileProgressCallback, object userData)
        {
            // See if sourceFile is null
            if (sourceFile == null)
            {
                throw new ArgumentNullException(nameof(sourceFile));
            }

            // See if destinationFile is null
            if (destinationFile == null)
            {
                throw new ArgumentNullException(nameof(destinationFile));
            }

            // Create a CopyFileProgress object
            CopyFileProgress fileInfoCopyProgress = new CopyFileProgress(sourceFile, destinationFile, copyFileProgressCallback, userData);

            // Cancel flag is always false
            bool cancel = false;

            // Call the native function
            if (!WimgApi.NativeMethods.WIMCopyFile(sourceFile, destinationFile, fileInfoCopyProgress.CopyProgressHandler, IntPtr.Zero, ref cancel, (DWORD)options))
            {
                // Throw a Win32Exception based on the last error code
                throw new Win32Exception();
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Copies an existing file to a new file.
 /// </summary>
 /// <param name="sourceFile">The name of an existing .wim file.</param>
 /// <param name="destinationFile">The name of the new file.</param>
 /// <param name="options">Specifies how the file is to be copied.</param>
 /// <exception cref="ArgumentNullException">sourceFile or destinationFile is null.</exception>
 /// <exception cref="Win32Exception">The Windows® Imaging API reported a failure.</exception>
 public static void CopyFile(string sourceFile, string destinationFile, WimCopyFileOptions options)
 {
     // Call an override
     WimgApi.CopyFile(sourceFile, destinationFile, options, null, null);
 }